Bug 1196032 - Don't show the urlbar search suggestions opt-in in private windows. r=mak, a=sylvestre
authorDrew Willcoxon <adw@mozilla.com>
Wed, 19 Aug 2015 13:38:04 -0700
changeset 288823 86e30962df7edab5c56781fb942930a7e79bf35d
parent 288822 9294d377bbc55b0aff865de1272036e5a4be0382
child 288824 2452b513ecc2b7d80392ca9c346d8a4ac9c53e00
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
bugs1196032
milestone42.0a2
Bug 1196032 - Don't show the urlbar search suggestions opt-in in private windows. r=mak, a=sylvestre
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
@@ -125,16 +125,28 @@ add_task(function* enable() {
   assertSuggestionsPresent(true);
   gURLBar.blur();
   gURLBar.focus();
   // Suggestions should still be present in a new search of course.
   yield promiseAutocompleteResultPopup("bar");
   assertSuggestionsPresent(true);
 });
 
+add_task(function* privateWindow() {
+  // Since suggestions are disabled in private windows, the notification should
+  // not appear even when suggestions are otherwise enabled.
+  let win = yield BrowserTestUtils.openNewBrowserWindow({ private: true });
+  win.gURLBar.blur();
+  win.gURLBar.focus();
+  yield promiseAutocompleteResultPopup("foo", win);
+  assertVisible(false, win);
+  win.gURLBar.blur();
+  yield BrowserTestUtils.closeWindow(win);
+});
+
 function assertSuggestionsPresent(expectedPresent) {
   let controller = gURLBar.popup.input.controller;
   let matchCount = controller.matchCount;
   let actualPresent = false;
   for (let i = 0; i < matchCount; i++) {
     let url = controller.getValueAt(i);
     let [, type, paramStr] = url.match(/^moz-action:([^,]+),(.*)$/);
     let params = {};
@@ -142,19 +154,19 @@ function assertSuggestionsPresent(expect
       params = JSON.parse(paramStr);
     } catch (err) {}
     let isSuggestion = type == "searchengine" && "searchSuggestion" in params;
     actualPresent = actualPresent || isSuggestion;
   }
   Assert.equal(actualPresent, expectedPresent);
 }
 
-function assertVisible(visible) {
+function assertVisible(visible, win=window) {
   let style =
-    window.getComputedStyle(gURLBar.popup.searchSuggestionsNotification);
+    win.getComputedStyle(win.gURLBar.popup.searchSuggestionsNotification);
   Assert.equal(style.visibility, visible ? "visible" : "collapse");
 }
 
 function promiseTransition() {
   return new Promise(resolve => {
     gURLBar.popup.addEventListener("transitionend", function onEnd() {
       gURLBar.popup.removeEventListener("transitionend", onEnd, true);
       // The urlbar needs to handle the transitionend first, but that happens
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -927,16 +927,17 @@ file, You can obtain one at http://mozil
 
       <field name="_userMadeSearchSuggestionsChoice"><![CDATA[
         false
       ]]></field>
 
       <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") &&
                  this._prefs.getBoolPref("unifiedcomplete");
         ]]></getter>
       </property>