Bug 486556. Don't rely on loadeddata firing before the document load event, per spec it might not. r=doublec
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 10 Apr 2009 13:12:19 +1200
changeset 27155 370798d494f88d76e953aa98bef5694aaac10191
parent 27154 e8c9280dce9196f971ef2a5876c7f4eaa7e9b893
child 27156 d64ac7af9d14cdbe4aa8169bdfa0d685edcbd6af
push id6411
push userrocallahan@mozilla.com
push dateFri, 10 Apr 2009 02:24:49 +0000
treeherdermozilla-central@c82f707141cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdoublec
bugs486556
milestone1.9.2a1pre
Bug 486556. Don't rely on loadeddata firing before the document load event, per spec it might not. r=doublec
content/media/video/test/test_delay_load.html
--- a/content/media/video/test/test_delay_load.html
+++ b/content/media/video/test/test_delay_load.html
@@ -5,34 +5,38 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <title>Test for Bug 479711</title>
   <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script>
   
-  var gLoadedDataCount = 0;
+  var gRegisteredElements = [];
   var gLog = false;
   var gTestWindow;
 
   function log(msg) {
     if (gLog) {
       document.getElementById('log').innerHTML += "<p>"+msg+"</p>";
       dump(msg + "\n");
     }
   }
   
-  function loadeddata() {
-    gLoadedDataCount++;
+  function register(v) {
+    gRegisteredElements.push(v);
   }
-  
+
   function loaded() {
-    is(gLoadedDataCount, 5, "onload was not delayed until after metadataloaded");
-    log("doc-loaded gLoadedDataCount = " + gLoadedDataCount);
+    log("onload fired!");
+
+    for (var i = 0; i < gRegisteredElements.length; ++i) {
+      var v = gRegisteredElements[i];
+      ok(v.readyState >= v.HAVE_CURRENT_DATA, "Video " + v.id + " is not ready before onload fired");
+    }
 
     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     gTestWindow.close();
 
     SimpleTest.finish();
   }
   
   addLoadEvent(loaded);
@@ -43,44 +47,46 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479711">Mozilla Bug 479711</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
 
 
-<video src="320x240.ogv" onloadeddata="loadeddata();"></video>
+<video src="320x240.ogv" id="v0"></video>
 
 
 <div id="log" style="font-size: small;"></div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 479711 **/
 
-var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'load', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
-
-function listener(evt) {
-  log('event ' + evt.target.id + " " + evt.type);
-}
+register(document.getElementById('v0'));
 
 function createVideo(id) {
   var v = document.createElement("video");
   v.id = id;
-  for (var i=0; i<gEventTypes.length; i++) {
-    var t = gEventTypes[i];
-    v.addEventListener(t, listener, false);
+  if (gLog) {
+    var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'load', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
+    function listener(evt) {
+      log('event ' + evt.target.id + " " + evt.type);
+    }
+
+    for (var i=0; i<gEventTypes.length; i++) {
+      var t = gEventTypes[i];
+      v.addEventListener(t, listener, false);
+    }
   }
-  v.addEventListener('loadeddata', loadeddata, false);
   v.src = "http://localhost:8888/tests/content/media/video/test/320x240.ogv";
+  register(v);
   return v;
 }
 
-
 // Load, add, then remove.
 var v1 = createVideo("v1");
 v1.load();
 document.body.appendChild(v1);
 v1.parentNode.removeChild(v1);
 
 // Load and add.
 var v2 = createVideo("v2");
@@ -96,13 +102,13 @@ netscape.security.PrivilegeManager.enabl
 var v4 = createVideo("v4");
 v4.load(); // load started while in this document, this doc's load will block until
             // the video's finished loading (in the other document).
 // Opening a new window to do this is a bit annoying, but if we use an iframe here,
 // delaying of the iframe's load event might interfere with the firing of our load event
 // in some confusing way. So it's simpler just to open another window.
 gTestWindow = window.open("", "testWindow", "width=400,height=400");
 gTestWindow.document.body.appendChild(v4);
-  
+
 </script>
 </pre>
 </body>
 </html>