Files
firefox/testing/web-platform/tests/web-locks/mode-shared.tentative.https.any.js
T
Joshua Bell 25cc578e6e Bug 1483074 [wpt PR 12449] - Web Locks API: Convert .html tests to .any.js where applicable, a=testonly
Automatic update from web-platform-testsWeb Locks API: Convert .html tests to .any.js where applicable

Most tests can run in window and worker contexts, so make it so.

Bug: 161072
Change-Id: Ic0df3a888e477d27562dce957807dde36dc8f420
Reviewed-on: https://chromium-review.googlesource.com/1171255
Commit-Queue: Victor Costan <[email protected]>
Reviewed-by: Victor Costan <[email protected]>
Cr-Commit-Position: refs/heads/master@{#582778}

--

wpt-commits: c792ea26624bde49b72afce348de07ab72fb9ad7
wpt-pr: 12449
2018-08-16 17:47:12 +00:00

38 lines
1.2 KiB
JavaScript

// META: title=Web Locks API: Shared Mode
'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');