test_delay_load.html (2843B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=479711 5 --> 6 <head> 7 <title>Test for Bug 479711</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 <script type="text/javascript" src="manifest.js"></script> 11 <script> 12 13 var gRegisteredElements = []; 14 var testWindows = []; 15 16 function register(v) { 17 gRegisteredElements.push(v); 18 } 19 20 function loaded() { 21 info("onload fired!"); 22 23 for (var i = 0; i < gRegisteredElements.length; ++i) { 24 var v = gRegisteredElements[i]; 25 ok(v.readyState >= v.HAVE_CURRENT_DATA, 26 v._name + ":" + v.id + " is not ready before onload fired (" + v.readyState + ")"); 27 } 28 29 for (i=0; i<testWindows.length; ++i) { 30 testWindows[i].close(); 31 } 32 33 mediaTestCleanup(); 34 35 SimpleTest.finish(); 36 } 37 38 addLoadEvent(loaded); 39 40 </script> 41 </head> 42 <body> 43 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479711">Mozilla Bug 479711</a> 44 <p id="display"></p> 45 <div id="content" style="display: none"></div> 46 <pre id="test"> 47 <script type="application/javascript"> 48 49 /** Test for Bug 479711 */ 50 51 function createVideo(name, type, id) { 52 var v = document.createElement("video"); 53 v.preload = "metadata"; 54 // Make sure each video is a unique resource 55 v.src = name + "?" + id; 56 v._name = name; 57 v.id = id; 58 register(v); 59 return v; 60 } 61 62 var test = getPlayableVideo(gSmallTests); 63 64 // Straightforward add, causing a load. 65 var v = createVideo(test.name, test.type, "1"); 66 document.body.appendChild(v); 67 68 // Load, add, then remove. 69 v = createVideo(test.name, test.type, "1"); 70 v.load(); 71 document.body.appendChild(v); 72 v.remove(); 73 74 // Load and add. 75 v = createVideo(test.name, test.type, "2"); 76 v.load(); 77 document.body.appendChild(v); 78 79 // Load outside of doc. 80 v = createVideo(test.name, test.type, "3"); 81 v.load(); 82 83 // Open a new window for the following test. We open it here instead of in 84 // the event handler to ensure that our document load event doesn't fire while 85 // window.open is spinning the event loop. 86 var w = window.open("", "testWindow", "width=400,height=400"); 87 testWindows.push(w); 88 89 v = createVideo(test.name, test.type, "4"); 90 v.onloadstart = function() { 91 // Using a new window to do this is a bit annoying, but if we use an iframe here, 92 // delaying of the iframe's load event might interfere with the firing of our load event 93 // in some confusing way. So it's simpler just to use another window. 94 w.document.body.appendChild(v); 95 }; 96 v.load(); // load started while in this document, this doc's load will block until 97 // the video's finished loading (in the other document). 98 99 if (gRegisteredElements.length) { 100 SimpleTest.waitForExplicitFinish(); 101 } else { 102 todo(false, "No types supported"); 103 } 104 105 </script> 106 </pre> 107 </body> 108 </html>