summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/hr-time/resources/clamped-time-origin.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/resources/clamped-time-origin.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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/resources/clamped-time-origin.js')
-rw-r--r--testing/web-platform/tests/hr-time/resources/clamped-time-origin.js30
1 files changed, 30 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.');
+};