From 238d522ed09585636b70e95bfe82702b70ad2384 Mon Sep 17 00:00:00 2001 From: stevenaw Date: Wed, 9 Mar 2011 12:36:52 -0500 Subject: [PATCH] [#280] Core tests added --- players/vimeo/popcorn.vimeo.js | 3 ++ popcorn.js | 10 ++++- test/popcorn.unit.js | 76 ++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/players/vimeo/popcorn.vimeo.js b/players/vimeo/popcorn.vimeo.js index 0e68641..8d18741 100644 --- a/players/vimeo/popcorn.vimeo.js +++ b/players/vimeo/popcorn.vimeo.js @@ -482,6 +482,9 @@ }, 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 diff --git a/popcorn.js b/popcorn.js index 5a91650..88fc775 100644 --- a/popcorn.js +++ b/popcorn.js @@ -114,7 +114,12 @@ // 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; @@ -298,6 +303,7 @@ // todo: play, pause, mute should toggle var methods = "load play pause currentTime playbackRate mute volume duration", + noArgMethods = /load|play|pause|mute/, ret = {}; @@ -308,7 +314,7 @@ 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 ); diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index d264316..8f6f373 100755 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -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(); -- 2.43.0