no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / docshell / test / navigation / browser_ghistorymaxsize_is_0.js
blob87331b9bb90b78c66e556672823fd55c09751614
1 add_task(async function () {
2   // The urls don't really matter as long as they are of the same origin
3   var URL =
4     "http://mochi.test:8888/browser/docshell/test/navigation/bug343515_pg1.html";
5   var URL2 =
6     "http://mochi.test:8888/browser/docshell/test/navigation/bug343515_pg3_1.html";
8   // We want to test a specific code path that leads to this call
9   // https://searchfox.org/mozilla-central/rev/e7c61f4a68b974d5fecd216dc7407b631a24eb8f/docshell/base/nsDocShell.cpp#10795
10   // when gHistoryMaxSize is 0 and mIndex and mRequestedIndex are -1
12   // 1. Navigate to URL
13   await BrowserTestUtils.withNewTab(
14     { gBrowser, url: URL },
15     async function (browser) {
16       // At this point, we haven't set gHistoryMaxSize to 0, and it is still 50 (default value).
17       if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
18         let sh = browser.browsingContext.sessionHistory;
19         is(
20           sh.count,
21           1,
22           "We should have entry in session history because we haven't changed gHistoryMaxSize to be 0 yet"
23         );
24         is(
25           sh.index,
26           0,
27           "Shistory's current index should be 0 because we haven't purged history yet"
28         );
29       } else {
30         await ContentTask.spawn(browser, null, () => {
31           var sh = content.window.docShell.QueryInterface(Ci.nsIWebNavigation)
32             .sessionHistory.legacySHistory;
33           is(
34             sh.count,
35             1,
36             "We should have entry in session history because we haven't changed gHistoryMaxSize to be 0 yet"
37           );
38           is(
39             sh.index,
40             0,
41             "Shistory's current index should be 0 because we haven't purged history yet"
42           );
43         });
44       }
46       var loadPromise = BrowserTestUtils.browserLoaded(browser, false, URL2);
47       // If we set the pref at the beginning of this page, then when we launch a child process
48       // to navigate to URL in Step 1, because of
49       // https://searchfox.org/mozilla-central/rev/e7c61f4a68b974d5fecd216dc7407b631a24eb8f/docshell/shistory/nsSHistory.cpp#308-312
50       // this pref will be set to the default value (currently 50). Setting this pref after the child process launches
51       // is a robust way to make sure it stays 0
52       await SpecialPowers.pushPrefEnv({
53         set: [["browser.sessionhistory.max_entries", 0]],
54       });
55       // 2. Navigate to URL2
56       // We are navigating to a page with the same origin so that we will stay in the same process
57       BrowserTestUtils.startLoadingURIString(browser, URL2);
58       await loadPromise;
60       // 3. Reload the browser with specific flags so that we end up here
61       // https://searchfox.org/mozilla-central/rev/e7c61f4a68b974d5fecd216dc7407b631a24eb8f/docshell/base/nsDocShell.cpp#10795
62       var promise = BrowserTestUtils.browserLoaded(browser);
63       browser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE);
64       await promise;
66       if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
67         let sh = browser.browsingContext.sessionHistory;
68         is(sh.count, 0, "We should not save any entries in session history");
69         is(sh.index, -1);
70         is(sh.requestedIndex, -1);
71       } else {
72         await ContentTask.spawn(browser, null, () => {
73           var sh = content.window.docShell.QueryInterface(Ci.nsIWebNavigation)
74             .sessionHistory.legacySHistory;
75           is(sh.count, 0, "We should not save any entries in session history");
76           is(sh.index, -1);
77           is(sh.requestedIndex, -1);
78         });
79       }
80     }
81   );
82 });