]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
added exec unit test to core tests, exec now uses a track event
authorScottDowne <sdowne@learn.senecac.on.ca>
Wed, 23 Feb 2011 18:05:51 +0000 (13:05 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Wed, 23 Feb 2011 18:05:51 +0000 (13:05 -0500)
popcorn.js
test/popcorn.unit.js

index 16deb0a709d4c380f284a7c15c60a9d25151758e..01ae29b4855e8bb8bf1bfcd8cd2813f744364d98 100644 (file)
     },
     
     exec: function ( time, fn ) {
-      
-      !fn && ( fn = Popcorn.nop );
-      
-      var self = this, 
-          guid = Popcorn.guid( "execCallback" ), 
-          callback = function execCallback( event ) {
 
-            if ( Math.round( this.currentTime() ) === time && !callback.fired ) {
-            
-              callback.fired = true;
-              
-              fn.call(self, event);
-              
-              //  Enforce a once per second execution
-              setTimeout(function() {
-                
-                callback.fired = false;
-                
-              }, 1000 );
-            }
-          };
-      
-      callback.fired = false;
-      callback.name = guid;
-      
-      this.listen("timeupdate", callback);
+      // creating a one second track event with an empty end
+      Popcorn.addTrackEvent( this, {
+        start: time,
+        end: time + 1,
+        _running: false,
+        _natives: {
+          start: fn,
+          type: "exec"
+        }
+      });
       
       return this;
     }
   
   
   Popcorn.addTrackEvent = function( obj, track ) {
-  
+
     if ( track._natives ) {
       // supports user defined track event id
       track._id = !track.id ? Popcorn.guid( track._natives.type ) : track.id;
index 1652bb03f94bce924d7ab4ff4ffda107f510a177..62230471ddce9dbffc0b326ebc7fe456f4262c2b 100644 (file)
@@ -179,22 +179,25 @@ test("exec", function () {
       hasLooped = false, 
       loop = 0;
 
-  expect(expects);
+  expect( expects + 1 );
   
   function plus(){ 
     if ( ++count == expects ) {
       
-      popped.unlisten( "timeupdate", "execCallback" );
-     
-    
-      start(); 
+      setTimeout( function() {
+
+        equals( loop, expects, "exec callback repeat check, only called twice" );
+        Popcorn.removePlugin( popped, "exec" );
+        start(); 
+
+      }, 1000 );
     }
   }
   
   stop( 10000 ); 
 
   popped.exec( 4, function () {
-    ok(true, "exec callback fired " + loop++ );
+    ok( loop < 2, "exec callback fired " + ++loop );
     plus();
 
     if ( !hasLooped ) {