fune/browser/components/sessionstore/test/browser_purge_shistory.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

65 lines
1.9 KiB
JavaScript

"use strict";
/**
* This test checks that pending tabs are treated like fully loaded tabs when
* purging session history. Just like for fully loaded tabs we want to remove
* every but the current shistory entry.
*/
const TAB_STATE = {
entries: [
{ url: "about:mozilla", triggeringPrincipal_base64 },
{ url: "about:robots", triggeringPrincipal_base64 },
],
index: 1,
};
function checkTabContents(browser) {
return SpecialPowers.spawn(browser, [], async function() {
let webNavigation = docShell.QueryInterface(Ci.nsIWebNavigation);
let history = webNavigation.sessionHistory;
Assert.ok(
history &&
history.count == 1 &&
content.document.documentURI == "about:mozilla",
"expected tab contents found"
);
});
}
add_task(async function() {
// Create a new tab.
let tab = BrowserTestUtils.addTab(gBrowser, "about:blank");
let browser = tab.linkedBrowser;
await promiseBrowserLoaded(browser);
await promiseTabState(tab, TAB_STATE);
// Create another new tab.
let tab2 = BrowserTestUtils.addTab(gBrowser, "about:blank");
let browser2 = tab2.linkedBrowser;
await promiseBrowserLoaded(browser2);
// The tab shouldn't be restored right away.
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
// Prepare the tab state.
let promise = promiseTabRestoring(tab2);
ss.setTabState(tab2, JSON.stringify(TAB_STATE));
ok(tab2.hasAttribute("pending"), "tab is pending");
await promise;
// Purge session history.
Services.obs.notifyObservers(null, "browser:purge-session-history");
await checkTabContents(browser);
ok(tab2.hasAttribute("pending"), "tab is still pending");
// Kick off tab restoration.
gBrowser.selectedTab = tab2;
await promiseTabRestored(tab2);
await checkTabContents(browser2);
ok(!tab2.hasAttribute("pending"), "tab is not pending anymore");
// Cleanup.
gBrowser.removeTab(tab2);
gBrowser.removeTab(tab);
});