]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Converted test to use qunit.
authorsecretrobotron <secretrobotron@gmail.com>
Thu, 17 Mar 2011 20:36:41 +0000 (16:36 -0400)
committersecretrobotron <secretrobotron@gmail.com>
Thu, 17 Mar 2011 20:36:41 +0000 (16:36 -0400)
Fixed a couple of manifest tests.

test/butter.unit.js [new file with mode: 0644]
test/butter_test.html

diff --git a/test/butter.unit.js b/test/butter.unit.js
new file mode 100644 (file)
index 0000000..427b816
--- /dev/null
@@ -0,0 +1,242 @@
+$(document).ready(function(){
+var video = document.getElementById('video');
+var popcorn = new Popcorn('#video');
+
+var pluginResults;
+var pluginOptions;
+var manifest = {
+  about: {name: 'test', version: '0.1', author: 'Bobby Richter', website: 'http://robothaus.org'},
+  options: {
+    start : {elem:'input', type:'text', label:'In'},
+    end : {elem:'input', type:'text', label:'Out'},
+    target : 'test-target',
+  }
+};
+var plugin = (Popcorn.plugin('test',{
+  manifest: manifest,
+  _setup:function(options){pluginOptions = options; pluginResults='_setup';}, 
+  start:function(options){pluginResults='start'}, 
+  end:function(options){pluginResults='end'}
+}));
+var pluginInstance = popcorn['test']({start: 1, end: 2});
+
+module("Popcorn");
+var tests = [
+  {
+    title: 'Popcorn.registry',
+    test: function() {
+      ok(Popcorn.registry, 'exists');
+    }
+  },
+  {
+    title: 'Popcorn.getTrackEvents',
+    test: function() {
+      ok(Popcorn.getTrackEvents, 'exists');
+    }
+  },
+  {
+    title: 'Popcorn.getTrackEvents(popcorn) returns correct results',
+    test: function() {
+      expect(2);
+      var results = Popcorn.getTrackEvents(popcorn);
+      equals(results[0].start, 1, 'start is 1');
+      equals(results[0].end, 2, 'end is 2');
+    }
+  },
+  {
+    title: 'Popcorn.getTrackEvents exists',
+    test: function() {
+      ok(Popcorn.getTrackEvents, 'exists');
+    }
+  },
+  {
+    title: 'Valid plugins are addressable as p[pluginName]',
+    test: function() {
+      ok(popcorn['test'], 'popcorn[\'test\'] exists');
+    }
+  },
+  {
+    title: 'Invalid plugin names yield undefined using p[invalidName]',
+    test: function() {
+      ok(popcorn['notValid'] === undefined, 'is undefined');
+    }
+  },
+  {
+    title: 'p[validPluginName] is expected plugin',
+    test: function() {
+      equals(popcorn['test'],plugin['test'], 'popcorn[\'test\'] == plugin[\'test\']');
+    }
+  },
+  {
+    title: 'Popcorn.registry must be a list',
+    test: function() {
+      expect(2);
+      ok(Popcorn.registry, 'registry exists');
+      equals(typeof(Popcorn.registry), 'object', 'Popcorn.registry is an object');
+    }
+  },
+  {
+    title: 'Popcorn.registry must contain plugins',
+    test: function() {
+      equals(Popcorn.registry[0], plugin, 'Popcorn.registry contains test plugin');
+    }
+  },
+  {
+    title: 'plugin.type must exist',
+    test: function() {
+      ok(plugin.type, 'exists');
+    }
+  },
+  {
+    title: 'Plugin instance options._natives must exist',
+    test: function() {
+      ok(pluginOptions._natives, 'exists');
+    }
+  },
+  {
+    title: 'Plugin instance options.target should exist',
+    test: function() {
+      ok(pluginOptions.target, 'exists');
+    }
+  },
+  {
+    title: 'Popcorn.manifest be a list',
+    test: function() {
+      expect(2);
+      ok(Popcorn.manifest, 'Popcorn.manifest exists');
+      equals(typeof(Popcorn.manifest), 'object', 'Popcorn.manifest is an object');
+    }
+  },
+  {
+    title: 'Popcorn.manifest must contain plugin manifests',
+    test: function() {
+      equals(Popcorn.manifest['test'], manifest);
+    }
+  },
+  {
+    title: 'Plugin manifest must contain options property',
+    test: function() {
+      ok(Popcorn.manifest['test'].options, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.video exists',
+    test: function() {
+      ok(popcorn.video, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.video.currentTime exists',
+    test: function() {
+      ok(popcorn.video.currentTime !== undefined, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.video.play exists',
+    test: function() {
+      ok(popcorn.video.play, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.video.pause exists',
+    test: function() {
+      ok(popcorn.video.pause, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.video.volume exists',
+    test: function() {
+      ok(popcorn.video.volume, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.video.duration exists',
+    test: function() {
+      ok(popcorn.video.duration !== undefined, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.video.readyState exists',
+    test: function() {
+      ok(popcorn.video.readyState !== undefined, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.data exists',
+    test: function() {
+      ok(popcorn.data, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.data.trackEvents exists',
+    test: function() {
+      ok(popcorn.data.trackEvents, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.data.trackEvents.byStart exists',
+    test: function() {
+      ok(popcorn.data.trackEvents.byStart, 'exists');
+    }
+  },
+  {
+    title: 'popcorn.data.history must be a list',
+    test: function() {
+      expect(2);
+      ok(popcorn.data.history, 'history exists');
+      equals(typeof(popcorn.data.history), 'object', 'history in an object');
+    }
+  },
+  {
+    title: 'popcorn.getLastTrackEventId exists and works',
+    test: function() {
+      expect(2);
+      ok(popcorn.getLastTrackEventId, 'exists');
+      ok(popcorn.getLastTrackEventId(), 'works');
+    }
+  },
+  {
+    title: 'popcorn.getTrackEvents exists and works',
+    test: function() {
+      expect(2);
+      ok(popcorn.getTrackEvents, 'exists');
+      ok(popcorn.getTrackEvents(), 'works');
+    }
+  },
+  {
+    title: 'popcorn.getTrackEvents === Popcorn.getTrackEvents(popcorn)',
+    test: function() {
+      expect(2);
+      var tracks1 = popcorn.getTrackEvents();
+      var tracks2 = Popcorn.getTrackEvents(popcorn);
+      equals(tracks1.length, tracks2.length, 'lengths are equal');
+      equals(tracks1[0], tracks2[0], 'objects are equal');
+    }
+  },
+  {
+    title: 'popcorn.listen exists && works',
+    test: function() {
+      expect(2);
+      ok(popcorn.listen, 'exists');
+      popcorn.listen('ended', function(){});
+      for (var i in popcorn.data.events['ended']) {
+        ok(popcorn.data.events['ended'][i], 'works');
+        break;
+      } //for
+    }
+  },
+  {
+    title: 'popcorn.removeTrackEvent exists and works',
+    test: function() {
+      expect(2);
+      ok(popcorn.removeTrackEvent, 'exists');
+      popcorn.removeTrackEvent(popcorn.getLastTrackEventId());
+      equals(popcorn.getTrackEvents().length, 0, 'works');
+    }
+  },
+];
+
+for (var i=0; i<tests.length; ++i) {
+  test(tests[i].title, tests[i].test);
+} //for
+});
index 3e683bd6663c1574ad981e70d33a5a30cd969f01..085974c9c3d549838d0b88d8f6e41ca223625f00 100644 (file)
 <html>
   <head>
     <title>Popcorn Butter Test</title>
-    <style>
-      body {
-        background-color: #a8a8a8;
-        font: 12pt Arial,sans-serif; 
-      }
-
-      #title {
-        font-size: 180%;
-        text-align: center;
-      }
-
-      #main-container {
-        width: 600px;
-        margin: auto;
-      }
-
-      #test-content {
-        border: 3px solid #0a0a0a;
-        border-radius: 10px;
-      }
-
-      .test-item {
-        padding: 3px;
-      }
-
-      .test-status {
-        font-weight: bold;
-      }
-
-      .test-info {
-        font-size: 70%;
-        margin-left: 1em;
-      }
-
-      .test-title:hover {
-        cursor: pointer;
-        text-decoration: underline;
-      }
-
-      #video-container {
-        display: none;
-      }
-    </style>
-    <script type="text/javascript" src="../popcorn.js"></script>
-    <script type="text/javascript" src="jquery.js"></script>
-    <script type="text/javascript">
-
-      $(document).ready(function() {
-        var video = document.getElementById('video');
-        var popcorn = new Popcorn('#video');
-
-        var pluginResults;
-        var pluginOptions;
-        var manifest = {
-            about: {name: 'test', version: '0.1', author: 'Bobby Richter', website: 'http://robothaus.org'},
-            options: {
-              start : {elem:'input', type:'text', label:'In'},
-              end : {elem:'input', type:'text', label:'Out'},
-              target : 'test-target',
-            }
-          };
-        var plugin = (Popcorn.plugin('test',{
-          manifest: manifest,
-          _setup:function(options){pluginOptions = options; pluginResults='_setup';}, 
-          start:function(options){pluginResults='start'}, 
-          end:function(options){pluginResults='end'}
-        }));
-        var pluginInstance = popcorn['test']({start: 1, end: 2});
-
-        var tests = [
-          {
-            title: 'Popcorn.registry',
-            test: function() {
-              return Popcorn.registry !== undefined;
-            }
-          },
-          {
-            title: 'Popcorn.getTrackEvents',
-            test: function() {
-              return Popcorn.getTrackEvents !== undefined;
-            }
-          },
-          {
-            title: 'Popcorn.getTrackEvents(popcorn) returns correct results',
-            test: function() {
-              var results = Popcorn.getTrackEvents(popcorn);
-              for (var i in results) {
-                if (results[i].start === 1 && results[i].end === 2) {
-                  return true;
-                } //if
-              } //for
-              return false;
-            }
-          },
-          {
-            title: 'Popcorn.getTrackEvents exists',
-            test: function() {
-              return Popcorn.getTrackEvents !== undefined;
-            }
-          },
-          {
-            title: 'Valid plugins are addressable as p[pluginName]',
-            test: function() {
-              return popcorn['test'] !== undefined;
-            }
-          },
-          {
-            title: 'Invalid plugin names yield undefined using p[invalidName]',
-            test: function() {
-              return popcorn['notValid'] === undefined;
-            }
-          },
-          {
-            title: 'p[validPluginName] is expected plugin',
-            test: function() {
-              return popcorn['test'] === plugin['test'];
-            }
-          },
-          {
-            title: 'Popcorn.registry must be a list',
-            test: function() {
-              return Popcorn.registry !== undefined && typeof(Popcorn.registry) === 'object';
-            }
-          },
-          {
-            title: 'Popcorn.registry must contain plugins',
-            test: function() {
-              for (var i in Popcorn.registry) {
-                if (Popcorn.registry[i] === plugin) {
-                  return true;
-                } //if
-              } //for
-              return false;
-            }
-          },
-          {
-            title: 'plugin.type must exist',
-            test: function() {
-              return plugin.type !== undefined;
-            }
-          },
-          {
-            title: 'Plugin instance options._natives must exist',
-            test: function() {
-              return pluginOptions._natives !== undefined;
-            }
-          },
-          {
-            title: 'Plugin instance options.target should exist',
-            test: function() {
-              return pluginOptions.target !== undefined;
-            }
-          },
-          {
-            title: 'Popcorn.manifest be a list',
-            test: function() {
-              return Popcorn.manifest !== undefined && typeof(Popcorn.manifest) === 'object';
-            }
-          },
-          {
-            title: 'Valid manifests are addressable as p[pluginName]',
-            test: function() {
-              return popcorn['test'] !== undefined;
-            }
-          },
-          {
-            title: 'Invalid manifests names yield undefined using p[invalidName]',
-            test: function() {
-              return popcorn['notValid'] === undefined;
-            }
-          },
-          {
-            title: 'Popcorn.manifest must contain plugin manifests',
-            test: function() {
-              for (var i in Popcorn.manifest) {
-                if (Popcorn.manifest[i] === manifest) {
-                  return true;
-                } //if
-              } //for
-              return false;
-            }
-          },
-          {
-            title: 'Plugin manifest must contain options property',
-            test: function() {
-              return Popcorn.manifest['test'].options !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.video exists',
-            test: function() {
-              return popcorn.video !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.video.currentTime exists',
-            test: function() {
-              return popcorn.video.currentTime !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.video.play exists',
-            test: function() {
-              return popcorn.video.play !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.video.pause exists',
-            test: function() {
-              return popcorn.video.pause !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.video.volume exists',
-            test: function() {
-              return popcorn.video.volume !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.video.duration exists',
-            test: function() {
-              return popcorn.video.duration !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.video.readyState exists',
-            test: function() {
-              return popcorn.video.readyState !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.data exists',
-            test: function() {
-              return popcorn.data !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.data.trackEvents exists',
-            test: function() {
-              return popcorn.data.trackEvents !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.data.trackEvents.byStart exists',
-            test: function() {
-              return popcorn.data.trackEvents.byStart !== undefined;
-            }
-          },
-          {
-            title: 'popcorn.data.history must be a list',
-            test: function() {
-              return popcorn.data.history !== undefined && typeof(popcorn.data.history) === 'object';
-            }
-          },
-          {
-            title: 'popcorn.getLastTrackEventId exists and works',
-            test: function() {
-              var exists = popcorn.getLastTrackEventId !== undefined;
-              var works = popcorn.getLastTrackEventId() !== undefined;
-              return exists && works;
-            }
-          },
-          {
-            title: 'popcorn.getTrackEvents exists and works',
-            test: function() {
-              var exists = popcorn.getTrackEvents !== undefined;
-              var works = popcorn.getTrackEvents();
-              return exists && works;
-            }
-          },
-          {
-            title: 'popcorn.getTrackEvents === Popcorn.getTrackEvents(popcorn)',
-            test: function() {
-              var exists = popcorn.getTrackEvents !== undefined;
-              var tracks1 = popcorn.getTrackEvents();
-              var tracks2 = Popcorn.getTrackEvents(popcorn);
-              var works = tracks1.length === tracks2.length && tracks1[0] === tracks2[0];
-              return exists && works;
-            }
-          },
-          {
-            title: 'popcorn.listen exists && works',
-            test: function() {
-              var exists = popcorn.listen !== undefined;
-              popcorn.listen('ended', function(){});
-              for (var i in popcorn.data.events['ended']) {
-                return exists && true;
-              } //for
-              return false;
-            }
-          },
-          {
-            title: 'popcorn.removeTrackEvent exists and works',
-            test: function() {
-              var exists = popcorn.removeTrackEvent !== undefined;
-              popcorn.removeTrackEvent(popcorn.getLastTrackEventId());
-              var works = popcorn.getTrackEvents().length === 0;
-              return exists && works;
-            }
-          },
-        ];
-
-        var content = document.getElementById('test-content');
-        for (var i=0; i<tests.length; ++i) {
-          var testItem = tests[i];
-          var testElement = testItem.element = document.createElement('div');
-          var testTitle = document.createElement('span');
-          var testStatus = testItem.statusElement = document.createElement('span');
-          var testInfo = testItem.infoElement = document.createElement('div');
-          testElement.className = 'test-item';
-          testElement.style.position = 'relative';
-          testTitle.innerHTML = testItem.title;
-          testTitle.className = 'test-title';
-          testStatus.className = 'test-status';
-          testStatus.style.position = 'absolute';
-          testStatus.style.right = '6px';
-          testStatus.innerHTML = '?';
-          testInfo.innerHTML = testItem.test.toString();
-          testInfo.className = 'test-info';
-          testElement.appendChild(testTitle);
-          testElement.appendChild(testStatus);
-          testElement.appendChild(document.createElement('br'));
-          testElement.appendChild(testInfo);
-          content.appendChild(testElement);
-
-          (function(){
-            var ti = testInfo;
-            var tt = testTitle;
-            $(ti).hide();
-            $(tt).click(function() {
-              $(ti).toggle('fast');
-            });
-          })();
-        } //for
-
-        var scoreDiv = document.createElement('div');
-        scoreDiv.className = 'test-item';
-        scoreDiv.innerHTML = 'Score: N/A';
-        scoreDiv.style.fontWeight = 'bold';
-        content.appendChild(document.createElement('br'));
-        content.appendChild(scoreDiv);
-
-        var testIndex = 0;
-        var score = 0;
-        var waitTime = 50;
-        function runNextTest() {
-          var test = tests[testIndex];
-          try {
-            var result = test.test();
-            test.statusElement.innerHTML = result ? '&#x2713;' : '&#x2717;';
-          }
-          catch (e) {
-            test.statusElement.innerHTML = '!';
-            test.infoElement.innerHTML += '<br /><b>Error:</b> ' + e.message;
-          } //try
-          ++testIndex;
-          if (testIndex < tests.length) {
-            setTimeout(runNextTest, waitTime);
-          } //if
-          score += (result ? 1 : 0);
-
-          scoreDiv.innerHTML = 'Score: ' + score + '/' + tests.length;
-        } //runNextTest
-
-        setTimeout(runNextTest, waitTime);
-      });
-    </script>
+    <link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
+    <script src="jquery.js"></script>
+    <script src="qunit/qunit.js"></script>
+    <script src="../popcorn.js"></script>
+    <script src="butter.unit.js"></script>
   </head>
   <body>
-    <div id="main-container">
-      <div id="title">
-        Butter Dependency Test
-      </div>
-      <div id="test-content">
-      </div>
+    <h1 id="qunit-header">Butter Popcorn Dependencies</h1>
+    <h2 id="qunit-banner"></h2>
+    <div id="qunit-testrunner-toolbar"></div>
+    <h2 id="qunit-userAgent"></h2>
+    <ol id="qunit-tests"></ol>
+    <div id="qunit-fixture">
     </div>
     <div id="video-container">
       <video id="video" />