}
// These tests come close to 10 seconds on chrome, increasing to 15
- stop( 15000 );
+ stop();
Popcorn.plugin( "forwards", function () {
return {
options.startFired = true;
backwardStart = !backwardStart;
- p2.currentTime(0).play();
ok( true, "backward's start fired" );
plus();
}
backwardEnd = !backwardEnd;
ok( backwardEnd, "backward's end fired" );
plus();
- p2.currentTime( 5 ).play();
+ p2.currentTime( 0 ).play();
}
}
};
});
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();
});
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 )" );
-
+
});
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
});
+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"),
Popcorn.removePlugin("testPlugin");
Popcorn.removePlugin("pluginOptions1");
Popcorn.removePlugin("pluginOptions2");
+
+ popped.destroy();
start();
}
}
var popcorn = Popcorn( "#video" ),
expects = 5,
count = 0,
- counter = 0;
+ counter = 0;
expect( expects );
stop();