FileSystemFileHandle-writable-file-stream-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 [createAndReleaseWFS] = getRemoteFuncs('createAndReleaseWFS'); 15 16 for (const mode of WFS_MODES) { 17 await createAndReleaseWFS(mode, 'hello.txt'); 18 await assertBFCacheEligibility(/*shouldRestoreFromBFCache=*/ true); 19 } 20 }, 'Creating an WFS 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 [createWFS, releaseWFS, createAndReleaseWFS] = 28 getRemoteFuncs('createWFS', 'releaseWFS', 'createAndReleaseWFS'); 29 30 async function testTakeLockOnForward( 31 mode, fileName, shouldRestoreFromBFCache) { 32 await forward(); 33 34 assert_true(await createAndReleaseWFS(mode, fileName)); 35 36 await back(shouldRestoreFromBFCache); 37 } 38 39 for (const backMode of WFS_MODES) { 40 for (const forwMode of WFS_MODES) { 41 const contentiousLocks = wfsModesAreContentious(backMode, forwMode); 42 43 // Create a lock on the page that will be BFCached. 44 const lockId = await createWFS(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 releaseWFS(lockId); 61 } 62 } 63 } 64 }, `Creating a WFS on an active page evicts an inactive page on contention.`)