Bug 1181173: Move the URL bar search suggestions preference to the search section. r=mak a=sylvestre
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 13 Aug 2015 15:44:44 -0700
changeset 288840 c11fa31e5fc1cf899d683b29dd27a92d3b4ee67b
parent 288839 d00f8aacf0e64a5fd05d21ceae46f32735c34eb2
child 288841 bf5fb167c2f51eeb94e6f3340c22995625a549e2
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, sylvestre
bugs1181173
milestone42.0a2
Bug 1181173: Move the URL bar search suggestions preference to the search section. r=mak a=sylvestre
browser/components/preferences/in-content/privacy.js
browser/components/preferences/in-content/privacy.xul
browser/components/preferences/in-content/search.js
browser/components/preferences/in-content/search.xul
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_privacypane_5.js
browser/components/preferences/in-content/tests/browser_searchsuggestions.js
--- a/browser/components/preferences/in-content/privacy.js
+++ b/browser/components/preferences/in-content/privacy.js
@@ -111,19 +111,16 @@ var gPrivacyPane = {
     setEventListener("privateBrowsingAutoStart", "command",
                      gPrivacyPane.updateAutostart);
     setEventListener("cookieExceptions", "command",
                      gPrivacyPane.showCookieExceptions);
     setEventListener("showCookiesButton", "command",
                      gPrivacyPane.showCookies);
     setEventListener("clearDataSettings", "command",
                      gPrivacyPane.showClearPrivateDataSettings);
-
-    document.getElementById("searchesSuggestion").hidden = 
-      !Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
   },
 
   // HISTORY MODE
 
   /**
    * The list of preferences which affect the initial history mode settings.
    * If the auto start private browsing mode pref is active, the initial
    * history mode would be set to "Don't remember anything".
--- a/browser/components/preferences/in-content/privacy.xul
+++ b/browser/components/preferences/in-content/privacy.xul
@@ -36,19 +36,16 @@
               name="browser.urlbar.suggest.bookmark"
               type="bool"/>
   <preference id="browser.urlbar.suggest.history"
               name="browser.urlbar.suggest.history"
               type="bool"/>
   <preference id="browser.urlbar.suggest.openpage"
               name="browser.urlbar.suggest.openpage"
               type="bool"/>
-  <preference id="browser.urlbar.suggest.searches"
-              name="browser.urlbar.suggest.searches"
-              type="bool"/>
 
   <!-- History -->
   <preference id="places.history.enabled"
               name="places.history.enabled"
               type="bool"/>
   <preference id="browser.formfill.enable"
               name="browser.formfill.enable"
               type="bool"/>
@@ -256,13 +253,12 @@
             accesskey="&locbar.history.accesskey;"
             preference="browser.urlbar.suggest.history"/>
   <checkbox id="bookmarkSuggestion" label="&locbar.bookmarks.label;"
             accesskey="&locbar.bookmarks.accesskey;"
             preference="browser.urlbar.suggest.bookmark"/>
   <checkbox id="openpageSuggestion" label="&locbar.openpage.label;"
             accesskey="&locbar.openpage.accesskey;"
             preference="browser.urlbar.suggest.openpage"/>
-  <checkbox id="searchesSuggestion" label="&locbar.searches.label;"
-            hidden="true"
-            accesskey="&locbar.searches.accesskey;"
-            preference="browser.urlbar.suggest.searches"/>
+  <label class="text-link" onclick="if (event.button == 0) gotoPref('search')">
+    &suggestionSettings.label;
+  </label>
 </groupbox>
--- a/browser/components/preferences/in-content/search.js
+++ b/browser/components/preferences/in-content/search.js
@@ -24,16 +24,35 @@ document.addEventListener("Initialized",
   if (document.location.hash == "#search")
     document.location.hash = "";
 });
 
 var gEngineView = null;
 
 var gSearchPane = {
 
+  /**
+   * Initialize autocomplete to ensure prefs are in sync.
+   */
+  _initAutocomplete: function () {
+    let unifiedCompletePref = false;
+    try {
+      unifiedCompletePref =
+        Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
+    } catch (ex) {}
+
+    if (unifiedCompletePref) {
+      Components.classes["@mozilla.org/autocomplete/search;1?name=unifiedcomplete"]
+                .getService(Components.interfaces.mozIPlacesAutoComplete);
+    } else {
+      Components.classes["@mozilla.org/autocomplete/search;1?name=history"]
+                .getService(Components.interfaces.mozIPlacesAutoComplete);
+    }
+  },
+
   init: function ()
   {
     gEngineView = new EngineView(new EngineStore());
     document.getElementById("engineList").view = gEngineView;
     this.buildDefaultEngineDropDown();
 
     window.addEventListener("click", this, false);
     window.addEventListener("command", this, false);
@@ -41,16 +60,28 @@ var gSearchPane = {
     window.addEventListener("keypress", this, false);
     window.addEventListener("select", this, false);
     window.addEventListener("blur", this, true);
 
     Services.obs.addObserver(this, "browser-search-engine-modified", false);
     window.addEventListener("unload", () => {
       Services.obs.removeObserver(this, "browser-search-engine-modified", false);
     });
+
+    this._initAutocomplete();
+
+    let urlbarSuggests = document.getElementById("urlBarSuggestion");
+    urlbarSuggests.hidden = !Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
+
+    let suggestsPref = document.getElementById("browser.search.suggest.enabled")
+    let updateSuggestsCheckbox = () => {
+      urlbarSuggests.disabled = !suggestsPref.value;
+    }
+    suggestsPref.addEventListener("change", updateSuggestsCheckbox);
+    updateSuggestsCheckbox();
   },
 
   buildDefaultEngineDropDown: function() {
     // This is called each time something affects the list of engines.
     let list = document.getElementById("defaultEngine");
     let currentEngine;
 
     // First, try to preserve the current selection.
--- a/browser/components/preferences/in-content/search.xul
+++ b/browser/components/preferences/in-content/search.xul
@@ -1,14 +1,18 @@
     <preferences id="searchPreferences" hidden="true" data-category="paneSearch">
 
       <preference id="browser.search.suggest.enabled"
                   name="browser.search.suggest.enabled"
                   type="bool"/>
 
+      <preference id="browser.urlbar.suggest.searches"
+                  name="browser.urlbar.suggest.searches"
+                  type="bool"/>
+
       <preference id="browser.search.hiddenOneOffs"
                   name="browser.search.hiddenOneOffs"
                   type="unichar"/>
 
       <preference id="browser.search.redirectWindowsSearch"
                   name="browser.search.redirectWindowsSearch"
                   type="bool"/>
 
@@ -32,16 +36,22 @@
       <label>&chooseYourDefaultSearchEngine.label;</label>
       <menulist id="defaultEngine">
         <menupopup/>
       </menulist>
       <checkbox id="suggestionsInSearchFieldsCheckbox"
                 label="&provideSearchSuggestions.label;"
                 accesskey="&provideSearchSuggestions.accesskey;"
                 preference="browser.search.suggest.enabled"/>
+      <hbox class="indent">
+        <checkbox id="urlBarSuggestion" label="&showURLBarSuggestions.label;"
+                  hidden="true"
+                  accesskey="&showURLBarSuggestions.accesskey;"
+                  preference="browser.urlbar.suggest.searches"/>
+      </hbox>
       <checkbox id="redirectSearchCheckbox"
                 label="&redirectWindowsSearch.label;"
                 accesskey="&redirectWindowsSearch.accesskey;"
                 preference="browser.search.redirectWindowsSearch"/>
     </groupbox>
 
     <groupbox id="oneClickSearchProvidersGroup" data-category="paneSearch">
       <caption label="&oneClickSearchEngines.label;"/>
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -20,14 +20,15 @@ skip-if = !healthreport || (os == 'linux
 [browser_proxy_backup.js]
 [browser_privacypane_1.js]
 [browser_privacypane_3.js]
 [browser_privacypane_4.js]
 [browser_privacypane_5.js]
 [browser_privacypane_8.js]
 skip-if = e10s # Bug ?????? -  "leaked until shutdown [nsGlobalWindow #99 about:preferences]"
 [browser_sanitizeOnShutdown_prefLocked.js]
+[browser_searchsuggestions.js]
 [browser_subdialogs.js]
 skip-if = e10s # Bug 1087114
 support-files = subdialog.xul
 [browser_telemetry.js]
 # Skip this test on Android and B2G as FHR and Telemetry are separate systems there.
 skip-if = !healthreport || !telemetry || (os == 'linux' && debug) || (os == 'android') || (os == 'b2g')
--- a/browser/components/preferences/in-content/tests/browser_privacypane_5.js
+++ b/browser/components/preferences/in-content/tests/browser_privacypane_5.js
@@ -15,13 +15,10 @@ function test() {
   let tests = [
     test_locbar_suggestion_retention("history", true),
     test_locbar_suggestion_retention("bookmark", true),
     test_locbar_suggestion_retention("openpage", false),
     test_locbar_suggestion_retention("history", true),
     test_locbar_suggestion_retention("history", false),
   ];
 
-  if (Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete"))
-    tests.push(test_locbar_suggestion_retention("searches", true));
-
   run_test_subset(tests);
 }
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_searchsuggestions.js
@@ -0,0 +1,43 @@
+let original = Services.prefs.getBoolPref("browser.search.suggest.enabled");
+
+registerCleanupFunction(() => {
+  Services.prefs.setBoolPref("browser.search.suggest.enabled", original);
+});
+
+// Open with suggestions enabled
+add_task(function*() {
+  Services.prefs.setBoolPref("browser.search.suggest.enabled", true);
+
+  yield openPreferencesViaOpenPreferencesAPI("search", undefined, { leaveOpen: true });
+
+  let doc = gBrowser.selectedBrowser.contentDocument;
+  let urlbarBox = doc.getElementById("urlBarSuggestion");
+  ok(!urlbarBox.disabled, "Checkbox should be enabled");
+
+  Services.prefs.setBoolPref("browser.search.suggest.enabled", false);
+
+  ok(urlbarBox.disabled, "Checkbox should be disabled");
+
+  gBrowser.removeCurrentTab();
+});
+
+// Open with suggestions disabled
+add_task(function*() {
+  Services.prefs.setBoolPref("browser.search.suggest.enabled", false);
+
+  yield openPreferencesViaOpenPreferencesAPI("search", undefined, { leaveOpen: true });
+
+  let doc = gBrowser.selectedBrowser.contentDocument;
+  let urlbarBox = doc.getElementById("urlBarSuggestion");
+  ok(urlbarBox.disabled, "Checkbox should be disabled");
+
+  Services.prefs.setBoolPref("browser.search.suggest.enabled", true);
+
+  ok(!urlbarBox.disabled, "Checkbox should be enabled");
+
+  gBrowser.removeCurrentTab();
+});
+
+add_task(function*() {
+  Services.prefs.setBoolPref("browser.search.suggest.enabled", original);
+});