tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / dom / script-tests / webtiming.js
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.");
2
3 var performance = window.performance || {};
4 var navigation = performance.navigation || {};
5 var timing = performance.timing || {};
6
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;
11
12 function sleepFiftyMilliseconds() {
13   var endTime = (new Date()).getTime() + 50;
14   while ((new Date().getTime() < endTime)) { }
15 }
16 window.addEventListener("load", sleepFiftyMilliseconds, false);
17
18 function checkTimingBeforeLoad()
19 {
20     shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
21
22     shouldBe("timing.redirectStart", "0");
23     shouldBe("timing.redirectEnd", "0");
24     shouldBe("navigation.redirectCount", "0");
25
26     shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
27
28     shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
29     shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
30
31     shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
32     shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
33
34     shouldBe("timing.secureConnectionStart", "0");
35
36     shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
37
38     shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
39
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");
45
46     shouldBe("timing.loadEventStart", "0");
47     shouldBe("timing.loadEventEnd", "0");
48 }
49
50 function checkTimingWhileDeferred()
51 {
52     shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
53
54     shouldBe("timing.redirectStart", "0");
55     shouldBe("timing.redirectEnd", "0");
56     shouldBe("navigation.redirectCount", "0");
57
58     shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
59
60     shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
61     shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
62
63     shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
64     shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
65
66     shouldBe("timing.secureConnectionStart", "0");
67
68     shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
69
70     shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
71
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");
77
78     shouldBe("timing.loadEventStart", "0");
79     shouldBe("timing.loadEventEnd", "0");
80
81     window.addEventListener("DOMContentLoaded", checkWebTimingOnDOMContentLoaded, false);
82 }
83
84 function checkWebTimingOnDOMContentLoaded() {
85     shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
86
87     shouldBe("timing.redirectStart", "0");
88     shouldBe("timing.redirectEnd", "0");
89     shouldBe("navigation.redirectCount", "0");
90
91     shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
92
93     shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
94     shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
95
96     shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
97     shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
98
99     shouldBe("timing.secureConnectionStart", "0");
100
101     shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
102
103     shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
104
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");
110
111     shouldBe("timing.loadEventStart", "0");
112     shouldBe("timing.loadEventEnd", "0");
113
114     var body = document.getElementsByTagName("body")[0];
115     var script = document.createElement("script");
116     script.async = true;
117     script.type = "text/javascript";
118     script.src = "script-tests/webtiming-async.js";
119     body.appendChild(script);
120 }
121
122 function checkWebTimingWhileAsync()
123 {
124     shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
125
126     shouldBe("timing.redirectStart", "0");
127     shouldBe("timing.redirectEnd", "0");
128     shouldBe("navigation.redirectCount", "0");
129
130     shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
131
132     shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
133     shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
134
135     shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
136     shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
137
138     shouldBe("timing.secureConnectionStart", "0");
139
140     shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
141
142     shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
143
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");
149
150     shouldBe("timing.loadEventStart", "0");
151     shouldBe("timing.loadEventEnd", "0");
152
153     window.addEventListener("load", checkWebTimingOnLoad, false);
154 }
155
156 function checkWebTimingOnLoad()
157 {
158     shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
159
160     shouldBe("timing.redirectStart", "0");
161     shouldBe("timing.redirectEnd", "0");
162     shouldBe("navigation.redirectCount", "0");
163
164     shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
165
166     shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
167     shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
168
169     shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
170     shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
171
172     shouldBe("timing.secureConnectionStart", "0");
173
174     shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
175
176     shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
177     shouldBeGreaterThanOrEqual("timing.responseEnd", "timing.responseStart");
178
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");
184
185     shouldBeGreaterThanOrEqual("timing.loadEventStart", "timing.responseEnd");
186     shouldBe("timing.loadEventEnd", "0");
187
188     setTimeout("checkWebTimingAfterLoad()", 0);
189 }
190
191 function checkWebTimingAfterLoad()
192 {
193     shouldBeGreaterThanOrEqual("timing.navigationStart", "oneHourAgoUTC");
194
195     shouldBe("timing.redirectStart", "0");
196     shouldBe("timing.redirectEnd", "0");
197     shouldBe("navigation.redirectCount", "0");
198
199     shouldBeGreaterThanOrEqual("timing.fetchStart", "timing.navigationStart");
200
201     shouldBeGreaterThanOrEqual("timing.domainLookupStart", "timing.fetchStart");
202     shouldBeGreaterThanOrEqual("timing.domainLookupEnd", "timing.domainLookupStart");
203
204     shouldBeGreaterThanOrEqual("timing.connectStart", "timing.domainLookupEnd");
205     shouldBeGreaterThanOrEqual("timing.connectEnd", "timing.connectStart");
206
207     shouldBe("timing.secureConnectionStart", "0");
208
209     shouldBeGreaterThanOrEqual("timing.requestStart", "timing.connectEnd");
210
211     shouldBeGreaterThanOrEqual("timing.responseStart", "timing.requestStart");
212     shouldBeGreaterThanOrEqual("timing.responseEnd", "timing.responseStart");
213
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");
219
220     shouldBeGreaterThanOrEqual("timing.loadEventStart", "timing.responseEnd");
221     shouldBeGreaterThanOrEqual("timing.loadEventEnd", "timing.loadEventStart + 50");
222
223     finishJSTest();
224 }
225
226 jsTestIsAsync = true;
227 checkTimingBeforeLoad();