gecko-dev/browser/components/sessionstore/test/browser_switch_remoteness.js
Mark Banner 92c422a2d6 Bug 1342459 - Add a rule to automatically detect ContentTask.spawn and inject the relevant globals. r=mossop
This reduces the amount of places where we need to specify the mozilla/frame-script environment. It does have
the side effect of allowing those globals in the whole file, but that is what specifying the environment would
do, and this is also for mochitest test files only.

MozReview-Commit-ID: 1LLFbn6fFJR

--HG--
extra : rebase_source : 82a6934d90bbbbd25f91b7b06bf4f9354e38865a
2017-04-05 10:00:25 +01:00

49 lines
1.7 KiB
JavaScript

"use strict";
const URL = "http://example.com/browser_switch_remoteness_";
function countHistoryEntries(browser, expected) {
return ContentTask.spawn(browser, { expected }, function* (args) {
let Ci = Components.interfaces;
let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation);
let history = webNavigation.sessionHistory.QueryInterface(Ci.nsISHistoryInternal);
Assert.equal(history && history.count, args.expected,
"correct number of shistory entries");
});
}
add_task(function* () {
// Open a new window.
let win = yield promiseNewWindowLoaded();
// Add a new tab.
let tab = win.gBrowser.addTab("about:blank");
let browser = tab.linkedBrowser;
yield 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++) {
browser.loadURI(URL + i);
yield promiseBrowserLoaded(browser);
ok(browser.isRemoteBrowser, "browser is still remote");
}
// Check we have the right number of shistory entries.
yield countHistoryEntries(browser, MAX_BACK + 2);
// Load a non-remote page.
browser.loadURI("about:robots");
yield promiseTabRestored(tab);
ok(!browser.isRemoteBrowser, "browser is not remote anymore");
// Check that we didn't lose any shistory entries.
yield countHistoryEntries(browser, MAX_BACK + 3);
// Cleanup.
yield BrowserTestUtils.closeWindow(win);
});