summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fs/FileSystemFileHandle-writable-file-stream-back-forward-cache.https.tentative.window.js
blob: 7195dff654da81af3a99774610eec7f64415b407 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// 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 [createAndReleaseWFS] = getRemoteFuncs('createAndReleaseWFS');

  for (const mode of WFS_MODES) {
    await createAndReleaseWFS(mode, 'hello.txt');
    await assertBFCacheEligibility(/*shouldRestoreFromBFCache=*/ true);
  }
}, 'Creating an WFS 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 [createWFS, releaseWFS, createAndReleaseWFS] =
      getRemoteFuncs('createWFS', 'releaseWFS', 'createAndReleaseWFS');

  async function testTakeLockOnForward(
      mode, fileName, shouldRestoreFromBFCache) {
    await forward();

    assert_true(await createAndReleaseWFS(mode, fileName));

    await back(shouldRestoreFromBFCache);
  }

  for (const backMode of WFS_MODES) {
    for (const forwMode of WFS_MODES) {
      const contentiousLocks = wfsModesAreContentious(backMode, forwMode);

      // Create a lock on the page that will be BFCached.
      const lockId = await createWFS(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 releaseWFS(lockId);
      }
    }
  }
}, `Creating a WFS on an active page evicts an inactive page on contention.`)