mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-10 13:18:45 +02:00
Automatic update from web-platform-testsWeb Locks API: Run tests in additional globals Use the "META: global=" annotation to run the web-locks/ tests in shared and service workers, as appropriate. Change-Id: I1d6acd9b4e2932bf3a60b1e41285cbe74e3cb8ff Reviewed-on: https://chromium-review.googlesource.com/1208447 Commit-Queue: Victor Costan <pwnall@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Cr-Commit-Position: refs/heads/master@{#590265} -- wpt-commits: 7d538d126b49411702cdd88354f520cdf9a65702 wpt-pr: 12860 --HG-- extra : rebase_source : 125cfaf5b02d72d5746aaeb894d27ef8da08c929 extra : source : 703c030316ba169ade809c83d901a58f1881677c
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
// 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');
|