From: rwldrn Date: Sat, 26 Mar 2011 14:55:54 +0000 (-0400) Subject: [#459] Fixes tagName property assumption bug introduced by #450 X-Git-Tag: v0.5~38^2^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4834f6b77fb43e95604c0a21e5c47b36d445bd97;p=popcorn-js.git [#459] Fixes tagName property assumption bug introduced by #450 --- diff --git a/popcorn.js b/popcorn.js index e918ad2..73df0f7 100644 --- a/popcorn.js +++ b/popcorn.js @@ -145,8 +145,7 @@ entity; // Create an audio or video element property reference - this[ this.media.tagName.toLowerCase() ] = this.media; - + this[ ( this.media.tagName && this.media.tagName.toLowerCase() ) || "video" ] = this.media; // Register new instance Popcorn.addInstance( this ); diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 36f1872..0f63263 100755 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -1,118 +1,118 @@ module("Popcorn"); test("API", function () { - - var expects = 4, + + var expects = 4, count = 0; - + expect(expects); - + function plus(){ if ( ++count == expects ) start(); } stop( 10000 ); - + try { - + ok( Popcorn, "Popcorn exists"); plus(); - + } catch (e) {}; - - + + try { - + ok( typeof Popcorn === "function", "Popcorn is a function"); plus(); - + } catch (e) {}; - - try { - + + try { + equals( Setup.getGlobalSize(), Setup.globalSize + 1 , "Popcorn API creates only 1 global reference"); plus(); - + } catch (e) {}; - - - try { - - Popcorn(function() { - - ok(1, "Popcorn calls its function argument"); + + + try { + + Popcorn(function() { + + ok(1, "Popcorn calls its function argument"); plus(); - - + + }); - - } catch (e) {}; - + } catch (e) {}; + + }); test("Utility", function () { - + expect(7); // TODO: comprehensive tests for these utilities - + equals( typeof Popcorn.forEach, "function" , "Popcorn.forEach is a provided utility function"); equals( typeof Popcorn.extend, "function" , "Popcorn.extend is a provided utility function"); - equals( typeof Popcorn.error, "function" , "Popcorn.error is a provided utility function"); + equals( typeof Popcorn.error, "function" , "Popcorn.error is a provided utility function"); equals( typeof Popcorn.guid, "function" , "Popcorn.guid is a provided utility function"); equals( typeof Popcorn.sizeOf, "function" , "Popcorn.sizeOf is a provided utility function"); equals( typeof Popcorn.nop, "function" , "Popcorn.nop is a provided utility function"); equals( typeof Popcorn.addTrackEvent, "function" , "Popcorn.addTrackEvent is a provided utility function"); - - - - + + + + }); test("Instances", function() { - var expects = 11, + var expects = 11, count = 0, instance; - + expect(expects); - - function plus(){ + + function plus(){ if ( ++count == expects ) { - start(); - } + start(); + } } stop(); Popcorn("#video"); - + ok( typeof Popcorn.addInstance === "function" , "Popcorn.addInstance is a provided utility function"); plus(); - + ok( typeof Popcorn.removeInstance === "function" , "Popcorn.removeInstance is a provided utility function"); plus(); - + ok( typeof Popcorn.getInstanceById === "function" , "Popcorn.getInstanceById is a provided utility function"); plus(); - ok( typeof Popcorn.removeInstanceById === "function" , "Popcorn.removeInstanceById is a provided utility function"); + ok( typeof Popcorn.removeInstanceById === "function" , "Popcorn.removeInstanceById is a provided utility function"); plus(); - + ok( typeof Popcorn.instanceIds === "object" , "Popcorn.instanceIds is a provided cache object"); plus(); - - ok( "length" in Popcorn.instances && "join" in Popcorn.instances, "Popcorn.instances is a provided cache array"); + + ok( "length" in Popcorn.instances && "join" in Popcorn.instances, "Popcorn.instances is a provided cache array"); plus(); instance = Popcorn.getInstanceById("video"); - + ok( instance.video, "Stored instance as a `video` property" ); plus(); - + ok( instance.data, "Stored instance as a `data` property" ); plus(); - + ok( instance instanceof Popcorn, "Instance instanceof Popcorn" ); plus(); - + equal( Popcorn.instances.length, 2, "There are the correct number of Popcorn instances" ); plus(); @@ -128,52 +128,52 @@ test("Instances", function() { }); test("guid", function () { - + expect(6); - - var count = 3, - guids = [], + + var count = 3, + guids = [], temp; - + for ( var i = 0; i < count; i++ ) { - + temp = Popcorn.guid(); - + if ( i > 0 ) { notEqual( temp, guids[ guids.length - 1 ], "Current guid does not equal last guid" ); } else { ok( temp, "Popcorn.guid() returns value" ); } - + guids.push(temp); } guids = []; - + for ( var i = 0; i < count; i++ ) { - + temp = Popcorn.guid( "pre" ); - + if ( i > 0 ) { notEqual( temp, guids[ guids.length - 1 ], "Current guid does not equal last guid" ); } else { ok( temp, "Popcorn.guid( 'pre' ) returns value" ); } - + guids.push(temp); - } - + } + }); test("Protected", function () { - + expect(1); // TODO: comprehensive tests for these utilities - + ok( !!Popcorn.protect , "Popcorn.protect exists"); - - + + }); @@ -186,18 +186,18 @@ test( "Object", function () { methods = "load play pause currentTime mute volume roundTime exec removePlugin", count = 0, expects = 30; - + expect( expects ); - + function plus() { if ( ++count === expects ) { - start(); + start(); } } - stop( 10000 ); + stop( 10000 ); // testing element passed by id ok( "video" in popped, "instance by id has `video` property" ); @@ -253,13 +253,13 @@ module("Popcorn Methods"); test("roundTime", function () { - + QUnit.reset(); - + var popped = Popcorn("#video"); - + popped.play().pause().currentTime( 0.98 ); - + equals( 1, popped.roundTime(), ".roundTime() returns 1 when currentTime is 0.98s" ); @@ -267,40 +267,40 @@ test("roundTime", function () { test("exec", function () { - + QUnit.reset(); - + var popped = Popcorn("#video"), - expects = 2, - count = 0, - hasLooped = false, + expects = 2, + count = 0, + hasLooped = false, loop = 0; expect( expects + 1 ); - - function plus(){ + + function plus(){ if ( ++count == expects ) { - + setTimeout( function() { equals( loop, expects, "exec callback repeat check, only called twice" ); Popcorn.removePlugin( popped, "exec" ); - start(); + start(); }, 1000 ); } } - - stop( 10000 ); + + stop( 10000 ); popped.exec( 4, function () { ok( loop < 2, "exec callback fired " + ++loop ); plus(); if ( !hasLooped ) { - + popped.currentTime(3).play(); - + hasLooped = true; } }).currentTime(3).play(); @@ -311,51 +311,51 @@ test("exec", function () { module("Popcorn Events"); test("Stored By Type", function () { - + QUnit.reset(); - + expect(6) - - var p = Popcorn("#video"), + + var p = Popcorn("#video"), count = 0, - fired = 0, + fired = 0, wants = 4; - function plus(){ + function plus(){ if ( ++count === 4 ) { - + equals( fired, wants, "Number of callbacks fired from 1 handler" ); p.unlisten("play"); - + ok( !p.data.events["play"], "play handlers removed" ); - + start(); - } + } } - stop( 10000 ); - - + stop( 10000 ); + + p.listen("play", function () { fired++; - + ok(true, "Play fired " + fired); plus(); }); - + p.listen("play", function () { fired++; - ok(true, "Play fired " + fired); + ok(true, "Play fired " + fired); plus(); }); p.listen("play", function () { fired++; - ok(true, "Play fired " + fired); + ok(true, "Play fired " + fired); plus(); }); @@ -365,161 +365,161 @@ test("Stored By Type", function () { ok(true, "Play fired " + fired); plus(); }); - + p.trigger("play"); if (fired < 4) { start(); } - + p.unlisten("play"); - + }); test("Simulated", function () { - + QUnit.reset(); - + var p = Popcorn("#video"), completed = []; - - var expects = Setup.events.length, + + var expects = Setup.events.length, count = 0; expect(expects); - - function plus(){ - if ( ++count == expects ) start(); + + function plus(){ + if ( ++count == expects ) start(); } - - stop( 10000 ); - - + + stop( 10000 ); + + Setup.events.forEach(function ( name ) { p.listen( name, function (event) { - + if ( completed.indexOf(name) === -1 ) { ok(true, name + " fired"); plus(); - + completed.push(name); } - - - }); + + + }); }); Setup.events.forEach(function ( name ) { - p.trigger( name ); + p.trigger( name ); }); - - + + }); test("Real", function () { - + QUnit.reset(); var p = Popcorn("#video"), - completed = []; - - - var expects = 5, + completed = []; + + + var expects = 5, count = 0; - function plus(){ - if ( ++count == expects ) start(); + function plus(){ + if ( ++count == expects ) start(); } - - stop( 10000 ); - - + + stop( 10000 ); + + [ "play", "pause", "volumechange", "seeking", "seeked" ].forEach(function ( name ) { - + p.listen( name, function (event) { - + if ( completed.indexOf(name) === -1 ) { ok(true, name + " fired"); plus(); - + completed.push(name); } - - - }); + + + }); }); - + p.pause(); - + p.play(); - + p.volume(0.9); - + p.currentTime(49); - - + + }); test("Custom", function () { - var expects = 1, + var expects = 1, count = 0; - + expect(expects); - + function plus(){ if ( ++count == expects ) start(); } stop( 10000 ); - + var p = Popcorn("#video"); - - + + p.listen("eventz0rz", function ( event ) { - + ok( true, "Custom event fired" ); plus(); }); - + p.trigger("eventz0rz"); - - + + }); test("UI/Mouse", function () { - var expects = 1, + var expects = 1, count = 0; - + expect(expects); - + function plus(){ if ( ++count == expects ) start(); } stop( 10000 ); - + var p = Popcorn("#video"); - - + + p.listen("click", function ( event ) { - + ok( true, "click event fired" ); plus(); }); - + p.trigger("click"); - - + + }); module("Popcorn Plugin") @@ -527,36 +527,36 @@ test("Manifest", function () { - var p = Popcorn("#video"), + var p = Popcorn("#video"), expects = 5, - run = 1, + run = 1, count = 0; function plus() { if ( ++count === expects ) { - start(); + start(); // clean up added events after tests Popcorn.removePlugin("footnote"); } } - + stop( 10000 ); Popcorn.plugin( "footnote" , function(){ return { _setup: function( options ) { ok( options.target, "`options.target exists`" ); plus(); - + if ( run === 2 ) { equals( options.target, 'custom-target', "Uses custom target if one is specified" ); plus(); - } + } if ( run === 1 ) { equals( options.target, 'text-container', "Uses manifest target by default" ); plus(); - - run++; + + run++; } }, start: function(event, options){ @@ -565,9 +565,9 @@ test("Manifest", function () { end: function(event, options){ } - + }; - + }, { about:{ @@ -579,34 +579,34 @@ test("Manifest", function () { options: { start : { elem:'input', type:'text', label:'In' }, end : { elem:'input', type:'text', label:'Out' }, - text : { elem:'input', type:'text', label:'Manifest Text' }, + text : { elem:'input', type:'text', label:'Manifest Text' }, target : 'text-container' } }); - - + + expect(expects); - + equal( Popcorn.sizeOf( Popcorn.manifest ), 1, "One manifest stored" ); plus(); - + // add more tests - + p.footnote({}); - + p.footnote({ target: "custom-target" }); - - + + }); test("Update Timer", function () { QUnit.reset(); - var p2 = Popcorn("#video"), - expects = 4, + var p2 = Popcorn("#video"), + expects = 4, count = 0, // These make sure events are only fired once // any second call will produce a failed test @@ -617,14 +617,14 @@ test("Update Timer", function () { function plus() { if ( ++count === expects ) { - start(); + start(); // clean up added events after tests Popcorn.removePlugin("forwards"); Popcorn.removePlugin("backwards"); } } - - stop(); + + stop(10000); Popcorn.plugin("forwards", function () { return { @@ -643,7 +643,7 @@ test("Update Timer", function () { }); p2.forwards({ - start: 3, + start: 3, end: 4 }); @@ -664,7 +664,7 @@ test("Update Timer", function () { }); p2.backwards({ - start: 1, + start: 1, end: 2 }); @@ -673,15 +673,15 @@ test("Update Timer", function () { }); test("Plugin Factory", function () { - + QUnit.reset(); - var popped = Popcorn("#video"), + var popped = Popcorn("#video"), methods = "load play pause currentTime mute volume roundTime exec removePlugin", - expects = 34, + expects = 34, count = 0; - function plus() { + function plus() { if ( ++count == expects ) { Popcorn.removePlugin("executor"); Popcorn.removePlugin("complicator"); @@ -693,9 +693,9 @@ test("Plugin Factory", function () { stop( 10000 ); Popcorn.plugin("executor", function () { - + return { - + start: function () { var self = this; @@ -703,7 +703,7 @@ test("Plugin Factory", function () { methods.split(/\s+/g).forEach(function (k,v) { ok( k in self, "executor instance has method: " + k ); - + plus(); }); @@ -719,30 +719,30 @@ test("Plugin Factory", function () { ok( "trackEvents" in this.data, "executor instance has `trackEvents` property" ); plus(); - ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "executor trackEvents property is an object" ) - plus(); - }, + ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "executor trackEvents property is an object" ) + plus(); + }, end: function () { - + } }; }); - + ok( "executor" in popped, "executor plugin is now available to instance" ); plus(); equals( Popcorn.registry.length, 1, "One item in the registry"); - plus(); - - - + plus(); + + + popped.executor({ - start: 1, + start: 1, end: 2 }); Popcorn.plugin("complicator", { - + start: function ( event ) { var self = this; @@ -751,7 +751,7 @@ test("Plugin Factory", function () { methods.split(/\s+/g).forEach(function (k,v) { ok( k in self, "complicator instance has method: " + k ); - + plus(); }); @@ -767,41 +767,41 @@ test("Plugin Factory", function () { ok( "trackEvents" in this.data, " complicatorinstance has `trackEvents` property" ); plus(); - ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" ) - plus(); + ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" ) + plus(); }, end: function () { - + //start(); - - }, + + }, timeupdate: function () { - } + } }); ok( "complicator" in popped, "complicator plugin is now available to instance" ); plus(); equals( Popcorn.registry.length, 2, "Two items in the registry"); plus(); - + popped.complicator({ - start: 3, + start: 3, end: 4 - }); + }); popped.currentTime(0).play(); }); test("Plugin Breaker", function () { - + QUnit.reset(); - var popped = Popcorn("#video"), - expects = 6, + var popped = Popcorn("#video"), + expects = 6, count = 0; - function plus() { + function plus() { if ( ++count == expects ) { Popcorn.removePlugin("breaker"); start(); @@ -812,62 +812,62 @@ test("Plugin Breaker", function () { stop( 10000 ); var breaker = { - - start: 0, + + start: 0, end: 0 - + }; Popcorn.plugin("breaker", { - + start: function () { - + breaker.start++; - + ok(true, "breaker started"); plus(); }, end: function () { - + breaker.end++; - + ok(true, "breaker ended"); plus(); - + equals( breaker.start, 1, "plugin start method fires only once"); plus(); equals( breaker.end, 1, "plugin end method fires only once"); plus(); - - - } + + + } }); ok( "breaker" in popped, "breaker plugin is now available to instance" ); plus(); equals( Popcorn.registry.length, 1, "Three items in the registry"); plus(); - + popped.breaker({ - start: 1, + start: 1, end: 2 - }); + }); popped.currentTime(0).play(); }); test("Plugin Empty", function () { - + QUnit.reset(); - var popped = Popcorn("#video"), + var popped = Popcorn("#video"), expects = 2, testObj = {}, count = 0; - function plus() { + function plus() { if ( ++count == expects ) { Popcorn.removePlugin("empty"); start(); @@ -891,15 +891,15 @@ test("Plugin Empty", function () { }); test("Plugin Closure", function () { - + QUnit.reset(); - var popped = Popcorn("#video"), + var popped = Popcorn("#video"), methods = "load play pause currentTime mute volume roundTime exec removePlugin", - expects = 8, + expects = 8, count = 0; - function plus() { + function plus() { if ( ++count == expects ) { Popcorn.removePlugin("closure"); start(); @@ -929,11 +929,11 @@ test("Plugin Closure", function () { // likewise for endCount equals( endCount++, options.endCount++, options.nick + " has correct end counts" ); plus(); - + // running tracks again to make sure data increments uniquly popped.currentTime(5).play(); } - }; + }; }); popped.closure({ @@ -952,14 +952,14 @@ test("Plugin Closure", function () { }); test("Remove Plugin", function () { - + var p = Popcorn("#video"), p2 = Popcorn("#video"), rlen = Popcorn.registry.length, count = 0, expects = 19, interval; - + function plus() { if ( ++count === expects ) { start(); @@ -979,7 +979,7 @@ test("Remove Plugin", function () { plus(); Popcorn.plugin("removeme", { - + start: function () { }, @@ -991,22 +991,22 @@ test("Remove Plugin", function () { p.removeme({ start: 2, end: 3 - }); + }); p2.removeme({ start: 2, end: 3 }); - + equals( Popcorn.registry.length, 1, "Popcorn.registry.length is 1"); plus(); equals( p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart is updated and has 3 entries"); plus(); equals( p.data.trackEvents.byEnd.length, 3, "p.data.trackEvents.byEnd is updated and has 3 entries"); plus(); - + p.removePlugin("removeme"); - + // p.removeme still exists on the prototype, even though we said to remove it // the tracks of that type though, are removed. // think of it as removing all tracks of plugin type attached to an instance @@ -1030,14 +1030,14 @@ test("Remove Plugin", function () { equals( p.data.trackEvents.byEnd.length, 2, "p.data.trackEvents.byEnd is updated and has 2 entries"); plus(); Popcorn.removePlugin("removeme"); - + ok( !("removeme" in p2), "removeme plugin is no longer available to p2 instance" ); plus(); ok( !("removeme" in Popcorn.prototype), "removeme plugin is no longer available to Popcorn.prototype" ); plus(); equals( Popcorn.registry.length, 0, "Popcorn.registry.length is empty again"); plus(); - + interval = setInterval( function() { if( p2.currentTime() > 3 ) { @@ -1050,7 +1050,7 @@ test("Remove Plugin", function () { } }, 1); p2.currentTime( 2 ).play(); - + }); @@ -1058,7 +1058,7 @@ test("Remove Plugin", function () { test("Protected Names", function () { //QUnit.reset(); - + expect(8); var popped = Popcorn("#video"); @@ -1080,9 +1080,9 @@ test("Functions", function () { // TODO: break this into sep. units per function expect(19); - + var popped = Popcorn("#video"), ffTrackId, rwTrackId, rw2TrackId, rw3TrackId, historyRef, trackEvents; - + Popcorn.plugin("ff", function () { return { @@ -1092,14 +1092,14 @@ test("Functions", function () { }); popped.ff({ - start: 3, + start: 3, end: 4 }); - - + + ffTrackId = popped.getLastTrackEventId(); - - + + Popcorn.plugin("rw", function () { return { @@ -1109,97 +1109,97 @@ test("Functions", function () { }); popped.rw({ - start: 1, + start: 1, end: 2 - }); - - + }); + + rwTrackId = popped.getLastTrackEventId(); - + historyRef = popped.data.history; - - + + equals( historyRef.length, 2, "2 TrackEvents in history index"); equals( popped.data.trackEvents.byStart.length, 4, "4 TrackEvents in popped.data.trackEvents.byStart "); equals( popped.data.trackEvents.byEnd.length, 4, "4 TrackEvents in popped.data.trackEvents.byEnd "); - - + + trackEvents = popped.getTrackEvents(); - + equals( trackEvents.length, 2, "2 user created trackEvents returned by popped.getTrackEvents()" ) - + ok( ffTrackId !== rwTrackId, "Track Events have different ids" ); - + popped.removeTrackEvent( rwTrackId ); - + equals( popped.data.history.length, 1, "1 TrackEvent in history index - after popped.removeTrackEvent( rwTrackId ); "); equals( popped.data.trackEvents.byStart.length, 3, "3 TrackEvents in popped.data.trackEvents.byStart "); - equals( popped.data.trackEvents.byEnd.length, 3, "3 TrackEvents in popped.data.trackEvents.byEnd "); - + equals( popped.data.trackEvents.byEnd.length, 3, "3 TrackEvents in popped.data.trackEvents.byEnd "); + trackEvents = popped.getTrackEvents(); - + equals( trackEvents.length, 1, "1 user created trackEvents returned by popped.getTrackEvents()" ) popped.rw({ - start: 1, + start: 1, end: 2 - }); - - + }); + + rw2TrackId = popped.getLastTrackEventId(); - + equals( popped.data.history.length, 2, "2 TrackEvents in history index - after new track added "); - - + + ok( rw2TrackId !== rwTrackId, "rw2TrackId !== rwTrackId" ); - + equals( popped.data.trackEvents.byStart.length, 4, "4 TrackEvents in popped.data.trackEvents.byStart - after new track added"); - equals( popped.data.trackEvents.byEnd.length, 4, "4 TrackEvents in popped.data.trackEvents.byEnd - after new track added"); - - + equals( popped.data.trackEvents.byEnd.length, 4, "4 TrackEvents in popped.data.trackEvents.byEnd - after new track added"); + + trackEvents = popped.getTrackEvents(); - + equals( trackEvents.length, 2, "2 user created trackEvents returned by popped.getTrackEvents()" ) - - + + popped.rw({ - id: "my-track-id", - start: 3, + id: "my-track-id", + start: 3, end: 10 - }); - + }); + rw3TrackId = popped.getLastTrackEventId(); - + equals( popped.data.history.length, 3, "3 TrackEvents in history index - after new track added "); equals( popped.data.trackEvents.byStart.length, 5, "5 TrackEvents in popped.data.trackEvents.byStart - after new track added"); - equals( popped.data.trackEvents.byEnd.length, 5, "5 TrackEvents in popped.data.trackEvents.byEnd - after new track added"); - + equals( popped.data.trackEvents.byEnd.length, 5, "5 TrackEvents in popped.data.trackEvents.byEnd - after new track added"); + equals( rw3TrackId, "my-track-id", "TrackEvent has user defined id"); - + trackEvents = popped.getTrackEvents(); - - equals( trackEvents.length, 3, "3 user created trackEvents returned by popped.getTrackEvents()" ) - - - + equals( trackEvents.length, 3, "3 user created trackEvents returned by popped.getTrackEvents()" ) + + + + }); test("Index Integrity", function () { - - - + + + var trackLen, hasrun = false, lastrun = false; - - + + Popcorn.plugin("ff", function () { return { start: function () { var div = document.createElement('div'); div.id = "index-test"; div.innerHTML = "foo"; - + document.body.appendChild(div); }, end: function () { @@ -1207,70 +1207,70 @@ test("Index Integrity", function () { } }; }); - - + + var p = Popcorn("#video"); - + p.ff({ id: "removeable-track-event", - start: 40, + start: 40, end: 41 }); - - p.currentTime(40).pause(); - + + p.currentTime(40).pause(); + stop( 10000 ); - + equals(p.data.trackEvents.endIndex, 0, "p.data.trackEvents.endIndex is 0"); equals(p.data.trackEvents.startIndex, 0, "p.data.trackEvents.startIndex is 0"); equals(p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart.length is 3 - before play" ); - - - - + + + + p.listen("timeupdate", function () { - + if ( p.roundTime() > 40 && p.roundTime() < 42 && !hasrun ) { } - + if ( p.roundTime() > 40 && p.roundTime() < 42 && hasrun && !lastrun ) { - + lastrun = true; - + equals( document.getElementById('index-test'), null, "document.getElementById('index-test') is null on second run - after removeTrackEvent" ); - + start(); } - + if ( p.roundTime() >= 42 && !hasrun ) { - + hasrun = true; p.pause(); - + equals(p.data.trackEvents.byStart.length, 3, "p.data.trackEvents.byStart.length is 3 - after play, before removeTrackEvent" ); - equals(p.data.trackEvents.startIndex, 2, "p.data.trackEvents.startIndex is 2 - after play, before removeTrackEvent"); + equals(p.data.trackEvents.startIndex, 2, "p.data.trackEvents.startIndex is 2 - after play, before removeTrackEvent"); equals(p.data.trackEvents.endIndex, 2, "p.data.trackEvents.endIndex is 2 - after play, before removeTrackEvent"); - - + + p.removeTrackEvent("removeable-track-event"); - + equals(p.data.trackEvents.byStart.length, 2, "p.data.trackEvents.byStart.length is 2 - after removeTrackEvent" ); equals(p.data.trackEvents.startIndex, 1, "p.data.trackEvents.startIndex is 1 - after removeTrackEvent"); equals(p.data.trackEvents.endIndex, 1, "p.data.trackEvents.endIndex is 1 - after removeTrackEvent"); - - - + + + p.currentTime(40).play(); - - - + + + } }); - + p.play(); - + }); @@ -1281,70 +1281,70 @@ test("Index Integrity", function () { module("Popcorn XHR"); test("Basic", function () { - + expect(2); - + equals( typeof Popcorn.xhr, "function" , "Popcorn.xhr is a provided utility function"); equals( typeof Popcorn.xhr.httpData, "function" , "Popcorn.xhr.httpData is a provided utility function"); - + }); test("Text Response", function () { - var expects = 2, + var expects = 2, count = 0; - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop() Popcorn.xhr({ - url: 'data/test.txt', + url: 'data/test.txt', success: function( data ) { - + ok(data, "xhr returns data"); plus(); - + equals( data.text, "This is a text test", "test.txt returns the string 'This is a text test'"); plus(); - + } }); }); test("dataType: Text Response", function () { - var expects = 2, + var expects = 2, count = 0; - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop() Popcorn.xhr({ - url: 'data/test.txt', + url: 'data/test.txt', dataType: "text", success: function( data ) { - + ok(data, "xhr returns data"); plus(); - + equals( data, "This is a text test", "dataType: 'text', test.txt returns the string 'This is a text test'"); plus(); - + } }); }); @@ -1352,33 +1352,33 @@ test("dataType: Text Response", function () { test("JSON Response", function () { - var expects = 2, + var expects = 2, count = 0; - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop() - var testObj = { "data": {"lang": "en", "length": 25} }; + var testObj = { "data": {"lang": "en", "length": 25} }; Popcorn.xhr({ - url: 'data/test.js', + url: 'data/test.js', success: function( data ) { - + ok(data, "xhr returns data"); plus(); - - + + ok( QUnit.equiv(data.json, testObj) , "data.json returns an object of data"); plus(); - + } }); @@ -1386,34 +1386,34 @@ test("JSON Response", function () { test("dataType: JSON Response", function () { - var expects = 2, + var expects = 2, count = 0; - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop() - var testObj = { "data": {"lang": "en", "length": 25} }; + var testObj = { "data": {"lang": "en", "length": 25} }; Popcorn.xhr({ - url: 'data/test.js', + url: 'data/test.js', dataType: "json", success: function( data ) { - + ok(data, "xhr returns data"); plus(); - - + + ok( QUnit.equiv(data, testObj) , "dataType: 'json', data returns an object of data"); plus(); - + } }); @@ -1424,7 +1424,7 @@ if ( !/file/.test( location.protocol ) ) { test("JSONP Response", function () { - var expects = 8, + var expects = 8, count = 0; function plus() { @@ -1438,12 +1438,12 @@ if ( !/file/.test( location.protocol ) ) { stop(10000); - var testObj = { "data": {"lang": "en", "length": 25} }; + var testObj = { "data": {"lang": "en", "length": 25} }; Popcorn.xhr({ url: 'data/jsonp.php?callback=jsonp', - dataType: 'jsonp', + dataType: 'jsonp', success: function( data ) { ok(data, "getJSONP returns data"); @@ -1483,11 +1483,11 @@ if ( !/file/.test( location.protocol ) ) { plus(); equal( typeof data, "object", "getJSONP returns flickr data"); - plus(); + plus(); } - ); + ); Popcorn.getJSONP( 'data/jsonp.php?callback=jsonp', @@ -1503,7 +1503,7 @@ if ( !/file/.test( location.protocol ) ) { plus(); } - ); + ); }); } else { @@ -1520,100 +1520,100 @@ if ( !/file/.test( location.protocol ) ) { test("Popcorn.getScript()", function () { - var expects = 8, + var expects = 8, count = 0; - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop(); Popcorn.xhr({ - + url: "data/remoteA.js", - - dataType: "script", - + + dataType: "script", + success: function() { - + ok( true, "getScript A returned"); plus(); - - - + + + ok( Popcorn.AlphaLib, "Popcorn.xhr.getScript remoteA.js loaded: `Popcorn.AlphaLib` is available"); plus(); - + } }); Popcorn.getScript( - - "data/remoteB.js", - + + "data/remoteB.js", + function() { - + ok( true, "getScript B returned"); plus(); - + ok( Popcorn.BetaLib , "Popcorn.getScript remoteB.js loaded: `Popcorn.BetaLib` is available "); plus(); - + } ); Popcorn.getScript( - - "https://github.com/rwldrn/has.js/raw/master/has.js", - + + "https://github.com/rwldrn/has.js/raw/master/has.js", + function() { - + ok( true, "getScript C returned"); plus(); - + ok( ("has" in window) , "Popcorn.getScript https://github.com/rwldrn/has.js/raw/master/has.js loaded: `has` is available"); plus(); - - + + delete window["has"]; } ); - + Popcorn.xhr({ - + url: "data/remoteA.js", - - dataType: "script", - + + dataType: "script", + success: function( exists ) { - + ok( exists, "Success, remoteA loaded once"); plus() } }); Popcorn.getScript( - - "data/remoteB.js", - + + "data/remoteB.js", + function( exists ) { - + ok( exists, "Success, remoteB loaded once"); plus() - + } - ); + ); }); @@ -1621,34 +1621,34 @@ test("Popcorn.getScript()", function () { test("XML Response", function () { - var expects = 2, + var expects = 2, count = 0; - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop() Popcorn.xhr({ - url: 'data/test.xml', + url: 'data/test.xml', success: function( data ) { - + ok(data, "xhr returns data"); plus(); - - var parser = new DOMParser(), + + var parser = new DOMParser(), xml = parser.parseFromString(' ',"text/xml"); - - + + equals( data.xml.toString(), xml.toString(), "data.xml returns a document of xml"); plus(); - + } }); @@ -1656,35 +1656,35 @@ test("XML Response", function () { test("dataType: XML Response", function () { - var expects = 2, + var expects = 2, count = 0; - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop() Popcorn.xhr({ - url: 'data/test.xml', + url: 'data/test.xml', dataType: "xml", success: function( data ) { - + ok(data, "xhr returns data"); plus(); - - var parser = new DOMParser(), + + var parser = new DOMParser(), xml = parser.parseFromString(' ',"text/xml"); - - + + equals( data.toString(), xml.toString(), "dataType: 'xml', data.xml returns a document of xml"); plus(); - + } }); @@ -1699,15 +1699,15 @@ test("Parsing Functions", function () { var expects = 3, count = 0, popperly = Popcorn("#video"); - + function plus() { if ( ++count === expects ) { start(); } } - + expect(expects); - + stop( 10000 ); ok(typeof Popcorn.parser === "function", "Popcorn.parser is a function"); @@ -1731,7 +1731,7 @@ test("Parsing Integrity", function () { count = 0, timeOut = 0, poppercore = Popcorn( "#video" ); - + function plus() { if ( ++count === expects ) { start(); @@ -1757,7 +1757,7 @@ test("Parsing Integrity", function () { }); Popcorn.plugin("parserTest", { - + start: function () { ok(true, "parserTest started"); plus(); @@ -1769,7 +1769,7 @@ test("Parsing Integrity", function () { }); poppercore.parseJSON2("data/parserData.json", function() { - + poppercore.parseJSON3("data/parserData.json", function() { poppercore.currentTime(5).play(); }); @@ -1786,7 +1786,7 @@ test("Parsing Handler - References unavailable plugin", function () { timeOut = 0, interval, poppercore = Popcorn( "#video" ); - + function plus() { if ( ++count === expects ) { start(); @@ -1795,13 +1795,13 @@ test("Parsing Handler - References unavailable plugin", function () { poppercore.removePlugin( "parserTest" ); } } - + expect(expects); - + stop(); Popcorn.parser( "parseJson", function( data ){ - + return data.json; }); @@ -1810,12 +1810,12 @@ test("Parsing Handler - References unavailable plugin", function () { // interval used to wait for data to be parsed interval = setInterval( function() { poppercore.currentTime(5).play().currentTime(6); - + ok( true, "Ignored call to missing plugin " ); plus(); - + }, 2000); - + }); module("Audio"); @@ -1826,18 +1826,18 @@ test( "Basic Audio Support", function () { methods = "load play pause currentTime mute volume roundTime exec removePlugin", count = 0, expects = 30; - + expect( expects ); - + function plus() { if ( ++count === expects ) { - start(); + start(); } } - stop( 10000 ); + stop( 10000 ); // testing element passed by id ok( "audio" in popped, "instance by id has `media` property" ); @@ -1909,7 +1909,7 @@ test("Parser Support", function () { Popcorn.plugin("testAudioParser", { - + start: function() { ok(true, "testAudioParser started: " + Math.round(this.currentTime()) ); plus(); @@ -1936,17 +1936,17 @@ test("Parser Support", function () { module("Popcorn Test Runner End"); test("Last Check", function () { - + // ALWAYS RUN LAST - try { - + try { + equals( Setup.getGlobalSize(), Setup.globalSize + 1 , "Popcorn API did not leak"); - + if ( !Setup.globalDiff.length ) { //console.log(Setup.globalDiff); } - + } catch (e) {}; - + });