]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Fixed bad currentTime call in youtube unit test [#423]
authorChristopher De Cairos <chris.decairos@gmail.com>
Wed, 28 Sep 2011 19:42:47 +0000 (15:42 -0400)
committerChristopher De Cairos <chris.decairos@gmail.com>
Wed, 28 Sep 2011 19:42:47 +0000 (15:42 -0400)
players/youtube/popcorn.youtube.unit.js
popcorn.js
test/popcorn.unit.js

index e93b55352715ed1bc44f11466184e7eb828c33e7..88999424f699f4ecc1da9fd7aa2bda280edd68df 100644 (file)
@@ -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 )" );
-   
+
 });
 
index 83ecbb645b4f2dbc4515f59de5a0bc89f0673498..81857b195a9dc8d02524987db4604a1dd53ce093 100644 (file)
       second = second || Popcorn.nop;
 
       return function() {
-
         first.apply( this, arguments );
         second.apply( this, arguments );
       };
 
     // 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 ) {
       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 ];
 
         // 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;
     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
index d4d93c43ea2be1c97ca2b249fa2c828cb9fcc5aa..310e3d2f0222531432d966653a4090386a59c010 100644 (file)
@@ -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();