зеркало из https://github.com/mozilla/popcorn-js.git
Added teardown for players [#804]
Fixed conflict between unit tests added for the 'ended' event [#820] Conflicts: players/youtube/popcorn.youtube.unit.js
This commit is contained in:
Коммит
ecd7f3c048
|
@ -1,5 +1,18 @@
|
|||
(function( Popcorn ) {
|
||||
|
||||
// combines calls of two function calls into one
|
||||
var combineFn = function( first, second ) {
|
||||
|
||||
first = first || Popcorn.nop;
|
||||
second = second || Popcorn.nop;
|
||||
|
||||
return function() {
|
||||
|
||||
first.apply( this, arguments );
|
||||
second.apply( this, arguments );
|
||||
};
|
||||
};
|
||||
|
||||
Popcorn.player = function( name, player ) {
|
||||
|
||||
// ID string matching
|
||||
|
@ -225,6 +238,14 @@
|
|||
|
||||
popcorn = new Popcorn.p.init( basePlayer, options );
|
||||
|
||||
if ( player._teardown ) {
|
||||
|
||||
popcorn.destroy = combineFn( popcorn.destroy, function() {
|
||||
|
||||
player._teardown.call( basePlayer, options );
|
||||
});
|
||||
}
|
||||
|
||||
return popcorn;
|
||||
};
|
||||
|
||||
|
@ -237,4 +258,4 @@
|
|||
object.__defineSetter__( description, options.set || Popcorn.nop );
|
||||
};
|
||||
|
||||
})( Popcorn );
|
||||
})( Popcorn );
|
||||
|
|
|
@ -187,3 +187,25 @@ test( "Base player functionality", function() {
|
|||
|
||||
p2.currentTime( 3 ).play();
|
||||
});
|
||||
|
||||
test( "player gets a proper _teardown", function() {
|
||||
|
||||
QUnit.reset();
|
||||
|
||||
var teardownCalled = false;
|
||||
|
||||
expect( 1 );
|
||||
stop( 10000 );
|
||||
|
||||
Popcorn.player( "teardownTester", {
|
||||
_teardown: function() {
|
||||
teardownCalled = true;
|
||||
}
|
||||
});
|
||||
|
||||
var pop = Popcorn.teardownTester( "#video" );
|
||||
pop.destroy();
|
||||
|
||||
equal( teardownCalled, true, "teardown function was called." );
|
||||
start();
|
||||
});
|
||||
|
|
|
@ -27,6 +27,8 @@ Popcorn.player( "youtube", {
|
|||
media.paused = undefined;
|
||||
container.id = media.id + Popcorn.guid();
|
||||
|
||||
options._container = container;
|
||||
|
||||
media.appendChild( container );
|
||||
|
||||
var youtubeInit = function() {
|
||||
|
@ -129,7 +131,7 @@ Popcorn.player( "youtube", {
|
|||
|
||||
var timeupdate = function() {
|
||||
|
||||
if ( !media.paused ) {
|
||||
if ( !media.paused && youtubeObject.getCurrentTime ) {
|
||||
|
||||
currentTime = youtubeObject.getCurrentTime();
|
||||
media.dispatchEvent( "timeupdate" );
|
||||
|
@ -139,19 +141,22 @@ Popcorn.player( "youtube", {
|
|||
|
||||
var volumeupdate = function() {
|
||||
|
||||
if ( lastMuted !== youtubeObject.isMuted() ) {
|
||||
if ( youtubeObject.isMuted ) {
|
||||
|
||||
lastMuted = youtubeObject.isMuted();
|
||||
media.dispatchEvent( "volumechange" );
|
||||
if ( lastMuted !== youtubeObject.isMuted() ) {
|
||||
|
||||
lastMuted = youtubeObject.isMuted();
|
||||
media.dispatchEvent( "volumechange" );
|
||||
}
|
||||
|
||||
if ( lastVolume !== youtubeObject.getVolume() ) {
|
||||
|
||||
lastVolume = youtubeObject.getVolume();
|
||||
media.dispatchEvent( "volumechange" );
|
||||
}
|
||||
|
||||
setTimeout( volumeupdate, 250 );
|
||||
}
|
||||
|
||||
if ( lastVolume !== youtubeObject.getVolume() ) {
|
||||
|
||||
lastVolume = youtubeObject.getVolume();
|
||||
media.dispatchEvent( "volumechange" );
|
||||
}
|
||||
|
||||
setTimeout( volumeupdate, 250 );
|
||||
};
|
||||
|
||||
media.play = function() {
|
||||
|
@ -276,5 +281,9 @@ Popcorn.player( "youtube", {
|
|||
|
||||
youtubeInit();
|
||||
}
|
||||
},
|
||||
_teardown: function( options ) {
|
||||
|
||||
this.removeChild( document.getElementById( options._container.id ) );
|
||||
}
|
||||
});
|
||||
|
|
|
@ -4,19 +4,26 @@ test( "Player play, pause, autoplay", function() {
|
|||
var count = 0,
|
||||
expects = 4,
|
||||
orderCheck1 = 0,
|
||||
orderCheck2 = 0;
|
||||
orderCheck2 = 0,
|
||||
pop1, pop2, pop3, pop4;
|
||||
|
||||
expect( expects );
|
||||
|
||||
function plus() {
|
||||
if ( ++count === expects ) {
|
||||
|
||||
pop1.destroy();
|
||||
pop2.destroy();
|
||||
pop3.destroy();
|
||||
pop4.destroy();
|
||||
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
stop( 20000 );
|
||||
|
||||
var pop1 = Popcorn.youtube( "#video6", "http://www.youtube.com/watch?v=nfGV32RNkhw" );
|
||||
pop1 = Popcorn.youtube( "#video6", "http://www.youtube.com/watch?v=nfGV32RNkhw" );
|
||||
|
||||
pop1.listen( "load", function() {
|
||||
|
||||
|
@ -26,7 +33,7 @@ test( "Player play, pause, autoplay", function() {
|
|||
plus();
|
||||
});
|
||||
|
||||
var pop2 = Popcorn.youtube( "#video7", "http://www.youtube.com/watch?v=nfGV32RNkhw" );
|
||||
pop2 = Popcorn.youtube( "#video7", "http://www.youtube.com/watch?v=nfGV32RNkhw" );
|
||||
|
||||
pop2.listen( "load", function() {
|
||||
|
||||
|
@ -34,7 +41,7 @@ test( "Player play, pause, autoplay", function() {
|
|||
plus();
|
||||
});
|
||||
|
||||
var pop3 = Popcorn.youtube( "#video8", "http://www.youtube.com/watch?v=nfGV32RNkhw&autoplay=0" );
|
||||
pop3 = Popcorn.youtube( "#video8", "http://www.youtube.com/watch?v=nfGV32RNkhw&autoplay=0" );
|
||||
|
||||
pop3.listen( "load", function() {
|
||||
|
||||
|
@ -42,7 +49,7 @@ test( "Player play, pause, autoplay", function() {
|
|||
plus();
|
||||
});
|
||||
|
||||
var pop4 = Popcorn.youtube( "#video9", "http://www.youtube.com/watch?v=nfGV32RNkhw&autoplay=1" );
|
||||
pop4 = Popcorn.youtube( "#video9", "http://www.youtube.com/watch?v=nfGV32RNkhw&autoplay=1" );
|
||||
|
||||
pop4.listen( "load", function() {
|
||||
|
||||
|
@ -74,6 +81,7 @@ test("Update Timer", function () {
|
|||
Popcorn.removePlugin( "backwards" );
|
||||
Popcorn.removePlugin( "wrapper" );
|
||||
p2.removePlugin( "exec" );
|
||||
p2.destroy();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
@ -235,6 +243,7 @@ test("Plugin Factory", function () {
|
|||
if ( ++count == expects ) {
|
||||
Popcorn.removePlugin("executor");
|
||||
Popcorn.removePlugin("complicator");
|
||||
popped.destroy();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
@ -342,11 +351,6 @@ test("Plugin Factory", function () {
|
|||
});
|
||||
|
||||
test( "Popcorn YouTube Plugin Url and Duration Tests", function() {
|
||||
function plus(){
|
||||
if ( ++count == expects ) {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
QUnit.reset();
|
||||
|
||||
|
@ -354,6 +358,13 @@ test( "Popcorn YouTube Plugin Url and Duration Tests", function() {
|
|||
expects = 3,
|
||||
popcorn = Popcorn.youtube( '#video2', 'http://www.youtube.com/watch?v=nfGV32RNkhw' );
|
||||
|
||||
function plus(){
|
||||
if ( ++count == expects ) {
|
||||
popcorn.destroy();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
expect( expects );
|
||||
stop( 10000 );
|
||||
|
||||
|
@ -421,6 +432,9 @@ test( "Popcorn YouTube Plugin Url Regex Test", function() {
|
|||
popcorn.pause();
|
||||
|
||||
count++;
|
||||
|
||||
popcorn.destroy();
|
||||
|
||||
if ( count === expects ) {
|
||||
|
||||
start();
|
||||
|
@ -433,32 +447,79 @@ test( "Controls and Annotations toggling", function() {
|
|||
|
||||
QUnit.reset();
|
||||
|
||||
expect( 6 );
|
||||
var count = 0,
|
||||
expects = 6;
|
||||
//popcorn = Popcorn.youtube( '#video2', 'http://www.youtube.com/watch?v=nfGV32RNkhw' );
|
||||
|
||||
var popcorn = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=nfGV32RNkhw" ),
|
||||
targetDiv = document.getElementById( "video" );
|
||||
testTarget = targetDiv.querySelector( "object" ).data;
|
||||
function plus(){
|
||||
if ( ++count == expects ) {
|
||||
//popcorn.destroy();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
popcorn.volume( 0 );
|
||||
expect( expects );
|
||||
//expect( 6 );
|
||||
stop( 10000 );
|
||||
|
||||
ok( !/controls/.test( testTarget ), "controls are defaulted to 1 ( displayed )" );
|
||||
ok( !/iv_load_policy/.test( testTarget ), "annotations ( iv_load_policy ) are defaulted to ( enabled )" );
|
||||
var popcorn1 = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=nfGV32RNkhw" );
|
||||
|
||||
targetDiv.innerHTML = "";
|
||||
popcorn1.listen( "loadeddata", function() {
|
||||
|
||||
var targetDiv = document.getElementById( "video" ),
|
||||
testTarget = targetDiv.querySelector( "object" ).data;
|
||||
|
||||
popcorn = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=nfGV32RNkhw&controls=1&iv_load_policy=1" );
|
||||
popcorn.volume( 0 );
|
||||
popcorn1.volume( 0 );
|
||||
|
||||
ok( !/controls/.test( testTarget ), "controls are defaulted to 1 ( displayed )" );
|
||||
plus();
|
||||
ok( !/iv_load_policy/.test( testTarget ), "annotations ( iv_load_policy ) are defaulted to ( enabled )" );
|
||||
plus();
|
||||
|
||||
popcorn1.destroy();
|
||||
|
||||
var popcorn2 = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=nfGV32RNkhw&controls=1&iv_load_policy=1" );
|
||||
popcorn2.listen( "loadeddata", function() {
|
||||
|
||||
var targetDiv = document.getElementById( "video" ),
|
||||
testTarget = targetDiv.querySelector( "object" ).data;
|
||||
|
||||
popcorn2.volume( 0 );
|
||||
|
||||
ok( /controls=1/.test( testTarget ), "controls is set to 1 ( displayed )" );
|
||||
plus();
|
||||
ok( /iv_load_policy=1/.test( testTarget ), "annotations ( iv_load_policy ) is set to 1 ( enabled )" );
|
||||
plus();
|
||||
|
||||
popcorn2.destroy();
|
||||
|
||||
var popcorn3 = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=nfGV32RNkhw&controls=0&iv_load_policy=3" );
|
||||
popcorn3.listen( "loadeddata", function() {
|
||||
|
||||
var targetDiv = document.getElementById( "video" ),
|
||||
testTarget = targetDiv.querySelector( "object" ).data;
|
||||
|
||||
popcorn3.volume( 0 );
|
||||
|
||||
ok( /controls=0/.test( testTarget ), "controls is set to 0 ( hidden )" );
|
||||
plus();
|
||||
ok( /iv_load_policy=3/.test( testTarget ), "annotations ( iv_load_policy ) is set to 3 ( hidden )" );
|
||||
plus();
|
||||
|
||||
popcorn3.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/*popcorn2.volume( 0 );
|
||||
testTarget = targetDiv.querySelector( "object" ).data;
|
||||
ok( /controls=1/.test( testTarget ), "controls is set to 1 ( displayed )" );
|
||||
ok( /iv_load_policy=1/.test( testTarget ), "annotations ( iv_load_policy ) is set to 1 ( enabled )" );
|
||||
|
||||
targetDiv.innerHTML = "";
|
||||
|
||||
popcorn = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=nfGV32RNkhw&controls=0&iv_load_policy=3" );
|
||||
var popcorn3 = Popcorn.youtube( "#video", "http://www.youtube.com/watch?v=nfGV32RNkhw&controls=0&iv_load_policy=3" );
|
||||
testTarget = targetDiv.querySelector( "object" ).data;
|
||||
ok( /controls=0/.test( testTarget ), "controls is set to 0 ( hidden )" );
|
||||
ok( /iv_load_policy=3/.test( testTarget ), "annotations ( iv_load_policy ) is set to 3 ( hidden )" );
|
||||
|
||||
popcorn3.destroy();*/
|
||||
});
|
||||
|
||||
test( "Player height and width", function() {
|
||||
|
@ -483,6 +544,9 @@ test( "Player height and width", function() {
|
|||
|
||||
equal( popcorn2.media.children[ 0 ].width, 0, "Youtube player explicit width is 0" );
|
||||
equal( popcorn2.media.children[ 0 ].height, 0, "Youtube player explicit height is 0" );
|
||||
|
||||
popcorn1.destroy();
|
||||
popcorn2.destroy();
|
||||
start();
|
||||
}
|
||||
};
|
||||
|
@ -505,9 +569,12 @@ test( "Popcorn Youtube Plugin offsetHeight && offsetWidth Test", function() {
|
|||
|
||||
function plus() {
|
||||
if ( ++count === expects ) {
|
||||
|
||||
popped.destroy();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
popped = Popcorn.youtube( "#video6", "http://www.youtube.com/watch?v=nfGV32RNkhw" );
|
||||
|
||||
var runner = function() {
|
||||
|
@ -538,6 +605,7 @@ test( "Player Errors", function() {
|
|||
error: function() {
|
||||
|
||||
ok( true, "error trigger by invalid URL" );
|
||||
pop.destroy();
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
@ -557,3 +625,29 @@ test( "YouTube ended event", function() {
|
|||
});
|
||||
pop.play( 150 );
|
||||
});
|
||||
|
||||
test( "youtube player gets a proper _teardown", function() {
|
||||
|
||||
QUnit.reset();
|
||||
|
||||
var count = 0,
|
||||
expects = 1;
|
||||
|
||||
function plus() {
|
||||
if ( ++count === expects ) {
|
||||
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
expect( expects );
|
||||
stop( 10000 );
|
||||
|
||||
var popcorn = Popcorn.youtube( "#video9", "http://www.youtube.com/watch?v=nfGV32RNkhw" );
|
||||
popcorn.listen( "loadeddata", function() {
|
||||
|
||||
popcorn.destroy();
|
||||
equal( popcorn.media.children.length, 0, "" );
|
||||
plus();
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче