summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-locks/mode-shared.https.any.js
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/web-locks/mode-shared.https.any.js
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/web-locks/mode-shared.https.any.js')
-rw-r--r--testing/web-platform/tests/web-locks/mode-shared.https.any.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-locks/mode-shared.https.any.js b/testing/web-platform/tests/web-locks/mode-shared.https.any.js
new file mode 100644
index 0000000000..fc4a6012fa
--- /dev/null
+++ b/testing/web-platform/tests/web-locks/mode-shared.https.any.js
@@ -0,0 +1,38 @@
+// META: title=Web Locks API: Shared Mode
+// META: global=window,dedicatedworker,sharedworker,serviceworker
+
+'use strict';
+
+promise_test(async t => {
+ const granted = [];
+ function log_grant(n) { return () => { granted.push(n); }; }
+
+ await Promise.all([
+ navigator.locks.request('a', {mode: 'shared'}, log_grant(1)),
+ navigator.locks.request('b', {mode: 'shared'}, log_grant(2)),
+ navigator.locks.request('c', {mode: 'shared'}, log_grant(3)),
+ navigator.locks.request('a', {mode: 'shared'}, log_grant(4)),
+ navigator.locks.request('b', {mode: 'shared'}, log_grant(5)),
+ navigator.locks.request('c', {mode: 'shared'}, log_grant(6)),
+ ]);
+
+ assert_array_equals(granted, [1, 2, 3, 4, 5, 6]);
+}, 'Lock requests are granted in order');
+
+promise_test(async t => {
+ let a_acquired = false, a_acquired_again = false;
+
+ await navigator.locks.request('a', {mode: 'shared'}, async lock => {
+ a_acquired = true;
+
+ // Since lock is held, this request would be blocked if the
+ // lock was not 'shared', causing this test to time out.
+
+ await navigator.locks.request('a', {mode: 'shared'}, lock => {
+ a_acquired_again = true;
+ });
+ });
+
+ assert_true(a_acquired, 'first lock acquired');
+ assert_true(a_acquired_again, 'second lock acquired');
+}, 'Shared locks are not exclusive');