Files
sousa-gecko/testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-back-forward-cache.https.tentative.window.js
T
Nathan Memmott 26979f91cc Bug 1862343 [wpt PR 42879] - FSA: Return LockHandle after eviction, a=testonly
Automatic update from web-platform-tests
FSA: Return LockHandle after eviction

This is the final changes needed to implement BFCache logic for the File
System Access API. This change makes it so that when we attempt to take
a Lock on file with an existing contentious Lock, we can evict the Lock
if it is held by only inactive pages, and return the new Lock after
eviction.

When we evict a Lock to take a new Lock, the new Lock is pending until
the evicting Lock has been evicted. The pending Lock is not given to the
TakeLock caller until it is no longer pending.

While it is pending though, it is still considered an active Lock, and
all further calls to TakeLock will assume it exists.

If we attempt to take a Lock that is a child of a pending Lock, then it
will also be pending and the caller will not receive the Lock until the
ancestor pending Lock's evicting Lock has been evicted.

If we attempt to take a Lock that is in contention with a pending Lock,
then we can also evict the pending Lock if it is held only by inactive
pages. The callers for the evicting pending Lock will never receive it.
And the new pending Lock waits for the eviction of the original evicting
Lock that the evicting pending Lock was waiting on.

If we evict a Lock that has multiple pending Lock children, then the new
Lock must wait for the eviction of all the child pending Locks' evicting
locks.

Bug: 1382215, 1241174
Change-Id: Iabd602a6ae37bfb69f10e13f08cfb3c1c77bdbd2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4994423
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Nathan Memmott <memmott@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1226460}

--

wpt-commits: 4d050239d67b36f034a273b7c1d93e29235c1497
wpt-pr: 42879
2023-11-22 12:52:29 +00:00

65 lines
2.3 KiB
JavaScript

// META: script=/common/dispatcher/dispatcher.js
// META: script=/common/utils.js
// META: script=resources/test-helpers.js
// META: script=resources/messaging-helpers.js
// META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/rc-helper.js
// META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js
// META: timeout=long
'use strict';
createBFCacheTest(async (t, testControls) => {
const {getRemoteFuncs, assertBFCacheEligibility} = testControls;
const [createAndReleaseSAH] = getRemoteFuncs('createAndReleaseSAH');
for (const mode of SAH_MODES) {
await createAndReleaseSAH(mode, 'hello.txt');
await assertBFCacheEligibility(/*shouldRestoreFromBFCache=*/ true);
}
}, 'Creating an SAH should not make it ineligible for the BFCache.');
createBFCacheTest(async (t, testControls) => {
const origFile = 'hello.txt';
const diffFile = 'world.txt';
const {getRemoteFuncs, forward, back} = testControls;
const [createSAH, releaseSAH, createAndReleaseSAH] =
getRemoteFuncs('createSAH', 'releaseSAH', 'createAndReleaseSAH');
async function testTakeLockOnForward(
mode, fileName, shouldRestoreFromBFCache) {
await forward();
assert_true(await createAndReleaseSAH(mode, fileName));
await back(shouldRestoreFromBFCache);
}
for (const backMode of SAH_MODES) {
for (const forwMode of SAH_MODES) {
const contentiousLocks = sahModesAreContentious(backMode, forwMode);
// Create a lock on the page that will be BFCached.
const lockId = await createSAH(backMode, origFile);
assert_true(lockId !== undefined);
// Navigating to a new page and taking a lock on a different file should
// not evict the page from BFCache.
await testTakeLockOnForward(
forwMode, diffFile, /*shouldRestoreFromBFCache=*/ true);
// Navigating to a new page and taking a lock on the same file should only
// evict if the locks are contentious.
await testTakeLockOnForward(
forwMode, origFile, /*shouldRestoreFromBFCache=*/ !contentiousLocks);
// Release the lock when there isn't contention since it won't have been
// evicted.
if (!contentiousLocks) {
await releaseSAH(lockId);
}
}
}
}, `Creating a SAH on an active page evicts an inactive page on contention.`)