]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
merge branch 'annasob/0.5' into plugin-inheritance
authorDaniel Brooks <db48x@db48x.net>
Tue, 29 Mar 2011 12:28:53 +0000 (07:28 -0500)
committerDaniel Brooks <db48x@db48x.net>
Tue, 29 Mar 2011 12:28:53 +0000 (07:28 -0500)
1  2 
popcorn.js
test/popcorn.unit.js

diff --cc popcorn.js
index 51cda50c3b596f1053b41faf9e8d153eb21b4c42,73df0f7dfdd37ed90ab9ae7b5f0d1278cf89ac99..763bebf905bdea96a928fe6b69cb02bf07bf2110
      Popcorn.extend( Popcorn.p, plugin );
  
      //  Push into the registry
 -    Popcorn.registry.push(
 -      Popcorn.extend( plugin, {
 -        type: name
 -      })
 -     );
 +    var entry = {
 +      function: plugin[ name ],
 +      definition: definition,
 +      base_definition: definition,
 +      parents: [],
 +      name: name
 +    };
 +    Popcorn.registry.push( entry );
 +    Popcorn.registryHash[ name ] = entry;
+ 
      return plugin;
    };
  
index 482ca888cc250603933b4cbf7287fe28b86e1f90,0f63263743651292588a665be32a77b67b44e9e3..4054d397ded74273d291a194d3bb727e89af6f1f
mode 100644,100755..100644
@@@ -671,15 -673,15 +673,15 @@@ test("Update Timer", function () 
  });
  
  test("Plugin Factory", function () {
-   
+ 
    QUnit.reset();
  
-   var popped = Popcorn("#video"), 
+   var popped = Popcorn("#video"),
        methods = "load play pause currentTime mute volume roundTime exec removePlugin",
 -      expects = 34,
 -      count = 0;
 +      expects = 80, // 15*2+16*2+6+12. executor/complicator each do 15
 +      count = 0;    
  
-   function plus() { 
+   function plus() {
      if ( ++count == expects ) {
        Popcorn.removePlugin("executor");
        Popcorn.removePlugin("complicator");
    }
  
    expect( expects );
 -  stop( 10000 );
 +  stop( 15000 );
  
    Popcorn.plugin("executor", function () {
-     
+ 
      return {
-       
+ 
        start: function () {
          var self = this;
  
      };
  
    });
-  
+ 
 +  Popcorn.pluginInherit("executor_inherits", "executor", function (options) {
 +    return {
 +      start: function() { ok(true, "child class method executed"); plus(); }
 +    };
 +  });
 +
    ok( "executor" in popped, "executor plugin is now available to instance" );
    plus();
 -  equals( Popcorn.registry.length, 1, "One item in the registry");
 +  ok( "executor_inherits" in popped, "executor-inerits plugin is now available to instance" );
 +  plus();
 +  equals( Popcorn.registry.length, 2, "One item in the registry");
    plus();
 -
 -
  
    popped.executor({
-     start: 1, 
+     start: 1,
      end: 2
    });
 +  popped.executor_inherits({
 +    start: 2, 
 +    end: 3
 +  });
  
    Popcorn.plugin("complicator", {
-     
+ 
      start: function ( event ) {
  
        var self = this;
  
        ok( "trackEvents" in this.data, " complicatorinstance has `trackEvents` property" );
        plus();
-       ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" )      
-       plus();     
+       ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" )
+       plus();
      },
      end: function () {
-     
+ 
        //start();
-     
-     }, 
+ 
+     },
      timeupdate: function () {
-     }    
+     }
    });
  
 +  Popcorn.pluginInherit("complicator_inherits", "executor", {
 +    start: function() { ok(true, "child class method executed"); plus(); }
 +  });
 +
    ok( "complicator" in popped, "complicator plugin is now available to instance" );
    plus();
 -  equals( Popcorn.registry.length, 2, "Two items in the registry");
 +  ok( "complicator_inherits" in popped, "complicator plugin is now available to instance" );
 +  plus();
 +  equals( Popcorn.registry.length, 4, "Two items in the registry");
    plus();
-   
+ 
    popped.complicator({
 -    start: 3,
 -    end: 4
 +    start: 4, 
 +    end: 5
 +  }); 
 +  popped.complicator_inherits({
 +    start: 5, 
 +    end: 6
 +  }); 
 +
 +  var counts = { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
 +  Popcorn.plugin("A", function(options) {
 +    return { start: function() { counts.a++; } };
 +  });
 +  Popcorn.plugin("B", function(options) {
 +    return { start: function() { counts.b++; } };
    });
 +  Popcorn.pluginInherit("C", "B", function(options) {
 +    return { start: function() { counts.c++; } };
 +  });
 +  Popcorn.pluginInherit("D", ["A", "B"], function(options) {
 +    return { start: function() { counts.d++; } };
 +  });
 +  Popcorn.pluginInherit("E", ["B"], function(options) {
 +    return { start: function() { counts.e++; } };
 +  });
 +  Popcorn.pluginInherit("F", ["E", "C"], function(options) {
 +    return { start: function() { counts.f++; } };
 +  });
 +
 +  equals(counts.a, 0, "plugin A should not have been run yet");
 +  plus();
 +  equals(counts.b, 0, "plugin B should not have been run yet");
 +  plus();
 +  equals(counts.c, 0, "plugin C should not have been run yet");
 +  plus();
 +  equals(counts.d, 0, "plugin D should not have been run yet");
 +  plus();
 +  equals(counts.e, 0, "plugin E should not have been run yet");
 +  plus();
 +  equals(counts.f, 0, "plugin F should not have been run yet");
 +  plus();
 +
 +  popped.C({ start: 6, end: 7 });
 +  popped.D({ start: 7, end: 8 });
 +  popped.F({ start: 8, end: 9 });
 +
 +  setTimeout(function() {
 +    equals(counts.a, 1, "plugin A should have been run once");
 +    plus();
 +    equals(counts.b, 3, "plugin B should have been run thrice");
 +    plus();
 +    equals(counts.c, 2, "plugin C should have been run twice");
 +    plus();
 +    equals(counts.d, 1, "plugin D should have been run once");
 +    plus();    
 +    equals(counts.e, 1, "plugin E should have been run once");
 +    plus();    
 +    equals(counts.f, 1, "plugin F should have been run once");
 +    plus();    
 +  }, 10000);
  
    popped.currentTime(0).play();