Bug 1345857 - Clone TabData entries when restoring tabs, r=mikedeboer

MozReview-Commit-ID: BhAbhSHgXWt
This commit is contained in:
Michael Layzell 2017-03-09 17:19:36 -05:00
Родитель 45e778c301
Коммит f083c8ec83
4 изменённых файлов: 30 добавлений и 2 удалений

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

@ -3570,7 +3570,9 @@ var SessionStoreInternal = {
// Update the persistent tab state cache with |tabData| information.
TabStateCache.update(browser, {
history: {entries: tabData.entries, index: tabData.index},
// NOTE: Copy the entries array shallowly, so as to not screw with the
// original tabData's history when getting history updates.
history: {entries: [...tabData.entries], index: tabData.index},
scroll: tabData.scroll || null,
storage: tabData.storage || null,
formdata: tabData.formdata || null,

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

@ -179,7 +179,10 @@ var TabStateInternal = {
}
if (key === "history") {
tabData.entries = value.entries;
// Make a shallow copy of the entries array. We (currently) don't update
// entries in place, so we don't have to worry about performing a deep
// copy.
tabData.entries = [...value.entries];
if (value.hasOwnProperty("userContextId")) {
tabData.userContextId = value.userContextId;

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

@ -243,3 +243,4 @@ skip-if = !e10s # GroupedSHistory is e10s-only
[browser_closed_objects_changed_notifications_tabs.js]
[browser_closed_objects_changed_notifications_windows.js]
[browser_duplicate_history.js]

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

@ -0,0 +1,22 @@
XPCOMUtils.defineLazyModuleGetter(this, "SessionStore",
"resource:///modules/sessionstore/SessionStore.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TabStateCache",
"resource:///modules/sessionstore/TabStateCache.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "TabStateFlusher",
"resource:///modules/sessionstore/TabStateFlusher.jsm");
add_task(function* () {
yield BrowserTestUtils.withNewTab("http://example.com", function* (aBrowser) {
let tab = gBrowser.getTabForBrowser(aBrowser);
yield TabStateFlusher.flush(aBrowser);
let before = TabStateCache.get(aBrowser);
let newTab = SessionStore.duplicateTab(window, tab);
yield BrowserTestUtils.browserLoaded(newTab.linkedBrowser);
let after = TabStateCache.get(newTab.linkedBrowser);
isnot(before.history.entries, after.history.entries,
"The entry objects should not be shared");
yield BrowserTestUtils.removeTab(newTab);
});
});