content/media/test/test_delay_load.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 type="application/javascript" 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>
    13   var gRegisteredElements = [];
    14   var gLog = false;
    15   var testWindows = [];
    17   function log(msg) {
    18     if (gLog) {
    19       document.getElementById('log').innerHTML += "<p>"+msg+"</p>";
    20       dump(msg + "\n");
    21     }
    22   }
    24   function register(v) {
    25     gRegisteredElements.push(v);
    26   }
    28   function loaded() {
    29     log("onload fired!");
    31     for (var i = 0; i < gRegisteredElements.length; ++i) {
    32       var v = gRegisteredElements[i];
    33       ok(v.readyState >= v.HAVE_CURRENT_DATA,
    34          v._name + ":" + v.id + " is not ready before onload fired (" + v.readyState + ")");
    35     }
    37     for (i=0; i<testWindows.length; ++i) {
    38       testWindows[i].close();
    39     }
    41     mediaTestCleanup();    
    43     SimpleTest.finish();
    44   }
    46   addLoadEvent(loaded);
    49   </script>
    50 </head>
    51 <body>
    52 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479711">Mozilla Bug 479711</a>
    53 <p id="display"></p>
    54 <div id="content" style="display: none">
    56 </div>
    59 <div id="log" style="font-size: small;"></div>
    60 <pre id="test">
    61 <script type="application/javascript">
    63 /** Test for Bug 479711 **/
    65 function createVideo(name, type, id) {
    66   var v = document.createElement("video");
    67   // Make sure each video is a unique resource
    68   v.src = name + "?" + id;
    69   v._name = name;
    70   v.id = id;
    71   register(v);
    72   return v;
    73 }
    75 var test = getPlayableVideo(gSmallTests);
    77 // Straightforward add, causing a load.
    78 var v = createVideo(test.name, test.type, "1");
    79 document.body.appendChild(v);
    81 // Load, add, then remove.
    82 v = createVideo(test.name, test.type, "1");
    83 v.load();
    84 document.body.appendChild(v);
    85 v.parentNode.removeChild(v);
    87 // Load and add.
    88 v = createVideo(test.name, test.type, "2");
    89 v.load();
    90 document.body.appendChild(v);
    92 // Load outside of doc.
    93 v = createVideo(test.name, test.type, "3");
    94 v.load();
    96 // Open a new window for the following test. We open it here instead of in
    97 // the event handler to ensure that our document load event doesn't fire while
    98 // window.open is spinning the event loop.
    99 var w = window.open("", "testWindow", "width=400,height=400");
   100 testWindows.push(w);
   102 v = createVideo(test.name, test.type, "4");
   103 v.onloadstart = function(e) {
   104   // Using a new window to do this is a bit annoying, but if we use an iframe here,
   105   // delaying of the iframe's load event might interfere with the firing of our load event
   106   // in some confusing way. So it's simpler just to use another window.
   107   w.document.body.appendChild(v);
   108 };
   109 v.load(); // load started while in this document, this doc's load will block until
   110           // the video's finished loading (in the other document).
   112 if (gRegisteredElements.length > 0) {
   113   SimpleTest.waitForExplicitFinish();
   114 } else {
   115   todo(false, "No types supported");
   116 }
   118 </script>
   119 </pre>
   120 </body>
   121 </html>

mercurial