]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#178] Renaming files in /test
authorrwldrn <waldron.rick@gmail.com>
Sun, 5 Dec 2010 15:30:13 +0000 (10:30 -0500)
committerrwldrn <waldron.rick@gmail.com>
Sun, 5 Dec 2010 15:30:13 +0000 (10:30 -0500)
test/index.html
test/popcorn.unit.js [new file with mode: 0644]
test/popcorn.unit.setup.js [new file with mode: 0644]

index 77f12bc8ee47050c22e7b4e088babd6ab08a5a8c..8255c32536006026b5e8c2f29b2a89ae14d20163 100644 (file)
@@ -9,10 +9,10 @@
     do not move - this must be called immediately prior to 
     popcorn-api-draft.js
   -->
-  <script src="popcorn-api-draft-unit-setup.js"></script>
+  <script src="popcorn.unit.setup.js"></script>
   
   <script src="../popcorn.js"></script>
-  <script src="popcorn-api-draft-unit.js"></script>
+  <script src="popcorn.unit.js"></script>
 </head>
 <body>
   <h1 id="qunit-header">Popcorn API</h1>
diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js
new file mode 100644 (file)
index 0000000..d13c5ac
--- /dev/null
@@ -0,0 +1,332 @@
+test("Popcorn API", function () {
+  
+  var expects = 3, 
+      count = 0;
+  
+  expect(expects);
+  
+  function plus(){ if ( ++count == expects ) start(); }
+
+  stop();
+
+  
+  try {
+    
+    ok( Popcorn, "Popcorn exists");
+    plus();
+    
+  } catch (e) {};
+    
+  
+  try {
+    
+    ok( typeof Popcorn === "function", "Popcorn is a function");
+    plus();
+    
+  } catch (e) {};
+  
+  try {  
+    
+    equals( Setup.getGlobalSize(), Setup.globalSize + 1 , "Popcorn API creates only 1 global reference");
+    plus();
+    
+  } catch (e) {};
+
+  
+});
+
+test("Popcorn Utility", function () {
+  
+  equals( typeof Popcorn.forEach, "function" , "Popcorn.forEach is a provided utility function");
+  equals( typeof Popcorn.extend, "function" , "Popcorn.extend is a provided utility function");
+
+});
+
+
+test("Popcorn Object", function () {
+
+  
+  var popped = Popcorn("#video"), 
+      methods = "load play pause currentTime mute volume";
+  
+  //console.log(popped);
+  
+  popped.play();
+
+  methods.split(/\s+/g).forEach(function (k,v) {
+
+    ok( k in popped, "instance has method: " + k );
+
+  });
+
+  ok( "video" in popped, "instance has `video` property" );
+  ok( Object.prototype.toString.call(popped.video) === "[object HTMLVideoElement]", "video property is a HTMLVideoElement" );
+
+  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 Array]", "tracks property is an array" )
+  
+});
+
+
+test("Popcorn Events Stored By Type", function () {
+  
+  QUnit.reset();
+  
+  expect(6)
+  
+  var p = Popcorn("#video"), 
+      count = 0,
+      fired = 0, 
+      wants = 4
+      ;
+
+  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();  
+  
+  
+  p.listen("play", function () {
+    fired++;
+    
+    ok(true, "Play fired " + fired);
+    plus();
+  });
+      
+  p.listen("play", function () {
+    fired++;
+
+    ok(true, "Play fired " + fired);    
+    plus();
+  });
+
+  p.listen("play", function () {
+    fired++;
+
+    ok(true, "Play fired " + fired);    
+    plus();
+  });
+
+  p.listen("play", function () {
+    fired++;
+
+    ok(true, "Play fired " + fired);
+    plus();
+  });
+  
+  p.trigger("play");
+  
+  p.unlisten("play");
+  
+});
+
+
+test("Popcorn Events Simulated", function () {
+  
+  QUnit.reset();
+  
+  var p = Popcorn("#video"),
+      completed = [], 
+      eventtest = "loadstart progress suspend emptied stalled play pause " + 
+                  "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
+                  "seeking seeked timeupdate ended ratechange durationchange volumechange", 
+      events = eventtest.split(/\s+/g);                              
+
+  
+  var expects = events.length, 
+      count = 0;
+
+  expect(expects);
+  
+  function plus(){ 
+    if ( ++count == expects ) start(); 
+  }
+  
+  stop();  
+  
+  
+  events.forEach(function ( name ) {
+    p.listen( name, function (event) {
+      
+      if ( completed.indexOf(name) === -1 ) {
+        ok(true, name + " fired");
+        plus();
+        
+        completed.push(name);
+      }
+      
+      
+    });  
+  });
+
+  events.forEach(function ( name ) {
+    p.trigger( name );  
+  });
+  
+  
+});
+
+
+test("Popcorn Events Real", function () {
+  
+  QUnit.reset();
+
+  var p = Popcorn("#video"),
+      completed = [], 
+      eventtest = "loadstart progress suspend emptied stalled play pause " + 
+                        "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
+                        "seeking seeked timeupdate ended ratechange durationchange volumechange", 
+      events = eventtest.split(/\s+/g);                              
+  
+  
+  var expects = 11, 
+      count = 0;
+
+  //expect(expects);
+  // not in full use
+  function plus(){ 
+    if ( ++count == expects ) start(); 
+  }
+  
+  stop();  
+  
+  
+  events.forEach(function ( name ) {
+    p.listen( name, function (event) {
+      
+      if ( completed.indexOf(name) === -1 ) {
+        ok(true, name + " fired");
+        plus();
+        
+        completed.push(name);
+      }
+      
+      
+    });  
+  });
+
+
+  
+  p.pause();
+  
+  p.mute(true);
+  
+  p.play();
+  
+  p.volume(0.9);
+  
+  p.currentTime(49);
+
+  
+  
+});
+
+test("Popcorn Plugin", function () {
+  
+  QUnit.reset();
+  
+  // needs expectation
+
+  var popped = Popcorn("#video"), 
+      methods = "load play pause currentTime mute volume";
+      
+  
+  stop();
+  
+  
+  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" );
+
+    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");
+  
+  
+  
+  
+  
+  Popcorn.plugin("complicator", {
+    
+    start: function ( event ) {
+      
+      
+      equals( ~~this.currentTime(), 1, "~~this.currentTime() === 1");
+      
+      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" );
+
+      ok( "tracks" in this.data, "instance has `tracks` property" );
+      ok( Object.prototype.toString.call(popped.data.tracks) === "[object Array]", "tracks property is an array" )      
+      
+    },
+    end: function () {
+    
+      start();
+    
+    }, 
+    timeupdate: function () {
+    }    
+  });
+  
+  
+  ok( "complicator" in popped, "complicator plugin is now available to instance" );
+  ok( Popcorn.registry.length === 2, "Two items in the registry");
+  
+  
+  
+  popped.currentTime(0);
+  
+  popped.complicator({
+    start: 1, 
+    end: 2
+  });  
+  
+  
+});
\ No newline at end of file
diff --git a/test/popcorn.unit.setup.js b/test/popcorn.unit.setup.js
new file mode 100644 (file)
index 0000000..5999b04
--- /dev/null
@@ -0,0 +1,37 @@
+
+(function (global) { 
+  
+  //  Store the number of global properties that exist prior to Popcorn API definition
+  
+  var Setup = {
+    globalSize: 0
+  };
+
+  Setup.getGlobalSize = function() {
+
+    var size = 0;
+
+    for( var p in window ) {
+      if ( p !== "_firebug" ) {
+        size++;
+      }
+    }
+
+    //  account for self
+    size++;
+    
+    //  Store the number of global properties internally
+    if ( !Setup.globalSize ) {
+      Setup.globalSize = size;
+    }
+
+    return size;
+  };
+  
+  
+  global.Setup = Setup;
+
+})(window);
+
+
+Setup.getGlobalSize();
\ No newline at end of file