summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/hr-time/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/hr-time/resources
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/hr-time/resources')
-rw-r--r--testing/web-platform/tests/hr-time/resources/clamped-time-origin.js30
-rw-r--r--testing/web-platform/tests/hr-time/resources/now_frame.html9
-rw-r--r--testing/web-platform/tests/hr-time/resources/post.html4
-rw-r--r--testing/web-platform/tests/hr-time/resources/timing-attack.js42
-rw-r--r--testing/web-platform/tests/hr-time/resources/unload-a.html13
-rw-r--r--testing/web-platform/tests/hr-time/resources/unload-b.html13
-rw-r--r--testing/web-platform/tests/hr-time/resources/unload-c.html13
-rw-r--r--testing/web-platform/tests/hr-time/resources/unload.js51
8 files changed, 175 insertions, 0 deletions
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 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
+ <title>window.performance.now frame</title>
+ <link rel="author" title="Google" href="http://www.google.com/" />
+ </head>
+ <body></body>
+</html>
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 @@
+<!DOCTYPE HTML>
+<script>
+ window.parent.postMessage('done');
+</script> \ 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 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Helper page for ../unload-manual.html</title>
+</head>
+<body>
+ <script src="./unload.js"></script>
+ <script>
+ setupListeners("a", "./unload-b.html");
+ </script>
+ <button id="proceed">Click me!</button>
+</body>
+</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 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Helper page for ../unload-manual.html</title>
+</head>
+<body>
+ <script src="./unload.js"></script>
+ <script>
+ setupListeners("b", "./unload-c.html");
+ </script>
+ <button id="proceed">Click me again!</button>
+</body>
+</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 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Helper page for ../unload-manual.html</title>
+</head>
+<body>
+ <script src="./unload.js"></script>
+ <script>
+ setupListeners("c", null);
+ </script>
+ <button id="proceed">Click me, one last time!</button>
+</body>
+</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); }
+ });
+};
+