Bug 1276117 - part 2: fix the URL bar state when loading about:home from a new tab page, r=mikedeboer
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 30 May 2016 12:54:56 +0100
changeset 340710 34ef5d33979dd4fa8c7943b3c86128e53f840c14
parent 340709 8bd046e409fb8644677d92206d6ba04163a2705b
child 340711 0e8945f94a996763f92d12ea14a48e2043e91246
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1276117
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1276117 - part 2: fix the URL bar state when loading about:home from a new tab page, r=mikedeboer MozReview-Commit-ID: FADnX8bymNE
browser/base/content/tabbrowser.xml
browser/base/content/test/urlbar/browser_urlbarAboutHomeLoading.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -632,25 +632,32 @@
               if (aStateFlags & nsIWebProgressListener.STATE_START &&
                   aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
                 if (aWebProgress.isTopLevel) {
                   // Need to use originalLocation rather than location because things
                   // like about:home and about:privatebrowsing arrive with nsIRequest
                   // pointing to their resolved jar: or file: URIs.
                   if (!(originalLocation && gInitialPages.includes(originalLocation.spec) &&
                         originalLocation != "about:blank" &&
+                        this.mBrowser.initialPageLoadedFromURLBar != originalLocation.spec &&
                         this.mBrowser.currentURI && this.mBrowser.currentURI.spec == "about:blank")) {
-                    // This will trigger clearing the location bar. Don't do it if
-                    // we loaded off a blank browser and this is an initial page load
-                    // (e.g. about:privatebrowsing, about:newtab, etc.) so we avoid
-                    // clearing the location bar in case the user is typing in it.
-                    // loading about:blank shouldn't trigger this, either, because its
-                    // loads are "special".
+                    // Indicating that we started a load will allow the location
+                    // bar to be cleared when the load finishes.
+                    // In order to not overwrite user-typed content, we avoid it
+                    // (see if condition above) in a very specific case:
+                    // If the load is of an 'initial' page (e.g. about:privatebrowsing,
+                    // about:newtab, etc.), was not explicitly typed in the location
+                    // bar by the user, is not about:blank (because about:blank can be
+                    // loaded by websites under their principal), and the current
+                    // page in the browser is about:blank (indicating it is a newly
+                    // created or re-created browser, e.g. because it just switched
+                    // remoteness or is a new tab/window).
                     this.mBrowser.urlbarChangeTracker.startedLoad();
                   }
+                  delete this.mBrowser.initialPageLoadedFromURLBar;
                   // If the browser is loading it must not be crashed anymore
                   this.mTab.removeAttribute("crashed");
                 }
 
                 if (this._shouldShowProgress(aRequest)) {
                   if (!(aStateFlags & nsIWebProgressListener.STATE_RESTORING)) {
                     this.mTab.setAttribute("busy", "true");
 
--- a/browser/base/content/test/urlbar/browser_urlbarAboutHomeLoading.js
+++ b/browser/base/content/test/urlbar/browser_urlbarAboutHomeLoading.js
@@ -36,8 +36,31 @@ add_task(function* clearURLBarAfterParen
   });
   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);
 });
 
+/**
+ * Load about:home directly from an about:newtab page. Because it is an
+ * 'initial' page, we need to treat this specially if the user actually
+ * loads a page like this from the URL bar.
+ */
+add_task(function* clearURLBarAfterManuallyLoadingAboutHome() {
+  let promiseTabOpenedAndSwitchedTo = BrowserTestUtils.switchTab(gBrowser, () => {});
+  // This opens about:newtab:
+  BrowserOpenTab();
+  let tab = yield promiseTabOpenedAndSwitchedTo;
+  is(gURLBar.value, "", "URL bar should be empty");
+  is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
+
+  gURLBar.value = "about:home";
+  gURLBar.select();
+  let aboutHomeLoaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, "about:home");
+  EventUtils.sendKey("return");
+  yield aboutHomeLoaded;
+
+  is(gURLBar.value, "", "URL bar should be empty");
+  is(tab.linkedBrowser.userTypedValue, null, "userTypedValue should be null");
+  yield BrowserTestUtils.removeTab(tab);
+});
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -377,16 +377,19 @@ file, You can obtain one at http://mozil
               }
             });
           }
 
           function continueOperation()
           {
             this.value = url;
             gBrowser.userTypedValue = url;
+            if (gInitialPages.includes(url)) {
+              gBrowser.selectedBrowser.initialPageLoadedFromURLBar = url;
+            }
             try {
               addToUrlbarHistory(url);
             } catch (ex) {
               // Things may go wrong when adding url to session history,
               // but don't let that interfere with the loading of the url.
               Cu.reportError(ex);
             }