From: Rick Waldron Date: Tue, 7 Dec 2010 17:50:23 +0000 (-0500) Subject: [#200] Ensure Plugin definition context is always Popcorn object X-Git-Tag: v0.2~56^2~7 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=5c4c6e8e037bbd2f5dee294e0f013516b135ab4c;p=popcorn-js.git [#200] Ensure Plugin definition context is always Popcorn object --- diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 8b3d31e..a3a85e9 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -350,51 +350,28 @@ test("Plugin API", function () { // needs expectation var popped = Popcorn("#video"), - methods = "load play pause currentTime mute volume"; - - - stop(); + methods = "load play pause currentTime mute volume roundTime exec", + expects = 21, + count = 0; + expect(expects); - Popcorn.plugin("subtitles", function () { - - var self = this; - - // These ensure that a popcorn instance is the value of `this` inside a plugin definition - - methods.split(/\s+/g).forEach(function (k,v) { - ok( k in self, "instance has method: " + k ); - }); - - ok( "video" in this, "instance has `video` property" ); - ok( Object.prototype.toString.call(popped.video) === "[object HTMLVideoElement]", "video property is a HTMLVideoElement" ); - - ok( "data" in this, "instance has `data` property" ); - ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" ); + function plus() { + if ( ++count == expects ) { + start(); + } + } - ok( "tracks" in this.data, "instance has `tracks` property" ); - ok( Object.prototype.toString.call(popped.data.tracks) === "[object Array]", "tracks property is an array" ) - }); - - - // Call plugin to test scope within - popped.subtitles(); - - - - ok( "subtitles" in popped, "subtitles plugin is now available to instance" ); - ok( Popcorn.registry.length === 1, "One item in the registry"); - - - - + stop(); + Popcorn.plugin("complicator", { start: function ( event ) { - + equals( ~~this.currentTime(), 1, "~~this.currentTime() === 1"); + plus(); var self = this; @@ -402,16 +379,24 @@ test("Plugin API", function () { methods.split(/\s+/g).forEach(function (k,v) { ok( k in self, "instance has method: " + k ); + + plus(); }); ok( "video" in this, "instance has `video` property" ); + plus(); ok( Object.prototype.toString.call(popped.video) === "[object HTMLVideoElement]", "video property is a HTMLVideoElement" ); + plus(); ok( "data" in this, "instance has `data` property" ); + plus(); ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" ); + plus(); ok( "tracks" in this.data, "instance has `tracks` property" ); + plus(); ok( Object.prototype.toString.call(popped.data.tracks) === "[object Array]", "tracks property is an array" ) + plus(); }, end: function () { @@ -425,18 +410,22 @@ test("Plugin API", function () { ok( "complicator" in popped, "complicator plugin is now available to instance" ); - ok( Popcorn.registry.length === 2, "Two items in the registry"); + plus(); + ok( Popcorn.registry.length === 1, "Two items in the registry"); + plus(); + - popped.currentTime(0); popped.complicator({ start: 1, - end: 2 + end: 20 }); + popped.currentTime(0).play(); + var breaker = { start: 0, @@ -451,16 +440,22 @@ test("Plugin API", function () { breaker.start++; ok(true, "plugin:breaker started"); + plus(); }, end: function () { breaker.end++; ok(true, "plugin:ended started"); - start(); + plus(); + equals( 1, breaker.start, "plugin start method fires only once"); + plus(); equals( 1, breaker.end, "plugin end method fires only once"); + plus(); + + start() } }); @@ -566,4 +561,4 @@ test("wait()", function () { }); -*/ \ No newline at end of file +*/