summaryrefslogtreecommitdiffstats
path: root/docshell/test/mochitest/test_bug570341.html
blob: 363f9854075140dee0349a8d3c41f9337fa41fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=570341
-->
<head>
  <title>Test for Bug 570341</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script>
  var start = Date.now();
  var moments = {};

  var unload = 0;
  var wasEnabled = true;

  function collectMoments() {
    var win = frames[0];
    var timing = (win.performance && win.performance.timing) || {};
    for (let p in timing) {
      moments[p] = timing[p];
    }
    for (let p in win) {
      if (p.substring(0, 9) == "_testing_") {
        moments[p.substring(9)] = win[p];
      }
    }
    moments.evt_unload = unload;
    return moments;
  }

  function showSequence(node) {
    while (node.firstChild) {
      node.firstChild.remove();
    }
    var sequence = [];
    for (var p in moments) {
      sequence.push(p);
    }
    sequence.sort(function(a, b) {
      return moments[a] - moments[b];
    });
    var table = document.createElement("table");
    node.appendChild(table);
    var row = document.createElement("tr");
    table.appendChild(row);
    var cell = document.createElement("td");
    row.appendChild(cell);
    cell.appendChild(document.createTextNode("start"));
    cell = document.createElement("td");
    row.appendChild(cell);
    cell.appendChild(document.createTextNode(start));
    for (var i = 0; i < sequence.length; ++i) {
      var prop = sequence[i];
      row = document.createElement("tr");
      table.appendChild(row);
      cell = document.createElement("td");
      row.appendChild(cell);
      cell.appendChild(document.createTextNode(prop));
      cell = document.createElement("td");
      row.appendChild(cell);
      cell.appendChild(document.createTextNode(moments[prop]));
    }
  }

  function checkValues() {
    var win = frames[0];
    ok(win.performance,
        "window.performance is missing or not accessible for frame");
    ok(!win.performance || win.performance.timing,
        "window.performance.timing is missing or not accessible for frame");
    collectMoments();

    var sequences = [
      ["navigationStart", "unloadEventStart", "unloadEventEnd"],
      ["navigationStart", "fetchStart", "domainLookupStart", "domainLookupEnd",
       "connectStart", "connectEnd", "requestStart", "responseStart", "responseEnd"],
      ["responseStart", "domLoading", "domInteractive", "domComplete"],
      ["domContentLoadedEventStart", "domContentLoadedEventEnd",
       "loadEventStart", "loadEventEnd"],
    ];

    for (var i = 0; i < sequences.length; ++i) {
      var seq = sequences[i];
      for (var j = 0; j < seq.length; ++j) {
        var prop = seq[j];
        if (j > 0) {
          var prevProp = seq[j - 1];
          ok(moments[prevProp] <= moments[prop],
              ["Expected ", prevProp, " to happen before ", prop,
              ", got ", prevProp, " = ", moments[prevProp],
              ", ", prop, " = ", moments[prop]].join(""));
        }
      }
    }

    SimpleTest.finish();
  }

window.onload = function() {
  var win = frames[0];
  win.addEventListener("unload", function() {
    unload = Date.now();
  }, true);
  var seenLoad = 0;
  win.addEventListener("load", function() {
    seenLoad = Date.now();
  }, true);
  frames[0].location = "bug570341_recordevents.html";
  var interval = setInterval(function() {
    // time constants here are arbitrary, chosen to allow the test to pass
    var stopPolling = (win.performance && win.performance.loadEventEnd) ||
                      (seenLoad && Date.now() >= seenLoad + 3000) ||
                      Date.now() >= start + 30000;
    if (stopPolling) {
      clearInterval(interval);
      checkValues();
    } else if (win._testing_evt_load) {
      seenLoad = Date.now();
    }
  }, 100);
};
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=570341">Mozilla Bug 570341</a>
<div id="frames">
<iframe name="child0" src="navigation/blank.html"></iframe>
</div>
<button type="button" onclick="showSequence(document.getElementById('display'))">
    Show Events</button>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>