fune/browser/components/sessionstore/test/browser_switch_remoteness.js
Kris Maglione 94e3b0bd8d Bug 1596918: Part 3a - Scripted rewrite of most ContentTask.spawn calls to SpecialPowers.spawn calls. r=mccr8,remote-protocol-reviewers,ato
This is generally pretty straightforward, and rewrites nearly all calls. It
skips the ones that it can detect using frame script globals like
`sendAsyncMessage`, though.

Differential Revision: https://phabricator.services.mozilla.com/D53740

--HG--
extra : moz-landing-system : lando
2019-12-13 20:36:16 +00:00

53 lines
1.7 KiB
JavaScript

"use strict";
const URL = "http://example.com/browser_switch_remoteness_";
function countHistoryEntries(browser, expected) {
return SpecialPowers.spawn(browser, [{ expected }], async function(args) {
let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation);
let history = webNavigation.sessionHistory;
Assert.equal(
history && history.count,
args.expected,
"correct number of shistory entries"
);
});
}
add_task(async function() {
// Open a new window.
let win = await promiseNewWindowLoaded();
// Add a new tab.
let tab = BrowserTestUtils.addTab(win.gBrowser, "about:blank");
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
ok(browser.isRemoteBrowser, "browser is remote");
// Get the maximum number of preceding entries to save.
const MAX_BACK = Services.prefs.getIntPref(
"browser.sessionstore.max_serialize_back"
);
ok(MAX_BACK > -1, "check that the default has a value that caps data");
// Load more pages than we would save to disk on a clean shutdown.
for (let i = 0; i < MAX_BACK + 2; i++) {
BrowserTestUtils.loadURI(browser, URL + i);
await promiseBrowserLoaded(browser);
ok(browser.isRemoteBrowser, "browser is still remote");
}
// Check we have the right number of shistory entries.
await countHistoryEntries(browser, MAX_BACK + 2);
// Load a non-remote page.
BrowserTestUtils.loadURI(browser, "about:robots");
await promiseTabRestored(tab);
ok(!browser.isRemoteBrowser, "browser is not remote anymore");
// Check that we didn't lose any shistory entries.
await countHistoryEntries(browser, MAX_BACK + 3);
// Cleanup.
await BrowserTestUtils.closeWindow(win);
});