});
- test("Popcorn.* Static Methods", function () {
+ test("Popcorn.* Static Methods", function() {
var statics = [ "forEach", "extend", "error", "guid", "sizeOf", "nop",
- "addTrackEvent", "removeTrackEvent", "getTrackEvents", "getTrackEvent", "position", "disable", "enable" ],
+ "addTrackEvent", "removeTrackEvent", "getTrackEvents", "getTrackEvent", "position", "disable", "enable", "timeUpdate" ],
substatics = [ "addTrackEvent", "removeTrackEvent", "getTrackEvents", "getTrackEvent"];
expect(statics.length + substatics.length);
});
+ test("Update Timer (frameAnimation)", function() {
-test("Plugin Factory", function() {
+ QUnit.reset();
+
+ var p2 = Popcorn("#video", { frameAnimation: true }),
+ expects = 12,
+ count = 0,
+ execCount = 0,
+ // These make sure events are only fired once
+ // any second call will produce a failed test
+ forwardStart = false,
+ forwardEnd = false,
+ backwardStart = false,
+ backwardEnd = false,
+ wrapperRunning = { one: false, two: false, };
+
+ function plus() {
+ if ( ++count === expects ) {
+ // clean up added events after tests
+ Popcorn.removePlugin( "forwards" );
+ Popcorn.removePlugin( "backwards" );
+ Popcorn.removePlugin( "wrapper" );
+ p2.removePlugin( "exec" );
+ start();
+ }
+ }
+
+ // These tests come close to 10 seconds on chrome, increasing to 15
+ stop( 15000 );
+
+ Popcorn.plugin( "forwards", function() {
+ return {
+ start: function( event, options ) {
+
+ if ( !options.startFired ) {
+
+ options.startFired = true;
+ forwardStart = !forwardStart;
+ ok( forwardStart, "forward's start fired" );
+ plus();
+ }
+ },
+ end: function( event, options ) {
+
+ if ( !options.endFired ) {
+
+ options.endFired = true;
+ forwardEnd = !forwardEnd;
+ p2.currentTime(1).play();
+ ok( forwardEnd, "forward's end fired" );
+ plus();
+ }
+ }
+ };
+ });
+
+ p2.forwards({
+ start: 3,
+ end: 4
+ });
+
+ Popcorn.plugin( "backwards", function() {
+ return {
+ start: function( event, options ) {
+
+ if ( !options.startFired ) {
+
+ options.startFired = true;
+ backwardStart = !backwardStart;
+ p2.currentTime(0).play();
+ ok( true, "backward's start fired" );
+ plus();
+ }
+ },
+ end: function( event, options ) {
+
+ if ( !options.endFired ) {
+
+ options.endFired = true;
+ backwardEnd = !backwardEnd;
+ ok( backwardEnd, "backward's end fired" );
+ plus();
+ p2.currentTime( 5 ).play();
+ }
+ }
+ };
+ });
+
+ p2.backwards({
+ start: 1,
+ end: 2
+ });
+
+ Popcorn.plugin( "wrapper", {
+ start: function( event, options ) {
+
+ wrapperRunning[ options.wrapper ] = true;
+ },
+ end: function( event, options ) {
+
+ wrapperRunning[ options.wrapper ] = false;
+ }
+ });
+
+ // second instance of wrapper is wrapping the first
+ p2.wrapper({
+ start: 6,
+ end: 7,
+ wrapper: "one"
+ })
+ .wrapper({
+ start: 5,
+ end: 8,
+ wrapper: "two"
+ })
+ // checking wrapper 2's start
+ .exec( 5, function() {
+
+ if ( execCount === 0 ) {
+
+ execCount++;
+ ok( wrapperRunning.two, "wrapper two is running at second 5" );
+ plus();
+ ok( !wrapperRunning.one, "wrapper one is stopped at second 5" );
+ plus();
+ }
+ })
+ // checking wrapper 1's start
+ .exec( 6, function() {
+
+ if ( execCount === 1 ) {
+
+ execCount++;
+ ok( wrapperRunning.two, "wrapper two is running at second 6" );
+ plus();
+ ok( wrapperRunning.one, "wrapper one is running at second 6" );
+ plus();
+ }
+ })
+ // checking wrapper 1's end
+ .exec( 7, function() {
+
+ if ( execCount === 2 ) {
+
+ execCount++;
+ ok( wrapperRunning.two, "wrapper two is running at second 7" );
+ plus();
+ ok( !wrapperRunning.one, "wrapper one is stopped at second 7" );
+ plus();
+ }
+ })
+ // checking wrapper 2's end
+ .exec( 8, function() {
+
+ if ( execCount === 3 ) {
+
+ execCount++;
+ ok( !wrapperRunning.two, "wrapper two is stopped at second 9" );
+ plus();
+ ok( !wrapperRunning.one, "wrapper one is stopped at second 9" );
+ plus();
+ }
+ });
+
+ p2.currentTime(3).play();
+
+ });
+
+
++<<<<<<< HEAD
+test("timeUpdate add track event while paused", function() {
+
+ var $pop = Popcorn( "#video" ),
+ count = 0,
+ expects = 3;
+
+ expect( expects );
+
+ function plus() {
+ if ( ++count === expects ) {
+ Popcorn.removePlugin( "timeUpdateTester" );
+ Popcorn.removeInstance( $pop );
+ }
+ }
+
+ 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"));
+ }
+ };
+ });
+
+ $pop.currentTime(40).pause();
+
+ equals( $pop.getTrackEvents().length, 0, "Initially no trackEvents" );
+ plus();
+
+ $pop.timeUpdateTester({
+ id:"timeUpdateID",
+ start:40,
+ end: 41
+ });
+
+ equals( $pop.getTrackEvents().length, 1, "trackEvent successfully added" );
+ plus();
+
+ ok( document.getElementById( "timeUpdate-test" ), "trackEvent successfully added, content was displayed while video was paused" );
+ plus();
+
+ $pop.removeTrackEvent( "timeUpdateID" );
+
+});
+
+test("Plugin Factory", function () {
QUnit.reset();
stop( 10000 );
- equals(p.data.trackEvents.endIndex, 0, "p.data.trackEvents.endIndex is 0");
- equals(p.data.trackEvents.startIndex, 0, "p.data.trackEvents.startIndex is 0");
+ equals(p.data.trackEvents.endIndex, 1, "p.data.trackEvents.endIndex is 1");
+ equals(p.data.trackEvents.startIndex, 1, "p.data.trackEvents.startIndex is 1");
equals(p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart.length is 3 - before play" );
+ p.listen("timeupdate", function() {
+
+ if ( p.roundTime() > 40 && p.roundTime() < 42 && hasrun && !lastrun ) {
+
+ lastrun = true;
+
+ equals( document.getElementById("index-test"), null, "document.getElementById('index-test') is null on second run - after removeTrackEvent" );
+ start();
+ }
+
+ if ( p.roundTime() >= 42 && !hasrun ) {
+
+ hasrun = true;
+ p.pause();
+ equals(p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart.length is 3 - after play, before removeTrackEvent" );
+ equals(p.data.trackEvents.startIndex, 2, "p.data.trackEvents.startIndex is 2 - after play, before removeTrackEvent");
+ equals(p.data.trackEvents.endIndex, 2, "p.data.trackEvents.endIndex is 2 - after play, before removeTrackEvent");
+
+ p.removeTrackEvent("removeable-track-event");
+
+ equals(p.data.trackEvents.byStart.length, 2, "p.data.trackEvents.byStart.length is 2 - after removeTrackEvent" );
+ equals(p.data.trackEvents.startIndex, 1, "p.data.trackEvents.startIndex is 1 - after removeTrackEvent");
+ equals(p.data.trackEvents.endIndex, 1, "p.data.trackEvents.endIndex is 1 - after removeTrackEvent");
- p.listen("timeupdate", function () {
+ p.currentTime(40).play();
- if ( p.roundTime() > 40 && p.roundTime() < 42 && !hasrun ) {
}
+ });
+
+ p.play();
+ });
+
+ test("Index Integrity (frameAnimation)", function() {
+
+ var trackLen,
+ hasrun = false,
+ lastrun = false;
+
+ Popcorn.plugin("ff", function() {
+ return {
+ start: function() {
+ var div = document.createElement("div");
+ div.id = "index-test";
+ div.innerHTML = "foo";
+
+ document.body.appendChild(div);
+ },
+ end: function() {
+ document.getElementById("index-test").parentNode.removeChild(document.getElementById("index-test"));
+ }
+ };
+ });
+
+ var p = Popcorn("#video", { frameAnimation: true });
+
+ p.ff({
+ id: "removeable-track-event",
+ start: 40,
+ end: 41
+ });
+
+ p.currentTime(40).pause();
+
+ stop( 10000 );
+
+ equals(p.data.trackEvents.endIndex, 0, "p.data.trackEvents.endIndex is 0");
+ equals(p.data.trackEvents.startIndex, 0, "p.data.trackEvents.startIndex is 0");
+ equals(p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart.length is 3 - before play" );
+
+ p.listen("timeupdate", function() {
if ( p.roundTime() > 40 && p.roundTime() < 42 && hasrun && !lastrun ) {