tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_error_on_404.html (2110B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=476731
      5 -->
      6 <head>
      7  <title>Test for Bug 476731</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 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=476731">Mozilla Bug </a>
     14 <p id="display"></p>
     15 <div id="content" style="display: none">
     16 </div>
     17 <pre id="test">
     18 <script type="application/javascript">
     19 /** Test for Bug 476731 */
     20 
     21 var videos = [];
     22 
     23 function FinishedLoads() {
     24  if (!videos.length)
     25    return false;
     26  for (var i=0; i<videos.length; ++i) {
     27    if (videos[i]._loadedData) {
     28      // A video loadeddata, it should have 404'd. Signal the end of the test
     29      // so the error will be reported.
     30      return true;
     31    }
     32    if (!videos[i]._loadError) {
     33      return false;
     34    }
     35  }
     36  return true;
     37 }
     38 
     39 function loadError(evt) {
     40  var v = evt.target;
     41  is(v._loadError, false, "Shouldn't receive multiple error events for " + v.src);
     42  v._loadError = true;
     43  is(v._loadStart, true, "Receive loadstart for " + v.src);
     44  is(v._loadedData, false, "Shouldn't receive loadeddata for " + v.src);
     45  if (FinishedLoads(videos))
     46    SimpleTest.finish();
     47 }
     48 
     49 function loadedData(evt) {
     50  evt.target._loadedData = true;
     51 }
     52 
     53 function loadStart(evt) {
     54  evt.target._loadStart = true;
     55 }
     56 
     57 // Create all video objects.
     58 for (var i=0; i<g404Tests.length; ++i) {
     59  var v = document.createElement("video");
     60  v.preload = "metadata";
     61  var test = g404Tests[i];
     62  if (!v.canPlayType(test.type)) {
     63    continue;
     64   }
     65   v.src = test.name;
     66   v._loadedData = false;
     67   v._loadStart = false;
     68   v._loadError = false;
     69   v.addEventListener("error", loadError);
     70   v.addEventListener("loadstart", loadStart);
     71   v.addEventListener("loadeddata", loadedData);
     72   document.body.appendChild(v); // Will start load.
     73   videos.push(v);
     74 }
     75 
     76 if (!videos.length) {
     77  todo(false, "No types supported");
     78 } else {
     79  SimpleTest.waitForExplicitFinish();
     80 }
     81 </script>
     82 </pre>
     83 </body>
     84 </html>