});
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,
- count = 0;
+ expects = 80, // 15*2+16*2+6+12. executor/complicator each do 15
+ count = 0;
- function plus() {
+ function plus() {
if ( ++count == expects ) {
Popcorn.removePlugin("executor");
Popcorn.removePlugin("complicator");
}
expect( expects );
- stop( 10000 );
+ stop( 15000 );
Popcorn.plugin("executor", function () {
-
+
return {
-
+
start: function () {
var self = this;
};
});
-
+
+ Popcorn.pluginInherit("executor_inherits", "executor", function (options) {
+ return {
+ start: function() { ok(true, "child class method executed"); plus(); }
+ };
+ });
+
ok( "executor" in popped, "executor plugin is now available to instance" );
plus();
- equals( Popcorn.registry.length, 1, "One item in the registry");
+ ok( "executor_inherits" in popped, "executor-inerits plugin is now available to instance" );
+ plus();
+ equals( Popcorn.registry.length, 2, "One item in the registry");
plus();
-
-
popped.executor({
- start: 1,
+ start: 1,
end: 2
});
+ popped.executor_inherits({
+ start: 2,
+ end: 3
+ });
Popcorn.plugin("complicator", {
-
+
start: function ( event ) {
var self = this;
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 () {
- }
+ }
});
+ Popcorn.pluginInherit("complicator_inherits", "executor", {
+ start: function() { ok(true, "child class method executed"); plus(); }
+ });
+
ok( "complicator" in popped, "complicator plugin is now available to instance" );
plus();
- equals( Popcorn.registry.length, 2, "Two items in the registry");
+ ok( "complicator_inherits" in popped, "complicator plugin is now available to instance" );
+ plus();
+ equals( Popcorn.registry.length, 4, "Two items in the registry");
plus();
-
+
popped.complicator({
- start: 3,
- end: 4
+ start: 4,
+ end: 5
+ });
+ popped.complicator_inherits({
+ start: 5,
+ end: 6
+ });
+
+ var counts = { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0 };
+ Popcorn.plugin("A", function(options) {
+ return { start: function() { counts.a++; } };
+ });
+ Popcorn.plugin("B", function(options) {
+ return { start: function() { counts.b++; } };
});
+ Popcorn.pluginInherit("C", "B", function(options) {
+ return { start: function() { counts.c++; } };
+ });
+ Popcorn.pluginInherit("D", ["A", "B"], function(options) {
+ return { start: function() { counts.d++; } };
+ });
+ Popcorn.pluginInherit("E", ["B"], function(options) {
+ return { start: function() { counts.e++; } };
+ });
+ Popcorn.pluginInherit("F", ["E", "C"], function(options) {
+ return { start: function() { counts.f++; } };
+ });
+
+ equals(counts.a, 0, "plugin A should not have been run yet");
+ plus();
+ equals(counts.b, 0, "plugin B should not have been run yet");
+ plus();
+ equals(counts.c, 0, "plugin C should not have been run yet");
+ plus();
+ equals(counts.d, 0, "plugin D should not have been run yet");
+ plus();
+ equals(counts.e, 0, "plugin E should not have been run yet");
+ plus();
+ equals(counts.f, 0, "plugin F should not have been run yet");
+ plus();
+
+ popped.C({ start: 6, end: 7 });
+ popped.D({ start: 7, end: 8 });
+ popped.F({ start: 8, end: 9 });
+
+ setTimeout(function() {
+ equals(counts.a, 1, "plugin A should have been run once");
+ plus();
+ equals(counts.b, 3, "plugin B should have been run thrice");
+ plus();
+ equals(counts.c, 2, "plugin C should have been run twice");
+ plus();
+ equals(counts.d, 1, "plugin D should have been run once");
+ plus();
+ equals(counts.e, 1, "plugin E should have been run once");
+ plus();
+ equals(counts.f, 1, "plugin F should have been run once");
+ plus();
+ }, 10000);
popped.currentTime(0).play();