]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#415] Fixed missing comma; Complete unit test rewrite for: relative, absolute, fixed...
authorrwldrn <waldron.rick@gmail.com>
Fri, 1 Apr 2011 16:59:52 +0000 (12:59 -0400)
committerrwldrn <waldron.rick@gmail.com>
Fri, 1 Apr 2011 16:59:52 +0000 (12:59 -0400)
popcorn.js
test/index.html
test/popcorn.unit.js

index 2220f0aa55be2cc32f1e50d618dae59480564dd5..bb7dfb67ba45a830b7d78c727b559e1648a427d2 100644 (file)
       });
 
       return this;
-    }
+    },
+
     //  Popcorn Object Element Utils
     position: function() {
       var  media = this.video,  
index c075015ba2a4292f65d750364e83ca80044826e1..dc69bc2f7b33a383440f7aebad51592abcbc780d 100644 (file)
 
        <audio id='audio' src="italia.ogg" data-timeline-sources="data/parserData.json" controls> 
        </audio>
+
+
+       <!-- Position Tests Adapted From jQuery offsets/dimensions Tests -->
+       <style type="text/css" media="screen">
+               #position-tests { display:none;margin:0; position: fixed;top:0px;left:0px;      }
+               
+               div.absolute { position: absolute; margin: 0px; width: 100px; height: 100px; background: #fff; }
+               #absolute-1 { top: 0; left: 0; }
+               #absolute-1-1 { top: 1px; left: 1px; }
+               #absolute-1-1-1 { top: 1px; left: 1px; }
+               #absolute-2 { top: 19px; left: 19px; }
+
+               div.relative { position: relative; top: 0; left: 0; width: 100px; height: 100px; background: #fff; overflow: hidden; }
+               #relative-2 { top: 20px; left: 20px; }
+
+               div.fixed { position: fixed; width: 100px; height: 100px; background: #fff; overflow: hidden; }
+               #fixed-1 { top: 0; left: 0; }
+               #fixed-2 { top: 20px; left: 20px; }
+
+               div.static { position: static; top: 0; left: 0; width: 100px; height: 100px; background: #fff; overflow: hidden; }
+               #static-2 { top: 20px; left: 20px; }            
+
+       </style>
+
+       <div id="position-tests">
+               <div id="absolute-1" class="absolute"><video id="vid-absolute-1" src="trailer.ogv" style="visibility:hidden"></video>
+                       <div id="absolute-1-1" class="absolute"><video  id="vid-absolute-1-1"" src="trailer.ogv" style="visibility:hidden"></video>
+                               <div id="absolute-1-1-1" class="absolute"><video  id="vid-absolute-1-1-1" src="trailer.ogv" style="visibility:hidden"></video></div>
+                       </div>
+               </div>
+               <div id="absolute-2" class="absolute"><video  id="vid-absolute-2" src="trailer.ogv" style="visibility:hidden"></video></div>
+
+               <div id="relative-1" class="relative"><video  id="vid-relative-1" src="trailer.ogv" style="visibility:hidden"></video>
+                       <div id="relative-1-1" class="relative"><video  id="vid-relative-1-1" src="trailer.ogv" style="visibility:hidden"></video>
+                               <div id="relative-1-1-1" class="relative"><video  id="vid-relative-1-1-1" src="trailer.ogv" style="visibility:hidden"></video></div>
+                       </div>
+               </div>
+               <div id="relative-2" class="relative"><video  id="vid-relative-2" src="trailer.ogv" style="visibility:hidden"></video></div>
+
+
+               <div id="fixed-1" class="fixed"><video  id="vid-fixed-1" src="trailer.ogv" style="visibility:hidden"></video></div>
+               <div id="fixed-2" class="fixed"><video  id="vid-fixed-2" src="trailer.ogv" style="visibility:hidden"></video></div>
+
+               <div id="static-1" class="static"><video  id="vid-static-1" src="trailer.ogv" style="visibility:hidden">
+                       <div id="static-1-1" class="static"><video  id="vid-static-1-1" src="trailer.ogv" style="visibility:hidden">
+                               <div id="static-1-1-1" class="static"><video  id="vid-static-1-1-1" src="trailer.ogv" style="visibility:hidden"></div>
+                       </div>
+               </div>
+               <div id="static-2" class="static"><video  id="vid-static-2" src="trailer.ogv" style="visibility:hidden"></div>
+
+       </div>
+
+       
 </body>
 </html>
index 4d4aa966d03b6be3b1a89c24f42baa93ede6683a..593a798d2db758661c19214c381a8214edf3d358 100755 (executable)
@@ -310,46 +310,66 @@ test("exec", function () {
 module("Popcorn Position");
 test("position", function () {
 
-  var pops = [ Popcorn("#pos-1"),
-                Popcorn("#pos-2"),
-                Popcorn("#pos-3"),
-                Popcorn("#pos-4")
-            ],
-      expects = 22,
-      count = 0,
-      tests = [
-                {"top":0,"height":150,"width":300,"bottom":150,"left":1123,"right":1423},
-                {"top":100,"height":150,"width":300,"bottom":250,"left":1023,"right":1323},
-                {"height":150,"width":300,"left":1366,"right":1666},
-                {"top":0,"height":150,"width":300,"bottom":150,"left":1123,"right":1423}
-                ],
-      bounds,
-      against,
-      styles;
-
-  expect( expects );
-
-  function plus(){ 
-    if ( ++count == expects ) {
-      start();
-    }
-  }
-
-  stop( 10000 ); 
+       expect(24);
+       
+  var $absolute = $(".absolute"), 
+      $relative = $(".relative"), 
+      $fixed = $(".fixed"),
+      $static = $(".static"),  
+      tests;
+
+       $("#position-tests").show();
+//  console.log( $absolute );
+//  console.log( $fixed );
+//  console.log( $relative );
+//  console.log( $static );
+
+  tests = [
+    { id: "absolute-1",     top:  0, left:  0 },
+    { id: "absolute-1-1",   top:  1, left:  1 },
+    { id: "absolute-1-1-1", top:  2, left:  2 },
+    { id: "absolute-2",     top: 19, left: 19 }
+  ];
+  
+  Popcorn.forEach( tests, function( test ) {
+    equals( Popcorn( "#vid-" + test.id ).position().top,  test.top,  "Popcorn('#vid-" + test.id + "').position().top" );
+    equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
+  });
 
-  pops.forEach(function( pop, idx ) {
+  tests = [
+    { id: "relative-1", top:   0, left:  0 },
+    { id: "relative-2", top: 120, left: 20 }
+  ];
+
+  Popcorn.forEach( tests, function( test ) {
+    equals( Popcorn( "#vid-" + test.id ).position().top,  test.top,  "Popcorn('#vid-" + test.id + "').position().top" );
+    equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
+  });  
+
+  tests = [
+    { id: "fixed-1", top:  0, left:  0 },
+    { id: "fixed-2", top: 20, left: 20 }
+  ];
+
+  Popcorn.forEach( tests, function( test ) {
+    equals( Popcorn( "#vid-" + test.id ).position().top,  test.top,  "Popcorn('#vid-" + test.id + "').position().top" );
+    equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
+  });  
+
+  tests = [
+    { id: "static-1",     top:  200, left:  0 },
+    { id: "static-1-1",   top:  0, left:  0 },
+    { id: "static-1-1-1", top:  0, left:  0 },
+    { id: "static-2",     top: 300, left: 0 }
+  ];
+  
+  Popcorn.forEach( tests, function( test ) {
+    equals( Popcorn( "#vid-" + test.id ).position().top,  test.top,  "Popcorn('#vid-" + test.id + "').position().top" );
+    equals( Popcorn( "#vid-" + test.id ).position().left, test.left, "Popcorn('#vid-" + test.id + "').position().left" );
+  });
 
-    bounds = pop.position();
-    against = tests[ idx ];
-    styles = document.getElementById( pop.video.id ).style;
 
-    for ( var p in bounds ) {
-      if ( p in against ) {
-        equal( bounds[ p ], against[ p ], "video#" + pop.video.id + ": " + p );
-        plus();
-      }
-    }
-  });
+       $("#position-tests").hide();
 });
 
 test("position called from plugin", function () {