]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#280] Core tests added
authorstevenaw <sweerdenburg@gmail.com>
Wed, 9 Mar 2011 17:36:52 +0000 (12:36 -0500)
committerstevenaw <sweerdenburg@gmail.com>
Wed, 9 Mar 2011 17:36:52 +0000 (12:36 -0500)
players/vimeo/popcorn.vimeo.js
popcorn.js
test/popcorn.unit.js

index 0e6864183c6bb5e957cb24ba7e3a1a5b7475db60..8d18741118bb53cd6b365121f4675a4254bd91d2 100644 (file)
     },
     removeEventListener: function( evtName, fn ) {
       return this.evtHolder.removeEventListener( evtName, fn );
+    },
+    dispatchEvent: function( evtName ) {
+      return this.evtHolder.dispatchEvent( evtName );
     }
   });
 })( Popcorn );
\ No newline at end of file
index 5a916504581dc26629912fd52f0ca91db941f9fe..88fc775290499e19a84598c2ad3cec83c8483f24 100644 (file)
           // adding padding to the front and end of the arrays
           // this is so we do not fall off either end
 
-          var duration = typeof that.video.duration === "function" ? that.video.duration() : that.video.duration;
+          var duration = that.video.duration;
+          
+          if( typeof that.video.duration === "function") {
+            duration = that.video.duration();
+          }
+          
           // Check for no duration info (NaN)
           var videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
 
 
       // todo: play, pause, mute should toggle
       var methods = "load play pause currentTime playbackRate mute volume duration",
+          noArgMethods = /load|play|pause|mute/,
           ret = {};
 
 
 
           var isFunc = typeof this.video[name] === "function";
 
-          if ( /load|play|pause|mute/.test( name ) || ( arg !== false && arg !== null && typeof arg !== "undefined" ) ) {
+          if ( noArgMethods.test( name ) || ( arg !== false && arg !== null && typeof arg !== "undefined" ) ) {
 
             if ( isFunc ) {
               this.video[ name ]( arg );
index d2643165f6147d30d3be360ace72fa5d4b94e1c4..8f6f373eb9f1f7b52651b2881ede198401a5ebd0 100755 (executable)
@@ -279,6 +279,82 @@ test("Stored By Type", function () {
 });
 
 
+test("Passed an object", function () {
+  
+  QUnit.reset();
+  
+  var evtMethods = "addEventListener dispatchEvent".split(/\s+/),
+      methods = "load play pause currentTime playbackRate mute volume duration".split(/\s+/),
+      attributes = "readyState autoplay".split(/\s+/),
+      obj = {},
+      p,
+      playEvent,
+      count = 0,
+      wants;
+
+  function plus(){ 
+
+    if ( ++count === wants ) {  
+      start();
+    } 
+  }
+  
+  Popcorn.forEach( methods, function( method ) {
+    obj[method] = (function() {
+      var calledWithArgs = 0,
+          calledWithoutArgs = 0;
+          
+      return function( arg ) {
+        if ( arg && !calledWithArgs ) {
+          calledWithArgs = 1;
+          ok(true, method+" called with argument");
+          plus();
+        } else if ( !arg && !calledWithoutArgs ) {
+          calledWithoutArgs = 1;
+          ok(true, method+" called without argument");
+          plus();
+        }
+      }
+    })();
+  });
+  
+  Popcorn.forEach( evtMethods, function( method ) {
+    obj[method] = (function() {
+      var hasCalled = 0;
+      
+      return function() {
+        if ( hasCalled ) {
+          return;
+        }
+        
+        hasCalled = 1;
+        ok(true, method+" called");
+        plus();
+      };
+    })()
+  });
+  
+  Popcorn.forEach( attributes, function( attr ) {
+    obj[attr] = 3;
+  });
+  
+  p = Popcorn( obj );
+  wants = methods.length*2 + evtMethods.length;
+
+  expect( wants );
+  stop( 10000 );
+  
+  p.listen( "play", Popcorn.nop );
+  
+  Popcorn.forEach( methods, function( method ) {
+    p[method]();
+    p[method]( 1 );
+  });
+  
+  p.trigger( "play" );
+});
+
+
 test("Simulated", function () {
   
   QUnit.reset();