content/media/test/test_delay_load.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_delay_load.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=479711
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 479711</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +  <script type="text/javascript" src="manifest.js"></script>
    1.14 +  <script>
    1.15 +  
    1.16 +  var gRegisteredElements = [];
    1.17 +  var gLog = false;
    1.18 +  var testWindows = [];
    1.19 +
    1.20 +  function log(msg) {
    1.21 +    if (gLog) {
    1.22 +      document.getElementById('log').innerHTML += "<p>"+msg+"</p>";
    1.23 +      dump(msg + "\n");
    1.24 +    }
    1.25 +  }
    1.26 +  
    1.27 +  function register(v) {
    1.28 +    gRegisteredElements.push(v);
    1.29 +  }
    1.30 +
    1.31 +  function loaded() {
    1.32 +    log("onload fired!");
    1.33 +
    1.34 +    for (var i = 0; i < gRegisteredElements.length; ++i) {
    1.35 +      var v = gRegisteredElements[i];
    1.36 +      ok(v.readyState >= v.HAVE_CURRENT_DATA,
    1.37 +         v._name + ":" + v.id + " is not ready before onload fired (" + v.readyState + ")");
    1.38 +    }
    1.39 +
    1.40 +    for (i=0; i<testWindows.length; ++i) {
    1.41 +      testWindows[i].close();
    1.42 +    }
    1.43 +
    1.44 +    mediaTestCleanup();    
    1.45 +
    1.46 +    SimpleTest.finish();
    1.47 +  }
    1.48 +  
    1.49 +  addLoadEvent(loaded);
    1.50 +  
    1.51 +
    1.52 +  </script>
    1.53 +</head>
    1.54 +<body>
    1.55 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479711">Mozilla Bug 479711</a>
    1.56 +<p id="display"></p>
    1.57 +<div id="content" style="display: none">
    1.58 +  
    1.59 +</div>
    1.60 +
    1.61 +
    1.62 +<div id="log" style="font-size: small;"></div>
    1.63 +<pre id="test">
    1.64 +<script type="application/javascript">
    1.65 +
    1.66 +/** Test for Bug 479711 **/
    1.67 +
    1.68 +function createVideo(name, type, id) {
    1.69 +  var v = document.createElement("video");
    1.70 +  // Make sure each video is a unique resource
    1.71 +  v.src = name + "?" + id;
    1.72 +  v._name = name;
    1.73 +  v.id = id;
    1.74 +  register(v);
    1.75 +  return v;
    1.76 +}
    1.77 +
    1.78 +var test = getPlayableVideo(gSmallTests);
    1.79 +
    1.80 +// Straightforward add, causing a load.
    1.81 +var v = createVideo(test.name, test.type, "1");
    1.82 +document.body.appendChild(v);
    1.83 +
    1.84 +// Load, add, then remove.
    1.85 +v = createVideo(test.name, test.type, "1");
    1.86 +v.load();
    1.87 +document.body.appendChild(v);
    1.88 +v.parentNode.removeChild(v);
    1.89 +
    1.90 +// Load and add.
    1.91 +v = createVideo(test.name, test.type, "2");
    1.92 +v.load();
    1.93 +document.body.appendChild(v);
    1.94 +
    1.95 +// Load outside of doc.
    1.96 +v = createVideo(test.name, test.type, "3");
    1.97 +v.load();
    1.98 +
    1.99 +// Open a new window for the following test. We open it here instead of in
   1.100 +// the event handler to ensure that our document load event doesn't fire while
   1.101 +// window.open is spinning the event loop.
   1.102 +var w = window.open("", "testWindow", "width=400,height=400");
   1.103 +testWindows.push(w);
   1.104 +
   1.105 +v = createVideo(test.name, test.type, "4");
   1.106 +v.onloadstart = function(e) {
   1.107 +  // Using a new window to do this is a bit annoying, but if we use an iframe here,
   1.108 +  // delaying of the iframe's load event might interfere with the firing of our load event
   1.109 +  // in some confusing way. So it's simpler just to use another window.
   1.110 +  w.document.body.appendChild(v);
   1.111 +};
   1.112 +v.load(); // load started while in this document, this doc's load will block until
   1.113 +          // the video's finished loading (in the other document).
   1.114 +
   1.115 +if (gRegisteredElements.length > 0) {
   1.116 +  SimpleTest.waitForExplicitFinish();
   1.117 +} else {
   1.118 +  todo(false, "No types supported");
   1.119 +}
   1.120 +
   1.121 +</script>
   1.122 +</pre>
   1.123 +</body>
   1.124 +</html>

mercurial