summaryrefslogtreecommitdiffstats
path: root/docshell/test/browser/browser_bug1347823.js
blob: e30706b74555f551d213faa4e9d6e1a405a54f44 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
 * Test that session history's expiration tracker would remove bfcache on
 * expiration.
 */

// With bfcache not expired.
add_task(async function testValidCache() {
  // Make an unrealistic large timeout.
  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.sessionhistory.contentViewerTimeout", 86400],
      // If Fission is disabled, the pref is no-op.
      ["fission.bfcacheInParent", true],
    ],
  });

  await BrowserTestUtils.withNewTab(
    { gBrowser, url: "data:text/html;charset=utf-8,pageA1" },
    async function (browser) {
      // Make a simple modification for bfcache testing.
      await SpecialPowers.spawn(browser, [], () => {
        content.document.body.textContent = "modified";
      });

      // Load a random page.
      BrowserTestUtils.startLoadingURIString(
        browser,
        "data:text/html;charset=utf-8,pageA2"
      );
      await BrowserTestUtils.browserLoaded(browser);

      // Go back and verify text content.
      let awaitPageShow = BrowserTestUtils.waitForContentEvent(
        browser,
        "pageshow"
      );
      browser.goBack();
      await awaitPageShow;
      await SpecialPowers.spawn(browser, [], () => {
        is(content.document.body.textContent, "modified");
      });
    }
  );
});

// With bfcache expired.
add_task(async function testExpiredCache() {
  // Make bfcache timeout in 1 sec.
  await SpecialPowers.pushPrefEnv({
    set: [
      ["browser.sessionhistory.contentViewerTimeout", 1],
      // If Fission is disabled, the pref is no-op.
      ["fission.bfcacheInParent", true],
    ],
  });

  await BrowserTestUtils.withNewTab(
    { gBrowser, url: "data:text/html;charset=utf-8,pageB1" },
    async function (browser) {
      // Make a simple modification for bfcache testing.
      await SpecialPowers.spawn(browser, [], () => {
        content.document.body.textContent = "modified";
      });

      // Load a random page.
      BrowserTestUtils.startLoadingURIString(
        browser,
        "data:text/html;charset=utf-8,pageB2"
      );
      await BrowserTestUtils.browserLoaded(browser);

      // Wait for 3 times of expiration timeout, hopefully it's evicted...
      await SpecialPowers.spawn(browser, [], () => {
        return new Promise(resolve => {
          content.setTimeout(resolve, 5000);
        });
      });

      // Go back and verify text content.
      let awaitPageShow = BrowserTestUtils.waitForContentEvent(
        browser,
        "pageshow"
      );
      browser.goBack();
      await awaitPageShow;
      await SpecialPowers.spawn(browser, [], () => {
        is(content.document.body.textContent, "pageB1");
      });
    }
  );
});