OLD | NEW |
1 /* | 1 /* |
2 Distributed under both the W3C Test Suite License [1] and the W3C | 2 Distributed under both the W3C Test Suite License [1] and the W3C |
3 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the | 3 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
4 policies and contribution forms [3]. | 4 policies and contribution forms [3]. |
5 | 5 |
6 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license | 6 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license |
7 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license | 7 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license |
8 [3] http://www.w3.org/2004/10/27-testcases | 8 [3] http://www.w3.org/2004/10/27-testcases |
9 */ | 9 */ |
10 | 10 |
11 // | 11 // |
12 // Helper Functions for NavigationTiming W3C tests | 12 // Helper Functions for NavigationTiming W3C tests |
13 // | 13 // |
14 | 14 |
15 var performanceNamespace = window.performance; | |
16 var timingAttributes = [ | 15 var timingAttributes = [ |
17 'connectEnd', | 16 'connectEnd', |
18 'connectStart', | 17 'connectStart', |
19 'domComplete', | 18 'domComplete', |
20 'domContentLoadedEventEnd', | 19 'domContentLoadedEventEnd', |
21 'domContentLoadedEventStart', | 20 'domContentLoadedEventStart', |
22 'domInteractive', | 21 'domInteractive', |
23 'domLoading', | 22 'domLoading', |
24 'domainLookupEnd', | 23 'domainLookupEnd', |
25 'domainLookupStart', | 24 'domainLookupStart', |
26 'fetchStart', | 25 'fetchStart', |
27 'loadEventEnd', | 26 'loadEventEnd', |
28 'loadEventStart', | 27 'loadEventStart', |
29 'navigationStart', | 28 'navigationStart', |
30 'redirectEnd', | 29 'redirectEnd', |
31 'redirectStart', | 30 'redirectStart', |
32 'requestStart', | 31 'requestStart', |
33 'responseEnd', | 32 'responseEnd', |
34 'responseStart', | 33 'responseStart', |
35 'unloadEventEnd', | 34 'unloadEventEnd', |
36 'unloadEventStart' | 35 'unloadEventStart' |
37 ]; | 36 ]; |
38 | 37 |
39 var namespace_check = false; | |
40 | |
41 // | |
42 // All test() functions in the WebPerf test suite should use wp_test() instead. | |
43 // | |
44 // wp_test() validates the window.performance namespace exists prior to running
tests and | |
45 // immediately shows a single failure if it does not. | |
46 // | |
47 | |
48 function wp_test(func, msg, properties) | |
49 { | |
50 // only run the namespace check once | |
51 if (!namespace_check) | |
52 { | |
53 namespace_check = true; | |
54 | |
55 if (performanceNamespace === undefined || performanceNamespace == null) | |
56 { | |
57 // show a single error that window.performance is undefined | |
58 test(function() { assert_true(performanceNamespace !== undefined &&
performanceNamespace != null, "window.performance is defined and not null"); },
"window.performance is defined and not null.", {author:"W3C http://www.w3.org/",
help:"http://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute",
assert:"The window.performance attribute provides a hosting area for performance
related attributes. "}); | |
59 } | |
60 } | |
61 | |
62 test(func, msg, properties); | |
63 } | |
64 | |
65 function test_namespace(child_name, skip_root) | 38 function test_namespace(child_name, skip_root) |
66 { | 39 { |
67 if (skip_root === undefined) { | 40 if (skip_root === undefined) { |
68 var msg = 'window.performance is defined'; | 41 var msg = 'window.performance is defined'; |
69 wp_test(function () { assert_true(performanceNamespace !== undefined, ms
g); }, msg,{author:"W3C http://www.w3.org/",help:"http://www.w3.org/TR/navigatio
n-timing/#sec-window.performance-attribute",assert:"The window.performance attri
bute provides a hosting area for performance related attributes. "}); | 42 wp_test(function () { assert_true(performanceNamespace !== undefined, ms
g); }, msg,{author:"W3C http://www.w3.org/",help:"http://www.w3.org/TR/navigatio
n-timing/#sec-window.performance-attribute",assert:"The window.performance attri
bute provides a hosting area for performance related attributes. "}); |
70 } | 43 } |
71 | 44 |
72 if (child_name !== undefined) { | 45 if (child_name !== undefined) { |
73 var msg2 = 'window.performance.' + child_name + ' is defined'; | 46 var msg2 = 'window.performance.' + child_name + ' is defined'; |
74 wp_test(function() { assert_true(performanceNamespace[child_name] !== un
defined, msg2); }, msg2,{author:"W3C http://www.w3.org/",help:"http://www.w3.org
/TR/navigation-timing/#sec-window.performance-attribute",assert:"The window.perf
ormance attribute provides a hosting area for performance related attributes. "}
); | 47 wp_test(function() { assert_true(performanceNamespace[child_name] !== un
defined, msg2); }, msg2,{author:"W3C http://www.w3.org/",help:"http://www.w3.org
/TR/navigation-timing/#sec-window.performance-attribute",assert:"The window.perf
ormance attribute provides a hosting area for performance related attributes. "}
); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 var start = new Date().getTime(); | 95 var start = new Date().getTime(); |
123 while (true) { | 96 while (true) { |
124 if ((new Date().getTime() - start) >= n) break; | 97 if ((new Date().getTime() - start) >= n) break; |
125 } | 98 } |
126 } | 99 } |
127 | 100 |
128 // | 101 // |
129 // Common helper functions | 102 // Common helper functions |
130 // | 103 // |
131 | 104 |
132 function test_true(value, msg, properties) | |
133 { | |
134 wp_test(function () { assert_true(value, msg); }, msg, properties); | |
135 } | |
136 | |
137 function test_equals(value, equals, msg, properties) | |
138 { | |
139 wp_test(function () { assert_equals(value, equals, msg); }, msg, properties)
; | |
140 } | |
141 | |
142 function test_greater_than(value, greater_than, msg, properties) | 105 function test_greater_than(value, greater_than, msg, properties) |
143 { | 106 { |
144 wp_test(function () { assert_true(value > greater_than, msg); }, msg, proper
ties); | 107 wp_test(function () { assert_true(value > greater_than, msg); }, msg, proper
ties); |
145 } | 108 } |
146 | 109 |
147 function test_greater_or_equals(value, greater_than, msg, properties) | 110 function test_greater_or_equals(value, greater_than, msg, properties) |
148 { | 111 { |
149 wp_test(function () { assert_true(value >= greater_than, msg); }, msg, prope
rties); | 112 wp_test(function () { assert_true(value >= greater_than, msg); }, msg, prope
rties); |
150 } | 113 } |
151 | 114 |
152 function test_not_equals(value, notequals, msg, properties) | 115 function test_not_equals(value, notequals, msg, properties) |
153 { | 116 { |
154 wp_test(function() { assert_true(value !== notequals, msg); }, msg, properti
es); | 117 wp_test(function() { assert_true(value !== notequals, msg); }, msg, properti
es); |
155 } | 118 } |
OLD | NEW |