|
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 type="application/javascript" 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 (var p in timing) { |
|
21 moments[p] = timing[p]; |
|
22 } |
|
23 for (var 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.removeChild(node.firstChild); |
|
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 table = document.createElement('table'); |
|
44 node.appendChild(table); |
|
45 row = document.createElement('tr'); |
|
46 table.appendChild(row); |
|
47 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 var stopPolling = (win.performance && win.performance.loadEventEnd) || |
|
112 (seenLoad && Date.now() >= seenLoad + 200) || |
|
113 Date.now() >= start + 5000; |
|
114 if (stopPolling) { |
|
115 clearInterval(interval); |
|
116 checkValues(); |
|
117 } else if (win._testing_evt_load) { |
|
118 seenLoad = Date.now(); |
|
119 } |
|
120 }, 100); |
|
121 } |
|
122 </script> |
|
123 </head> |
|
124 <body> |
|
125 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=570341">Mozilla Bug 570341</a> |
|
126 <div id="frames"> |
|
127 <iframe name="child0" src="navigation/blank.html"></iframe> |
|
128 </div> |
|
129 <button type="button" onclick="showSequence(document.getElementById('display'))"> |
|
130 Show Events</button> |
|
131 <p id="display"></p> |
|
132 <div id="content" style="display: none"> |
|
133 |
|
134 </div> |
|
135 <pre id="test"> |
|
136 <script type="application/javascript"> |
|
137 SimpleTest.waitForExplicitFinish(); |
|
138 </script> |
|
139 </pre> |
|
140 </body> |
|
141 </html> |