Files
sousa-gecko/testing/web-platform/tests/web-locks/bfcache/contention.https.window.js
T
Anna Sato be557f6832 Bug 2037846 [wpt PR 59720] - [WebLocks] Synchronously release BFCached clients on contention, a=testonly
Automatic update from web-platform-tests
[WebLocks] Synchronously release BFCached clients on contention

When a new lock request cannot be granted immediately, LockManager
notifies the current holders. If a holder is evicted from BFCache as a
result, LockManager now synchronously breaks its lock, allowing the new
request to be granted immediately.

This change also adds WPT variants to verify contention scenarios
involving `ifAvailable: true` requests.

Bug: 483882230
Change-Id: I6d71c741371cb5e7820b4e3f7abebc103d6dd3a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7775615
Reviewed-by: Fergal Daly <fergal@chromium.org>
Commit-Queue: Anna Sato <annasato@chromium.org>
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1626795}

--

wpt-commits: 9e7ae89170eff630799648f4980b44887e2a4ea4
wpt-pr: 59720
2026-05-12 08:47:37 +00:00

87 lines
3.1 KiB
JavaScript

// META: title=Web Locks API: bfcache contention test
// META: timeout=long
// META: variant=?context=document&contention=request
// META: variant=?context=worker&contention=request
// META: variant=?context=nested-worker&contention=request
// META: variant=?context=shared-worker&contention=request
// META: variant=?context=document&contention=request-if-available
// META: variant=?context=worker&contention=request-if-available
// META: variant=?context=nested-worker&contention=request-if-available
// META: variant=?context=shared-worker&contention=request-if-available
// META: variant=?context=document&contention=query
// META: variant=?context=worker&contention=query
// META: variant=?context=nested-worker&contention=query
// META: variant=?context=shared-worker&contention=query
// META: script=/common/utils.js
// META: script=/common/dispatcher/dispatcher.js
// META: script=/web-locks/resources/helpers.js
// META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js
// META: script=./helpers.js
const contexts = {
'document': {
description: 'the main thread',
funcBeforeNavigation: (name) => {
navigator.locks.request(name, () => new Promise(() => {}));
},
},
'worker': {
description: 'a worker',
funcBeforeNavigation: async (name) => {
window.worker = new Worker('/web-locks/resources/worker.js');
await postToWorkerAndWait(worker, {op: 'request', name: name});
},
},
'nested-worker': {
description: 'a nested worker',
funcBeforeNavigation: async (name) => {
window.worker = new Worker('/web-locks/resources/parentworker.js');
await postToWorkerAndWait(worker, {op: 'request', name: name});
},
},
'shared-worker': {
description: 'a shared worker',
funcBeforeNavigation: async (name) => {
window.worker = new SharedWorker('/web-locks/resources/worker.js');
worker.port.start();
await postToWorkerAndWait(worker.port, {op: 'request', name: name});
},
},
};
const contentions = {
'request': {
description: 'on navigator.locks.request()',
funcBeforeBackNavigation: (name) => {
return navigator.locks.request(name, () => {});
},
},
'request-if-available': {
description: 'on navigator.locks.request() with ifAvailable: true',
funcBeforeBackNavigation: (name) => {
return navigator.locks.request(name, { ifAvailable: true }, () => {});
},
},
'query': {
description: 'on navigator.locks.query()',
funcBeforeBackNavigation: () => navigator.locks.query(),
}
};
const params = new URLSearchParams(location.search);
const context = contexts[params.get('context')];
const contention = contentions[params.get('contention')];
const lockName = uniqueNameByQuery();
runWebLocksBfcacheTest(
{
targetOrigin: originSameOrigin,
argsBeforeNavigation: [lockName],
argsBeforeBackNavigation: [lockName],
funcBeforeNavigation: context.funcBeforeNavigation,
funcBeforeBackNavigation: contention.funcBeforeBackNavigation,
shouldBeCached: false,
},
`A held lock on ${context.description} should cause eviction ${
contention.description}`);