| 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 = self.performance; | |
| 16 var timingAttributes = [ | 15 var timingAttributes = [ |
| 17 "navigationStart", | 16 "navigationStart", |
| 18 "unloadEventStart", | 17 "unloadEventStart", |
| 19 "unloadEventEnd", | 18 "unloadEventEnd", |
| 20 "redirectStart", | 19 "redirectStart", |
| 21 "redirectEnd", | 20 "redirectEnd", |
| 22 "fetchStart", | 21 "fetchStart", |
| 23 "domainLookupStart", | 22 "domainLookupStart", |
| 24 "domainLookupEnd", | 23 "domainLookupEnd", |
| 25 "connectStart", | 24 "connectStart", |
| 26 "connectEnd", | 25 "connectEnd", |
| 27 "secureConnectionStart", | 26 "secureConnectionStart", |
| 28 "requestStart", | 27 "requestStart", |
| 29 "responseStart", | 28 "responseStart", |
| 30 "responseEnd", | 29 "responseEnd", |
| 31 "domLoading", | 30 "domLoading", |
| 32 "domInteractive", | 31 "domInteractive", |
| 33 "domContentLoadedEventStart", | 32 "domContentLoadedEventStart", |
| 34 "domContentLoadedEventEnd", | 33 "domContentLoadedEventEnd", |
| 35 "domComplete", | 34 "domComplete", |
| 36 "loadEventStart", | 35 "loadEventStart", |
| 37 "loadEventEnd" | 36 "loadEventEnd" |
| 38 ]; | 37 ]; |
| 39 | 38 |
| 40 var namespace_check = false; | |
| 41 | |
| 42 function has_required_interfaces() | 39 function has_required_interfaces() |
| 43 { | 40 { |
| 44 if (window.performance.mark == undefined || | 41 if (window.performance.mark == undefined || |
| 45 window.performance.clearMarks == undefined || | 42 window.performance.clearMarks == undefined || |
| 46 window.performance.measure == undefined || | 43 window.performance.measure == undefined || |
| 47 window.performance.clearMeasures == undefined || | 44 window.performance.clearMeasures == undefined || |
| 48 window.performance.getEntriesByName == undefined || | 45 window.performance.getEntriesByName == undefined || |
| 49 window.performance.getEntriesByType == undefined || | 46 window.performance.getEntriesByType == undefined || |
| 50 window.performance.getEntries == undefined) { | 47 window.performance.getEntries == undefined) { |
| 51 return false; | 48 return false; |
| 52 } | 49 } |
| 53 | 50 |
| 54 return true; | 51 return true; |
| 55 } | 52 } |
| 56 | 53 |
| 57 // | |
| 58 // All test() functions in the WebPerf test suite should use wp_test() instead. | |
| 59 // | |
| 60 // wp_test() validates the window.performance namespace exists prior to running
tests and | |
| 61 // immediately shows a single failure if it does not. | |
| 62 // | |
| 63 | |
| 64 function wp_test(func, msg, properties) | |
| 65 { | |
| 66 // only run the namespace check once | |
| 67 if (!namespace_check) | |
| 68 { | |
| 69 namespace_check = true; | |
| 70 | |
| 71 if (performanceNamespace === undefined || performanceNamespace == null) | |
| 72 { | |
| 73 // show a single error that window.performance is undefined | |
| 74 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. "}); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 test(func, msg, properties); | |
| 79 } | |
| 80 | |
| 81 function test_namespace(child_name, skip_root) | 54 function test_namespace(child_name, skip_root) |
| 82 { | 55 { |
| 83 if (skip_root === undefined) { | 56 if (skip_root === undefined) { |
| 84 var msg = 'window.performance is defined'; | 57 var msg = 'window.performance is defined'; |
| 85 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. "}); | 58 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. "}); |
| 86 } | 59 } |
| 87 | 60 |
| 88 if (child_name !== undefined) { | 61 if (child_name !== undefined) { |
| 89 var msg2 = 'window.performance.' + child_name + ' is defined'; | 62 var msg2 = 'window.performance.' + child_name + ' is defined'; |
| 90 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. "}
); | 63 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... |
| 138 var start = new Date().getTime(); | 111 var start = new Date().getTime(); |
| 139 while (true) { | 112 while (true) { |
| 140 if ((new Date().getTime() - start) >= n) break; | 113 if ((new Date().getTime() - start) >= n) break; |
| 141 } | 114 } |
| 142 } | 115 } |
| 143 | 116 |
| 144 // | 117 // |
| 145 // Common helper functions | 118 // Common helper functions |
| 146 // | 119 // |
| 147 | 120 |
| 148 function test_true(value, msg, properties) | |
| 149 { | |
| 150 wp_test(function () { assert_true(value, msg); }, msg, properties); | |
| 151 } | |
| 152 | |
| 153 function test_equals(value, equals, msg, properties) | |
| 154 { | |
| 155 wp_test(function () { assert_equals(value, equals, msg); }, msg, properties)
; | |
| 156 } | |
| 157 | |
| 158 function test_greater_than(value, greater_than, msg, properties) | 121 function test_greater_than(value, greater_than, msg, properties) |
| 159 { | 122 { |
| 160 wp_test(function () { assert_true(value > greater_than, msg); }, msg, proper
ties); | 123 wp_test(function () { assert_true(value > greater_than, msg); }, msg, proper
ties); |
| 161 } | 124 } |
| 162 | 125 |
| 163 function test_greater_or_equals(value, greater_than, msg, properties) | 126 function test_greater_or_equals(value, greater_than, msg, properties) |
| 164 { | 127 { |
| 165 wp_test(function () { assert_true(value >= greater_than, msg); }, msg, prope
rties); | 128 wp_test(function () { assert_true(value >= greater_than, msg); }, msg, prope
rties); |
| 166 } | 129 } |
| 167 | 130 |
| 168 function test_not_equals(value, notequals, msg, properties) | 131 function test_not_equals(value, notequals, msg, properties) |
| 169 { | 132 { |
| 170 wp_test(function() { assert_true(value !== notequals, msg); }, msg, properti
es); | 133 wp_test(function() { assert_true(value !== notequals, msg); }, msg, properti
es); |
| 171 } | 134 } |
| OLD | NEW |