From 2e6b415c499d1a5e6fed42534f40414e520cfe88 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Wed, 21 Sep 2011 16:11:10 -0400 Subject: [PATCH] [#729] Adds in cadecairos' tests from #t705 --- popcorn.js | 2 +- test/popcorn.unit.js | 58 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/popcorn.js b/popcorn.js index b0e9e0a..2e4e9ea 100644 --- a/popcorn.js +++ b/popcorn.js @@ -422,7 +422,7 @@ // Support for shorthanded play(n)/pause(n) jump to currentTime // If arg is not null or undefined and called by one of the // allowed shorthandable methods, then set the currentTime - // Supports time as seconds or SMPTE + // Supports time as seconds or SMPTE if ( arg != null && /play|pause/.test( name ) ) { this.media.currentTime = Popcorn.util.toSeconds( arg ); } diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 61b9a86..55a5e9a 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -601,7 +601,7 @@ test("mute", function() { }); -test("play(n) as shorthand to currentTime(n).play()", function() { +test( "play(n)/pause(n) as shorthand to currentTime(n).play()/pause()", function() { var $pop = Popcorn( "#video" ), expects = 2, @@ -641,6 +641,58 @@ test("play(n) as shorthand to currentTime(n).play()", function() { poll(); }); +// Originally written for #705 by chris de cairos +test( "play(n)/pause(n) custom stop()", function() { + + // Implement custom stop() method + Popcorn.p.stop = function() { + return this.pause( 0 ); + }; + + var outerHTML = document.getElementById("video").outerHTML, + count = 0, + expects = 2, + $pop; + + document.getElementById("qunit-fixture").innerHTML = outerHTML.replace('id="video"', 'id="video-fixture"'); + + $pop = Popcorn( "#video-fixture" ); + + expect( expects ); + + function plus() { + if ( ++count === expects ) { + // Remove custom stop() method + delete Popcorn.p.stop; + start(); + } + } + + stop( 8000 ); + + $pop.listen( "canplayall", function() { + + this.exec( 4, function() { + + this.listen( "seeked", function() { + + this.unlisten( "seeked" ); + + equal( this.currentTime(), 0, "currentTime is 0" ); + plus(); + + equal( this.media.paused, true, "The media is paused" ); + plus(); + + // Call custom "stop()" + }).stop(); + }); + + // Play from 3s + this.play( 3 ); + }); +}); + module("Popcorn Static Methods"); @@ -1591,7 +1643,7 @@ test("Update Timer (timeupdate)", function() { Popcorn.removePlugin( "forwards" ); Popcorn.removePlugin( "backwards" ); Popcorn.removePlugin( "wrapper" ); - p2.removePlugin( "exec" ); + p2.removePlugin( "exec" ); // TODO: David, remove this during test suite cleanup ^RW start(); } } @@ -1759,7 +1811,7 @@ test("Update Timer (frameAnimation)", function() { Popcorn.removePlugin( "forwards" ); Popcorn.removePlugin( "backwards" ); Popcorn.removePlugin( "wrapper" ); - p2.removePlugin( "exec" ); + p2.removePlugin( "exec" ); // TODO: David, remove this during test suite cleanup ^RW start(); } } -- 2.43.0