Bug 1452666 - Simplify SessionHistory serialization code and test expanded principals are serialized and can restore tabs. r=bz,mikedeboer

MozReview-Commit-ID: EV39wz2TFlj

--HG--
extra : rebase_source : 736cc42fe3325f46856aba9bf894b1bad2a16368
This commit is contained in:
Jonathan Kingston 2018-05-19 14:42:52 +01:00
Родитель 286e8f602d
Коммит daad797972
3 изменённых файлов: 72 добавлений и 16 удалений

Просмотреть файл

@ -135,6 +135,7 @@ skip-if = !e10s || !crashreporter # the tab's process is killed during the test.
[browser_ext_sessions_getRecentlyClosed_private.js]
[browser_ext_sessions_getRecentlyClosed_tabs.js]
[browser_ext_sessions_restore.js]
[browser_ext_sessions_restoreTab.js]
[browser_ext_sessions_window_tab_value.js]
[browser_ext_settings_overrides_default_search.js]
[browser_ext_sidebarAction.js]

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
ChromeUtils.defineModuleGetter(this, "SessionStore",
"resource:///modules/sessionstore/SessionStore.jsm");
/**
This test checks that after closing an extension made tab it restores correctly.
The tab is given an expanded triggering principal and we didn't use to serialize
these correctly into session history.
*/
// Check that we can restore a tab modified by an extension.
add_task(async function test_restoringModifiedTab() {
function background() {
browser.tabs.create({url: "http://example.com/"});
browser.test.onMessage.addListener((msg, filter) => {
if (msg == "change-tab") {
browser.tabs.executeScript({code: 'location.href += "?changedTab";'});
}
});
}
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["tabs", "<all_urls>"],
},
"browser_action": {
"default_title": "Navigate current tab via content script",
},
background,
});
const contentScriptTabURL = "http://example.com/?changedTab";
let win = await BrowserTestUtils.openNewBrowserWindow({});
// Open and close a tabs.
let tabPromise = BrowserTestUtils.waitForNewTab(win.gBrowser, "http://example.com/");
await extension.startup();
let firstTab = await tabPromise;
let locationChange = BrowserTestUtils.waitForLocationChange(win.gBrowser, contentScriptTabURL);
extension.sendMessage("change-tab");
await locationChange;
is(firstTab.linkedBrowser.currentURI.spec, contentScriptTabURL, "Got expected URL");
let sessionPromise = BrowserTestUtils.waitForSessionStoreUpdate(firstTab);
BrowserTestUtils.removeTab(firstTab);
await sessionPromise;
tabPromise = BrowserTestUtils.waitForNewTab(win.gBrowser, contentScriptTabURL, true);
SessionStore.undoCloseTab(win, 0);
let restoredTab = await tabPromise;
ok(restoredTab, "We returned a tab here");
is(restoredTab.linkedBrowser.currentURI.spec, contentScriptTabURL, "Got expected URL");
await extension.unload();
BrowserTestUtils.removeTab(restoredTab);
// Close the window.
await BrowserTestUtils.closeWindow(win);
});

Просмотреть файл

@ -214,25 +214,11 @@ var SessionHistoryInternal = {
// Collect triggeringPrincipal data for the current history entry.
if (shEntry.principalToInherit) {
try {
let principalToInherit = Utils.serializePrincipal(shEntry.principalToInherit);
if (principalToInherit) {
entry.principalToInherit_base64 = principalToInherit;
}
} catch (e) {
debug(e);
}
entry.principalToInherit_base64 = Utils.serializePrincipal(shEntry.principalToInherit);
}
if (shEntry.triggeringPrincipal) {
try {
let triggeringPrincipal = Utils.serializePrincipal(shEntry.triggeringPrincipal);
if (triggeringPrincipal) {
entry.triggeringPrincipal_base64 = triggeringPrincipal;
}
} catch (e) {
debug(e);
}
entry.triggeringPrincipal_base64 = Utils.serializePrincipal(shEntry.triggeringPrincipal);
}
entry.docIdentifier = shEntry.BFCacheEntry.ID;
@ -461,6 +447,12 @@ var SessionHistoryInternal = {
if (entry.triggeringPrincipal_base64) {
shEntry.triggeringPrincipal = Utils.deserializePrincipal(entry.triggeringPrincipal_base64);
}
// Ensure that we have a null principal if we couldn't deserialize it.
// This won't always work however is safe to use.
if (!shEntry.triggeringPrincipal) {
debug("Couldn't deserialize the triggeringPrincipal, falling back to NullPrincipal");
shEntry.triggeringPrincipal = Services.scriptSecurityManager.createNullPrincipal({});
}
if (entry.principalToInherit_base64) {
shEntry.principalToInherit = Utils.deserializePrincipal(entry.principalToInherit_base64);
}