Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/external/wpt/server-timing/resources/webperftestharness.js |
| diff --git a/third_party/WebKit/LayoutTests/external/wpt/server-timing/resources/webperftestharness.js b/third_party/WebKit/LayoutTests/external/wpt/server-timing/resources/webperftestharness.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2676ef42471cc28688e9a4774d275883cd7ec5f1 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/external/wpt/server-timing/resources/webperftestharness.js |
| @@ -0,0 +1,53 @@ |
| +/* |
| +Distributed under both the W3C Test Suite License [1] and the W3C |
| +3-clause BSD License [2]. To contribute to a W3C Test Suite, see the |
| +policies and contribution forms [3]. |
| + |
| +[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license |
| +[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license |
| +[3] http://www.w3.org/2004/10/27-testcases |
| + */ |
|
panicker
2017/04/06 22:48:19
Could you provide some context on this test helper
cvazac
2017/04/06 23:50:00
Yes, I added the 4th copy of `wp_test()` :), here
panicker
2017/04/07 23:01:32
Please let's not add the 4th copy :)
You could eit
|
| + |
| +var namespace_check = false |
| +function wp_test(func, msg, properties) { |
| + if (!namespace_check) { |
| + namespace_check = true |
| + var performanceNamespace = window.performance |
| + if (performanceNamespace === undefined || performanceNamespace == null) { |
| + // show a single error that window.performance is undefined |
| + 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. " |
| + }) |
| + } |
| + } |
| + |
| + test(func, msg, properties) |
| +} |
| + |
| +function test_true(value, msg, properties) { |
| + wp_test(function () { |
| + assert_true(value, msg) |
| + }, msg, properties) |
| +} |
| + |
| +function test_equals(value, equals, msg, properties) { |
| + wp_test(function () { |
| + assert_equals(value, equals, msg) |
| + }, msg, properties) |
| +} |
| + |
| +// assert for every entry in `expectedEntries`, there is a matching entry _somewhere_ in `actualEntries` |
| +function test_entries(actualEntries, expectedEntries) { |
| + test_equals(actualEntries.length, expectedEntries.length) |
| + expectedEntries.forEach(function (expectedEntry) { |
| + test_true(!!actualEntries.find(function (actualEntry) { |
| + return typeof Object.keys(expectedEntry).find(function (key) { |
| + return actualEntry[key] !== expectedEntry[key] |
| + }) === 'undefined' |
| + })) |
| + }) |
| +} |