From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../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 ++++++++++++++++++++++ 8 files changed, 175 insertions(+) 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 (limited to 'testing/web-platform/tests/hr-time/resources') 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); } + }); +}; + -- cgit v1.2.3