Bug 1294496 - allow search suggestions for multi-word searches even for whitelisted domains, and test response to "DNS first" pref, r?mak draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Fri, 02 Sep 2016 23:06:50 +0100
changeset 410235 26f6a3a861fea5650cabaf8400138c9fbc33b873
parent 409041 d5f20820c80514476f596090292a5d77c4b41e3b
child 530533 04042e46ec41e0d8bc13bf22e410f69725db27e0
push id28686
push userbmo:gijskruitbosch+bugs@gmail.com
push dateTue, 06 Sep 2016 12:26:48 +0000
reviewersmak
bugs1294496
milestone51.0a1
Bug 1294496 - allow search suggestions for multi-word searches even for whitelisted domains, and test response to "DNS first" pref, r?mak MozReview-Commit-ID: ACxt9WuDr3I
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -1056,26 +1056,26 @@ Search.prototype = {
   _prohibitSearchSuggestionsFor(searchString) {
     if (this._prohibitSearchSuggestions)
       return true;
 
     // Suggestions for a single letter are unlikely to be useful.
     if (searchString.length < 2)
       return true;
 
-    let tokens = searchString.split(REGEXP_SPACES);
-
     // The first token may be a whitelisted host.
-    if (REGEXP_SINGLEWORD_HOST.test(tokens[0]) &&
-        Services.uriFixup.isDomainWhitelisted(tokens[0], -1))
+    if (this._searchTokens.length == 1 &&
+        REGEXP_SINGLEWORD_HOST.test(this._searchTokens[0]) &&
+        Services.uriFixup.isDomainWhitelisted(this._searchTokens[0], -1)) {
       return true;
+    }
 
     // Disallow fetching search suggestions for strings looking like URLs, to
     // avoid disclosing information about networks or passwords.
-    return tokens.some(looksLikeUrl);
+    return this._searchTokens.some(looksLikeUrl);
   },
 
   _matchKnownUrl: function* (conn) {
     // Hosts have no "/" in them.
     let lastSlashIndex = this._searchString.lastIndexOf("/");
     // Search only URLs if there's a slash in the search string...
     if (lastSlashIndex != -1) {
       // ...but not if it's exactly at the end of the search string.
--- a/toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_searchSuggestions.js
@@ -477,16 +477,104 @@ add_task(function* prohibit_suggestions(
   yield check_autocomplete({
     search: "localhost",
     searchParam: "enable-actions",
     matches: [
       makeVisitMatch("localhost", "http://localhost/", { heuristic: true }),
     ],
   });
 
+  // When using multiple words, we should still get suggestions:
+  yield check_autocomplete({
+    search: "localhost other",
+    searchParam: "enable-actions",
+    matches: [
+      makeSearchMatch("localhost other", { engineName: ENGINE_NAME, heuristic: true }),
+      {
+        uri: makeActionURI(("searchengine"), {
+          engineName: ENGINE_NAME,
+          input: "localhost other foo",
+          searchQuery: "localhost other",
+          searchSuggestion: "localhost other foo",
+        }),
+        title: ENGINE_NAME,
+        style: ["action", "searchengine"],
+        icon: "",
+      },
+      {
+        uri: makeActionURI(("searchengine"), {
+          engineName: ENGINE_NAME,
+          input: "localhost other bar",
+          searchQuery: "localhost other",
+          searchSuggestion: "localhost other bar",
+        }),
+        title: ENGINE_NAME,
+        style: ["action", "searchengine"],
+        icon: "",
+      },
+    ],
+  });
+
+  // Clear the whitelist for localhost, and try preferring DNS for any single
+  // word instead:
+  Services.prefs.clearUserPref("browser.fixup.domainwhitelist.localhost");
+  Services.prefs.setBoolPref("browser.fixup.dns_first_for_single_words", true);
+  do_register_cleanup(() => {
+    Services.prefs.clearUserPref("browser.fixup.dns_first_for_single_words");
+  });
+
+  yield check_autocomplete({
+    search: "localhost",
+    searchParam: "enable-actions",
+    matches: [
+      makeVisitMatch("localhost", "http://localhost/", { heuristic: true }),
+    ],
+  });
+
+  yield check_autocomplete({
+    search: "somethingelse",
+    searchParam: "enable-actions",
+    matches: [
+      makeVisitMatch("somethingelse", "http://somethingelse/", { heuristic: true }),
+    ],
+  });
+
+  // When using multiple words, we should still get suggestions:
+  yield check_autocomplete({
+    search: "localhost other",
+    searchParam: "enable-actions",
+    matches: [
+      makeSearchMatch("localhost other", { engineName: ENGINE_NAME, heuristic: true }),
+      {
+        uri: makeActionURI(("searchengine"), {
+          engineName: ENGINE_NAME,
+          input: "localhost other foo",
+          searchQuery: "localhost other",
+          searchSuggestion: "localhost other foo",
+        }),
+        title: ENGINE_NAME,
+        style: ["action", "searchengine"],
+        icon: "",
+      },
+      {
+        uri: makeActionURI(("searchengine"), {
+          engineName: ENGINE_NAME,
+          input: "localhost other bar",
+          searchQuery: "localhost other",
+          searchSuggestion: "localhost other bar",
+        }),
+        title: ENGINE_NAME,
+        style: ["action", "searchengine"],
+        icon: "",
+      },
+    ],
+  });
+
+  Services.prefs.clearUserPref("browser.fixup.dns_first_for_single_words");
+
   yield check_autocomplete({
     search: "1.2.3.4",
     searchParam: "enable-actions",
     matches: [
       makeVisitMatch("1.2.3.4", "http://1.2.3.4/", { heuristic: true }),
     ],
   });
   yield check_autocomplete({