1 add_task(async function () {
2 // The urls don't really matter as long as they are of the same origin
4 "http://mochi.test:8888/browser/docshell/test/navigation/bug343515_pg1.html";
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
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;
22 "We should have entry in session history because we haven't changed gHistoryMaxSize to be 0 yet"
27 "Shistory's current index should be 0 because we haven't purged history yet"
30 await ContentTask.spawn(browser, null, () => {
31 var sh = content.window.docShell.QueryInterface(Ci.nsIWebNavigation)
32 .sessionHistory.legacySHistory;
36 "We should have entry in session history because we haven't changed gHistoryMaxSize to be 0 yet"
41 "Shistory's current index should be 0 because we haven't purged history yet"
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]],
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);
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);
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");
70 is(sh.requestedIndex, -1);
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");
77 is(sh.requestedIndex, -1);