mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 05:39:41 +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
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
// META: title=Web Locks API: Mixed Modes
|
|
// META: global=window,dedicatedworker,sharedworker,serviceworker
|
|
|
|
'use strict';
|
|
|
|
promise_test(async t => {
|
|
let unblock;
|
|
const blocked = new Promise(r => { unblock = r; });
|
|
|
|
const granted = [];
|
|
|
|
// These should be granted immediately, and held until unblocked.
|
|
navigator.locks.request('a', {mode: 'shared'}, async lock => {
|
|
granted.push('a-shared-1'); await blocked; });
|
|
navigator.locks.request('a', {mode: 'shared'}, async lock => {
|
|
granted.push('a-shared-2'); await blocked; });
|
|
navigator.locks.request('a', {mode: 'shared'}, async lock => {
|
|
granted.push('a-shared-3'); await blocked; });
|
|
|
|
// This should be blocked.
|
|
let exclusive_lock;
|
|
const exclusive_request = navigator.locks.request('a', async lock => {
|
|
granted.push('a-exclusive');
|
|
exclusive_lock = lock;
|
|
});
|
|
|
|
// This should be granted immediately (different name).
|
|
await navigator.locks.request('b', {mode: 'exclusive'}, lock => {
|
|
granted.push('b-exclusive'); });
|
|
|
|
assert_array_equals(
|
|
granted, ['a-shared-1', 'a-shared-2', 'a-shared-3', 'b-exclusive']);
|
|
|
|
// Release the shared locks granted above.
|
|
unblock();
|
|
|
|
// Now the blocked request can be granted.
|
|
await exclusive_request;
|
|
assert_equals(exclusive_lock.mode, 'exclusive');
|
|
|
|
assert_array_equals(
|
|
granted,
|
|
['a-shared-1', 'a-shared-2', 'a-shared-3', 'b-exclusive', 'a-exclusive']);
|
|
|
|
}, 'Lock requests are granted in order');
|