]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
added unit tests to check plugin scope
authorrwldrn <waldron.rick@gmail.com>
Fri, 3 Dec 2010 23:38:07 +0000 (18:38 -0500)
committerrwldrn <waldron.rick@gmail.com>
Fri, 3 Dec 2010 23:38:07 +0000 (18:38 -0500)
popcorn-api-draft.js
test/popcorn-api-draft-unit.js

index 9876d387416ac7551c92ca034ee2f0fb9fa9647d..1c506c002c4364a39d540e618002cde201bee4f1 100644 (file)
@@ -41,8 +41,8 @@
       this.video = elem ? elem : null;
       
       this.data = {
-        events:    {},
-        timelines: []
+        events: {},
+        tracks: []
       };
       
       return this;
           this.data.events[type] = {};
         }
         
-        //  setup for custom event system
+        //  Register 
         this.data.events[type][ fn.toString() + Popcorn.guid() ] = fn;
         
         if ( Popcorn.events.all.indexOf( type ) > -1 ) {
     Popcorn.p[key] = Popcorn.events.fn[key];
   });  
   
+  //  Plugins are registered 
+  Popcorn.registry  = [];
   //  An interface for extending Popcorn 
   //  with plugin functionality
   Popcorn.plugin = function( name, definition ) {
     Popcorn.extend( Popcorn.p, plugin );
     
     
-    
-    
-    
+    if ( Popcorn.registry ) {
+      Popcorn.registry.push({ 
+        name: name,
+        plugin: plugin
+      });
+    }
     
     //  within the context of a plugin, the `timeupdate` or any of the events can be listened to 
-
   };
+  
 
   global.Popcorn = Popcorn;
   
index 6d205fb8e718c0a75b852493b6fc047b4439a92e..e18d2f04fc1e4252153e378d04d49b0ae5206522 100644 (file)
@@ -71,38 +71,57 @@ test("Popcorn Object", function () {
   ok( "data" in popped, "instance has `data` property" );
   ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
 
-  ok( "timelines" in popped.data, "instance has `timelines` property" );
-  ok( Object.prototype.toString.call(popped.data.timelines) === "[object Array]", "timelines property is an array" )
+  ok( "tracks" in popped.data, "instance has `tracks` property" );
+  ok( Object.prototype.toString.call(popped.data.tracks) === "[object Array]", "tracks property is an array" )
   
 });
 
 
 test("Popcorn Plugin", function () {
-
-  
-  Popcorn.plugin("subtitles", function ( ) {
   
-    
-    console.log(this);
   
+  // needs expectation
+
+  var popped = Popcorn("#video"), 
+      methods = "load play pause currentTime mute volume";
   
   
+  Popcorn.plugin("subtitles", function ( ) {
+    
+    var self = this;
+    
+    // These ensure that a popcorn instance is the value of `this` inside a plugin definition
+    
+    methods.split(/\s+/g).forEach(function (k,v) {
+      ok( k in self, "instance has method: " + k );
+    });
+
+    ok( "video" in this, "instance has `video` property" );
+    ok( Object.prototype.toString.call(popped.video) === "[object HTMLVideoElement]", "video property is a HTMLVideoElement" );
+
+    ok( "data" in this, "instance has `data` property" );
+    ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
+
+    ok( "tracks" in this.data, "instance has `tracks` property" );
+    ok( Object.prototype.toString.call(popped.data.tracks) === "[object Array]", "tracks property is an array" )
   });
   
   
-  var popped = Popcorn("#video");
   
   
   ok( "subtitles" in popped, "plugin is now available to instance" );
   
+  popped.subtitles();
   
   
-  
+  ok( Popcorn.registry.length === 1, "One item in the registry");
   
 });
 
 
-test("Popcorn Events", function () {
+
+
+test("Popcorn Events Simulated", function () {
 
 
   var p = Popcorn("#video"),
@@ -110,10 +129,51 @@ test("Popcorn Events", function () {
       eventtest = "loadstart progress suspend emptied stalled play pause " + 
                         "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
                         "seeking seeked timeupdate ended ratechange durationchange volumechange", 
+      events = eventtest.split(/\s+/g);                              
+  
+  
+  var expects = events.length, 
+      count = 0;
+
+  expect(expects);
+  
+  function plus(){ 
+    if ( ++count == expects ) start(); 
+  }
+  
+  stop();  
   
   
+  events.forEach(function ( name ) {
+    p.listen( name, function (event) {
+      
+      if ( completed.indexOf(name) === -1 ) {
+        ok(true, name + " fired");
+        plus();
+        
+        completed.push(name);
+      }
+      
+      
+    });  
+  });
+
+  events.forEach(function ( name ) {
+    p.trigger( name );  
+  });
   
   
+});
+
+
+test("Popcorn Events Real", function () {
+
+
+  var p = Popcorn("#video"),
+      completed = [], 
+      eventtest = "loadstart progress suspend emptied stalled play pause " + 
+                        "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
+                        "seeking seeked timeupdate ended ratechange durationchange volumechange", 
       events = eventtest.split(/\s+/g);