tests for update forwards and backwards, initial removePlugin

This commit is contained in:
ScottDowne 2010-12-13 14:46:29 -05:00
Родитель ae5121d8c4
Коммит 1d37cb0d8a
2 изменённых файлов: 114 добавлений и 22 удалений

Просмотреть файл

@ -6,6 +6,9 @@
hasOwn = Object.prototype.hasOwnProperty,
slice = Array.prototype.slice,
// intentionally left undefined
undef,
// ID string matching
rIdExp = /^(#([\w\-\_\.]+))$/,
@ -34,7 +37,7 @@
this.data = {
events: {},
tracks: {
trackEvents: {
byStart: [{start: -1, end: -1}],
byEnd: [{start: -1, end: -1}],
startIndex: 0,
@ -50,13 +53,13 @@
// this is so we do not fall off either end
var videoDurationPlus = that.video.duration + 1;
Popcorn.addTrack(that, {start: videoDurationPlus, end: videoDurationPlus});
Popcorn.addTrackEvent(that, {start: videoDurationPlus, end: videoDurationPlus});
that.video.addEventListener( "timeupdate", function( event ) {
var currentTime = this.currentTime,
previousTime = that.data.tracks.previousUpdateTime
tracks = that.data.tracks,
previousTime = that.data.trackEvents.previousUpdateTime
tracks = that.data.trackEvents,
tracksByEnd = tracks.byEnd,
tracksByStart = tracks.byStart;
@ -155,15 +158,15 @@
return dest;
};
Popcorn.addTrack = function( obj, track ) {
Popcorn.addTrackEvent = function( obj, track ) {
console.log(obj);
// Store this definition in an array sorted by times
obj.data.tracks.byStart.push( track );
obj.data.tracks.byEnd.push( track );
obj.data.tracks.byStart.sort( function( a, b ){
obj.data.trackEvents.byStart.push( track );
obj.data.trackEvents.byEnd.push( track );
obj.data.trackEvents.byStart.sort( function( a, b ){
return ( a.start - b.start );
});
obj.data.tracks.byEnd.sort( function( a, b ){
obj.data.trackEvents.byEnd.sort( function( a, b ){
return ( a.end - b.end );
});
};
@ -357,7 +360,6 @@
this.video.addEventListener( type, function( event ) {
Popcorn.forEach( self.data.events[type], function ( obj, key ) {
if ( typeof obj === "function" ) {
obj.call(self, event);
}
@ -385,12 +387,30 @@
play: function () {
// renders all of the interally stored track commands
}
},
removePlugin: function( name ) {
this[name] = undef;
// remove plugin reference from registry
for (var i = 0, rl = Popcorn.registry.length; i < rl; i++) {
if (Popcorn.registry[i].type === name) {
Popcorn.registry.splice(i, 1);
break; // plugin found, stop checking
}
}
// remove all trackEvents
for (var trackEvent in this.data.trackEvents) {
// still working on this, need to clear tracks, failing one test because of it
}
}
}
};
// Extend listen and trigger to all Popcorn instances
Popcorn.forEach( ["trigger", "listen", "unlisten"], function ( key ) {
Popcorn.forEach( ["trigger", "listen", "unlisten", "removePlugin"], function ( key ) {
Popcorn.p[key] = Popcorn.events.fn[key];
});
@ -415,7 +435,7 @@
var natives = Popcorn.events.all,
reserved = [ "start", "end"],
plugin = {},
plugin = {type: name},
pluginFn,
setup;
@ -455,7 +475,7 @@
}
Popcorn.addTrack( this, options );
Popcorn.addTrackEvent( this, options );
// Future support for plugin event definitions

Просмотреть файл

@ -39,7 +39,7 @@ test("API", function () {
test("Utility", function () {
expect(6);
expect(7);
// TODO: comprehensive tests for these utilities
equals( typeof Popcorn.forEach, "function" , "Popcorn.forEach is a provided utility function");
@ -48,6 +48,7 @@ test("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");
@ -82,8 +83,8 @@ test("Object", function () {
ok( "data" in popped, "instance has `data` property" );
ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
ok( "tracks" in popped.data, "instance has `tracks` property" );
ok( Object.prototype.toString.call(popped.data.tracks) === "[object Object]", "tracks property is an object" )
ok( "trackEvents" in popped.data, "instance has `trackEvents` property" );
ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "trackEvents property is an object" )
popped.play();
@ -158,8 +159,7 @@ test("Stored By Type", function () {
var p = Popcorn("#video"),
count = 0,
fired = 0,
wants = 4
;
wants = 4;
function plus(){
@ -365,6 +365,78 @@ test("UI/Mouse", function () {
});
module("Popcorn Plugin")
test("Update Timer", function () {
QUnit.reset();
var p2 = Popcorn("#video"),
expects = 4,
count = 0,
// These make sure events are only fired once
// any second call will produce a failed test
forwardStart = false,
forwardEnd = false,
backwardStart = false,
backwardEnd = false;
function plus() {
if ( ++count === expects ) {
start();
// clean up added events after tests
p2.removePlugin("forwards");
p2.removePlugin("backwards");
}
}
stop();
Popcorn.plugin("forwards", function () {
return {
start: function () {
forwardStart = !forwardStart;
ok( forwardStart, "forward's start fired");
plus();
},
end: function () {
forwardEnd = !forwardEnd;
p2.currentTime(1).play();
ok( forwardEnd, "forward's end fired");
plus();
}
};
});
p2.forwards({
start: 3,
end: 4
});
Popcorn.plugin("backwards", function () {
return {
start: function () {
backwardStart = !backwardStart;
p2.currentTime(0).play();
ok( true, "backward's start fired");
plus();
},
end: function () {
backwardEnd = !backwardEnd;
ok( backwardEnd, "backward's end fired");
plus();
}
};
});
p2.backwards({
start: 1,
end: 2
});
p2.currentTime(3).play();
});
test("Plugin Factory", function () {
QUnit.reset();
@ -412,9 +484,9 @@ test("Plugin Factory", function () {
ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
plus();
ok( "tracks" in this.data, "executor instance has `tracks` property" );
ok( "trackEvents" in this.data, "executor instance has `trackEvents` property" );
plus();
ok( Object.prototype.toString.call(popped.data.tracks) === "[object Object]", "executor tracks property is an object" )
ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "executor trackEvents property is an object" )
plus();
},
end: function () {
@ -461,9 +533,9 @@ test("Plugin Factory", function () {
ok( Object.prototype.toString.call(popped.data) === "[object Object]", "complicator data property is an object" );
plus();
ok( "tracks" in this.data, " complicatorinstance has `tracks` property" );
ok( "trackEvents" in this.data, " complicatorinstance has `trackEvents` property" );
plus();
ok( Object.prototype.toString.call(popped.data.tracks) === "[object Object]", "complicator tracks property is an object" )
ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" )
plus();
},
end: function () {