Bug 1211726 - part 1: add results from a hardcoded list of top sites, r?gijs draft
authorSvetlana Orlik <sorlik@mozilla.com>
Mon, 02 Jan 2017 03:28:31 +0300
changeset 461318 99e512c136ad7b4d51b565291504f9b9abaa13a1
parent 447633 ad993783599ab2ede0cf931fdec02f4df40a7a6d
child 542294 fcc2b347c9b9a12f8232a66b3a49a393d5c8fedd
push id41647
push userbmo:sveta.orlik.code@gmail.com
push dateMon, 16 Jan 2017 12:42:25 +0000
reviewersgijs
bugs1211726
milestone53.0a1
Bug 1211726 - part 1: add results from a hardcoded list of top sites, r?gijs MozReview-Commit-ID: 21FN4awJaXf
modules/libpref/init/all.js
testing/profiles/prefs_general.js
toolkit/components/places/UnifiedComplete.js
toolkit/components/places/tests/head_common.js
toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
toolkit/components/places/tests/unifiedcomplete/test_1211726.js
toolkit/components/places/tests/unifiedcomplete/test_autofill_default_behavior.js
toolkit/components/places/tests/unifiedcomplete/xpcshell.ini
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1056,16 +1056,17 @@ pref("application.use_ns_plugin_finder",
 pref("browser.fixup.alternate.enabled", true);
 pref("browser.fixup.alternate.prefix", "www.");
 pref("browser.fixup.alternate.suffix", ".com");
 pref("browser.fixup.dns_first_for_single_words", false);
 pref("browser.fixup.hide_user_pass", true);
 
 // Location Bar AutoComplete
 pref("browser.urlbar.autocomplete.enabled", true);
+pref("browser.urlbar.defaultdomaincompletion.enabled", true);
 
 // Print header customization
 // Use the following codes:
 // &T - Title
 // &U - Document URL
 // &D - Date/Time
 // &P - Page Number
 // &PT - Page Number "of" Page total
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -332,16 +332,18 @@ user_pref("media.webspeech.synth.test", 
 // Turn off search suggestions in the location bar so as not to trigger network
 // connections.
 user_pref("browser.urlbar.suggest.searches", false);
 
 // Turn off the location bar search suggestions opt-in.  It interferes with
 // tests that don't expect it to be there.
 user_pref("browser.urlbar.userMadeSearchSuggestionsChoice", true);
 
+user_pref("browser.urlbar.defaultdomaincompletion.enabled", false);
+
 user_pref("dom.audiochannel.mutedByDefault", false);
 
 user_pref("webextensions.tests", true);
 user_pref("startup.homepage_welcome_url", "about:blank");
 user_pref("startup.homepage_welcome_url.additional", "");
 
 // For Firefox 52 only, ESR will support non-Flash plugins while release will
 // not, so we keep testing the non-Flash pathways
--- a/toolkit/components/places/UnifiedComplete.js
+++ b/toolkit/components/places/UnifiedComplete.js
@@ -53,16 +53,26 @@ const QUERYTYPE_FILTERED            = 0;
 const QUERYTYPE_AUTOFILL_HOST       = 1;
 const QUERYTYPE_AUTOFILL_URL        = 2;
 
 // This separator is used as an RTL-friendly way to split the title and tags.
 // It can also be used by an nsIAutoCompleteResult consumer to re-split the
 // "comment" back into the title and the tag.
 const TITLE_TAGS_SEPARATOR = " \u2013 ";
 
+const TOP500_SITES = [
+  ["Google.com", "Google"],
+  ["Youtube.com", "YouTube"],
+  ["Facebook.com", "Facebook"],
+  ["Baidu.com", "\u767E\u5EA6\u4E00\u4E0B\uFF0C\u4F60\u5C31\u77E5\u9053"],
+  ["Wikipedia.org", "Wikipedia"],
+  ["toop500.org", "TOP500 test site"],
+];
+const TOP500_FRECENCY = 1;
+
 // Telemetry probes.
 const TELEMETRY_1ST_RESULT = "PLACES_AUTOCOMPLETE_1ST_RESULT_TIME_MS";
 const TELEMETRY_6_FIRST_RESULTS = "PLACES_AUTOCOMPLETE_6_FIRST_RESULTS_TIME_MS";
 // The default frecency value used when inserting matches with unknown frecency.
 const FRECENCY_DEFAULT = 1000;
 
 // Remote matches are appended when local matches are below a given frecency
 // threshold (FRECENCY_DEFAULT) as soon as they arrive.  However we'll
@@ -934,16 +944,21 @@ Search.prototype = {
     // to true so that when the result is added, "heuristic" can be included in
     // its style.
     this._addingHeuristicFirstMatch = true;
     let hasHeuristic = yield this._matchFirstHeuristicResult(conn);
     this._addingHeuristicFirstMatch = false;
     if (!this.pending)
       return;
 
+    dump("++++++++++++++++++++++++++++++++++ " + Services.prefs.getBoolPref("browser.urlbar.defaultdomaincompletion.enabled"));
+    if ( Services.prefs.getBoolPref("browser.urlbar.defaultdomaincompletion.enabled") ) {
+      this._matchTop500()
+    }
+
     // We sleep a little between adding the heuristicFirstMatch and matching
     // any other searches so we aren't kicking off potentially expensive
     // searches on every keystroke.
     // Though, if there's no heuristic result, we start searching immediately,
     // since autocomplete may be waiting for us.
     if (hasHeuristic) {
       yield this._sleep(Prefs.delay);
       if (!this.pending)
@@ -993,16 +1008,31 @@ Search.prototype = {
       ExtensionSearchHandler.handleInputCancelled();
     }
 
     // Ensure to fill any remaining space. Suggestions which come from extensions are
     // inserted at the beginning, so any suggestions
     yield Promise.all(this._remoteMatchesPromises);
   }),
 
+  _matchTop500() {
+    for (let [url, title] of TOP500_SITES) {
+      if (url.toLowerCase().includes(this._searchString) ||
+          title.toLowerCase().includes(this._searchString)) {
+        let match = {
+          value: url,
+          comment: title,
+          style: "prefill-site",
+          frecency: TOP500_FRECENCY,
+        };
+        this._addMatch(match);
+      }
+    }
+  },
+
   *_matchFirstHeuristicResult(conn) {
     // We always try to make the first result a special "heuristic" result.  The
     // heuristics below determine what type of result it will be, if any.
 
     let hasSearchTerms = this._searchTokens.length > 0;
 
     if (hasSearchTerms) {
       // It may be a keyword registered by an extension.
--- a/toolkit/components/places/tests/head_common.js
+++ b/toolkit/components/places/tests/head_common.js
@@ -876,8 +876,10 @@ function compareAscending(a, b) {
     return -1;
   }
   return 0;
 }
 
 function sortBy(array, prop) {
   return array.sort((a, b) => compareAscending(a[prop], b[prop]));
 }
+
+Services.prefs.setBoolPref("browser.urlbar.defaultdomaincompletion.enabled", false);
--- a/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
+++ b/toolkit/components/places/tests/unifiedcomplete/head_autocomplete.js
@@ -22,32 +22,35 @@ Cu.import("resource://testing-common/htt
 // Put any other stuff relative to this test folder below.
 
 const TITLE_SEARCH_ENGINE_SEPARATOR = " \u00B7\u2013\u00B7 ";
 
 function run_test() {
   run_next_test();
 }
 
+Services.prefs.setBoolPref("browser.urlbar.defaultdomaincompletion.enabled", false);
+
 function* cleanup() {
   Services.prefs.clearUserPref("browser.urlbar.autocomplete.enabled");
   Services.prefs.clearUserPref("browser.urlbar.autoFill");
   Services.prefs.clearUserPref("browser.urlbar.autoFill.typed");
   Services.prefs.clearUserPref("browser.urlbar.autoFill.searchEngines");
   let suggestPrefs = [
     "history",
     "bookmark",
     "history.onlyTyped",
     "openpage",
     "searches",
   ];
   for (let type of suggestPrefs) {
     Services.prefs.clearUserPref("browser.urlbar.suggest." + type);
   }
   Services.prefs.clearUserPref("browser.search.suggest.enabled");
+  Services.prefs.clearUserPref("browser.urlbar.defaultdomaincompletion.enabled");
   yield PlacesUtils.bookmarks.eraseEverything();
   yield PlacesTestUtils.clearHistory();
 }
 do_register_cleanup(cleanup);
 
 /**
  * @param aSearches
  *        Array of AutoCompleteSearch names.
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/unifiedcomplete/test_1211726.js
@@ -0,0 +1,13 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+add_task(function* test_it_works() {
+  do_print("Searching in 'TOP 500 SITES' hard-codded array");
+  yield check_autocomplete({
+    search: "toop",
+    autofilled: "toop500.org",
+    completed: "toop500.org"
+  });
+  yield cleanup();
+});
--- a/toolkit/components/places/tests/unifiedcomplete/test_autofill_default_behavior.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_autofill_default_behavior.js
@@ -2,16 +2,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * Test autoFill for different default behaviors.
  */
 
 add_task(function* test_default_behavior_host() {
+  do_print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " + Services.prefs.getBoolPref("browser.urlbar.defaultdomaincompletion.enabled"));
+
   let uri1 = NetUtil.newURI("http://typed/");
   let uri2 = NetUtil.newURI("http://visited/");
   let uri3 = NetUtil.newURI("http://bookmarked/");
   let uri4 = NetUtil.newURI("http://tpbk/");
   let uri5 = NetUtil.newURI("http://tagged/");
 
   yield PlacesTestUtils.addVisits([
     { uri: uri1, title: "typed", transition: TRANSITION_TYPED },
--- a/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini
+++ b/toolkit/components/places/tests/unifiedcomplete/xpcshell.ini
@@ -28,16 +28,17 @@ support-files =
 [test_ignore_protocol.js]
 [test_keyword_search.js]
 [test_keyword_search_actions.js]
 [test_keywords.js]
 [test_match_beginning.js]
 [test_multi_word_search.js]
 [test_query_url.js]
 [test_remote_tab_matches.js]
+[test_1211726.js]
 skip-if = !sync
 [test_search_engine_alias.js]
 [test_search_engine_current.js]
 [test_search_engine_host.js]
 [test_search_engine_restyle.js]
 [test_search_suggestions.js]
 [test_special_search.js]
 [test_swap_protocol.js]