Bug 1773413: Stop autofilling matched with protocol part when user's input has no protocol expression. r=adw
authorDaisuke Akatsuka <daisuke@birchill.co.jp>
Fri, 10 Jun 2022 05:50:41 +0000
changeset 620490 4ccd82ad4423b9bc4883bcbb7c6f3704b51f98a4
parent 620489 65177f9de8c413ed4cdb40bbefb80449e8dcdd27
child 620491 c195015fa4fad1ac8a97bfcca7588d179029f55c
push id164322
push userdakatsuka.birchill@mozilla.com
push dateFri, 10 Jun 2022 05:53:02 +0000
treeherderautoland@4ccd82ad4423 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1773413
milestone103.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 1773413: Stop autofilling matched with protocol part when user's input has no protocol expression. r=adw Differential Revision: https://phabricator.services.mozilla.com/D148787
browser/components/urlbar/UrlbarProviderAutofill.jsm
browser/components/urlbar/tests/unit/test_autofill_adaptiveHistory.js
--- a/browser/components/urlbar/UrlbarProviderAutofill.jsm
+++ b/browser/components/urlbar/UrlbarProviderAutofill.jsm
@@ -572,38 +572,50 @@ class ProviderAutofill extends UrlbarPro
     } else if (
       queryContext.sources.includes(UrlbarUtils.RESULT_SOURCE.BOOKMARKS)
     ) {
       additionalCondition = "h.foreign_count > 0";
     } else {
       return [];
     }
 
+    // Change the search target dependent on user's input contains URI scheme.
+    let selectFixedURL;
+    let urlCondition;
+    if (this._strippedPrefix) {
+      selectFixedURL = "NULL AS fixed_url_match";
+      urlCondition =
+        "(h.url COLLATE NOCASE BETWEEN :searchString AND :searchString || X'FFFF')";
+    } else {
+      selectFixedURL = `
+        fixup_url(h.url) AS fixed_url,
+        fixup_url(h.url) COLLATE NOCASE BETWEEN :searchString AND :searchString || X'FFFF' AS fixed_url_match
+      `;
+      urlCondition = "fixed_url_match";
+    }
+
     const params = {
       queryType: QUERYTYPE.AUTOFILL_ADAPTIVE,
       searchString: queryContext.searchString.toLowerCase(),
       useCountThreshold: UrlbarPrefs.get(
         "autoFillAdaptiveHistoryUseCountThreshold"
       ),
     };
 
     const query = `
       SELECT
         :queryType AS query_type,
         :searchString AS search_string,
         i.input AS input,
         h.url AS url,
-        fixup_url(h.url) AS fixed_url,
-        fixup_url(h.url) COLLATE NOCASE BETWEEN :searchString AND :searchString || X'FFFF' AS fixed_url_match
+        ${selectFixedURL}
       FROM moz_places h
       JOIN moz_inputhistory i ON i.place_id = h.id
       WHERE :searchString BETWEEN i.input AND i.input || X'FFFF'
-      AND (
-        fixed_url_match OR (h.url COLLATE NOCASE BETWEEN :searchString AND :searchString || X'FFFF')
-      )
+      AND ${urlCondition}
       AND i.use_count >= :useCountThreshold
       ${additionalCondition ? `AND ${additionalCondition}` : ""}
       ORDER BY i.use_count DESC, fixed_url_match DESC, h.frecency DESC, h.id DESC
       LIMIT 1
     `;
 
     return [query, params];
   }
--- a/browser/components/urlbar/tests/unit/test_autofill_adaptiveHistory.js
+++ b/browser/components/urlbar/tests/unit/test_autofill_adaptiveHistory.js
@@ -619,43 +619,47 @@ const TEST_DATA = [
   },
   {
     description: "Prefixed URL for input history and 'http' for user input",
     pref: true,
     visitHistory: ["http://example.com/test"],
     inputHistory: [{ uri: "http://example.com/test", input: "http" }],
     userInput: "http",
     expected: {
-      autofilled: "http://example.com/test",
-      completed: "http://example.com/test",
       results: [
         context =>
+          makeSearchResult(context, {
+            engineName: "Suggestions",
+            heuristic: true,
+          }),
+        context =>
           makeVisitResult(context, {
             uri: "http://example.com/test",
-            title: "example.com/test",
-            heuristic: true,
+            title: "test visit for http://example.com/test",
           }),
       ],
     },
   },
   {
     description: "Prefixed URL for input history and 'http:' for user input",
     pref: true,
     visitHistory: ["http://example.com/test"],
     inputHistory: [{ uri: "http://example.com/test", input: "http:" }],
     userInput: "http:",
     expected: {
-      autofilled: "http://example.com/test",
-      completed: "http://example.com/test",
       results: [
         context =>
+          makeSearchResult(context, {
+            engineName: "Suggestions",
+            heuristic: true,
+          }),
+        context =>
           makeVisitResult(context, {
             uri: "http://example.com/test",
-            title: "example.com/test",
-            heuristic: true,
+            title: "test visit for http://example.com/test",
           }),
       ],
     },
   },
   {
     description: "Prefixed URL for input history and 'http:/' for user input",
     pref: true,
     visitHistory: ["http://example.com/test"],