tor-browser

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

test_bug570341.html (4337B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=570341
      5 -->
      6 <head>
      7  <title>Test for Bug 570341</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 <script>
     11  var start = Date.now();
     12  var moments = {};
     13 
     14  var unload = 0;
     15  var wasEnabled = true;
     16 
     17  function collectMoments() {
     18    var win = frames[0];
     19    var timing = (win.performance && win.performance.timing) || {};
     20    for (let p in timing) {
     21      moments[p] = timing[p];
     22    }
     23    for (let p in win) {
     24      if (p.substring(0, 9) == "_testing_") {
     25        moments[p.substring(9)] = win[p];
     26      }
     27    }
     28    moments.evt_unload = unload;
     29    return moments;
     30  }
     31 
     32  function showSequence(node) {
     33    while (node.firstChild) {
     34      node.firstChild.remove();
     35    }
     36    var sequence = [];
     37    for (var p in moments) {
     38      sequence.push(p);
     39    }
     40    sequence.sort(function(a, b) {
     41      return moments[a] - moments[b];
     42    });
     43    var table = document.createElement("table");
     44    node.appendChild(table);
     45    var row = document.createElement("tr");
     46    table.appendChild(row);
     47    var cell = document.createElement("td");
     48    row.appendChild(cell);
     49    cell.appendChild(document.createTextNode("start"));
     50    cell = document.createElement("td");
     51    row.appendChild(cell);
     52    cell.appendChild(document.createTextNode(start));
     53    for (var i = 0; i < sequence.length; ++i) {
     54      var prop = sequence[i];
     55      row = document.createElement("tr");
     56      table.appendChild(row);
     57      cell = document.createElement("td");
     58      row.appendChild(cell);
     59      cell.appendChild(document.createTextNode(prop));
     60      cell = document.createElement("td");
     61      row.appendChild(cell);
     62      cell.appendChild(document.createTextNode(moments[prop]));
     63    }
     64  }
     65 
     66  function checkValues() {
     67    var win = frames[0];
     68    ok(win.performance,
     69        "window.performance is missing or not accessible for frame");
     70    ok(!win.performance || win.performance.timing,
     71        "window.performance.timing is missing or not accessible for frame");
     72    collectMoments();
     73 
     74    var sequences = [
     75      ["navigationStart", "unloadEventStart", "unloadEventEnd"],
     76      ["navigationStart", "fetchStart", "domainLookupStart", "domainLookupEnd",
     77       "connectStart", "connectEnd", "requestStart", "responseStart", "responseEnd"],
     78      ["responseStart", "domLoading", "domInteractive", "domComplete"],
     79      ["domContentLoadedEventStart", "domContentLoadedEventEnd",
     80       "loadEventStart", "loadEventEnd"],
     81    ];
     82 
     83    for (var i = 0; i < sequences.length; ++i) {
     84      var seq = sequences[i];
     85      for (var j = 0; j < seq.length; ++j) {
     86        var prop = seq[j];
     87        if (j > 0) {
     88          var prevProp = seq[j - 1];
     89          ok(moments[prevProp] <= moments[prop],
     90              ["Expected ", prevProp, " to happen before ", prop,
     91              ", got ", prevProp, " = ", moments[prevProp],
     92              ", ", prop, " = ", moments[prop]].join(""));
     93        }
     94      }
     95    }
     96 
     97    SimpleTest.finish();
     98  }
     99 
    100 window.onload = function() {
    101  var win = frames[0];
    102  win.addEventListener("unload", function() {
    103    unload = Date.now();
    104  }, true);
    105  var seenLoad = 0;
    106  win.addEventListener("load", function() {
    107    seenLoad = Date.now();
    108  }, true);
    109  frames[0].location = "bug570341_recordevents.html";
    110  var interval = setInterval(function() {
    111    // time constants here are arbitrary, chosen to allow the test to pass
    112    var stopPolling = (win.performance && win.performance.loadEventEnd) ||
    113                      (seenLoad && Date.now() >= seenLoad + 3000) ||
    114                      Date.now() >= start + 30000;
    115    if (stopPolling) {
    116      clearInterval(interval);
    117      checkValues();
    118    } else if (win._testing_evt_load) {
    119      seenLoad = Date.now();
    120    }
    121  }, 100);
    122 };
    123 </script>
    124 </head>
    125 <body>
    126 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=570341">Mozilla Bug 570341</a>
    127 <div id="frames">
    128 <iframe name="child0" src="navigation/blank.html"></iframe>
    129 </div>
    130 <button type="button" onclick="showSequence(document.getElementById('display'))">
    131    Show Events</button>
    132 <p id="display"></p>
    133 <div id="content" style="display: none">
    134 
    135 </div>
    136 <pre id="test">
    137 <script type="application/javascript">
    138 SimpleTest.waitForExplicitFinish();
    139 </script>
    140 </pre>
    141 </body>
    142 </html>