Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Updated Teardown functionality to run _end on track events that are r…
Browse files Browse the repository at this point in the history
…unning [#704]
  • Loading branch information
Christopher De Cairos committed Nov 1, 2011
2 parents c0b6ddc + 050ec17 commit a5d5db2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,16 @@
natives.start = natives.start || natives[ "in" ];
natives.end = natives.end || natives[ "out" ];

// extend teardown to always call end if running
natives._teardown = combineFn (function() {

// end function signature is not the same as teardown,
// put null on the front of arguments for the event parameter
Array.prototype.unshift.call( arguments, null );
// only call end if event is running
arguments[ 1 ]._running && natives.end.apply( this, arguments );
}, natives._teardown );

// Check for previously set default options
defaults = this.options.defaults && this.options.defaults[ options._natives && options._natives.type ];

Expand Down
52 changes: 52 additions & 0 deletions test/popcorn.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,58 @@ test( "Popcorn Compose", function() {
popped.currentTime( 0 ).play();
});

test( "Teardown end tester", function() {

QUnit.reset();

var popped = Popcorn( "#video" ),
expects = 4,
count = 0;

function plus() {
if ( ++count === expects ) {
Popcorn.removePlugin( "teardownEndTester" );
start();
}
}

expect( expects );
stop( 15000 );

Popcorn.plugin( "teardownEndTester", {
_setup: function( options ) {
options.endCalled = false;
options.teardownCalled = false;
},
start: function( event, options ) {
},
end: function( event, options ) {
// passes if end is called before teardown, and only called once
equal( options.endCalled, false, "ensure only teardown can call this end" );
plus();
equal( options.teardownCalled, false, "ensure teardown is not yet called" );
plus();
options.endCalled = true;
},
_teardown: function( options ) {

// passes if teardown is called after end, and only called once
equal( options.endCalled, true, "ensure end was previously called" );
plus();
equal( options.teardownCalled, false, "ensure teardown is not yet called" );
plus();
options.teardownCalled = true;
}
});

// start and end times to deault to entire video,
// to ensure the end function will never be called outside of _teardown
popped.teardownEndTester({});

popped.currentTime( 0 ).play();
popped.removePlugin( "teardownEndTester" );
});

test( "Plugin Breaker", function() {

QUnit.reset();
Expand Down

0 comments on commit a5d5db2

Please sign in to comment.