Bug 1686820 [wpt PR 27193] - Origin-keyed agent clusters: make COI imply origin-keyin...
[gecko.git] / docshell / test / browser / browser_bug1347823.js
blob551ddca8ab15482d898764a6541d117757511903
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: [["browser.sessionhistory.contentViewerTimeout", 86400]],
11   });
13   await BrowserTestUtils.withNewTab(
14     { gBrowser, url: "data:text/html;charset=utf-8,page1" },
15     async function(browser) {
16       // Make a simple modification for bfcache testing.
17       await SpecialPowers.spawn(browser, [], () => {
18         content.document.body.textContent = "modified";
19       });
21       // Load a random page.
22       BrowserTestUtils.loadURI(browser, "data:text/html;charset=utf-8,page2");
23       await BrowserTestUtils.browserLoaded(browser);
25       // Go back and verify text content.
26       let awaitPageShow = BrowserTestUtils.waitForContentEvent(
27         browser,
28         "pageshow"
29       );
30       browser.goBack();
31       await awaitPageShow;
32       await SpecialPowers.spawn(browser, [], () => {
33         is(content.document.body.textContent, "modified");
34       });
35     }
36   );
37 });
39 // With bfcache expired.
40 add_task(async function testExpiredCache() {
41   // Make bfcache timeout in 1 sec.
42   await SpecialPowers.pushPrefEnv({
43     set: [["browser.sessionhistory.contentViewerTimeout", 1]],
44   });
46   await BrowserTestUtils.withNewTab(
47     { gBrowser, url: "data:text/html;charset=utf-8,page1" },
48     async function(browser) {
49       // Make a simple modification for bfcache testing.
50       await SpecialPowers.spawn(browser, [], () => {
51         content.document.body.textContent = "modified";
52       });
54       // Load a random page.
55       BrowserTestUtils.loadURI(browser, "data:text/html;charset=utf-8,page2");
56       await BrowserTestUtils.browserLoaded(browser);
58       // Wait for 3 times of expiration timeout, hopefully it's evicted...
59       await SpecialPowers.spawn(browser, [], () => {
60         return new Promise(resolve => {
61           content.setTimeout(resolve, 3000);
62         });
63       });
65       // Go back and verify text content.
66       let awaitPageShow = BrowserTestUtils.waitForContentEvent(
67         browser,
68         "pageshow"
69       );
70       browser.goBack();
71       await awaitPageShow;
72       await SpecialPowers.spawn(browser, [], () => {
73         is(content.document.body.textContent, "page1");
74       });
75     }
76   );
77 });