From dd46e2019d2f5b86eba7919246b19aad419ac5a6 Mon Sep 17 00:00:00 2001 From: David Seifried Date: Wed, 7 Sep 2011 12:58:27 -0400 Subject: [PATCH] Added tests for timeUpdate function and fixed other unit tests because of timing issues when trackEvents are added and timeUpdate is fired now --- popcorn.js | 2 +- test/popcorn.unit.js | 67 ++++++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/popcorn.js b/popcorn.js index 9f6b091..87aeeb3 100644 --- a/popcorn.js +++ b/popcorn.js @@ -410,7 +410,7 @@ // Creating a one second track event with an empty end Popcorn.addTrackEvent( this, { - start: time, + start: time + 0.25, end: time + 1, _running: false, _natives: { diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index e618179..a6ca948 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -2538,30 +2538,6 @@ test("getTrackEvent", function () { }); -test("timeUpdate functionality", function() { - - var $pop = Popcorn( "#video" ), - count = 0, - expects = 5; - - expect( expects ); - - function plus() { - if ( ++count === expects ) { - start(); - - Popcorn.removeInstance( $pop ); - } - } - - Popcorn.plugin("timeUpdateTester", function() { - return { - start: function(){}, - end: function(){} - }; - }); -}); - test("Index Integrity", function () { @@ -2649,6 +2625,49 @@ test("Index Integrity", function () { }); +test("timeUpdate functionality", function() { + + var $pop = Popcorn( "#video" ), + count = 0, + expects = 4; + + expect( expects ); + + Popcorn.plugin("timeUpdateTester", function() { + return { + start: function () { + var div = document.createElement("div"); + div.id = "timeUpdate-test"; + + document.body.appendChild(div); + }, + end: function () { + document.getElementById("timeUpdate-test").parentNode.removeChild(document.getElementById("timeUpdate-test")); + } + }; + }); + + equals( typeof Popcorn.timeUpdate, "function", "timeUpdate is a function of Popcorn" ); + + $pop.currentTime(40).pause(); + + equals( $pop.getTrackEvents().length, 0, "Initially no trackEvents" ); + + $pop.timeUpdateTester({ + id:"timeUpdateID", + start:40, + end: 41 + }); + + equals( $pop.getTrackEvents().length, 1, "trackEvent successfully added" ); + + ok( document.getElementById( "timeUpdate-test" ), "trackEvent successfully added, content was displayed while video was paused" ); + + $pop.removeTrackEvent( "timeUpdateID" ); + Popcorn.removeInstance( $pop ); + +}); + test("Popcorn.disable/enable/toggle", function() { -- 2.43.0