summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-locks/workers.tentative.https.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/web-locks/workers.tentative.https.html
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/web-locks/workers.tentative.https.html')
-rw-r--r--testing/web-platform/tests/web-locks/workers.tentative.https.html122
1 files changed, 122 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-locks/workers.tentative.https.html b/testing/web-platform/tests/web-locks/workers.tentative.https.html
new file mode 100644
index 0000000000..9fe38dbe38
--- /dev/null
+++ b/testing/web-platform/tests/web-locks/workers.tentative.https.html
@@ -0,0 +1,122 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>Web Locks API: Workers</title>
+<link rel=help href="https://w3c.github.io/web-locks/">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/helpers.js"></script>
+<script>
+'use strict';
+
+promise_test(async t => {
+ assert_implements(navigator.locks);
+ const worker = new Worker('resources/worker.js');
+ t.add_cleanup(() => { worker.terminate(); });
+
+ const res = 'shared resource 1';
+
+ const lock_id = (await postToWorkerAndWait(
+ worker, {op: 'request', name: res, mode: 'shared'})).lock_id;
+
+ await navigator.locks.request(res, {mode: 'shared'}, async lock => {
+ await postToWorkerAndWait(worker, {op: 'release', lock_id});
+ });
+
+}, 'Window and Worker - shared mode');
+
+promise_test(async t => {
+ assert_implements(navigator.locks);
+ const worker = new Worker('resources/worker.js');
+ t.add_cleanup(() => { worker.terminate(); });
+
+ const res = 'exclusive resource 1';
+
+ // worker acquires the lock.
+ const lock_id = (await postToWorkerAndWait(
+ worker, {op: 'request', name: res})).lock_id;
+
+ // This request should be blocked.
+ let lock_granted = false;
+ const blocked = navigator.locks.request(
+ res, lock => { lock_granted = true; });
+
+ // Verify we can't get it.
+ let available = undefined;
+ await navigator.locks.request(
+ res, {ifAvailable: true}, lock => { available = lock !== null; });
+ assert_false(available);
+ assert_false(lock_granted);
+
+ // Ask the worker to release it.
+ await postToWorkerAndWait(worker, {op: 'release', lock_id});
+
+ // Now we've got it.
+ const lock2 = await blocked;
+ assert_true(lock_granted);
+
+}, 'Window and Worker - exclusive mode');
+
+promise_test(async t => {
+ assert_implements(navigator.locks);
+ const worker1 = new Worker('resources/worker.js');
+ const worker2 = new Worker('resources/worker.js');
+ t.add_cleanup(() => { worker1.terminate(); worker2.terminate(); });
+
+ const res = 'exclusive resource 2';
+
+ // worker1 acquires the lock.
+ const lock_id = (await postToWorkerAndWait(
+ worker1, {op: 'request', name: res})).lock_id;
+
+ // This request should be blocked.
+ let lock_granted = false;
+ const blocked = postToWorkerAndWait(
+ worker2, {op: 'request', name: res});
+ blocked.then(f => { lock_granted = true; });
+
+ // Verify worker2 can't get it.
+ assert_true((await postToWorkerAndWait(worker2, {
+ op: 'request', name: res, ifAvailable: true
+ })).failed, 'Lock request should have failed');
+ assert_false(lock_granted);
+
+ // Ask worker1 to release it.
+ await postToWorkerAndWait(worker1, {op: 'release', lock_id});
+
+ // Now worker2 can get it.
+ const lock = await blocked;
+ assert_true(lock_granted);
+
+}, 'Worker and Worker - exclusive mode');
+
+promise_test(async t => {
+ assert_implements(navigator.locks);
+ const worker = new Worker('resources/worker.js');
+
+ const res = 'exclusive resource 3';
+
+ // Worker acquires the lock.
+ await postToWorkerAndWait(worker, {op: 'request', name: res});
+
+ // This request should be blocked.
+ let lock_granted = false;
+ const blocked = navigator.locks.request(
+ res, lock => { lock_granted = true; });
+
+ // Verify we can't get it.
+ let available = undefined;
+ await navigator.locks.request(
+ res, {ifAvailable: true}, lock => { available = lock !== null; });
+ assert_false(available);
+ assert_false(lock_granted);
+
+ // Implicitly release it by terminating the worker.
+ worker.terminate();
+
+ // Now we've got it.
+ const lock = await blocked;
+ assert_true(lock_granted);
+
+}, 'Terminated Worker - exclusive mode');
+
+</script>