Bug 1920800 Remove oldImages from check for flushed old principal handle r=pehrsons
[gecko.git] / docshell / test / browser / browser_bug1347823.js
blobe30706b74555f551d213faa4e9d6e1a405a54f44
1 /**
2  * Test that session history's expiration tracker would remove bfcache on
3  * expiration.
4  */
6 // With bfcache not expired.
7 add_task(async function testValidCache() {
8   // Make an unrealistic large timeout.
9   await SpecialPowers.pushPrefEnv({
10     set: [
11       ["browser.sessionhistory.contentViewerTimeout", 86400],
12       // If Fission is disabled, the pref is no-op.
13       ["fission.bfcacheInParent", true],
14     ],
15   });
17   await BrowserTestUtils.withNewTab(
18     { gBrowser, url: "data:text/html;charset=utf-8,pageA1" },
19     async function (browser) {
20       // Make a simple modification for bfcache testing.
21       await SpecialPowers.spawn(browser, [], () => {
22         content.document.body.textContent = "modified";
23       });
25       // Load a random page.
26       BrowserTestUtils.startLoadingURIString(
27         browser,
28         "data:text/html;charset=utf-8,pageA2"
29       );
30       await BrowserTestUtils.browserLoaded(browser);
32       // Go back and verify text content.
33       let awaitPageShow = BrowserTestUtils.waitForContentEvent(
34         browser,
35         "pageshow"
36       );
37       browser.goBack();
38       await awaitPageShow;
39       await SpecialPowers.spawn(browser, [], () => {
40         is(content.document.body.textContent, "modified");
41       });
42     }
43   );
44 });
46 // With bfcache expired.
47 add_task(async function testExpiredCache() {
48   // Make bfcache timeout in 1 sec.
49   await SpecialPowers.pushPrefEnv({
50     set: [
51       ["browser.sessionhistory.contentViewerTimeout", 1],
52       // If Fission is disabled, the pref is no-op.
53       ["fission.bfcacheInParent", true],
54     ],
55   });
57   await BrowserTestUtils.withNewTab(
58     { gBrowser, url: "data:text/html;charset=utf-8,pageB1" },
59     async function (browser) {
60       // Make a simple modification for bfcache testing.
61       await SpecialPowers.spawn(browser, [], () => {
62         content.document.body.textContent = "modified";
63       });
65       // Load a random page.
66       BrowserTestUtils.startLoadingURIString(
67         browser,
68         "data:text/html;charset=utf-8,pageB2"
69       );
70       await BrowserTestUtils.browserLoaded(browser);
72       // Wait for 3 times of expiration timeout, hopefully it's evicted...
73       await SpecialPowers.spawn(browser, [], () => {
74         return new Promise(resolve => {
75           content.setTimeout(resolve, 5000);
76         });
77       });
79       // Go back and verify text content.
80       let awaitPageShow = BrowserTestUtils.waitForContentEvent(
81         browser,
82         "pageshow"
83       );
84       browser.goBack();
85       await awaitPageShow;
86       await SpecialPowers.spawn(browser, [], () => {
87         is(content.document.body.textContent, "pageB1");
88       });
89     }
90   );
91 });