From: ScottDowne Date: Fri, 13 May 2011 20:01:03 +0000 (-0400) Subject: [#t484] teardown functions for plugins that need it + tests X-Git-Tag: v0.6~2^2~9^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=c540b761ce7883dd800af591a13dc40e68f93ed1;p=popcorn-js.git [#t484] teardown functions for plugins that need it + tests --- diff --git a/plugins/attribution/popcorn.attribution.js b/plugins/attribution/popcorn.attribution.js index 96bd15e..7331228 100644 --- a/plugins/attribution/popcorn.attribution.js +++ b/plugins/attribution/popcorn.attribution.js @@ -125,6 +125,9 @@ */ end: function(event, options){ options._container.style.display = "none"; + }, + _teardown: function( options ) { + document.getElementById( options.target ).removeChild( options._container ); } }; })()); diff --git a/plugins/attribution/popcorn.attribution.unit.js b/plugins/attribution/popcorn.attribution.unit.js index 2dc49a8..bb5bb16 100644 --- a/plugins/attribution/popcorn.attribution.unit.js +++ b/plugins/attribution/popcorn.attribution.unit.js @@ -1,8 +1,9 @@ test("Popcorn attribution Plugin", function () { var popped = Popcorn("#video"), - expects = 7, + expects = 8, count = 0, + setupId, attributiondiv = document.getElementById('attribdiv'); expect(expects); @@ -24,7 +25,7 @@ test("Popcorn attribution Plugin", function () { popped.attribution({ start: 0, // seconds - end: 5, // seconds + end: 0.5, // seconds nameofwork: "A Shared Culture", copyrightholder:"Jesse Dylan", license: "CC-BY-N6", @@ -32,8 +33,8 @@ test("Popcorn attribution Plugin", function () { target: 'attribdiv' } ) .attribution({ - start: 3, // seconds - end: 10, // seconds + start: 0.5, // seconds + end: 1, // seconds nameofwork: "Internet", nameofworkurl:"http://www.archive.org/details/CC1232_internet", copyrightholder:"The Computer Chronicles", @@ -43,22 +44,28 @@ test("Popcorn attribution Plugin", function () { } ) .volume(0); - popped.exec( 1, function() { + setupId = popped.getLastTrackEventId(); + + popped.exec( 0, function() { equals ( attributiondiv.childElementCount, 2, "attributiondiv now has two inner elements" ); plus(); equals (attributiondiv.children[0].style.display , "inline", "attribution is visible on the page" ); plus(); }); - popped.exec( 4, function() { + popped.exec( 0.5, function() { equals (attributiondiv.children[1].style.display , "inline", "second attribution is visible on the page" ); plus(); }); - popped.exec( 11, function() { - equals (attributiondiv.children[1].style.display , "none", "second attribution is no longer visible on the page" ); + popped.exec( 1, function() { + equals(attributiondiv.children[1].style.display , "none", "second attribution is no longer visible on the page" ); plus(); - equals (attributiondiv.children[0].style.display , "none", "first attribution is no longer visible on the page" ); + equals(attributiondiv.children[0].style.display , "none", "first attribution is no longer visible on the page" ); + plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !attributiondiv.children[1], "removed attribution was properly destroyed" ); plus(); }); diff --git a/plugins/flickr/popcorn.flickr.js b/plugins/flickr/popcorn.flickr.js index 6fba548..37977bd 100644 --- a/plugins/flickr/popcorn.flickr.js +++ b/plugins/flickr/popcorn.flickr.js @@ -139,6 +139,9 @@ */ end: function( event, options ){ containerDiv.style.display = "none"; + }, + _teardown: function( options ) { + document.getElementById( options.target ).removeChild( containerDiv ); } }; }, diff --git a/plugins/flickr/popcorn.flickr.unit.js b/plugins/flickr/popcorn.flickr.unit.js index 74e6758..d510f20 100644 --- a/plugins/flickr/popcorn.flickr.unit.js +++ b/plugins/flickr/popcorn.flickr.unit.js @@ -1,8 +1,9 @@ test("Popcorn Flickr Plugin", function () { var popped = Popcorn("#video"), - expects = 7, + expects = 8, count = 0, + setupId, flickrdiv = document.getElementById('flickrdiv'); expect( expects ); @@ -22,40 +23,45 @@ test("Popcorn Flickr Plugin", function () { plus(); popped.flickr({ - start: 1, // seconds - end: 3, // seconds + start: 0, // seconds + end: 1, // seconds userid: '35034346917@N01', numberofimages: '1', target: 'flickrdiv' } ) .flickr({ - start: 4, // seconds - end: 7, // seconds + start: 1, // seconds + end: 2, // seconds username: 'AniaSob', apikey: 'd1d249260dd1673ec8810c8ce5150ae1', numberofimages: '1', target: 'flickrdiv' - } );; + }); - popped.exec( 2, function() { + setupId = popped.getLastTrackEventId(); + + popped.exec( 0.5, function() { ok( /display: inline;/.test( flickrdiv.innerHTML ), "Div contents are displayed" ); plus(); ok( /img/.test( flickrdiv.innerHTML ), "An image exists" ); plus(); }); - popped.exec( 5, function() { + popped.exec( 1.5, function() { ok( /display: inline;/.test( flickrdiv.innerHTML ), "Div contents are displayed" ); plus(); ok( /img/.test( flickrdiv.innerHTML ), "An image exists" ); plus(); }); - popped.exec( 7, function() { + popped.exec( 2, function() { ok( /display: none;/.test( flickrdiv.innerHTML ), "Div contents are hidden again" ); plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !flickrdiv.children[1], "removed flickr was properly destroyed" ); + plus(); }); - popped.volume(0); - popped.play(); + popped.volume(0).play(); }); diff --git a/plugins/footnote/popcorn.footnote.js b/plugins/footnote/popcorn.footnote.js index 1f52dec..981d94a 100644 --- a/plugins/footnote/popcorn.footnote.js +++ b/plugins/footnote/popcorn.footnote.js @@ -65,8 +65,10 @@ */ end: function(event, options){ options._container.style.display = "none"; + }, + _teardown: function( options ) { + document.getElementById( options.target ).removeChild( options._container ); } - }); -})( Popcorn ); \ No newline at end of file +})( Popcorn ); diff --git a/plugins/footnote/popcorn.footnote.unit.js b/plugins/footnote/popcorn.footnote.unit.js index 7693bec..22df71c 100644 --- a/plugins/footnote/popcorn.footnote.unit.js +++ b/plugins/footnote/popcorn.footnote.unit.js @@ -1,8 +1,9 @@ test("Popcorn Footnote Plugin", function () { var popped = Popcorn("#video"), - expects = 7, + expects = 8, count = 0, + setupId, footnotediv = document.getElementById('footnotediv'); expect(expects); @@ -23,19 +24,20 @@ test("Popcorn Footnote Plugin", function () { popped.footnote({ start: 0, // seconds - end: 2, // seconds + end: 1, // seconds text: 'This video made exclusively for drumbeat.org', target: 'footnotediv' - } ) + }) .footnote({ - start: 2, // seconds - end: 4, // seconds + start: 1, // seconds + end: 2, // seconds text: 'Visit webmademovies.org for more details', target: 'footnotediv' - } ) - .volume(0); + }); - popped.exec( 1, function() { + setupId = popped.getLastTrackEventId(); + + popped.exec( 0, function() { equals ( footnotediv.childElementCount, 2, "footnotediv now has two inner elements" ); plus(); equals (footnotediv.children[0].innerHTML , "This video made exclusively for drumbeat.org", "footnote displaing correct information" ); @@ -44,15 +46,19 @@ test("Popcorn Footnote Plugin", function () { plus(); }); - popped.exec( 3, function() { + popped.exec( 1, function() { equals (footnotediv.children[1].style.display , "inline", "second footnote is visible on the page" ); plus(); }); - popped.exec( 5, function() { + popped.exec( 2, function() { ok (footnotediv.children[1].style.display === 'none' && footnotediv.children[0].style.display === 'none', "footnote are no longer vidible on the page" ); plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !footnotediv.children[1], "removed footnote was properly destroyed" ); + plus(); }); - popped.play(); + popped.play().volume(0); }); diff --git a/plugins/googlefeed/popcorn.googlefeed.js b/plugins/googlefeed/popcorn.googlefeed.js index acc919f..4d24794 100644 --- a/plugins/googlefeed/popcorn.googlefeed.js +++ b/plugins/googlefeed/popcorn.googlefeed.js @@ -112,6 +112,9 @@ */ end: function(event, options){ newdiv.setAttribute( "style", "display:none" ); + }, + _teardown: function( options ) { + document.getElementById( options.target ).removeChild( newdiv ); } }; }, diff --git a/plugins/googlefeed/popcorn.googlefeed.unit.js b/plugins/googlefeed/popcorn.googlefeed.unit.js index 83369b5..b2778c2 100644 --- a/plugins/googlefeed/popcorn.googlefeed.unit.js +++ b/plugins/googlefeed/popcorn.googlefeed.unit.js @@ -1,7 +1,8 @@ test("Popcorn Google Feed Plugin", function () { var popped = Popcorn("#video"), - expects = 10, + expects = 11, + setupId, count = 0; expect(expects); @@ -22,43 +23,49 @@ test("Popcorn Google Feed Plugin", function () { plus(); popped.googlefeed({ - start: 0, // seconds - end: 5, // seconds - target: "feed", - url: "http://zenit.senecac.on.ca/~chris.tyler/planet/rss20.xml", - title: "Planet Feed", - orientation: "Vertical" - } ) - .googlefeed({ - start: 0, // seconds - end: 5, // seconds - target: "feed1", - url: "http://blog.pikimal.com/geek/feed/", - title: "pikiGeek", - orientation: "Horizontal" - } ) - .volume(0); + start: 0, // seconds + end: 1, // seconds + target: "feed", + url: "http://zenit.senecac.on.ca/~chris.tyler/planet/rss20.xml", + title: "Planet Feed", + orientation: "Vertical" + }) + .googlefeed({ + start: 0, // seconds + end: 2, // seconds + target: "feed1", + url: "http://blog.pikimal.com/geek/feed/", + title: "pikiGeek", + orientation: "Horizontal" + }) + .volume(0); + + setupId = popped.getLastTrackEventId(); + popped.exec( 0, function() { + ok(google.load, "Google Feed is available"); + plus(); + ok(GFdynamicFeedControl, "Dynamic Feed Control Available"); + plus(); + ok (document.getElementById('_feed1'), "First feed is on the page" ); + plus(); + equals (document.getElementById('_feed1').offsetParent.id, "feed", "First feed is inside the 'feed' div" ); + plus(); + }); popped.exec( 1, function() { - ok(google.load, "Google Feed is available"); - plus(); - ok(GFdynamicFeedControl, "Dynamic Feed Control Available"); - plus(); - ok (document.getElementById('_feed1'), "First feed is on the page" ); - plus(); - equals (document.getElementById('_feed1').offsetParent.id, "feed", "First feed is inside the 'feed' div" ); - plus(); + ok (document.getElementById('_feed2'), "Second feed is on the page" ); + plus(); + equals (document.getElementById('_feed2').offsetParent.id, "feed1", "Second feed is inside the 'feed2' div" ); + plus(); }); popped.exec( 2, function() { - ok (document.getElementById('_feed2'), "Second feed is on the page" ); - plus(); - equals (document.getElementById('_feed2').offsetParent.id, "feed1", "Second feed is inside the 'feed2' div" ); - plus(); - }); - popped.exec( 6, function() { - ok (document.getElementById('_feed2').style.display === "none" && - document.getElementById('_feed1').style.display === "none", "Both feeds are no lnger visible" ); - plus(); + ok (document.getElementById('_feed2').style.display === "none" && + document.getElementById('_feed1').style.display === "none", "Both feeds are no lnger visible" ); + plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !document.getElementById('feed1').children[0], "removed footnote was properly destroyed" ); + plus(); }); popped.play(); diff --git a/plugins/googlemap/popcorn.googlemap.unit.js b/plugins/googlemap/popcorn.googlemap.unit.js index 778a59d..515bce6 100644 --- a/plugins/googlemap/popcorn.googlemap.unit.js +++ b/plugins/googlemap/popcorn.googlemap.unit.js @@ -76,9 +76,7 @@ test("Popcorn Google Map Plugin", function () { ok (document.getElementById('actualmap2').style.display === "none" && document.getElementById('actualmap1').style.display === "none", "Both maps are no longer visible" ); plus(); - popped.pause(); - - popped.removeTrackEvent( setupId ); + popped.pause().removeTrackEvent( setupId ); ok( !document.getElementById('actualmap3'), "removed map was properly destroyed" ); plus(); diff --git a/plugins/googlenews/popcorn.googlenews.js b/plugins/googlenews/popcorn.googlenews.js index d381795..e12e0bf 100644 --- a/plugins/googlenews/popcorn.googlenews.js +++ b/plugins/googlenews/popcorn.googlenews.js @@ -66,17 +66,19 @@ } options.container = document.createElement( 'div' ); + var container = document.createElement( 'div' ); if ( document.getElementById( options.target ) ) { document.getElementById( options.target ).appendChild( options.container ); + options.container.appendChild( container ); } var readyCheck = setInterval(function() { if ( !scriptLoaded ) { return; } - clearInterval(readyCheck); + clearInterval( readyCheck ); - var newsShow = new google.elements.NewsShow( options.container, { + options.newsShow = new google.elements.NewsShow( container, { format : "300x250", queryList : [ { q: options.topic || "Top Stories" } @@ -105,8 +107,13 @@ */ end: function( event, options ){ options.container.setAttribute( 'style', 'display:none' ); + }, + _teardown: function( options ) { + // google news does not like this, throws an error "a is null" + // doesn't hurt popcorn, and only happens once + document.getElementById( options.target ).removeChild( options.container ); + options.newsShow = null; } - }); })( Popcorn ); diff --git a/plugins/googlenews/popcorn.googlenews.unit.js b/plugins/googlenews/popcorn.googlenews.unit.js index 7cdfee8..b067de0 100644 --- a/plugins/googlenews/popcorn.googlenews.unit.js +++ b/plugins/googlenews/popcorn.googlenews.unit.js @@ -1,8 +1,9 @@ test( "Popcorn google news Plugin", function () { var popped = Popcorn( "#video" ), - expects = 7, + expects = 8, count = 0, + setupId, googlenewsdiv = document.getElementById( "googlenewsdiv" ); expect(expects); @@ -23,37 +24,43 @@ test( "Popcorn google news Plugin", function () { popped.googlenews({ start: 0, // seconds - end: 5, // seconds + end: 1, // seconds topic: "Oil Spill", target: "googlenewsdiv" }) .googlenews({ - start: 3, // seconds - end: 10, // seconds + start: 1, // seconds + end: 2, // seconds topic: "Village Telco", target: "googlenewsdiv" }) .volume( 0 ); + + setupId = popped.getLastTrackEventId(); - popped.exec( 1, function() { + popped.exec( 0, function() { equals( googlenewsdiv.childElementCount, 2, "googlenewsdiv now has two inner elements" ); plus(); equals( googlenewsdiv.children[0].style.display , "inline", "first googlenews is visible on the page" ); plus(); }); - popped.exec( 4, function() { + popped.exec( 1, function() { equals( googlenewsdiv.children[1].style.display , "inline", "second googlenews is visible on the page" ); plus(); }); - popped.exec( 11, function() { + popped.exec( 2, function() { equals( googlenewsdiv.children[1].style.display , "none", "second googlenews is no longer visible on the page" ); plus(); equals( googlenewsdiv.children[0].style.display , "none", "first googlenews is no longer visible on the page" ); plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !googlenewsdiv.children[1], "removed google news was properly destroyed" ); + plus(); }); popped.play(); -}); \ No newline at end of file +}); diff --git a/plugins/image/popcorn.image.js b/plugins/image/popcorn.image.js index d83b658..2b77387 100644 --- a/plugins/image/popcorn.image.js +++ b/plugins/image/popcorn.image.js @@ -107,8 +107,10 @@ */ end: function( event, options ) { options.link.style.display = "none"; + }, + _teardown: function( options ) { + document.getElementById( options.target ).removeChild( options.link ); } - }); })( Popcorn ); diff --git a/plugins/image/popcorn.image.unit.js b/plugins/image/popcorn.image.unit.js index f9102a4..29b82a1 100644 --- a/plugins/image/popcorn.image.unit.js +++ b/plugins/image/popcorn.image.unit.js @@ -1,8 +1,9 @@ test("Popcorn Image Plugin", function () { var popped = Popcorn("#video"), - expects = 5, + expects = 6, count = 0, + setupId, imagediv = document.getElementById('imagediv'); expect( expects ); @@ -30,16 +31,22 @@ test("Popcorn Image Plugin", function () { target: 'imagediv' }); + setupId = popped.getLastTrackEventId(); + popped.exec( 2, function() { - ok( /display: block;/.test( imagediv.innerHTML ), "Div contents are displayed" ); - plus(); - ok( /img/.test( imagediv.innerHTML ), "An image exists" ); - plus(); + ok( /display: block;/.test( imagediv.innerHTML ), "Div contents are displayed" ); + plus(); + ok( /img/.test( imagediv.innerHTML ), "An image exists" ); + plus(); }); popped.exec( 4, function() { - ok( /display: none;/.test( imagediv.innerHTML ), "Div contents are hidden again" ); - plus(); + ok( /display: none;/.test( imagediv.innerHTML ), "Div contents are hidden again" ); + plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !imagediv.children[0], "removed image was properly destroyed" ); + plus(); }); popped.volume(0).play(); diff --git a/plugins/lastfm/popcorn.lastfm.js b/plugins/lastfm/popcorn.lastfm.js index d0b3bab..b17b603 100644 --- a/plugins/lastfm/popcorn.lastfm.js +++ b/plugins/lastfm/popcorn.lastfm.js @@ -2,10 +2,12 @@ (function (Popcorn) { - var _artists = [], + var _artists = {}, lastFMcallback = function(data){ if (data.artist) { - var htmlString = '

'+data.artist.name+'

'; + var htmlString = ""; + + htmlString = '

'+data.artist.name+'

'; htmlString += ''; htmlString += '

'+ data.artist.bio.summary +'

'; htmlString += '

Tags

'; - _artists[data.artist.name.toLowerCase()] = htmlString; + _artists[data.artist.name.toLowerCase()].htmlString = htmlString; } }; @@ -83,10 +85,13 @@ if(!_artists[options.artist]) { - _artists[options.artist] = "Unknown Artist"; + _artists[options.artist] = { + count: 0, + htmlString: "Unknown Artist" + }; Popcorn.getJSONP("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="+ options.artist +"&api_key="+options.apikey+"&format=json&callback=lastFMcallback", lastFMcallback, false ); - } + _artists[options.artist].count++; }, /** @@ -96,7 +101,7 @@ * options variable */ start: function( event, options ) { - options._container.innerHTML = _artists[options.artist]; + options._container.innerHTML = _artists[options.artist].htmlString; options._container.style.display = "inline"; }, /** @@ -108,6 +113,11 @@ end: function( event, options ) { options._container.style.display = "none"; options._container.innerHTML = ""; + }, + _teardown: function( options ) { + // cleaning possible reference to _artist array; + --_artists[ options.artist ].count || delete _artists[ options.artist ]; + document.getElementById( options.target ).removeChild( options._container ); } }; })()); diff --git a/plugins/lastfm/popcorn.lastfm.unit.js b/plugins/lastfm/popcorn.lastfm.unit.js index c66b009..f02c13a 100644 --- a/plugins/lastfm/popcorn.lastfm.unit.js +++ b/plugins/lastfm/popcorn.lastfm.unit.js @@ -6,8 +6,9 @@ test("Popcorn LastFM Plugin", function () { plugin. Please do not use it for other purposes. */ var popped = Popcorn("#video"), - expects = 8, + expects = 9, count = 0, + setupId, lastfmdiv = document.getElementById('lastfmdiv'); expect( expects ); @@ -48,6 +49,8 @@ test("Popcorn LastFM Plugin", function () { apikey: '30ac38340e8be75f9268727cb4526b3d' }); + setupId = popped.getLastTrackEventId(); + popped.exec( 2, function() { equals ( lastfmdiv.childElementCount, 3, "lastfmdiv now has three inner elements" ); plus(); @@ -67,6 +70,10 @@ test("Popcorn LastFM Plugin", function () { popped.exec( 5, function() { equals (lastfmdiv.children[2].innerHTML , "Unknown Artist", "Artist information could not be found" ); plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !lastfmdiv.children[2], "removed artist was properly destroyed" ); + plus(); }); popped.volume(0).play(); diff --git a/plugins/mustache/popcorn.mustache.js b/plugins/mustache/popcorn.mustache.js index 3ae5cf5..86f318f 100644 --- a/plugins/mustache/popcorn.mustache.js +++ b/plugins/mustache/popcorn.mustache.js @@ -139,6 +139,9 @@ end: function( event, options ) { document.getElementById( options.target ).innerHTML = ''; + }, + _teardown: function( options ) { + getData, data, getTemplate, template = null; } }; }, diff --git a/plugins/openmap/popcorn.openmap.js b/plugins/openmap/popcorn.openmap.js index 988354e..ad7262e 100644 --- a/plugins/openmap/popcorn.openmap.js +++ b/plugins/openmap/popcorn.openmap.js @@ -250,8 +250,12 @@ var openmapCallback; if ( map ) { map.div.style.display = 'none'; } - } + }, + _teardown: function( options ) { + document.getElementById( options.target ).removeChild( newdiv ); + newdiv = map = centerlonlat = projection = displayProjection = pointLayer = selectControl = popup = null; + } }; }, { diff --git a/plugins/openmap/popcorn.openmap.unit.js b/plugins/openmap/popcorn.openmap.unit.js index 2be25a2..2f38431 100644 --- a/plugins/openmap/popcorn.openmap.unit.js +++ b/plugins/openmap/popcorn.openmap.unit.js @@ -1,12 +1,13 @@ test("Popcorn OpenMap Plugin", function () { var popped = Popcorn("#video"), - expects = 12, - count = 0, - mapInterval, - mapInterval2, - mapInterval3, - mapInterval4; + expects = 13, + count = 0, + setupId, + mapInterval, + mapInterval2, + mapInterval3, + mapInterval4; expect(expects); @@ -60,6 +61,8 @@ test("Popcorn OpenMap Plugin", function () { .volume(0) .play(); + setupId = popped.getLastTrackEventId(); + mapInterval = popped.exec( 4, function() { if( popped.currentTime() > 3 && popped.currentTime() <= 5 ) { ok(OpenLayers, "OpenLayers is available"); @@ -96,6 +99,10 @@ test("Popcorn OpenMap Plugin", function () { document.getElementById('actualmap1').style.display === "none", "All three maps are no longer visible" ); plus(); clearInterval( mapInterval4 ); + + popped.pause().removeTrackEvent( setupId ); + ok( !document.getElementById('actualmap3'), "removed map was properly destroyed" ); + plus(); } } ); -} ); \ No newline at end of file +} ); diff --git a/plugins/tagthisperson/popcorn.tagthisperson.js b/plugins/tagthisperson/popcorn.tagthisperson.js index 0ac95eb..029e500 100644 --- a/plugins/tagthisperson/popcorn.tagthisperson.js +++ b/plugins/tagthisperson/popcorn.tagthisperson.js @@ -1,6 +1,22 @@ // PLUGIN: tagthisperson (function (Popcorn) { + + var peopleArray = []; + // one People object per options.target + var People = function() { + this.name = ""; + this.contains = { }; + this.toString = function() { + var r = []; + for ( var j in this.contains ) { + if ( this.contains.hasOwnProperty( j ) ) { + r.push( " " + this.contains[ j ] ); + } + } + return r.toString(); + }; + }; /** * tagthisperson popcorn plug-in @@ -30,22 +46,6 @@ */ Popcorn.plugin( "tagthisperson" , ( function() { - var peopleArray = []; - // one People object per options.target - var People = function() { - this.name = ""; - this.contains = { }; - this.toString = function() { - var r = []; - for ( var j in this.contains ) { - if ( this.contains.hasOwnProperty( j ) ) { - r.push( " " + this.contains[ j ] ); - } - } - return r.toString(); - }; - }; - return { manifest: { about:{ diff --git a/plugins/twitter/popcorn.twitter.js b/plugins/twitter/popcorn.twitter.js index 5106b3b..8cdfe5e 100644 --- a/plugins/twitter/popcorn.twitter.js +++ b/plugins/twitter/popcorn.twitter.js @@ -146,6 +146,10 @@ */ end: function( event, options ) { options.container.style.display = "none"; + }, + _teardown: function( options ) { + + document.getElementById( options.target ).removeChild( options.container ); } }); diff --git a/plugins/twitter/popcorn.twitter.unit.js b/plugins/twitter/popcorn.twitter.unit.js index 3b6a026..9ec9d7b 100644 --- a/plugins/twitter/popcorn.twitter.unit.js +++ b/plugins/twitter/popcorn.twitter.unit.js @@ -1,8 +1,9 @@ test("Popcorn Twitter Plugin", function () { var popped = Popcorn("#video"), - expects = 6, + expects = 7, count = 0, + setupId, twitterdiv = document.getElementById('twitterdiv'); expect( expects ); @@ -34,7 +35,9 @@ test("Popcorn Twitter Plugin", function () { title: 'Steve Song', src: '@stevesong', target: 'twitterdiv', - } ); + }); + + setupId = popped.getLastTrackEventId(); popped.exec( 1, function() { ok( /display: inline;/.test( twitterdiv.innerHTML ), "Div contents are displayed" ); @@ -46,6 +49,10 @@ test("Popcorn Twitter Plugin", function () { popped.exec( 2, function() { ok( /display: none;/.test( twitterdiv.innerHTML ), "Div contents are hidden again" ); plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !twitterdiv.children[0], "removed twitter was properly destroyed" ); + plus(); }); popped.play(); diff --git a/plugins/webpage/popcorn.webpage.js b/plugins/webpage/popcorn.webpage.js index d37e57f..ecfabda 100644 --- a/plugins/webpage/popcorn.webpage.js +++ b/plugins/webpage/popcorn.webpage.js @@ -76,7 +76,10 @@ end: function(event, options){ // make the iframe invisible options._iframe.style.display = 'none'; + }, + _teardown: function( options ) { + + document.getElementById( options.target ).removeChild( options._iframe ); } - }); })( Popcorn ); diff --git a/plugins/webpage/popcorn.webpage.unit.js b/plugins/webpage/popcorn.webpage.unit.js index 91b4650..beaf6f2 100644 --- a/plugins/webpage/popcorn.webpage.unit.js +++ b/plugins/webpage/popcorn.webpage.unit.js @@ -1,8 +1,9 @@ test("Popcorn Webpage Plugin", function () { var popped = Popcorn("#video"), - expects = 10, + expects = 11, count = 0, + setupId, theiFrame = document.getElementsByTagName('iframe'); expect(expects); @@ -37,6 +38,8 @@ test("Popcorn Webpage Plugin", function () { }) .volume(0); + setupId = popped.getLastTrackEventId(); + popped.exec( 0, function() { ok (!!theiFrame[0], "iframe was created" ); plus(); @@ -48,11 +51,6 @@ test("Popcorn Webpage Plugin", function () { plus(); }); - popped.exec( 2, function() { - ok (theiFrame[0].style.display === 'none' && theiFrame[1].style.display === 'none', "both iframes are hidden" ); - plus(); - }); - popped.exec( 1, function() { ok (!!theiFrame[1], "iframe was created" ); plus(); @@ -62,6 +60,15 @@ test("Popcorn Webpage Plugin", function () { plus(); }); + popped.exec( 2, function() { + ok (theiFrame[0].style.display === 'none' && theiFrame[1].style.display === 'none', "both iframes are hidden" ); + plus(); + + popped.pause().removeTrackEvent( setupId ); + ok( !theiFrame[1], "removed webpage was properly destroyed" ); + plus(); + }); + popped.play(); }); diff --git a/plugins/wikipedia/popcorn.wikipedia.js b/plugins/wikipedia/popcorn.wikipedia.js index e0a50cf..726d368 100644 --- a/plugins/wikipedia/popcorn.wikipedia.js +++ b/plugins/wikipedia/popcorn.wikipedia.js @@ -136,7 +136,6 @@ var wikiCallback; document.getElementById( options.target ).removeChild( options._desc ); } } - }); })( Popcorn ); diff --git a/plugins/wikipedia/popcorn.wikipedia.unit.js b/plugins/wikipedia/popcorn.wikipedia.unit.js index 03b64f9..487f11d 100644 --- a/plugins/wikipedia/popcorn.wikipedia.unit.js +++ b/plugins/wikipedia/popcorn.wikipedia.unit.js @@ -42,9 +42,9 @@ test("Popcorn wikipedia Plugin", function () { plus(); equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" ); plus(); - equals (theArticle.childNodes[0].innerHTML, "this is an article", "wikidiv has the right title" ); + equals (theArticle.children[0].innerHTML, "this is an article", "wikidiv has the right title" ); plus(); - ok (theArticle.childNodes[1].innerHTML !=="", "wikidiv has some content" ); + ok (theArticle.children[1].innerHTML !=="", "wikidiv has some content" ); plus(); }); @@ -58,7 +58,7 @@ test("Popcorn wikipedia Plugin", function () { plus(); equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" ); plus(); - ok (theArticle.childNodes[1].innerHTML !== "", "wikidiv has the right content" ); + ok (theArticle.children[1].innerHTML !== "", "wikidiv has the right content" ); plus(); }); });