Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

add_task(async function () {
// The urls don't really matter as long as they are of the same origin
var URL =
var URL2 =
// We want to test a specific code path that leads to this call
// when gHistoryMaxSize is 0 and mIndex and mRequestedIndex are -1
// 1. Navigate to URL
await BrowserTestUtils.withNewTab(
{ gBrowser, url: URL },
async function (browser) {
// At this point, we haven't set gHistoryMaxSize to 0, and it is still 50 (default value).
if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
let sh = browser.browsingContext.sessionHistory;
is(
sh.count,
1,
"We should have entry in session history because we haven't changed gHistoryMaxSize to be 0 yet"
);
is(
sh.index,
0,
"Shistory's current index should be 0 because we haven't purged history yet"
);
} else {
await ContentTask.spawn(browser, null, () => {
var sh = content.window.docShell.QueryInterface(Ci.nsIWebNavigation)
.sessionHistory.legacySHistory;
is(
sh.count,
1,
"We should have entry in session history because we haven't changed gHistoryMaxSize to be 0 yet"
);
is(
sh.index,
0,
"Shistory's current index should be 0 because we haven't purged history yet"
);
});
}
var loadPromise = BrowserTestUtils.browserLoaded(browser, false, URL2);
// If we set the pref at the beginning of this page, then when we launch a child process
// to navigate to URL in Step 1, because of
// this pref will be set to the default value (currently 50). Setting this pref after the child process launches
// is a robust way to make sure it stays 0
await SpecialPowers.pushPrefEnv({
set: [["browser.sessionhistory.max_entries", 0]],
});
// 2. Navigate to URL2
// We are navigating to a page with the same origin so that we will stay in the same process
BrowserTestUtils.startLoadingURIString(browser, URL2);
await loadPromise;
// 3. Reload the browser with specific flags so that we end up here
var promise = BrowserTestUtils.browserLoaded(browser);
browser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE);
await promise;
if (SpecialPowers.Services.appinfo.sessionHistoryInParent) {
let sh = browser.browsingContext.sessionHistory;
is(sh.count, 0, "We should not save any entries in session history");
is(sh.index, -1);
is(sh.requestedIndex, -1);
} else {
await ContentTask.spawn(browser, null, () => {
var sh = content.window.docShell.QueryInterface(Ci.nsIWebNavigation)
.sessionHistory.legacySHistory;
is(sh.count, 0, "We should not save any entries in session history");
is(sh.index, -1);
is(sh.requestedIndex, -1);
});
}
}
);
});