From c924ea409fb1ae8910db1c8ee34706593061783d Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Mon, 1 Jun 2015 19:18:59 +0200 Subject: [PATCH] Bug 1170226 - Restore correct shistory index when setting up pending tabs r=billm --- .../sessionstore/ContentRestore.jsm | 12 ------- .../sessionstore/SessionHistory.jsm | 6 ++++ .../components/sessionstore/test/browser.ini | 1 + .../sessionstore/test/browser_pending_tabs.js | 32 +++++++++++++++++++ 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 browser/components/sessionstore/test/browser_pending_tabs.js diff --git a/browser/components/sessionstore/ContentRestore.jsm b/browser/components/sessionstore/ContentRestore.jsm index 75b7b330739..85f31e40783 100644 --- a/browser/components/sessionstore/ContentRestore.jsm +++ b/browser/components/sessionstore/ContentRestore.jsm @@ -193,11 +193,6 @@ ContentRestoreInternal.prototype = { if (loadArguments) { // A load has been redirected to a new process so get history into the // same state it was before the load started then trigger the load. - let activeIndex = tabData.index - 1; - if (activeIndex > 0) { - // Go to the right history entry, but don't load anything yet. - history.getEntryAtIndex(activeIndex, true); - } let referrer = loadArguments.referrer ? Utils.makeURI(loadArguments.referrer) : null; let referrerPolicy = ('referrerPolicy' in loadArguments @@ -210,12 +205,6 @@ ContentRestoreInternal.prototype = { // If the user typed a URL into the URL bar and hit enter right before // we crashed, we want to start loading that page again. A non-zero // userTypedClear value means that the load had started. - let activeIndex = tabData.index - 1; - if (activeIndex > 0) { - // Go to the right history entry, but don't load anything yet. - history.getEntryAtIndex(activeIndex, true); - } - // Load userTypedValue and fix up the URL if it's partial/broken. webNavigation.loadURI(tabData.userTypedValue, Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP, @@ -231,7 +220,6 @@ ContentRestoreInternal.prototype = { // In order to work around certain issues in session history, we need to // force session history to update its internal index and call reload // instead of gotoIndex. See bug 597315. - history.getEntryAtIndex(activeIndex, true); history.reloadCurrentEntry(); } else { // If there's nothing to restore, we should still blank the page. diff --git a/browser/components/sessionstore/SessionHistory.jsm b/browser/components/sessionstore/SessionHistory.jsm index 372692bc801..2a00d9efd50 100644 --- a/browser/components/sessionstore/SessionHistory.jsm +++ b/browser/components/sessionstore/SessionHistory.jsm @@ -265,6 +265,12 @@ let SessionHistoryInternal = { let persist = "persist" in entry ? entry.persist : true; history.addEntry(this.deserializeEntry(entry, idMap, docIdentMap), persist); } + + // Select the right history entry. + let index = tabData.index - 1; + if (index < history.count && history.index != index) { + history.getEntryAtIndex(index, true); + } }, /** diff --git a/browser/components/sessionstore/test/browser.ini b/browser/components/sessionstore/test/browser.ini index 176bea7b9dc..d49fd14251f 100644 --- a/browser/components/sessionstore/test/browser.ini +++ b/browser/components/sessionstore/test/browser.ini @@ -94,6 +94,7 @@ skip-if = buildapp == 'mulet' [browser_merge_closed_tabs.js] [browser_page_title.js] [browser_pageStyle.js] +[browser_pending_tabs.js] [browser_privatetabs.js] [browser_replace_load.js] [browser_restore_redirect.js] diff --git a/browser/components/sessionstore/test/browser_pending_tabs.js b/browser/components/sessionstore/test/browser_pending_tabs.js new file mode 100644 index 00000000000..d5cc0aa0753 --- /dev/null +++ b/browser/components/sessionstore/test/browser_pending_tabs.js @@ -0,0 +1,32 @@ +"use strict"; + +const TAB_STATE = { + entries: [{ url: "about:mozilla" }, { url: "about:robots" }], + index: 1, +}; + +add_task(function* () { + // Create a background tab. + let tab = gBrowser.addTab("about:blank"); + let browser = tab.linkedBrowser; + yield promiseBrowserLoaded(browser); + + // The tab shouldn't be restored right away. + Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true); + + // Prepare the tab state. + let promise = promiseTabRestoring(tab); + ss.setTabState(tab, JSON.stringify(TAB_STATE)); + ok(tab.hasAttribute("pending"), "tab is pending"); + yield promise; + + // Flush to ensure the parent has all data. + yield TabStateFlusher.flush(browser); + + // Check that the shistory index is the one we restored. + let tabState = TabState.collect(tab); + is(tabState.index, TAB_STATE.index, "correct shistory index"); + + // Cleanup. + gBrowser.removeTab(tab); +});