Bug 1333345 - Part 4: Fix address bar keyboard shortcuts to add domain name suffix instead of loading the domain suggested by autocomplete. r?mak draft
authorChris Peterson <cpeterson@mozilla.com>
Sat, 11 Feb 2017 13:36:02 -0800
changeset 490299 77b150b4a0fe1897694887dc2e56274aa909ba0a
parent 490298 af4b624b55fd39b85830e962f69a80c78c3aa5d9
child 547221 e5f5efbd6691ba0382a42cdd04052d097eae9659
push id47057
push usercpeterson@mozilla.com
push dateTue, 28 Feb 2017 02:48:55 +0000
reviewersmak
bugs1333345
milestone54.0a1
Bug 1333345 - Part 4: Fix address bar keyboard shortcuts to add domain name suffix instead of loading the domain suggested by autocomplete. r?mak If the default (first) result is selected, then it might be a URL, a search string, or a string that should be expanded to a URL. If any result other than the first is selected, then it must have been manually selected by the human. MozReview-Commit-ID: 2UrzfpoXZT0
browser/base/content/test/urlbar/browser_autocomplete_enter_race.js
browser/base/content/urlbarBindings.xml
build/pgo/server-locations.txt
--- a/browser/base/content/test/urlbar/browser_autocomplete_enter_race.js
+++ b/browser/base/content/test/urlbar/browser_autocomplete_enter_race.js
@@ -49,17 +49,17 @@ add_task(function* test_expand_search_st
   is(gURLBar.textValue, "example.com/", "Autocomplete should suggest 'example.com/' for 'example'");
 
   gURLBar.focus();
   EventUtils.synthesizeKey("VK_RETURN", {shiftKey: true});
 
   info("wait for the page to load");
   yield BrowserTestUtils.browserLoaded(gBrowser.selectedTab.linkedBrowser);
 
-  is(gURLBar.textValue, "example.com", "Shift+Enter should add 'www.' and '.net' to search string, but uses the autocomplete suggestion 'example.com' instead! This is bug 1333345.");
+  is(gURLBar.textValue, "www.example.net", "Shift+Enter should add 'www.' and '.net' to search string");
 });
 
 add_task(function* test_after_empty_search() {
   yield promiseAutocompleteResultPopup("");
   gURLBar.focus();
   gURLBar.value = "e";
   EventUtils.synthesizeKey("x", {});
   EventUtils.synthesizeKey("VK_RETURN", {});
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -624,28 +624,28 @@ file, You can obtain one at http://mozil
           details.type = eventType;
 
           BrowserSearch.recordSearchInTelemetry(engine, "urlbar", details);
           let submission = engine.getSubmission(query, null, "keyword");
           return [submission.uri.spec, submission.postData];
         ]]></body>
       </method>
 
-      <method name="maybeCanonizeURL">
+      <method name="expandSearchStringToURL">
         <parameter name="aTriggeringEvent"/>
-        <parameter name="aUrl"/>
         <body><![CDATA[
+          let url = this.mController.searchString;
+
           // Only add the suffix when the URL bar value isn't already "URL-like",
           // and only if we get a keyboard event, to match user expectations.
-          if (!/^\s*[^.:\/\s]+(?:\/.*|\s*)$/i.test(aUrl) ||
+          if (!/^\s*[^.:\/\s]+(?:\/.*|\s*)$/i.test(url) ||
               !(aTriggeringEvent instanceof KeyEvent)) {
             return;
           }
 
-          let url = aUrl;
           let accel = this.AppConstants.platform == "macosx" ?
                       aTriggeringEvent.metaKey :
                       aTriggeringEvent.ctrlKey;
           let shift = aTriggeringEvent.shiftKey;
           let suffix = "";
 
           switch (true) {
             case (accel && shift):
@@ -682,19 +682,26 @@ file, You can obtain one at http://mozil
           }
 
           this.popup.overrideValue = "http://www." + url;
         ]]></body>
       </method>
 
       <method name="handleEnterNow">
         <parameter name="aTriggeringEvent"/>
-        <parameter name="aURL"/>
         <body><![CDATA[
-          this.maybeCanonizeURL(aTriggeringEvent, aURL);
+          // If the default (first) result is selected, then it (this.
+          // mController.searchString) might be a URL, a search string, or
+          // a string that should be expanded to a URL. If any result other than
+          // the first is selected, then it must have been manually selected by
+          // the human. We let this explicit choice (this.value) be used as-is.
+          if (this.popup.selectedIndex == 0) {
+            this.expandSearchStringToURL(aTriggeringEvent);
+          }
+
           return this.mController.handleEnter(false, aTriggeringEvent);
         ]]></body>
       </method>
 
       <field name="_contentIsCropped">false</field>
 
       <method name="_initURLTooltip">
         <body><![CDATA[
@@ -1154,17 +1161,17 @@ file, You can obtain one at http://mozil
           // Note this is also used to detect if we should perform a delayed
           // handleEnter, in such a case it won't have been cleared.
           this.handleEnterInstance = {
             searchString: this.mController.searchString,
             event
           };
 
           if (this.popup.selectedIndex != 0 || this.gotResultForCurrentQuery) {
-            let rv = this.handleEnterNow(event, this.value);
+            let rv = this.handleEnterNow(event);
             this.handleEnterInstance = null;
             return rv;
           }
 
           return true;
         ]]></body>
       </method>
 
@@ -1834,17 +1841,17 @@ file, You can obtain one at http://mozil
               this.input.handleEnterInstance = null;
 
               // Don't handle this immediately or we could cause a recursive
               // loop where the controller sets popupOpen and re-enters here.
               setTimeout(() => {
                 // Safety check: handle only if the search string didn't change.
                 let { event, searchString } = instance;
                 if (this.input.mController.searchString == searchString) {
-                  this.input.handleEnterNow(event, searchString);
+                  this.input.handleEnterNow(event);
                 }
               }, 0);
             }
           ]]>
         </body>
       </method>
 
       <method name="_onSearchBegin">
--- a/build/pgo/server-locations.txt
+++ b/build/pgo/server-locations.txt
@@ -87,16 +87,17 @@ http://www.example.com:80            pri
 http://test1.example.com:80          privileged
 http://test2.example.com:80          privileged
 http://sub1.test1.example.com:80     privileged
 http://sub1.test2.example.com:80     privileged
 http://sub2.test1.example.com:80     privileged
 http://sub2.test2.example.com:80     privileged
 http://noxul.example.com:80          privileged,noxul
 http://example.net:80                privileged
+http://www.example.net:80            privileged
 # Used to test that clearing Service Workers for domain example.com, does not clear prefixexample.com
 http://prefixexample.com:80
 
 # The first HTTPS location is used to generate the Common Name (CN) value of the
 # certificate's Issued To field.
 https://example.com:443                privileged
 https://test1.example.com:443          privileged
 https://test2.example.com:443          privileged