summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js')
-rw-r--r--testing/web-platform/tests/hr-time/window-worker-timeOrigin.window.js30
1 files changed, 30 insertions, 0 deletions
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');