]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Fixed merge conflict
authorDavid Seifried <david.c.seifried@gmail.com>
Thu, 22 Sep 2011 15:15:29 +0000 (11:15 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Thu, 22 Sep 2011 15:15:29 +0000 (11:15 -0400)
1  2 
popcorn.js
test/popcorn.unit.js

diff --cc popcorn.js
index d50a864fefd5ede9d2142d0d83a354cd3b266eb5,16f3e7570c8b09f55ff9d928535fa4df8ddb4433..2baf6a9f15e5d6c444f1d571bfd3df7e52196712
  
          registryByName = Popcorn.registryByName,
  
-         byEnd, byStart, natives, type;
+         byEnd, byStart, byAnimate, natives, type;
  
      //  Playbar advancing
 -    if ( previousTime < currentTime ) {
 +    if ( previousTime <= currentTime ) {
  
        while ( tracks.byEnd[ end ] && tracks.byEnd[ end ].end <= currentTime ) {
  
index f5928ca3726052a71dc1266bc0090fa7de5f8081,1981ea529cadf2bda3fe06f43b23b5a525d7eb42..b41398aaadfbd55c4ad0ec4797064a56b7435a8d
@@@ -49,10 -41,10 +41,10 @@@ test("API", function() 
  
  });
  
- 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);
@@@ -1647,58 -1626,176 +1626,227 @@@ test("Update Timer (timeupdate)", funct
  
  });
  
+ 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();
  
@@@ -2626,17 -2719,82 +2772,82 @@@ test("Index Integrity (timeupdate)", fu
  
    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 ) {