From: Christopher De Cairos Date: Wed, 28 Sep 2011 19:42:47 +0000 (-0400) Subject: Fixed bad currentTime call in youtube unit test [#423] X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=c3481894693bfe00f446823b5057958ccffe039e;p=popcorn-js.git Fixed bad currentTime call in youtube unit test [#423] --- diff --git a/players/youtube/popcorn.youtube.unit.js b/players/youtube/popcorn.youtube.unit.js index e93b553..8899942 100644 --- a/players/youtube/popcorn.youtube.unit.js +++ b/players/youtube/popcorn.youtube.unit.js @@ -26,7 +26,7 @@ test("Update Timer", function () { } // These tests come close to 10 seconds on chrome, increasing to 15 - stop( 15000 ); + stop(); Popcorn.plugin( "forwards", function () { return { @@ -67,7 +67,6 @@ test("Update Timer", function () { options.startFired = true; backwardStart = !backwardStart; - p2.currentTime(0).play(); ok( true, "backward's start fired" ); plus(); } @@ -80,7 +79,7 @@ test("Update Timer", function () { backwardEnd = !backwardEnd; ok( backwardEnd, "backward's end fired" ); plus(); - p2.currentTime( 5 ).play(); + p2.currentTime( 0 ).play(); } } }; @@ -286,34 +285,34 @@ test("Plugin Factory", function () { }); test( "Popcorn YouTube Plugin Url and Duration Tests", function() { - function plus(){ + function plus(){ if ( ++count == expects ) { - start(); + start(); } } - + QUnit.reset(); - + var count = 0, expects = 3, popcorn = Popcorn.youtube( '#video2', 'http://www.youtube.com/watch?v=9oar9glUCL0' ); - + expect( expects ); stop( 10000 ); - + equals( popcorn.media.id, 'video2', 'Video id set' ); plus(); - + equals( popcorn.duration(), 0, 'Duration starts as 0'); plus(); - + popcorn.listen( "durationchange", function() { notEqual( popcorn.duration(), 0, "Duration has been changed from 0" ); plus(); - + popcorn.pause(); }); - + popcorn.play(); }); @@ -385,21 +384,21 @@ test( "Controls and Annotations toggling", function() { ok( /controls=1/.test( testTarget.value ), "controls are defaulted to 1 ( displayed )" ); ok( /iv_load_policy=1/.test( testTarget.value ), "annotations ( iv_load_policy ) are defaulted to ( enabled )" ); - + targetDiv.innerHTML = ""; - + popcorn = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=9oar9glUCL0", { controls: 1, annotations: 1 } ); testTarget = targetDiv.querySelector( "object" ).querySelector( "param[name=flashvars]" ); ok( /controls=1/.test( testTarget.value ), "controls is set to 1 ( displayed )" ); ok( /iv_load_policy=1/.test( testTarget.value ), "annotations ( iv_load_policy ) is set to 1 ( enabled )" ); - + targetDiv.innerHTML = ""; - + popcorn = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=9oar9glUCL0", { controls: 0, annotations: 3 } ); testTarget = targetDiv.querySelector( "object" ).querySelector( "param[name=flashvars]" ); ok( /controls=0/.test( testTarget.value ), "controls is set to 0 ( hidden )" ); ok( /iv_load_policy=3/.test( testTarget.value ), "annotations ( iv_load_policy ) is set to 3 ( hidden )" ); - + }); diff --git a/popcorn.js b/popcorn.js index 83ecbb6..81857b1 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1176,7 +1176,6 @@ second = second || Popcorn.nop; return function() { - first.apply( this, arguments ); second.apply( this, arguments ); }; @@ -1188,8 +1187,7 @@ // apply safe, and empty default functions methods.forEach(function( method ) { - - definition[ method ] = definition[ method ] || Popcorn.nop; + definition[ method ] = safeTry( definition[ method ] || Popcorn.nop, name ); }); var pluginFn = function( setup, options ) { @@ -1209,7 +1207,7 @@ options._running = false; natives.start = natives.start || natives[ "in" ]; - natives.end = natives.end || natives[ "out" ]; + natives.end = natives.end || natives[ "out" ]; // Check for previously set default options defaults = this.options.defaults && this.options.defaults[ options._natives && options._natives.type ]; @@ -1229,14 +1227,13 @@ // extends previous functions with compose function methods.forEach(function( method ) { - natives[ method ] = combineFn( natives[ method ], compose[ method ] ); }); }); // Ensure a manifest object, an empty object is a sufficient fallback options._natives.manifest = manifest; - + // Checks for expected properties if ( !( "start" in options ) ) { options.start = options[ "in" ] || 0; @@ -1310,6 +1307,30 @@ return plugin; }; + // Storage for plugin function errors + Popcorn.plugin.errors = []; + + // Returns wrapped plugin function + function safeTry( fn, pluginName ) { + return function() { + try { + return fn.apply( this, arguments ); + } catch ( ex ) { + // Push plugin function errors into logging queue + Popcorn.plugin.errors.push({ + plugin: pluginName, + thrown: ex, + source: fn.toString() + }); + + // Trigger an error that the instance can listen for + // and react to + this.trigger( "error", Popcorn.plugin.errors ); + } + }; + } + + // Debug-mode flag for plugin development Popcorn.plugin.debug = false; // removePlugin( type ) removes all tracks of that from all instances of popcorn diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index d4d93c4..310e3d2 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -1509,6 +1509,56 @@ test("Configurable Defaults", function() { }); +test( "Exceptions", function() { + + var $pop = Popcorn( "#video" ), + expects = 5, + count = 0; + + Popcorn.plugin.errors = []; + + function plus() { + if ( ++count == expects ) { + Popcorn.removePlugin( "exceptions" ); + Popcorn.plugin.errors = []; + start(); + $pop.destroy(); + } + } + + expect( expects ); + stop( 5000 ); + + Popcorn.plugin( "exceptions", { + start: function() { + foo(); + }, + end: function() { + } + }); + + $pop.listen( "canplayall", function() { + this.exceptions({ + start: 1, + end: 2 + }).exec( 3, function() { + equal( Popcorn.plugin.errors.length, 1, "Popcorn.plugin.errors has one item"); + plus(); + }).currentTime( 0 ).play(); + + this.listen( "error", function( errors ) { + ok( errors.length, "`errors` array has error objects" ); + plus(); + ok( errors[ 0 ].thrown, "`errors[ 0 ].thrown` property exists" ); + plus(); + ok( errors[ 0 ].plugin, "`errors[ 0 ].plugin` property exists" ); + plus(); + ok( errors[ 0 ].source, "`errors[ 0 ].source` property exists" ); + plus(); + }); + }); +}); + test("Start Zero Immediately", function() { var $pop = Popcorn("#video"), @@ -2103,6 +2153,8 @@ test( "Popcorn Compose", function() { Popcorn.removePlugin("testPlugin"); Popcorn.removePlugin("pluginOptions1"); Popcorn.removePlugin("pluginOptions2"); + + popped.destroy(); start(); } } @@ -2690,7 +2742,7 @@ test( "In/Out aliases", function() { var popcorn = Popcorn( "#video" ), expects = 5, count = 0, - counter = 0; + counter = 0; expect( expects ); stop();