Bug 1521702 - Hook up autofill with URL canonization. r=dao
authorDrew Willcoxon <adw@mozilla.com>
Thu, 07 Feb 2019 10:25:13 +0000
changeset 516254 ec61d092ed67
parent 516253 6d6ab46f6428
child 516255 14ee0b7ecef3
child 516256 4b7f6b2a9411
child 516293 dc5b5c16b532
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1521702
milestone67.0a1
first release with
nightly linux32
ec61d092ed67 / 67.0a1 / 20190209094021 / files
nightly linux64
ec61d092ed67 / 67.0a1 / 20190209094021 / files
nightly mac
ec61d092ed67 / 67.0a1 / 20190209094021 / files
nightly win32
ec61d092ed67 / 67.0a1 / 20190209094021 / files
nightly win64
ec61d092ed67 / 67.0a1 / 20190209094021 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1521702 - Hook up autofill with URL canonization. r=dao Differential Revision: https://phabricator.services.mozilla.com/D18620
browser/components/urlbar/UrlbarInput.jsm
browser/components/urlbar/tests/browser/browser_canonizeURL.js
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -305,18 +305,25 @@ class UrlbarInput {
 
     let where = this._whereToOpen(event);
     let {url, postData} = UrlbarUtils.getUrlFromResult(result);
     let openParams = {
       postData,
       allowInheritPrincipal: false,
     };
 
-    // TODO bug 1521702: Call _maybeCanonizeURL for autofilled results with the
-    // typed string (not the autofilled one).
+    if (result.autofill) {
+      // For autofilled results, the value that should be canonized is not the
+      // autofilled value but the value that the user typed.
+      let canonizedUrl = this._maybeCanonizeURL(event, this._lastSearchString);
+      if (canonizedUrl) {
+        this._loadURL(canonizedUrl, where, openParams);
+        return;
+      }
+    }
 
     switch (result.type) {
       case UrlbarUtils.RESULT_TYPE.TAB_SWITCH: {
         if (this.hasAttribute("actionoverride")) {
           where = "current";
           break;
         }
 
--- a/browser/components/urlbar/tests/browser/browser_canonizeURL.js
+++ b/browser/components/urlbar/tests/browser/browser_canonizeURL.js
@@ -75,8 +75,60 @@ add_task(async function checkPrefTurnsOf
 
   tabsToClose.push(await promiseTabOpened);
   is(initialTab.linkedBrowser.currentURI.spec, initialTabURL,
      "Original tab shouldn't have navigated");
   for (let t of tabsToClose) {
     gBrowser.removeTab(t);
   }
 });
+
+add_task(async function autofill() {
+  // Re-enable autofill and canonization.
+  await SpecialPowers.pushPrefEnv({set: [
+    ["browser.urlbar.autoFill", true],
+    ["browser.urlbar.ctrlCanonizesURLs", true],
+  ]});
+
+  // Quantumbar automatically disables autofill when the old search string
+  // starts with the new search string, so to make sure that doesn't happen and
+  // that earlier tests don't conflict with this one, start a new search for
+  // some other string.
+  gURLBar.focus();
+  EventUtils.sendString("blah");
+
+  // Add a visit that will be autofilled.
+  await PlacesUtils.history.clear();
+  await PlacesTestUtils.addVisits([{
+    uri: "http://example.com/",
+  }]);
+
+  let testcases = [
+    ["ex", "http://www.ex.com/", { ctrlKey: true }],
+    // Check that a direct load is not overwritten by a previous canonization.
+    ["ex", "http://example.com/", {}],
+    // search alias
+    ["@goo", "http://www%2E@goo.com/", { ctrlKey: true }],
+  ];
+
+  function promiseAutofill() {
+    return BrowserTestUtils.waitForEvent(gURLBar.inputField, "select");
+  }
+
+  for (let [inputValue, expectedURL, options] of testcases) {
+    let promiseLoad =
+      BrowserTestUtils.waitForDocLoadAndStopIt(expectedURL, gBrowser.selectedBrowser);
+    gURLBar.focus();
+    gURLBar.inputField.value = inputValue.slice(0, -1);
+    let autofillPromise = promiseAutofill();
+    EventUtils.sendString(inputValue.slice(-1));
+    await autofillPromise;
+    EventUtils.synthesizeKey("KEY_Enter", options);
+    await promiseLoad;
+
+    // Here again, make sure autofill isn't disabled for the next search.  See
+    // the comment above.
+    gURLBar.focus();
+    EventUtils.sendString("blah");
+  }
+
+  await PlacesUtils.history.clear();
+});