Bug 1198723 - Don't show the urlbar search suggestions opt-in if suggestions are enabled outside the opt-in. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Wed, 16 Sep 2015 11:21:59 -0700
changeset 295450 44fc4c98e5fe9fd5e32b7d394f5be15a724391d4
parent 295449 ece591e2a86291760b5b6880dbe85cb28e14969a
child 295451 268a150b0665e514beb6d46786164bc7d7c065df
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1198723
milestone43.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 1198723 - Don't show the urlbar search suggestions opt-in if suggestions are enabled outside the opt-in. r=mak
browser/base/content/test/general/browser_urlbarSearchSuggestionsNotification.js
browser/base/content/urlbarBindings.xml
--- a/browser/base/content/test/general/browser_urlbarSearchSuggestionsNotification.js
+++ b/browser/base/content/test/general/browser_urlbarSearchSuggestionsNotification.js
@@ -178,16 +178,29 @@ add_task(function* multipleWindows() {
   gURLBar.focus();
   yield promiseAutocompleteResultPopup("win1done");
   assertVisible(false);
 
   yield BrowserTestUtils.closeWindow(win2);
   yield BrowserTestUtils.closeWindow(win3);
 });
 
+add_task(function* enableOutsideNotification() {
+  // Setting the suggest.searches pref outside the notification (e.g., by
+  // ticking the checkbox in the preferences window) should hide it.
+  Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true);
+  Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, false);
+  yield setUserMadeChoicePref(false);
+
+  Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true);
+  gURLBar.focus();
+  yield promiseAutocompleteResultPopup("foo");
+  assertVisible(false);
+});
+
 /**
  * Setting the choice pref triggers a pref observer in the urlbar, which hides
  * the notification if it's present.  This function returns a promise that's
  * resolved once the observer fires.
  *
  * @param userMadeChoice  A boolean, the pref's new value.
  * @return A Promise that's resolved when the observer fires -- or, if the pref
  *         is currently the given value, that's resolved immediately.
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -61,19 +61,17 @@ file, You can obtain one at http://mozil
 
         this._prefs.addObserver("", this, false);
         this.clickSelectsAll = this._prefs.getBoolPref("clickSelectsAll");
         this.doubleClickSelectsAll = this._prefs.getBoolPref("doubleClickSelectsAll");
         this.completeDefaultIndex = this._prefs.getBoolPref("autoFill");
         this.timeout = this._prefs.getIntPref("delay");
         this._formattingEnabled = this._prefs.getBoolPref("formatting.enabled");
         this._mayTrimURLs = this._prefs.getBoolPref("trimURLs");
-        this._userMadeSearchSuggestionsChoice =
-          this._prefs.getBoolPref("userMadeSearchSuggestionsChoice");
-
+        this._cacheUserMadeSearchSuggestionsChoice();
         this.inputField.controllers.insertControllerAt(0, this._copyCutController);
         this.inputField.addEventListener("paste", this, false);
         this.inputField.addEventListener("mousedown", this, false);
         this.inputField.addEventListener("mousemove", this, false);
         this.inputField.addEventListener("mouseout", this, false);
         this.inputField.addEventListener("overflow", this, false);
         this.inputField.addEventListener("underflow", this, false);
 
@@ -658,27 +656,29 @@ file, You can obtain one at http://mozil
                 break;
               case "delay":
                 this.timeout = this._prefs.getIntPref(aData);
                 break;
               case "formatting.enabled":
                 this._formattingEnabled = this._prefs.getBoolPref(aData);
                 break;
               case "userMadeSearchSuggestionsChoice":
-                this._userMadeSearchSuggestionsChoice =
-                  this._prefs.getBoolPref(aData);
+              case "suggest.searches":
+                this._cacheUserMadeSearchSuggestionsChoice();
                 // Make sure the urlbar is focused.  It won't be, for example,
                 // if the user used an accesskey to make an opt-in choice.
                 // mIgnoreFocus prevents the text from being selected.
                 this.mIgnoreFocus = true;
                 this.focus();
                 this.mIgnoreFocus = false;
-                this.popup.searchSuggestionsNotificationWasDismissed(
-                  this._prefs.getBoolPref("suggest.searches")
-                );
+                if (this._userMadeSearchSuggestionsChoice) {
+                  this.popup.searchSuggestionsNotificationWasDismissed(
+                    this._prefs.getBoolPref("suggest.searches")
+                  );
+                }
                 break;
               case "trimURLs":
                 this._mayTrimURLs = this._prefs.getBoolPref(aData);
                 break;
               case "unifiedcomplete":
                 let useUnifiedComplete = false;
                 try {
                   useUnifiedComplete = this._prefs.getBoolPref(aData);
@@ -925,16 +925,24 @@ file, You can obtain one at http://mozil
           return this.mController.handleDelete();
         ]]></body>
       </method>
 
       <field name="_userMadeSearchSuggestionsChoice"><![CDATA[
         false
       ]]></field>
 
+      <method name="_cacheUserMadeSearchSuggestionsChoice">
+        <body><![CDATA[
+          this._userMadeSearchSuggestionsChoice =
+            this._prefs.getBoolPref("userMadeSearchSuggestionsChoice") ||
+            this._prefs.getBoolPref("suggest.searches");
+        ]]></body>
+      </method>
+
       <property name="shouldShowSearchSuggestionsNotification" readonly="true">
         <getter><![CDATA[
           return !this._userMadeSearchSuggestionsChoice &&
                  !this.inPrivateContext &&
                  // When _urlbarFocused is true, tabbrowser would close the
                  // popup if it's opened here, so don't show the notification.
                  !gBrowser.selectedBrowser._urlbarFocused &&
                  Services.prefs.getBoolPref("browser.search.suggest.enabled") &&