Bug 1276117 - part 1: fix URL bar state when loading about:home after about:preferences, r?mikedeboer draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 27 May 2016 14:06:02 +0100
changeset 372877 524641961ecb4017dd7b3bba54c49ac47a768084
parent 372106 3098ba832e42bb289a3951c5b7a9b3147b59aab5
child 372878 e6f67035c9dd568f984fd6c9c17d02337ae7f474
child 372921 a476421c53b172011135c1425965e653b68e2c2b
push id19612
push usergijskruitbosch@gmail.com
push dateMon, 30 May 2016 12:06:04 +0000
reviewersmikedeboer
bugs1276117
milestone49.0a1
Bug 1276117 - part 1: fix URL bar state when loading about:home after about:preferences, r?mikedeboer MozReview-Commit-ID: D5ecLsiJF3R
browser/base/content/test/urlbar/browser.ini
browser/base/content/test/urlbar/browser_urlbarAboutHomeLoading.js
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/content/content-sessionStore.js
--- a/browser/base/content/test/urlbar/browser.ini
+++ b/browser/base/content/test/urlbar/browser.ini
@@ -38,16 +38,17 @@ skip-if = os == "linux" # Linux: Intermi
 [browser_removeUnsafeProtocolsFromURLBarPaste.js]
 subsuite = clipboard
 [browser_search_favicon.js]
 [browser_tabMatchesInAwesomebar.js]
 support-files =
   moz.png
 [browser_tabMatchesInAwesomebar_perwindowpb.js]
 skip-if = os == 'linux' # Bug 1104755
+[browser_urlbarAboutHomeLoading.js]
 [browser_urlbarAutoFillTrimURLs.js]
 [browser_urlbarCopying.js]
 subsuite = clipboard
 support-files =
   authenticate.sjs
 [browser_urlbarDecode.js]
 [browser_urlbarDelete.js]
 [browser_urlbarEnter.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/urlbar/browser_urlbarAboutHomeLoading.js
@@ -0,0 +1,43 @@
+"use strict";
+
+/**
+ * Test what happens if loading a URL that should clear the
+ * location bar after a parent process URL.
+ */
+add_task(function* clearURLBarAfterParentProcessURL() {
+  let tab = yield new Promise(resolve => {
+    gBrowser.selectedTab = gBrowser.addTab("about:preferences");
+    let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
+    newTabBrowser.addEventListener("Initialized", function onInit() {
+      newTabBrowser.removeEventListener("Initialized", onInit, true);
+      resolve(gBrowser.selectedTab);
+    }, true);
+  });
+  document.getElementById("home-button").click();
+  yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+  is(gURLBar.value, "", "URL bar should be empty");
+  is(tab.linkedBrowser.userTypedValue, null, "The browser should have no recorded userTypedValue");
+  yield BrowserTestUtils.removeTab(tab);
+});
+
+/**
+ * Same as above, but open the tab without passing the URL immediately
+ * which changes behaviour in tabbrowser.xml.
+ */
+add_task(function* clearURLBarAfterParentProcessURLInExistingTab() {
+  let tab = yield new Promise(resolve => {
+    gBrowser.selectedTab = gBrowser.addTab();
+    let newTabBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
+    newTabBrowser.addEventListener("Initialized", function onInit() {
+      newTabBrowser.removeEventListener("Initialized", onInit, true);
+      resolve(gBrowser.selectedTab);
+    }, true);
+    newTabBrowser.loadURI("about:preferences");
+  });
+  document.getElementById("home-button").click();
+  yield BrowserTestUtils.browserLoaded(tab.linkedBrowser);
+  is(gURLBar.value, "", "URL bar should be empty");
+  is(tab.linkedBrowser.userTypedValue, null, "The browser should have no recorded userTypedValue");
+  yield BrowserTestUtils.removeTab(tab);
+});
+
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -779,17 +779,20 @@ var SessionStoreInternal = {
         let activePageData = tabData.entries[tabData.index - 1] || null;
         let uri = activePageData ? activePageData.url || null : null;
         // NB: we won't set initial URIs (about:home, about:newtab, etc.) here
         // because their load will not normally trigger a location bar clearing
         // when they finish loading (to avoid race conditions where we then
         // clear user input instead), so we shouldn't set them here either.
         // They also don't fall under the issues in bug 439675 where user input
         // needs to be preserved if the load doesn't succeed.
-        if (!browser.userTypedValue && uri && !win.gInitialPages.includes(uri)) {
+        // We also don't do this for remoteness updates, where it should not
+        // be necessary.
+        if (!browser.userTypedValue && uri && !data.isRemotenessUpdate &&
+            !win.gInitialPages.includes(uri)) {
           browser.userTypedValue = uri;
         }
 
         // If the page has a title, set it.
         if (activePageData) {
           if (activePageData.title) {
             tab.label = activePageData.title;
             tab.crop = "end";
@@ -3330,17 +3333,18 @@ var SessionStoreInternal = {
       // Start a new epoch to discard all frame script messages relating to a
       // previous epoch. All async messages that are still on their way to chrome
       // will be ignored and don't override any tab data set when restoring.
       let epoch = this.startNextEpoch(browser);
 
       browser.messageManager.sendAsyncMessage("SessionStore:restoreHistory", {
         tabData: tabData,
         epoch: epoch,
-        loadArguments: aLoadArguments
+        loadArguments: aLoadArguments,
+        isRemotenessUpdate,
       });
 
     }
 
     // If the restored browser wants to show view source content, start up a
     // view source browser that will load the required frame script.
     if (uri && ViewSourceBrowser.isViewSource(uri)) {
       new ViewSourceBrowser(browser);
--- a/browser/components/sessionstore/content/content-sessionStore.js
+++ b/browser/components/sessionstore/content/content-sessionStore.js
@@ -149,17 +149,17 @@ var MessageListener = {
         this.flush(data);
         break;
       default:
         debug("received unknown message '" + name + "'");
         break;
     }
   },
 
-  restoreHistory({epoch, tabData, loadArguments}) {
+  restoreHistory({epoch, tabData, loadArguments, isRemotenessUpdate}) {
     gContentRestore.restoreHistory(tabData, loadArguments, {
       // Note: The callbacks passed here will only be used when a load starts
       // that was not initiated by sessionstore itself. This can happen when
       // some code calls browser.loadURI() or browser.reload() on a pending
       // browser/tab.
 
       onLoadStarted() {
         // Notify the parent that the tab is no longer pending.
@@ -174,17 +174,17 @@ var MessageListener = {
     });
 
     // When restoreHistory finishes, we send a synchronous message to
     // SessionStore.jsm so that it can run SSTabRestoring. Users of
     // SSTabRestoring seem to get confused if chrome and content are out of
     // sync about the state of the restore (particularly regarding
     // docShell.currentURI). Using a synchronous message is the easiest way
     // to temporarily synchronize them.
-    sendSyncMessage("SessionStore:restoreHistoryComplete", {epoch});
+    sendSyncMessage("SessionStore:restoreHistoryComplete", {epoch, isRemotenessUpdate});
   },
 
   restoreTabContent({loadArguments, isRemotenessUpdate}) {
     let epoch = gCurrentEpoch;
 
     // We need to pass the value of didStartLoad back to SessionStore.jsm.
     let didStartLoad = gContentRestore.restoreTabContent(loadArguments, isRemotenessUpdate, () => {
       // Tell SessionStore.jsm that it may want to restore some more tabs,