From: ScottDowne Date: Wed, 23 Feb 2011 18:05:51 +0000 (-0500) Subject: added exec unit test to core tests, exec now uses a track event X-Git-Tag: v0.4~31^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ac006ae5b9db634b270d2885b5fe5b39d348f1ce;p=popcorn-js.git added exec unit test to core tests, exec now uses a track event --- diff --git a/popcorn.js b/popcorn.js index 16deb0a..01ae29b 100644 --- a/popcorn.js +++ b/popcorn.js @@ -327,32 +327,17 @@ }, 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; } @@ -492,7 +477,7 @@ 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; diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 1652bb0..6223047 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -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 ) {