From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- testing/web-platform/tests/hr-time/META.yml | 4 ++ testing/web-platform/tests/hr-time/basic.any.js | 37 +++++++++++ .../clamped-time-origin-isolated.https.html | 14 ++++ ...clamped-time-origin-isolated.https.html.headers | 2 + .../tests/hr-time/clamped-time-origin.html | 14 ++++ .../cross-origin-isolated-timing-attack.https.html | 22 +++++++ ...rigin-isolated-timing-attack.https.html.headers | 2 + .../tests/hr-time/idlharness-shadowrealm.window.js | 2 + .../web-platform/tests/hr-time/idlharness.any.js | 23 +++++++ .../tests/hr-time/monotonic-clock.any.js | 13 ++++ .../navigation-start-post-before-unload.html | 33 ++++++++++ .../tests/hr-time/performance-tojson.html | 76 ++++++++++++++++++++++ .../tests/hr-time/resources/clamped-time-origin.js | 30 +++++++++ .../tests/hr-time/resources/now_frame.html | 9 +++ .../web-platform/tests/hr-time/resources/post.html | 4 ++ .../tests/hr-time/resources/timing-attack.js | 42 ++++++++++++ .../tests/hr-time/resources/unload-a.html | 13 ++++ .../tests/hr-time/resources/unload-b.html | 13 ++++ .../tests/hr-time/resources/unload-c.html | 13 ++++ .../web-platform/tests/hr-time/resources/unload.js | 51 +++++++++++++++ .../tests/hr-time/test_cross_frame_start.html | 59 +++++++++++++++++ testing/web-platform/tests/hr-time/timeOrigin.html | 45 +++++++++++++ .../web-platform/tests/hr-time/timing-attack.html | 22 +++++++ .../web-platform/tests/hr-time/unload-manual.html | 73 +++++++++++++++++++++ .../hr-time/window-worker-timeOrigin.window.js | 30 +++++++++ 25 files changed, 646 insertions(+) create mode 100644 testing/web-platform/tests/hr-time/META.yml create mode 100644 testing/web-platform/tests/hr-time/basic.any.js create mode 100644 testing/web-platform/tests/hr-time/clamped-time-origin-isolated.https.html create mode 100644 testing/web-platform/tests/hr-time/clamped-time-origin-isolated.https.html.headers create mode 100644 testing/web-platform/tests/hr-time/clamped-time-origin.html create mode 100644 testing/web-platform/tests/hr-time/cross-origin-isolated-timing-attack.https.html create mode 100644 testing/web-platform/tests/hr-time/cross-origin-isolated-timing-attack.https.html.headers create mode 100644 testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.js create mode 100644 testing/web-platform/tests/hr-time/idlharness.any.js create mode 100644 testing/web-platform/tests/hr-time/monotonic-clock.any.js create mode 100644 testing/web-platform/tests/hr-time/navigation-start-post-before-unload.html create mode 100644 testing/web-platform/tests/hr-time/performance-tojson.html create mode 100644 testing/web-platform/tests/hr-time/resources/clamped-time-origin.js create mode 100644 testing/web-platform/tests/hr-time/resources/now_frame.html create mode 100644 testing/web-platform/tests/hr-time/resources/post.html create mode 100644 testing/web-platform/tests/hr-time/resources/timing-attack.js create mode 100644 testing/web-platform/tests/hr-time/resources/unload-a.html create mode 100644 testing/web-platform/tests/hr-time/resources/unload-b.html create mode 100644 testing/web-platform/tests/hr-time/resources/unload-c.html create mode 100644 testing/web-platform/tests/hr-time/resources/unload.js create mode 100644 testing/web-platform/tests/hr-time/test_cross_frame_start.html create mode 100644 testing/web-platform/tests/hr-time/timeOrigin.html create mode 100644 testing/web-platform/tests/hr-time/timing-attack.html create mode 100644 testing/web-platform/tests/hr-time/unload-manual.html create mode 100644 testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js (limited to 'testing/web-platform/tests/hr-time') diff --git a/testing/web-platform/tests/hr-time/META.yml b/testing/web-platform/tests/hr-time/META.yml new file mode 100644 index 0000000000..779d5b4af0 --- /dev/null +++ b/testing/web-platform/tests/hr-time/META.yml @@ -0,0 +1,4 @@ +spec: https://w3c.github.io/hr-time/ +suggested_reviewers: + - plehegar + - igrigorik diff --git a/testing/web-platform/tests/hr-time/basic.any.js b/testing/web-platform/tests/hr-time/basic.any.js new file mode 100644 index 0000000000..4cd6e42dfc --- /dev/null +++ b/testing/web-platform/tests/hr-time/basic.any.js @@ -0,0 +1,37 @@ +test(function() { + assert_true((self.performance !== undefined), "self.performance exists"); + assert_equals(typeof self.performance, "object", "self.performance is an object"); + assert_equals((typeof self.performance.now), "function", "self.performance.now() is a function"); + assert_equals(typeof self.performance.now(), "number", "self.performance.now() returns a number"); +}, "self.performance.now() is a function that returns a number"); + +test(function() { + assert_true(self.performance.now() > 0); +}, "self.performance.now() returns a positive number"); + +test(function() { + var now1 = self.performance.now(); + var now2 = self.performance.now(); + assert_true((now2-now1) >= 0); + }, "self.performance.now() difference is not negative"); + +async_test(function() { + // Check whether the performance.now() method is close to Date() within 30ms (due to inaccuracies) + var initial_hrt = self.performance.now(); + var initial_date = Date.now(); + this.step_timeout(function() { + var final_hrt = self.performance.now(); + var final_date = Date.now(); + assert_approx_equals(final_hrt - initial_hrt, final_date - initial_date, 30, 'High resolution time value increased by approximately the same amount as time from date object'); + this.done(); + }, 2000); +}, 'High resolution time has approximately the right relative magnitude'); + +test(function() { + var didHandle = false; + self.performance.addEventListener("testEvent", function() { + didHandle = true; + }, { once: true} ); + self.performance.dispatchEvent(new Event("testEvent")); + assert_true(didHandle, "Performance extends EventTarget, so event dispatching should work."); +}, "Performance interface extends EventTarget."); diff --git a/testing/web-platform/tests/hr-time/clamped-time-origin-isolated.https.html b/testing/web-platform/tests/hr-time/clamped-time-origin-isolated.https.html new file mode 100644 index 0000000000..ce30698b77 --- /dev/null +++ b/testing/web-platform/tests/hr-time/clamped-time-origin-isolated.https.html @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/testing/web-platform/tests/hr-time/clamped-time-origin-isolated.https.html.headers b/testing/web-platform/tests/hr-time/clamped-time-origin-isolated.https.html.headers new file mode 100644 index 0000000000..5f8621ef83 --- /dev/null +++ b/testing/web-platform/tests/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/testing/web-platform/tests/hr-time/clamped-time-origin.html b/testing/web-platform/tests/hr-time/clamped-time-origin.html new file mode 100644 index 0000000000..1f438e9fef --- /dev/null +++ b/testing/web-platform/tests/hr-time/clamped-time-origin.html @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/testing/web-platform/tests/hr-time/cross-origin-isolated-timing-attack.https.html b/testing/web-platform/tests/hr-time/cross-origin-isolated-timing-attack.https.html new file mode 100644 index 0000000000..88848740a9 --- /dev/null +++ b/testing/web-platform/tests/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/testing/web-platform/tests/hr-time/cross-origin-isolated-timing-attack.https.html.headers b/testing/web-platform/tests/hr-time/cross-origin-isolated-timing-attack.https.html.headers new file mode 100644 index 0000000000..5f8621ef83 --- /dev/null +++ b/testing/web-platform/tests/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/testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.js b/testing/web-platform/tests/hr-time/idlharness-shadowrealm.window.js new file mode 100644 index 0000000000..3209db5f41 --- /dev/null +++ b/testing/web-platform/tests/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/testing/web-platform/tests/hr-time/idlharness.any.js b/testing/web-platform/tests/hr-time/idlharness.any.js new file mode 100644 index 0000000000..6676b001a8 --- /dev/null +++ b/testing/web-platform/tests/hr-time/idlharness.any.js @@ -0,0 +1,23 @@ +// META: global=window,worker +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +'use strict'; + +// https://w3c.github.io/hr-time/ + +idl_test( + ['hr-time'], + ['html', 'dom'], + async idl_array => { + if (self.GLOBAL.isWorker()) { + idl_array.add_objects({ WorkerGlobalScope: ['self'] }); + } else { + idl_array.add_objects({ Window: ['self'] }); + } + idl_array.add_objects({ + Performance: ['performance'], + }); + } +); diff --git a/testing/web-platform/tests/hr-time/monotonic-clock.any.js b/testing/web-platform/tests/hr-time/monotonic-clock.any.js new file mode 100644 index 0000000000..c53b04d844 --- /dev/null +++ b/testing/web-platform/tests/hr-time/monotonic-clock.any.js @@ -0,0 +1,13 @@ +// The time values returned when calling the now method MUST be monotonically increasing and not subject to system clock adjustments or system clock skew. +test(function() { + assert_true(self.performance.now() > 0, "self.performance.now() returns positive numbers"); +}, "self.performance.now() returns a positive number"); + +// The difference between any two chronologically recorded time values returned from the now method MUST never be negative. +test(function() { + var now1 = self.performance.now(); + var now2 = self.performance.now(); + assert_true((now2-now1) >= 0, "self.performance.now() difference is not negative"); + }, + "self.performance.now() difference is not negative" +); diff --git a/testing/web-platform/tests/hr-time/navigation-start-post-before-unload.html b/testing/web-platform/tests/hr-time/navigation-start-post-before-unload.html new file mode 100644 index 0000000000..88ee5db77e --- /dev/null +++ b/testing/web-platform/tests/hr-time/navigation-start-post-before-unload.html @@ -0,0 +1,33 @@ + + + + + + + + + + diff --git a/testing/web-platform/tests/hr-time/performance-tojson.html b/testing/web-platform/tests/hr-time/performance-tojson.html new file mode 100644 index 0000000000..fd8049cb9a --- /dev/null +++ b/testing/web-platform/tests/hr-time/performance-tojson.html @@ -0,0 +1,76 @@ + + + + + + + + + + \ No newline at end of file diff --git a/testing/web-platform/tests/hr-time/resources/clamped-time-origin.js b/testing/web-platform/tests/hr-time/resources/clamped-time-origin.js new file mode 100644 index 0000000000..09967ed6d1 --- /dev/null +++ b/testing/web-platform/tests/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/testing/web-platform/tests/hr-time/resources/now_frame.html b/testing/web-platform/tests/hr-time/resources/now_frame.html new file mode 100644 index 0000000000..5bec688af9 --- /dev/null +++ b/testing/web-platform/tests/hr-time/resources/now_frame.html @@ -0,0 +1,9 @@ + + + + + window.performance.now frame + + + + diff --git a/testing/web-platform/tests/hr-time/resources/post.html b/testing/web-platform/tests/hr-time/resources/post.html new file mode 100644 index 0000000000..b8541016dd --- /dev/null +++ b/testing/web-platform/tests/hr-time/resources/post.html @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/testing/web-platform/tests/hr-time/resources/timing-attack.js b/testing/web-platform/tests/hr-time/resources/timing-attack.js new file mode 100644 index 0000000000..f1fc786903 --- /dev/null +++ b/testing/web-platform/tests/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/testing/web-platform/tests/hr-time/resources/unload-a.html b/testing/web-platform/tests/hr-time/resources/unload-a.html new file mode 100644 index 0000000000..40c1d06183 --- /dev/null +++ b/testing/web-platform/tests/hr-time/resources/unload-a.html @@ -0,0 +1,13 @@ + + + + Helper page for ../unload-manual.html + + + + + + + diff --git a/testing/web-platform/tests/hr-time/resources/unload-b.html b/testing/web-platform/tests/hr-time/resources/unload-b.html new file mode 100644 index 0000000000..7c2d90df27 --- /dev/null +++ b/testing/web-platform/tests/hr-time/resources/unload-b.html @@ -0,0 +1,13 @@ + + + + Helper page for ../unload-manual.html + + + + + + + diff --git a/testing/web-platform/tests/hr-time/resources/unload-c.html b/testing/web-platform/tests/hr-time/resources/unload-c.html new file mode 100644 index 0000000000..731da9db75 --- /dev/null +++ b/testing/web-platform/tests/hr-time/resources/unload-c.html @@ -0,0 +1,13 @@ + + + + Helper page for ../unload-manual.html + + + + + + + diff --git a/testing/web-platform/tests/hr-time/resources/unload.js b/testing/web-platform/tests/hr-time/resources/unload.js new file mode 100644 index 0000000000..ab6b121c2b --- /dev/null +++ b/testing/web-platform/tests/hr-time/resources/unload.js @@ -0,0 +1,51 @@ +const syncDelay = ms => { + const start = performance.now(); + let elapsedTime; + do { + elapsedTime = performance.now() - start; + } while (elapsedTime < ms); +}; + +const markTime = (docName, lifecycleEventName) => { + // Calculating these values before the below `mark` invocation ensures that delays in + // reaching across to the other window object doesn't interfere with the correctness + // of the test. + const dateNow = Date.now(); + const performanceNow = performance.now(); + + window.opener.mark({ + docName, + lifecycleEventName, + performanceNow: performanceNow, + dateNow: dateNow + }); +}; + +const setupUnloadPrompt = (docName, msg) => { + window.addEventListener("beforeunload", ev => { + markTime(docName, "beforeunload"); + return ev.returnValue = msg || "Click OK to continue test." + }); +}; + +const setupListeners = (docName, nextDocument) => { + window.addEventListener("load", () => { + markTime(docName, "load"); + document.getElementById("proceed").addEventListener("click", ev => { + ev.preventDefault(); + if (nextDocument) { + document.location = nextDocument; + } else { + window.close(); + } + }) + }); + + setupUnloadPrompt(docName); + + window.addEventListener("unload", () => { + markTime(docName, "unload"); + if (docName !== "c") { syncDelay(1000); } + }); +}; + diff --git a/testing/web-platform/tests/hr-time/test_cross_frame_start.html b/testing/web-platform/tests/hr-time/test_cross_frame_start.html new file mode 100644 index 0000000000..30e804bd73 --- /dev/null +++ b/testing/web-platform/tests/hr-time/test_cross_frame_start.html @@ -0,0 +1,59 @@ + + + + + window.performance.now across frames + + + + + + + + + + +

Description

+

This test validates the values of the window.performance.now() are based on the current document's navigationStart.

+
+ + diff --git a/testing/web-platform/tests/hr-time/timeOrigin.html b/testing/web-platform/tests/hr-time/timeOrigin.html new file mode 100644 index 0000000000..20aea75084 --- /dev/null +++ b/testing/web-platform/tests/hr-time/timeOrigin.html @@ -0,0 +1,45 @@ + + + + + + + + + + \ No newline at end of file diff --git a/testing/web-platform/tests/hr-time/timing-attack.html b/testing/web-platform/tests/hr-time/timing-attack.html new file mode 100644 index 0000000000..6352b4dbe3 --- /dev/null +++ b/testing/web-platform/tests/hr-time/timing-attack.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 100 microseconds for non-isolated contexts.

+ +
+ + + diff --git a/testing/web-platform/tests/hr-time/unload-manual.html b/testing/web-platform/tests/hr-time/unload-manual.html new file mode 100644 index 0000000000..18c4e0dc32 --- /dev/null +++ b/testing/web-platform/tests/hr-time/unload-manual.html @@ -0,0 +1,73 @@ + + + + time origin value manual test + + + + + + + + + + +

Description

+

This test validates the behavior of performance.now() with respect to its time origin.

+
+

Manual Test Steps

+
    +
  1. Click here +
+
+ + diff --git a/testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js b/testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js new file mode 100644 index 0000000000..1e5ef1cdff --- /dev/null +++ b/testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js @@ -0,0 +1,30 @@ +"use strict" +// https://w3c.github.io/hr-time/#time-origin + +async_test(function(test) { + // Cache global time before starting worker + const globalTimeOrigin = performance.timeOrigin; + const globalNowBeforeWorkerStart = performance.now(); + + // Start worker and retrieve time + const workerScript = "postMessage({timeOrigin: performance.timeOrigin, now: performance.now()})"; + const blob = new Blob([workerScript]); + let worker = new Worker(URL.createObjectURL(blob)); + + worker.addEventListener("message", test.step_func_done(function(event) { + const workerTimeOrigin = event.data.timeOrigin; + const workerNow = event.data.now; + + assert_not_equals(workerTimeOrigin, 0, "worker timeOrigin must not be 0"); + assert_not_equals(performance.timeOrigin, 0, "Document timeOrigin must not be 0"); + + assert_equals(globalTimeOrigin, performance.timeOrigin, "timeOrigin should not be changed in same document mode"); + assert_less_than(globalTimeOrigin, workerTimeOrigin, "Document timeOrigin must be earlier than worker timeOrigin"); + + // Document and worker's now() start from their respective timeOrigins. + const timeDiff = workerTimeOrigin - globalTimeOrigin; // convert worker's time to Document time. + assert_less_than(globalTimeOrigin + globalNowBeforeWorkerStart, globalTimeOrigin + timeDiff + workerNow, "Document old now is earlier than worker now."); + + // Comparing timing between Document and worker threads could be delicate as it relies on the thread implementation and could be subject to race conditions. + })); +}, 'timeOrigin and now() should be correctly ordered between window and worker'); -- cgit v1.2.3