]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
added subtitle unit tests. Added subtitle div id assignment to popcorn.subtitle.js
authorDan Ventura <distraction.attack@gmail.com>
Tue, 8 Mar 2011 23:03:44 +0000 (18:03 -0500)
committerDan Ventura <distraction.attack@gmail.com>
Tue, 8 Mar 2011 23:03:44 +0000 (18:03 -0500)
plugins/subtitle/popcorn.subtitle.js
plugins/subtitle/popcorn.subtitle.unit.html [new file with mode: 0644]
plugins/subtitle/popcorn.subtitle.unit.js [new file with mode: 0644]

index 0cad282ff7cab6a5ca69954ac5e51f725c3a245c..2dbfaae71a8361531b7e3f3a7da357ace8f1d246 100644 (file)
         // Creates a div for all subtitles to use
         if ( !this.container ) {
           this.container = document.createElement('div');
-
+          this.container.id = "subtitlediv";
           this.container.style.position   = "absolute";
           this.container.style.color      = "white";
           this.container.style.textShadow = "black 2px 2px 6px";
diff --git a/plugins/subtitle/popcorn.subtitle.unit.html b/plugins/subtitle/popcorn.subtitle.unit.html
new file mode 100644 (file)
index 0000000..66c1d43
--- /dev/null
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn Subtitle Plug-in Test</title>
+  <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+  <script src="../../test/qunit/qunit.js"></script>
+  <!-- 
+    do not move - this must be called immediately prior to 
+    popcorn-api-draft.js
+  -->
+  
+  <script src="../../popcorn.js"></script>
+  <script src="http://google.com/jsapi"></script>
+  <script>google.load("language", "1");</script>
+  <script src="popcorn.subtitle.js"></script>
+
+  <script src="popcorn.subtitle.unit.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Subtitle Plugin</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>
+  
+  <video id='video' 
+    controls preload='none' 
+    width= '250px'
+    poster="../../test/poster.png"> 
+
+    <source id='mp4'
+      src="../../test/trailer.mp4"
+      type='video/mp4; codecs="avc1, mp4a"'> 
+
+    <source id='ogv'
+      src="../../test/trailer.ogv"
+      type='video/ogg; codecs="theora, vorbis"'> 
+
+    <p>Your user agent does not support the HTML5 Video element.</p> 
+
+  </video> 
+  <h2>Choose your language</h2>
+  <select id="language">
+    <option value="en" selected="selected">English</option>
+  </select>
+  <div>
+    with help from <a href="http://google.com/translate">Google Translate</a><br />
+    <input type="checkbox" id="accessibility" checked="checked" />All subtitles (accessibility)
+  </div>
+</body>
+</html>
diff --git a/plugins/subtitle/popcorn.subtitle.unit.js b/plugins/subtitle/popcorn.subtitle.unit.js
new file mode 100644 (file)
index 0000000..9e7c58b
--- /dev/null
@@ -0,0 +1,83 @@
+test("Popcorn Subtitle Plugin", function () {
+  
+  var popped = Popcorn("#video"),
+      expects = 5,
+      count = 0,
+      interval,
+      interval2,
+      interval3,
+      interval4,
+      subtitlediv;
+  
+  expect(expects);
+  
+  function plus() {
+    if ( ++count===expects) {
+      start();
+    }
+  }
+  
+  stop();
+   
+  ok ('subtitle' in popped, "subtitle is a method of the popped instance");
+  plus();
+
+  popped.subtitle({
+      start: 3,
+      text: 'this is the first subtitle of 2011',
+      language: "en",
+      languagesrc: "language",
+      accessibilitysrc: "accessibility"
+    } )
+  .subtitle({
+      start: 10,
+      end: 15,
+      text: 'this is the second subtitle of 2011',
+      language: "en",
+      languagesrc: "language",
+      accessibilitysrc: "accessibility"
+    } )
+       .subtitle({
+      start: 20,
+      text: 'this is the third subtitle of 2011',
+      language: "en",
+      languagesrc: "language",
+      accessibilitysrc: "accessibility"
+    } )
+    .volume(0)
+    .play();
+  
+  interval = setInterval( function() {
+    if( popped.currentTime() >= 3 && popped.currentTime() < 10 ) {
+      subtitlediv = document.getElementById('subtitlediv'); // this div has only now been created
+      equals (subtitlediv.innerHTML, "this is the first subtitle of 2011", "subtitle displaying correct information" );
+      plus();
+      clearInterval( interval );
+    }
+  }, 500);
+  
+  interval2 = setInterval( function() {
+    if( popped.currentTime() >= 10 && popped.currentTime() < 15  ) {
+      equals (subtitlediv.innerHTML, "this is the second subtitle of 2011", "subtitle displaying correct information" );
+      plus();
+      clearInterval( interval2 );
+    }
+  }, 500);
+
+  interval3 = setInterval( function() {
+    if( popped.currentTime() >= 15 && popped.currentTime() < 20 ) {
+      equals (subtitlediv.innerHTML, "" );
+      plus();
+      clearInterval( interval3 );
+    }
+  }, 500);
+  
+  interval4 = setInterval( function() {
+    if( popped.currentTime() > 20) {
+      equals (subtitlediv.innerHTML, "this is the third subtitle of 2011", "subtitle displaying correct information" );
+      plus();
+      clearInterval( interval4 );
+    }
+  }, 500);
+
+});
\ No newline at end of file