From 537d52fa0f744295d9cea3a84311dc5347c51bfa Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 2 Aug 2022 10:17:09 -0400 Subject: [PATCH] test: update hr-time web platform tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/44100 Reviewed-By: Feng Yu Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca --- test/fixtures/wpt/README.md | 2 +- .../clamped-time-origin-isolated.https.html | 14 +++++++ ...ed-time-origin-isolated.https.html.headers | 2 + .../wpt/hr-time/clamped-time-origin.html | 14 +++++++ ...s-origin-isolated-timing-attack.https.html | 22 ++++++++++ ...-isolated-timing-attack.https.html.headers | 2 + .../hr-time/idlharness-shadowrealm.window.js | 2 + .../navigation-start-post-before-unload.html | 33 +++++++++++++++ .../hr-time/resources/clamped-time-origin.js | 30 +++++++++++++ test/fixtures/wpt/hr-time/resources/post.html | 4 ++ .../wpt/hr-time/resources/timing-attack.js | 42 +++++++++++++++++++ test/fixtures/wpt/hr-time/timing-attack.html | 39 ++--------------- test/fixtures/wpt/versions.json | 2 +- 13 files changed, 170 insertions(+), 38 deletions(-) create mode 100644 test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html create mode 100644 test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html.headers create mode 100644 test/fixtures/wpt/hr-time/clamped-time-origin.html create mode 100644 test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html create mode 100644 test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html.headers create mode 100644 test/fixtures/wpt/hr-time/idlharness-shadowrealm.window.js create mode 100644 test/fixtures/wpt/hr-time/navigation-start-post-before-unload.html create mode 100644 test/fixtures/wpt/hr-time/resources/clamped-time-origin.js create mode 100644 test/fixtures/wpt/hr-time/resources/post.html create mode 100644 test/fixtures/wpt/hr-time/resources/timing-attack.js diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 250090ddbb90b9..648298db082395 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -16,7 +16,7 @@ Last update: - dom/events: https://github.com/web-platform-tests/wpt/tree/f8821adb28/dom/events - encoding: https://github.com/web-platform-tests/wpt/tree/c1b24fce6e/encoding - FileAPI: https://github.com/web-platform-tests/wpt/tree/3b279420d4/FileAPI -- hr-time: https://github.com/web-platform-tests/wpt/tree/9910784394/hr-time +- hr-time: https://github.com/web-platform-tests/wpt/tree/34cafd797e/hr-time - html/webappapis/atob: https://github.com/web-platform-tests/wpt/tree/f267e1dca6/html/webappapis/atob - html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing - html/webappapis/structured-clone: https://github.com/web-platform-tests/wpt/tree/47d3fb280c/html/webappapis/structured-clone diff --git a/test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html b/test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html new file mode 100644 index 00000000000000..ce30698b77ae3f --- /dev/null +++ b/test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html.headers b/test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html.headers new file mode 100644 index 00000000000000..5f8621ef83660c --- /dev/null +++ b/test/fixtures/wpt/hr-time/clamped-time-origin-isolated.https.html.headers @@ -0,0 +1,2 @@ +Cross-Origin-Embedder-Policy: require-corp +Cross-Origin-Opener-Policy: same-origin diff --git a/test/fixtures/wpt/hr-time/clamped-time-origin.html b/test/fixtures/wpt/hr-time/clamped-time-origin.html new file mode 100644 index 00000000000000..1f438e9fefc0ff --- /dev/null +++ b/test/fixtures/wpt/hr-time/clamped-time-origin.html @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html b/test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html new file mode 100644 index 00000000000000..88848740a90cee --- /dev/null +++ b/test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html @@ -0,0 +1,22 @@ + + + + +window.performance.now should not enable timing attacks + + + + + + + + +

Description

+

The recommended minimum resolution of the Performance interface should be set to 5 microseconds.

+ +
+ + + diff --git a/test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html.headers b/test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html.headers new file mode 100644 index 00000000000000..5f8621ef83660c --- /dev/null +++ b/test/fixtures/wpt/hr-time/cross-origin-isolated-timing-attack.https.html.headers @@ -0,0 +1,2 @@ +Cross-Origin-Embedder-Policy: require-corp +Cross-Origin-Opener-Policy: same-origin diff --git a/test/fixtures/wpt/hr-time/idlharness-shadowrealm.window.js b/test/fixtures/wpt/hr-time/idlharness-shadowrealm.window.js new file mode 100644 index 00000000000000..3209db5f41b721 --- /dev/null +++ b/test/fixtures/wpt/hr-time/idlharness-shadowrealm.window.js @@ -0,0 +1,2 @@ +// META: script=/resources/idlharness-shadowrealm.js +idl_test_shadowrealm(["hr-time"], ["html", "dom"]); diff --git a/test/fixtures/wpt/hr-time/navigation-start-post-before-unload.html b/test/fixtures/wpt/hr-time/navigation-start-post-before-unload.html new file mode 100644 index 00000000000000..88ee5db77eb0e6 --- /dev/null +++ b/test/fixtures/wpt/hr-time/navigation-start-post-before-unload.html @@ -0,0 +1,33 @@ + + + + + + + + + + diff --git a/test/fixtures/wpt/hr-time/resources/clamped-time-origin.js b/test/fixtures/wpt/hr-time/resources/clamped-time-origin.js new file mode 100644 index 00000000000000..09967ed6d17ec0 --- /dev/null +++ b/test/fixtures/wpt/hr-time/resources/clamped-time-origin.js @@ -0,0 +1,30 @@ +const run_test = isolated => { + // Multiplier to convert the clamped timestamps to microseconds. + const multiplier = 1000; + const windowOrigin = performance.timeOrigin; + // Clamp to at least 5 microseconds in isolated contexts and at least 100 in + // non-isolated ones. + const resolution = isolated ? 5 : 100; + + const create_worker = () => { + return new Promise(resolve => { + const workerScript = 'postMessage({timeOrigin: performance.timeOrigin})'; + const blob = new Blob([workerScript]); + const worker = new Worker(URL.createObjectURL(blob)); + worker.addEventListener('message', event => { + resolve(event.data.timeOrigin); + }); + }); + }; + promise_test(async t => { + assert_equals(self.crossOriginIsolated, isolated, + "crossOriginIsolated is properly set"); + let prev = windowOrigin; + let current; + for (let i = 1; i < 100; ++i) { + current = await create_worker(); + assert_true(current === prev || current - prev > resolution / 1000); + prev = current; + } + }, 'timeOrigins are clamped.'); +}; diff --git a/test/fixtures/wpt/hr-time/resources/post.html b/test/fixtures/wpt/hr-time/resources/post.html new file mode 100644 index 00000000000000..b8541016dd776b --- /dev/null +++ b/test/fixtures/wpt/hr-time/resources/post.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/test/fixtures/wpt/hr-time/resources/timing-attack.js b/test/fixtures/wpt/hr-time/resources/timing-attack.js new file mode 100644 index 00000000000000..f1fc786903a864 --- /dev/null +++ b/test/fixtures/wpt/hr-time/resources/timing-attack.js @@ -0,0 +1,42 @@ +function run_test(isolated) { + let resolution = 100; + if (isolated) { + resolution = 5; + } + test(function() { + function check_resolutions(times, length) { + const end = length - 2; + + // we compare each value with the following ones + for (let i = 0; i < end; i++) { + const h1 = times[i]; + for (let j = i+1; j < end; j++) { + const h2 = times[j]; + const diff = h2 - h1; + assert_true((diff === 0) || ((diff * 1000) >= resolution), + "Differences smaller than ' + resolution + ' microseconds: " + diff); + } + } + return true; + } + + const times = new Array(10); + let index = 0; + let hrt1, hrt2, hrt; + assert_equals(self.crossOriginIsolated, isolated, "Document cross-origin isolated value matches"); + + // rapid firing of performance.now + hrt1 = performance.now(); + hrt2 = performance.now(); + times[index++] = hrt1; + times[index++] = hrt2; + + // ensure that we get performance.now() to return a different value + do { + hrt = performance.now(); + times[index++] = hrt; + } while ((hrt - hrt1) === 0); + + assert_true(check_resolutions(times, index), 'Difference should be at least ' + resolution + ' microseconds.'); + }, 'The recommended minimum resolution of the Performance interface has been set to ' + resolution + ' microseconds for cross-origin isolated contexts.'); +} diff --git a/test/fixtures/wpt/hr-time/timing-attack.html b/test/fixtures/wpt/hr-time/timing-attack.html index 71ade4a8c48ce2..6352b4dbe37e75 100644 --- a/test/fixtures/wpt/hr-time/timing-attack.html +++ b/test/fixtures/wpt/hr-time/timing-attack.html @@ -7,47 +7,14 @@ +

Description

-

The recommended minimum resolution of the Performance interface should be set to 5 microseconds.

+

The recommended minimum resolution of the Performance interface should be set to 100 microseconds for non-isolated contexts.

diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index fcfd7b302751bd..63fa4da214d049 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -24,7 +24,7 @@ "path": "FileAPI" }, "hr-time": { - "commit": "9910784394858a8e34d9eb4e5d00788765abf837", + "commit": "34cafd797e58dad280d20040eee012d49ccfa91f", "path": "hr-time" }, "html/webappapis/atob": {