1 description("This test checks that all of the <a href='http://dev.w3.org/2006/webapi/WebTiming/'>Web Timing</a> attributes are available and have reasonable values in the right order.");
3 var performance = window.performance || {};
4 var navigation = performance.navigation || {};
5 var timing = performance.timing || {};
7 // Get the order of magnitude correct without a chance for flakiness.
8 var oneHourMilliseconds = 60 * 60 * 1000;
9 var currentUTC = (new Date()).getTime();
10 var oneHourAgoUTC = currentUTC - oneHourMilliseconds;
12 function sleepFiftyMilliseconds() {
13 var endTime = (new Date()).getTime() + 50;
14 while ((new Date().getTime() < endTime)) { }
16 window.addEventListener("load", sleepFiftyMilliseconds, false);
18 function checkTimingBeforeLoad()
20 shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
22 shouldBe("timing.redirectStart", "0");
23 shouldBe("timing.redirectEnd", "0");
24 shouldBe("navigation.redirectCount", "0");
26 shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
28 shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
29 shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
31 shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
32 shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
34 shouldBe("timing.secureConnectionStart", "0");
36 shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
38 shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
40 shouldBeGreaterThanOrEqual("timing.domLoading", "timing.fetchStart");
41 shouldBe("timing.domInteractive", "0");
42 shouldBe("timing.domContentLoadedEventStart", "0");
43 shouldBe("timing.domContentLoadedEventEnd", "0");
44 shouldBe("timing.domComplete", "0");
46 shouldBe("timing.loadEventStart", "0");
47 shouldBe("timing.loadEventEnd", "0");
50 function checkTimingWhileDeferred()
52 shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
54 shouldBe("timing.redirectStart", "0");
55 shouldBe("timing.redirectEnd", "0");
56 shouldBe("navigation.redirectCount", "0");
58 shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
60 shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
61 shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
63 shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
64 shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
66 shouldBe("timing.secureConnectionStart", "0");
68 shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
70 shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
72 shouldBeGreaterThanOrEqual("timing.domLoading", "timing.fetchStart");
73 shouldBeGreaterThanOrEqual("timing.domInteractive", "timing.domLoading");
74 shouldBe("timing.domContentLoadedEventStart", "0");
75 shouldBe("timing.domContentLoadedEventEnd", "0");
76 shouldBe("timing.domComplete", "0");
78 shouldBe("timing.loadEventStart", "0");
79 shouldBe("timing.loadEventEnd", "0");
81 window.addEventListener("DOMContentLoaded", checkWebTimingOnDOMContentLoaded, false);
84 function checkWebTimingOnDOMContentLoaded() {
85 shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
87 shouldBe("timing.redirectStart", "0");
88 shouldBe("timing.redirectEnd", "0");
89 shouldBe("navigation.redirectCount", "0");
91 shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
93 shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
94 shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
96 shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
97 shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
99 shouldBe("timing.secureConnectionStart", "0");
101 shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
103 shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
105 shouldBeGreaterThanOrEqual("timing.domLoading", "timing.fetchStart");
106 shouldBeGreaterThanOrEqual("timing.domInteractive", "timing.domLoading");
107 shouldBeGreaterThanOrEqual("timing.domContentLoadedEventStart", "timing.domInteractive");
108 shouldBe("timing.domContentLoadedEventEnd", "0");
109 shouldBe("timing.domComplete", "0");
111 shouldBe("timing.loadEventStart", "0");
112 shouldBe("timing.loadEventEnd", "0");
114 var body = document.getElementsByTagName("body")[0];
115 var script = document.createElement("script");
117 script.type = "text/javascript";
118 script.src = "script-tests/webtiming-async.js";
119 body.appendChild(script);
122 function checkWebTimingWhileAsync()
124 shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
126 shouldBe("timing.redirectStart", "0");
127 shouldBe("timing.redirectEnd", "0");
128 shouldBe("navigation.redirectCount", "0");
130 shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
132 shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
133 shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
135 shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
136 shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
138 shouldBe("timing.secureConnectionStart", "0");
140 shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
142 shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
144 shouldBeGreaterThanOrEqual("timing.domLoading", "timing.fetchStart");
145 shouldBeGreaterThanOrEqual("timing.domInteractive", "timing.responseEnd");
146 shouldBeGreaterThanOrEqual("timing.domContentLoadedEventStart", "timing.domInteractive");
147 shouldBeGreaterThanOrEqual("timing.domContentLoadedEventEnd", "timing.domContentLoadedEventStart");
148 shouldBe("timing.domComplete", "0");
150 shouldBe("timing.loadEventStart", "0");
151 shouldBe("timing.loadEventEnd", "0");
153 window.addEventListener("load", checkWebTimingOnLoad, false);
156 function checkWebTimingOnLoad()
158 shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
160 shouldBe("timing.redirectStart", "0");
161 shouldBe("timing.redirectEnd", "0");
162 shouldBe("navigation.redirectCount", "0");
164 shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
166 shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
167 shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
169 shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
170 shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
172 shouldBe("timing.secureConnectionStart", "0");
174 shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
176 shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
177 shouldBeGreaterThanOrEqual("timing.responseEnd", "timing.responseStart");
179 shouldBeGreaterThanOrEqual("timing.domLoading", "timing.fetchStart");
180 shouldBeGreaterThanOrEqual("timing.domInteractive", "timing.responseEnd");
181 shouldBeGreaterThanOrEqual("timing.domContentLoadedEventStart", "timing.domInteractive");
182 shouldBeGreaterThanOrEqual("timing.domContentLoadedEventEnd", "timing.domContentLoadedEventStart");
183 shouldBeGreaterThanOrEqual("timing.domComplete", "timing.domContentLoadedEventEnd");
185 shouldBeGreaterThanOrEqual("timing.loadEventStart", "timing.responseEnd");
186 shouldBe("timing.loadEventEnd", "0");
188 setTimeout("checkWebTimingAfterLoad()", 0);
191 function checkWebTimingAfterLoad()
193 shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
195 shouldBe("timing.redirectStart", "0");
196 shouldBe("timing.redirectEnd", "0");
197 shouldBe("navigation.redirectCount", "0");
199 shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
201 shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
202 shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
204 shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
205 shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
207 shouldBe("timing.secureConnectionStart", "0");
209 shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
211 shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
212 shouldBeGreaterThanOrEqual("timing.responseEnd", "timing.responseStart");
214 shouldBeGreaterThanOrEqual("timing.domLoading", "timing.fetchStart");
215 shouldBeGreaterThanOrEqual("timing.domInteractive", "timing.responseEnd");
216 shouldBeGreaterThanOrEqual("timing.domContentLoadedEventStart", "timing.domInteractive");
217 shouldBeGreaterThanOrEqual("timing.domContentLoadedEventEnd", "timing.domContentLoadedEventStart");
218 shouldBeGreaterThanOrEqual("timing.domComplete", "timing.domContentLoadedEventEnd");
220 shouldBeGreaterThanOrEqual("timing.loadEventStart", "timing.responseEnd");
221 shouldBeGreaterThanOrEqual("timing.loadEventEnd", "timing.loadEventStart + 50");
226 jsTestIsAsync = true;
227 checkTimingBeforeLoad();