Skip to content

Commit

Permalink
[#1180] tracksetup and trackteardown events and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottDowne committed Sep 17, 2012
1 parent f38088a commit 157c116
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
18 changes: 17 additions & 1 deletion popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,14 @@
obj.data.history.push( track._id );

// Trigger _setup method if exists
track._natives._setup && track._natives._setup.call( obj, track );
if ( track._natives._setup ) {

track._natives._setup.call( obj, track );
obj.emit( "tracksetup", Popcorn.extend( {}, track, {
plugin: track._natives.type,
type: "tracksetup"
}));
}
}

track.start = Popcorn.util.toSeconds( track.start, obj.options.framerate );
Expand Down Expand Up @@ -1615,6 +1622,15 @@
natives.end.apply( this, args );
}, natives._teardown );

// extend teardown to always trigger trackteardown after teardown
natives._teardown = combineFn( natives._teardown, function() {

this.emit( "trackteardown", Popcorn.extend( {}, options, {
plugin: name,
type: "trackteardown"
}));
});

// default to an empty string if no effect exists
// split string into an array of effects
options.compose = options.compose && options.compose.split( " " ) || [];
Expand Down
67 changes: 59 additions & 8 deletions test/popcorn.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2232,10 +2232,10 @@ asyncTest( "Special track event listeners: trackadded", 3, function() {
var $pop = Popcorn( "#video" );

Popcorn.plugin( "trackaddedplugin", {
_setup: function(){},
_teardown: function() {},
start: function() {},
end: function() {}
_setup: Popcorn.nop,
_teardown: Popcorn.nop,
start: Popcorn.nop,
end: Popcorn.nop
});

$pop.on( "trackadded", function( e ) {
Expand All @@ -2252,16 +2252,40 @@ asyncTest( "Special track event listeners: trackadded", 3, function() {
$pop.trackaddedplugin({});
});

test( "Special track event listeners: tracksetup", 3, function() {

var $pop = Popcorn( "#video" );

Popcorn.plugin( "tracksetupplugin", {
_setup: Popcorn.nop,
_teardown: Popcorn.nop,
start: Popcorn.nop,
end: Popcorn.nop
});

$pop.on( "tracksetup", function( e ) {

ok( true, "tracksetup event fired" );
equal( e.type, "tracksetup", "event is of correct type" );
equal( e.plugin, "tracksetupplugin", "plugin is of correct type" );
});

$pop.tracksetupplugin({});

Popcorn.removePlugin( "tracksetupplugin" );
$pop.destroy();
});

asyncTest( "Special track event listeners: trackremoved", 3, function() {

var $pop = Popcorn( "#video" ),
pluginId = "trackremovedplugin";

Popcorn.plugin( "trackremovedplugin", {
_setup: function(){},
_teardown: function() {},
start: function() {},
end: function() {}
_setup: Popcorn.nop,
_teardown: Popcorn.nop,
start: Popcorn.nop,
end: Popcorn.nop
});

$pop.on( "trackremoved", function( e ) {
Expand All @@ -2279,6 +2303,33 @@ asyncTest( "Special track event listeners: trackremoved", 3, function() {
$pop.removeTrackEvent( pluginId );
});


test( "Special track event listeners: trackteardown", 3, function() {

var $pop = Popcorn( "#video" ),
pluginId = "trackteardownplugin";

Popcorn.plugin( "trackteardownplugin", {
_setup: Popcorn.nop,
_teardown: Popcorn.nop,
start: Popcorn.nop,
end: Popcorn.nop
});

$pop.on( "trackteardown", function( e ) {

ok( true, "trackteardown event fired" );
equal( e.type, "trackteardown", "event is of correct type" );
equal( e.plugin, "trackteardownplugin", "plugin is of correct type" );
});

$pop.trackteardownplugin( pluginId, {} );
$pop.removeTrackEvent( pluginId );

Popcorn.removePlugin( "trackteardownplugin" );
$pop.destroy();
});

asyncTest( "Special track event listeners: trackstart, trackend", function() {

var $pop = Popcorn( "#video" ),
Expand Down

0 comments on commit 157c116

Please sign in to comment.