Permalink
Browse files

[#1180] tracksetup and trackteardown events and tests.

  • Loading branch information...
1 parent f38088a commit 157c116f12136b2ad6268ec745b1608c598d80ef @ScottDowne ScottDowne committed Jul 30, 2012
Showing with 76 additions and 9 deletions.
  1. +17 −1 popcorn.js
  2. +59 −8 test/popcorn.unit.js
View
@@ -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 );
@@ -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( " " ) || [];
View
@@ -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 ) {
@@ -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 ) {
@@ -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" ),

0 comments on commit 157c116

Please sign in to comment.