]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Adding unit tests, and some error checking and such
authordseif <david.c.seifried@gmail.com>
Mon, 7 Mar 2011 22:00:31 +0000 (14:00 -0800)
committerdseif <david.c.seifried@gmail.com>
Mon, 7 Mar 2011 22:23:19 +0000 (14:23 -0800)
plugins/googlefeed/popcorn.googlefeed.js
plugins/googlefeed/popcorn.googlefeed.unit.html [new file with mode: 0644]
plugins/googlefeed/popcorn.googlefeed.unit.js [new file with mode: 0644]

index 084259a9d5b1560a050b0ab27b1e51c3a80b52a1..2ef2da3979b3529723afa82fdd3bd5e3c5f6143f 100644 (file)
@@ -26,7 +26,8 @@
   */
 
   var _feedFired = false,
-         _feedLoaded = false;
+         _feedLoaded = false,
+         i = 1;
   
   // insert google api and dynamic feed control script once, as well as the dynamic feed css file
   if ( !_feedFired ) {
     // that already exists in the parent div gets overwritten
     var newdiv = document.createElement( "div" );
     newdiv.style.display = "none";
+       newdiv.id = "_feed"+i;
+    newdiv.style.width = "100%";
+    newdiv.style.height = "100%";
+    i++;
     if ( document.getElementById( options.target ) ) {
       document.getElementById( options.target ).appendChild( newdiv );
     }
@@ -81,7 +86,6 @@
        */
       start: function( event, options ){
         newdiv.setAttribute( "style", "display:inline" );
-        
         // Default to vertical orientation if empty or incorrect input
         if( !options.orientation || ( options.orientation.toLowerCase() != "vertical" &&
           options.orientation.toLowerCase() != "horizontal" ) ) {
       orientation    : { elem:"input", type:"text", label:"orientation" }
     }
   });
+  
 })( Popcorn );
diff --git a/plugins/googlefeed/popcorn.googlefeed.unit.html b/plugins/googlefeed/popcorn.googlefeed.unit.html
new file mode 100644 (file)
index 0000000..15ad19a
--- /dev/null
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn API</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="popcorn.googlefeed.js"></script>
+
+  <script src="popcorn.googlefeed.unit.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Google Feed 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> 
+  <div id="feed" style="position:relative;float:left;width:400px;height:600px"></div> 
+  <div id="feed1" style="position:relative;float:left;width:600px;height:200px"></div>   
+</body>
+</html>
diff --git a/plugins/googlefeed/popcorn.googlefeed.unit.js b/plugins/googlefeed/popcorn.googlefeed.unit.js
new file mode 100644 (file)
index 0000000..108f332
--- /dev/null
@@ -0,0 +1,68 @@
+test("Popcorn Google Feed Plugin", function () {
+  
+  var popped = Popcorn("#video"),
+      expects = 10, 
+      count = 0;
+         
+  console.log(expects);
+  
+  expect(expects);
+  
+  function plus() {
+    if ( ++count===expects) {
+      start();
+    }
+  }
+  
+  stop();
+
+    ok ('googlefeed' in popped, "googlefeed is a method of the popped instance");
+    plus();
+    ok ( document.getElementById('feed').innerHTML === "", "initially, there is nothing inside the feed" );
+    plus();
+    ok ( document.getElementById('feed1').innerHTML === "", "initially, there is nothing inside the feed1" );
+    plus();
+  
+  popped.googlefeed({
+        start: 0, // seconds
+        end: 5, // seconds
+        target: "feed",
+        url: "http://zenit.senecac.on.ca/~chris.tyler/planet/rss20.xml",
+        title: "Planet Feed",
+        orientation: "Vertical"
+         } )
+         .googlefeed({
+        start: 0, // seconds
+        end: 5, // seconds
+        target: "feed1",
+        url: "http://blog.pikimal.com/geek/feed/",
+        title: "pikiGeek",
+        orientation: "Horizontal"
+      } )
+    .volume(0);
+  
+  popped.exec( 1, function() {
+      ok(google.load, "Google Feed is available");
+      plus();
+         ok(GFdynamicFeedControl, "Dynamic Feed Control Available");
+      plus();
+      ok (document.getElementById('_feed1'), "First feed is on the page" );
+      plus();
+      equals (document.getElementById('_feed1').offsetParent.id, "feed", "First feed is inside the 'feed' div" );
+      plus();
+  });
+  popped.exec( 2, function() {
+      ok (document.getElementById('_feed2'), "Second feed is on the page" );
+      plus();
+      equals (document.getElementById('_feed2').offsetParent.id, "feed1", "Second feed is inside the 'feed2' div" );
+      plus();
+  });
+  popped.exec( 6, function() {
+      ok (document.getElementById('_feed2').style.display === "none" && 
+          document.getElementById('_feed1').style.display === "none", "Both feeds are no lnger visible" );
+      plus();
+  });
+  
+  popped.play();
+  
+});