docshell/test/test_bug570341.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/test_bug570341.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=570341
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 570341</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>
    1.14 +  var start = Date.now();
    1.15 +  var moments = {};
    1.16 +
    1.17 +  var unload = 0;
    1.18 +  var wasEnabled = true;
    1.19 +
    1.20 +  function collectMoments() {
    1.21 +    var win = frames[0];
    1.22 +    var timing = (win.performance && win.performance.timing) || {};
    1.23 +    for (var p in timing) {
    1.24 +      moments[p] = timing[p];
    1.25 +    }
    1.26 +    for (var p in win) {
    1.27 +      if (p.substring(0,9) == '_testing_') {
    1.28 +        moments[p.substring(9)] = win[p];
    1.29 +      }
    1.30 +    }
    1.31 +    moments['evt_unload'] = unload;
    1.32 +    return moments;
    1.33 +  }
    1.34 +
    1.35 +  function showSequence(node){
    1.36 +    while(node.firstChild) {
    1.37 +      node.removeChild(node.firstChild);
    1.38 +    }
    1.39 +    var sequence = [];
    1.40 +    for (var p in moments) {
    1.41 +      sequence.push(p);
    1.42 +    }
    1.43 +    sequence.sort(function(a, b){
    1.44 +      return moments[a] - moments[b];
    1.45 +    });
    1.46 +    table = document.createElement('table');
    1.47 +    node.appendChild(table);
    1.48 +    row = document.createElement('tr');
    1.49 +    table.appendChild(row);
    1.50 +    cell = document.createElement('td');
    1.51 +    row.appendChild(cell);
    1.52 +    cell.appendChild(document.createTextNode('start'));
    1.53 +    cell = document.createElement('td');
    1.54 +    row.appendChild(cell);
    1.55 +    cell.appendChild(document.createTextNode(start));
    1.56 +    for (var i = 0; i < sequence.length; ++i) {
    1.57 +      var prop = sequence[i];
    1.58 +      row = document.createElement('tr');
    1.59 +      table.appendChild(row);
    1.60 +      cell = document.createElement('td');
    1.61 +      row.appendChild(cell);
    1.62 +      cell.appendChild(document.createTextNode(prop));
    1.63 +      cell = document.createElement('td');
    1.64 +      row.appendChild(cell);
    1.65 +      cell.appendChild(document.createTextNode(moments[prop]));
    1.66 +    }
    1.67 +  }
    1.68 +
    1.69 +  function checkValues(){
    1.70 +    var win = frames[0];
    1.71 +    ok(win.performance, 
    1.72 +        'window.performance is missing or not accessible for frame');
    1.73 +    ok(!win.performance || win.performance.timing, 
    1.74 +        'window.performance.timing is missing or not accessible for frame');
    1.75 +    collectMoments();
    1.76 +
    1.77 +    var sequences = [
    1.78 +      ['navigationStart', 'unloadEventStart', 'unloadEventEnd'],
    1.79 +      ['navigationStart', 'fetchStart', 'domainLookupStart', 'domainLookupEnd',
    1.80 +       'connectStart', 'connectEnd', 'requestStart', 'responseStart', 'responseEnd'],
    1.81 +      ['responseStart', 'domLoading', 'domInteractive', 'domComplete'],
    1.82 +      ['domContentLoadedEventStart', 'domContentLoadedEventEnd',
    1.83 +       'loadEventStart', 'loadEventEnd']
    1.84 +    ]
    1.85 +
    1.86 +    for (var i = 0; i < sequences.length; ++i) {
    1.87 +      var seq = sequences[i];
    1.88 +      for (var j = 0; j < seq.length; ++j) {
    1.89 +        var prop = seq[j];
    1.90 +        if (j > 0) {
    1.91 +          var prevProp = seq[j-1];
    1.92 +          ok(moments[prevProp] <= moments[prop],
    1.93 +              ['Expected ', prevProp, ' to happen before ', prop,
    1.94 +              ', got ', prevProp, ' = ', moments[prevProp],
    1.95 +              ', ', prop, ' = ', moments[prop]].join(''));
    1.96 +        }
    1.97 +      }
    1.98 +    }
    1.99 +
   1.100 +    SimpleTest.finish()
   1.101 +  }
   1.102 +
   1.103 +window.onload = function() {
   1.104 +  var win = frames[0];
   1.105 +  win.addEventListener('unload', function(){
   1.106 +    unload = Date.now();
   1.107 +  }, true);
   1.108 +  var seenLoad = 0;
   1.109 +  win.addEventListener('load', function (){
   1.110 +    seenLoad = Date.now();
   1.111 +  }, true);
   1.112 +  frames[0].location = 'bug570341_recordevents.html'
   1.113 +  var interval = setInterval(function () {
   1.114 +    var stopPolling = (win.performance && win.performance.loadEventEnd) ||
   1.115 +                      (seenLoad && Date.now() >= seenLoad + 200) ||
   1.116 +                      Date.now() >= start + 5000;
   1.117 +    if (stopPolling) {
   1.118 +      clearInterval(interval);
   1.119 +      checkValues();
   1.120 +    } else if (win._testing_evt_load) {
   1.121 +      seenLoad = Date.now();
   1.122 +    }
   1.123 +  }, 100);
   1.124 +}
   1.125 +</script>
   1.126 +</head>
   1.127 +<body>
   1.128 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=570341">Mozilla Bug 570341</a>
   1.129 +<div id="frames">
   1.130 +<iframe name="child0" src="navigation/blank.html"></iframe>
   1.131 +</div>
   1.132 +<button type="button" onclick="showSequence(document.getElementById('display'))">
   1.133 +    Show Events</button>
   1.134 +<p id="display"></p>
   1.135 +<div id="content" style="display: none">
   1.136 +
   1.137 +</div>
   1.138 +<pre id="test">
   1.139 +<script type="application/javascript">
   1.140 +SimpleTest.waitForExplicitFinish();
   1.141 +</script>
   1.142 +</pre>
   1.143 +</body>
   1.144 +</html>

mercurial