FileSystemFileHandle-sync-access-handle-back-forward-cache.https.tentative.window.js (2374B)
1 // META: script=/common/dispatcher/dispatcher.js 2 // META: script=/common/utils.js 3 // META: script=resources/test-helpers.js 4 // META: script=resources/messaging-helpers.js 5 // META: script=/html/browsers/browsing-the-web/back-forward-cache/resources/rc-helper.js 6 // META: script=/html/browsers/browsing-the-web/remote-context-helper/resources/remote-context-helper.js 7 // META: timeout=long 8 9 'use strict'; 10 11 12 createBFCacheTest(async (t, testControls) => { 13 const {getRemoteFuncs, assertBFCacheEligibility} = testControls; 14 const [createAndReleaseSAH] = getRemoteFuncs('createAndReleaseSAH'); 15 16 for (const mode of SAH_MODES) { 17 await createAndReleaseSAH(mode, 'hello.txt'); 18 await assertBFCacheEligibility(/*shouldRestoreFromBFCache=*/ true); 19 } 20 }, 'Creating an SAH should not make it ineligible for the BFCache.'); 21 22 createBFCacheTest(async (t, testControls) => { 23 const origFile = 'hello.txt'; 24 const diffFile = 'world.txt'; 25 26 const {getRemoteFuncs, forward, back} = testControls; 27 const [createSAH, releaseSAH, createAndReleaseSAH] = 28 getRemoteFuncs('createSAH', 'releaseSAH', 'createAndReleaseSAH'); 29 30 async function testTakeLockOnForward( 31 mode, fileName, shouldRestoreFromBFCache) { 32 await forward(); 33 34 assert_true(await createAndReleaseSAH(mode, fileName)); 35 36 await back(shouldRestoreFromBFCache); 37 } 38 39 for (const backMode of SAH_MODES) { 40 for (const forwMode of SAH_MODES) { 41 const contentiousLocks = sahModesAreContentious(backMode, forwMode); 42 43 // Create a lock on the page that will be BFCached. 44 const lockId = await createSAH(backMode, origFile); 45 assert_true(lockId !== undefined); 46 47 // Navigating to a new page and taking a lock on a different file should 48 // not evict the page from BFCache. 49 await testTakeLockOnForward( 50 forwMode, diffFile, /*shouldRestoreFromBFCache=*/ true); 51 52 // Navigating to a new page and taking a lock on the same file should only 53 // evict if the locks are contentious. 54 await testTakeLockOnForward( 55 forwMode, origFile, /*shouldRestoreFromBFCache=*/ !contentiousLocks); 56 57 // Release the lock when there isn't contention since it won't have been 58 // evicted. 59 if (!contentiousLocks) { 60 await releaseSAH(lockId); 61 } 62 } 63 } 64 }, `Creating a SAH on an active page evicts an inactive page on contention.`)