From 266b05cbf9762e78ce94bec94de94bd873898708 Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Wed, 5 Apr 2017 15:01:02 +0200 Subject: [PATCH] Bug 1344924 - Contextual onboarding for search suggestions in the awesomebar. r=adw Make the onboarding being opt-in or opt-out depending on the default value of the browser.urlbar.sugges.searches pref. In both cases respect userMadeSearchSuggestionChoice though, so we won't further nag users that made a choice already. MozReview-Commit-ID: D4rRMRbdMrW --- browser/app/profile/firefox.js | 5 +- browser/base/content/browser.css | 4 +- browser/base/content/test/urlbar/browser.ini | 6 +- .../urlbar/browser_autocomplete_a11y_label.js | 3 +- .../urlbar/browser_urlbarSearchSuggestions.js | 3 +- ...browser_urlbarSearchSuggestions_opt-in.js} | 64 ++-- ...browser_urlbarSearchSuggestions_opt-out.js | 118 ++++++++ .../urlbar/browser_urlbarSearchTelemetry.js | 3 +- browser/base/content/urlbarBindings.xml | 284 +++++++++++++----- .../test/browser/browser_ext_omnibox.js | 10 - ...er_ext_webNavigation_urlbar_transitions.js | 3 +- .../locales/en-US/chrome/browser/browser.dtd | 11 +- .../browser/browser_UsageTelemetry_urlbar.js | 3 +- ...rlbarSearchSuggestionsNotification.inc.css | 137 ++++++++- 14 files changed, 496 insertions(+), 158 deletions(-) rename browser/base/content/test/urlbar/{browser_urlbarSearchSuggestionsNotification.js => browser_urlbarSearchSuggestions_opt-in.js} (81%) create mode 100644 browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 97855a36b6f2..2f7c672f09a9 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -320,10 +320,11 @@ pref("browser.urlbar.suggest.bookmark", true); pref("browser.urlbar.suggest.openpage", true); pref("browser.urlbar.suggest.searches", false); pref("browser.urlbar.userMadeSearchSuggestionsChoice", false); -// 4 here means the suggestion notification will be automatically -// hidden the 4th day, so it will actually be shown on 3 different days. +// The suggestion opt-in notification will be shown on 4 different days. pref("browser.urlbar.daysBeforeHidingSuggestionsPrompt", 4); pref("browser.urlbar.lastSuggestionsPromptDate", 20160601); +// The suggestion opt-out hint will be hidden after being shown 4 times. +pref("browser.urlbar.timesBeforeHidingSuggestionsHint", 4); // Limit the number of characters sent to the current search engine to fetch // suggestions. diff --git a/browser/base/content/browser.css b/browser/base/content/browser.css index 926700fcfade..2e44793dbd0c 100644 --- a/browser/base/content/browser.css +++ b/browser/base/content/browser.css @@ -610,12 +610,12 @@ html|input.urlbar-input[textoverflow]:not([focused]) { transition: height 100ms; } -#PopupAutoCompleteRichResult > hbox[anonid="search-suggestions-notification"] { +#PopupAutoCompleteRichResult > deck[anonid="search-suggestions-notification"] { visibility: collapse; transition: margin-top 100ms; } -#PopupAutoCompleteRichResult.showSearchSuggestionsNotification > hbox[anonid="search-suggestions-notification"] { +#PopupAutoCompleteRichResult.showSearchSuggestionsNotification > deck[anonid="search-suggestions-notification"] { visibility: visible; } diff --git a/browser/base/content/test/urlbar/browser.ini b/browser/base/content/test/urlbar/browser.ini index 76ed00cd8774..a729a6152923 100644 --- a/browser/base/content/test/urlbar/browser.ini +++ b/browser/base/content/test/urlbar/browser.ini @@ -80,7 +80,11 @@ support-files = support-files = searchSuggestionEngine.xml searchSuggestionEngine.sjs -[browser_urlbarSearchSuggestionsNotification.js] +[browser_urlbarSearchSuggestions_opt-in.js] +support-files = + searchSuggestionEngine.xml + searchSuggestionEngine.sjs +[browser_urlbarSearchSuggestions_opt-out.js] support-files = searchSuggestionEngine.xml searchSuggestionEngine.sjs diff --git a/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js b/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js index b59887ad7db7..6904940cd183 100644 --- a/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js +++ b/browser/base/content/test/urlbar/browser_autocomplete_a11y_label.js @@ -25,11 +25,12 @@ add_task(async function searchSuggestions() { let oldCurrentEngine = Services.search.currentEngine; Services.search.currentEngine = engine; Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); + let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF); Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true); registerCleanupFunction(function() { Services.search.currentEngine = oldCurrentEngine; Services.prefs.clearUserPref(SUGGEST_ALL_PREF); - Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled); }); await promiseAutocompleteResultPopup("foo"); diff --git a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js index f41b10b40494..58baca6b49b0 100644 --- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js +++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions.js @@ -3,12 +3,13 @@ const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml"; // Must run first. add_task(async function prepare() { + let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF); Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true); let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME); let oldCurrentEngine = Services.search.currentEngine; Services.search.currentEngine = engine; registerCleanupFunction(async function() { - Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled); Services.search.currentEngine = oldCurrentEngine; // Clicking suggestions causes visits to search results pages, so clear that diff --git a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestionsNotification.js b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-in.js similarity index 81% rename from browser/base/content/test/urlbar/browser_urlbarSearchSuggestionsNotification.js rename to browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-in.js index 9b6df0ea3f9a..bdfeae98deff 100644 --- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestionsNotification.js +++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-in.js @@ -8,14 +8,19 @@ add_task(async function prepare() { let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME); let oldCurrentEngine = Services.search.currentEngine; Services.search.currentEngine = engine; + let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF); + let defaults = Services.prefs.getDefaultBranch("browser.urlbar."); + let searchSuggestionsDefault = defaults.getBoolPref("suggest.searches"); + defaults.setBoolPref("suggest.searches", false); registerCleanupFunction(async function() { + defaults.setBoolPref("suggest.searches", searchSuggestionsDefault); Services.search.currentEngine = oldCurrentEngine; Services.prefs.clearUserPref(SUGGEST_ALL_PREF); - Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled); // Disable the notification for future tests so it doesn't interfere with // them. clearUserPref() won't work because by default the pref is false. - await setUserMadeChoicePref(true); + Services.prefs.setBoolPref(CHOICE_PREF, true); // Make sure the popup is closed for the next test. gURLBar.blur(); @@ -26,16 +31,14 @@ add_task(async function prepare() { add_task(async function focus() { // Focusing the urlbar used to open the popup in order to show the // notification, but it doesn't anymore. Make sure it does not. - Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); - await setUserMadeChoicePref(false); + setupVisibleNotification(); gURLBar.blur(); gURLBar.focus(); Assert.ok(!gURLBar.popup.popupOpen, "popup should remain closed"); }); add_task(async function dismissWithoutResults() { - Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); - await setUserMadeChoicePref(false); + setupVisibleNotification(); gURLBar.blur(); gURLBar.focus(); let popupPromise = promisePopupShown(gURLBar.popup); @@ -60,8 +63,7 @@ add_task(async function dismissWithoutResults() { }); add_task(async function dismissWithResults() { - Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); - await setUserMadeChoicePref(false); + setupVisibleNotification(); gURLBar.blur(); gURLBar.focus(); await promiseAutocompleteResultPopup("foo"); @@ -84,8 +86,7 @@ add_task(async function dismissWithResults() { }); add_task(async function disable() { - Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); - await setUserMadeChoicePref(false); + setupVisibleNotification(); gURLBar.blur(); gURLBar.focus(); await promiseAutocompleteResultPopup("foo"); @@ -103,9 +104,7 @@ add_task(async function disable() { }); add_task(async function enable() { - Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); - Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, false); - await setUserMadeChoicePref(false); + setupVisibleNotification(); gURLBar.blur(); gURLBar.focus(); await promiseAutocompleteResultPopup("foo"); @@ -131,6 +130,7 @@ add_task(async function enable() { add_task(async function privateWindow() { // Since suggestions are disabled in private windows, the notification should // not appear even when suggestions are otherwise enabled. + setupVisibleNotification(); let win = await BrowserTestUtils.openNewBrowserWindow({ private: true }); win.gURLBar.blur(); win.gURLBar.focus(); @@ -143,9 +143,7 @@ add_task(async function privateWindow() { add_task(async function multipleWindows() { // Opening multiple windows, using their urlbars, and then dismissing the // notification in one should dismiss the notification in all. - Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); - Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, false); - await setUserMadeChoicePref(false); + setupVisibleNotification(); gURLBar.focus(); await promiseAutocompleteResultPopup("win1"); @@ -184,39 +182,19 @@ add_task(async function multipleWindows() { add_task(async 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); - await setUserMadeChoicePref(false); - + setupVisibleNotification(); Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true); gURLBar.focus(); await 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. - */ -function setUserMadeChoicePref(userMadeChoice) { - return new Promise(resolve => { - let currentUserMadeChoice = Services.prefs.getBoolPref(CHOICE_PREF); - if (currentUserMadeChoice != userMadeChoice) { - Services.prefs.addObserver(CHOICE_PREF, function obs(subj, topic, data) { - Services.prefs.removeObserver(CHOICE_PREF, obs); - resolve(); - }); - } - Services.prefs.setBoolPref(CHOICE_PREF, userMadeChoice); - if (currentUserMadeChoice == userMadeChoice) { - resolve(); - } - }); +function setupVisibleNotification() { + Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); + // Toggle to reset the whichNotification cache. + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, false); + Services.prefs.setBoolPref(CHOICE_PREF, false); } function suggestionsPresent() { diff --git a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js new file mode 100644 index 000000000000..d1c5a0e11671 --- /dev/null +++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js @@ -0,0 +1,118 @@ +// The order of the tests here matters! + +const SUGGEST_ALL_PREF = "browser.search.suggest.enabled"; +const SUGGEST_URLBAR_PREF = "browser.urlbar.suggest.searches"; +const CHOICE_PREF = "browser.urlbar.userMadeSearchSuggestionsChoice"; +const TIMES_PREF = "browser.urlbar.timesBeforeHidingSuggestionsHint"; +const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml"; + +add_task(async function prepare() { + let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME); + let oldCurrentEngine = Services.search.currentEngine; + Services.search.currentEngine = engine; + let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF); + let defaults = Services.prefs.getDefaultBranch("browser.urlbar."); + let searchSuggestionsDefault = defaults.getBoolPref("suggest.searches"); + defaults.setBoolPref("suggest.searches", true); + let suggestionsChoice = Services.prefs.getBoolPref(CHOICE_PREF); + Services.prefs.setBoolPref(CHOICE_PREF, false); + registerCleanupFunction(async function() { + defaults.setBoolPref("suggest.searches", searchSuggestionsDefault); + Services.search.currentEngine = oldCurrentEngine; + Services.prefs.clearUserPref(SUGGEST_ALL_PREF); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled); + Services.prefs.setBoolPref(CHOICE_PREF, suggestionsChoice); + + // Make sure the popup is closed for the next test. + gURLBar.blur(); + Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed"); + }); +}); + +add_task(async function focus() { + // Focusing the urlbar should open the popup in order to show the + // notification. + setupVisibleHint(); + gURLBar.blur(); + let popupPromise = promisePopupShown(gURLBar.popup); + gURLBar.focus(); + await popupPromise; + Assert.ok(gURLBar.popup.popupOpen, "popup should be open"); + assertVisible(true); + Assert.equal(gURLBar.popup._matchCount, 0, "popup should have no results"); + + // Start searching. + EventUtils.synthesizeKey("r", {}); + EventUtils.synthesizeKey("n", {}); + EventUtils.synthesizeKey("d", {}); + await promiseSearchComplete(); + Assert.ok(suggestionsPresent()); + assertVisible(true); + + // Check the Change Options link. + let changeOptionsLink = document.getElementById("search-suggestions-change-settings"); + let prefsPromise = BrowserTestUtils.waitForLocationChange(gBrowser, "about:preferences#general-search"); + changeOptionsLink.click(); + await prefsPromise; + Assert.ok(!gURLBar.popup.popupOpen, "popup should be closed"); +}); + + +add_task(async function privateWindow() { + // Since suggestions are disabled in private windows, the notification should + // not appear even when suggestions are otherwise enabled. + setupVisibleHint(); + let win = await BrowserTestUtils.openNewBrowserWindow({ private: true }); + await promiseAutocompleteResultPopup("foo", win); + assertVisible(false, win); + win.gURLBar.blur(); + await BrowserTestUtils.closeWindow(win); +}); + +add_task(async function enableOutsideNotification() { + // Setting the suggest.searches pref outside the notification (e.g., by + // ticking the checkbox in the preferences window) should hide it. + setupVisibleHint(); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, false); + await promiseAutocompleteResultPopup("foo"); + assertVisible(false); +}); + +add_task(async function userMadeChoice() { + // If the user made a choice already, he should not see the hint. + setupVisibleHint(); + Services.prefs.setBoolPref(CHOICE_PREF, true); + await promiseAutocompleteResultPopup("foo"); + assertVisible(false); +}); + +function setupVisibleHint() { + Services.prefs.clearUserPref(TIMES_PREF); + Services.prefs.setBoolPref(SUGGEST_ALL_PREF, true); + // Toggle to reset the whichNotification cache. + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, false); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true); +} + +function suggestionsPresent() { + let controller = gURLBar.popup.input.controller; + let matchCount = controller.matchCount; + for (let i = 0; i < matchCount; i++) { + let url = controller.getValueAt(i); + let mozActionMatch = url.match(/^moz-action:([^,]+),(.*)$/); + if (mozActionMatch) { + let [, type, paramStr] = mozActionMatch; + let params = JSON.parse(paramStr); + if (type == "searchengine" && "searchSuggestion" in params) { + return true; + } + } + } + return false; +} + +function assertVisible(visible, win = window) { + let style = + win.getComputedStyle(win.gURLBar.popup.searchSuggestionsNotification); + Assert.equal(style.visibility, visible ? "visible" : "collapse"); +} diff --git a/browser/base/content/test/urlbar/browser_urlbarSearchTelemetry.js b/browser/base/content/test/urlbar/browser_urlbarSearchTelemetry.js index 6950854c89b2..976effb76aed 100644 --- a/browser/base/content/test/urlbar/browser_urlbarSearchTelemetry.js +++ b/browser/base/content/test/urlbar/browser_urlbarSearchTelemetry.js @@ -7,13 +7,14 @@ const TEST_ENGINE_BASENAME = "searchSuggestionEngine.xml"; // Must run first. add_task(async function prepare() { + let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF); Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true); let engine = await promiseNewSearchEngine(TEST_ENGINE_BASENAME); let oldCurrentEngine = Services.search.currentEngine; Services.search.currentEngine = engine; registerCleanupFunction(async function() { - Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled); Services.search.currentEngine = oldCurrentEngine; // Clicking urlbar results causes visits to their associated pages, so clear diff --git a/browser/base/content/urlbarBindings.xml b/browser/base/content/urlbarBindings.xml index 9238c5a0032f..20f64929546c 100644 --- a/browser/base/content/urlbarBindings.xml +++ b/browser/base/content/urlbarBindings.xml @@ -70,15 +70,18 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. this._prefs = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService) .getBranch("browser.urlbar."); - this._prefs.addObserver("", this); + + this._defaultPrefs = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefService) + .getDefaultBranch("browser.urlbar."); + 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._cacheUserMadeSearchSuggestionsChoice(); this.inputField.controllers.insertControllerAt(0, this._copyCutController); this.inputField.addEventListener("paste", this); this.inputField.addEventListener("mousedown", this); @@ -945,14 +948,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. // binding's constructor. this._prefs.setBoolPref("searchSuggestionsChoice", this._prefs.getBoolPref("suggest.searches")); - // fall-through. - case "userMadeSearchSuggestionsChoice": - this._cacheUserMadeSearchSuggestionsChoice(); - if (this._userMadeSearchSuggestionsChoice) { - this.popup.searchSuggestionsNotificationWasDismissed( - this._prefs.getBoolPref("suggest.searches") - ); - } + // Clear the cached value to allow changing conditions in tests. + delete this._whichSearchSuggestionsNotification; break; case "trimURLs": this._mayTrimURLs = this._prefs.getBoolPref(aData); @@ -1203,30 +1200,70 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. ]]> - - - - - - - + + + + + + + + + + @@ -1258,6 +1295,38 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. if (this.getAttribute("pageproxystate") != "valid") { UpdatePopupNotificationsVisibility(); } + + // We may want to show the search suggestions hint. + if (!gBrowser.selectedBrowser._urlbarFocused) { + // We show the opt-out notification on every kind of focus to the urlbar + // included opening a new tab, but we want to enforce at least one + // notification when the user focuses it with the mouse. + let whichNotification = this.whichSearchSuggestionsNotification; + if (whichNotification == "opt-out" && + this._showSearchSuggestionNotificationOnMouseFocus === undefined) { + this._showSearchSuggestionNotificationOnMouseFocus = true; + } + + // Check whether the focus change came from a user mouse action. + let focusMethod = Services.focus.getLastFocusMethod(window); + let mouseFocused = !!(focusMethod & Services.focus.FLAG_BYMOUSE); + if (this._showSearchSuggestionNotificationOnMouseFocus && + mouseFocused) { + // Force showing the opt-out notification. + this._whichSearchSuggestionsNotification = whichNotification = "opt-out"; + } + + if (whichNotification == "opt-out") { + try { + this.popup.openAutocompletePopup(this, this); + } finally { + if (mouseFocused) { + delete this._whichSearchSuggestionsNotification; + this._showSearchSuggestionNotificationOnMouseFocus = false; + } + } + } + } } ]]> @@ -1335,34 +1404,62 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. - - - &urlbar.searchSuggestionsNotification.question; - - + + + + &urlbar.searchSuggestionsNotification.question; + + + + + + + + + + + &brandShortName; + + + + 💡 &urlbar.searchSuggestionsNotification.hintPrefix; + &urlbar.searchSuggestionsNotification.hint; + + + - - - - +#ifdef XP_WIN + value="&urlbar.searchSuggestionsNotification.changeSettingsWin;" + accesskey="&urlbar.searchSuggestionsNotification.changeSettingsWin.accesskey;" +#else + value="&urlbar.searchSuggestionsNotification.changeSettingsUnix;" + accesskey="&urlbar.searchSuggestionsNotification.changeSettingsUnix.accesskey;" +#endif + onclick="openPreferences('general-search');" + control="search-suggestions-change-settings"/> + + @@ -1377,6 +1474,11 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. + + window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + + 0 @@ -1463,7 +1565,10 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. Services.prefs.setBoolPref( "browser.urlbar.userMadeSearchSuggestionsChoice", true ); - // The input's pref observer will now hide the notification. + // Hide the notification. + this.searchSuggestionsNotificationWasDismissed( + Services.prefs.getBoolPref("browser.urlbar.suggest.searches") + ); ]]> @@ -1551,29 +1656,6 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. // to avoid impacting startup / new window performance aInput.popup.hidden = false; - let showNotification = aInput.shouldShowSearchSuggestionsNotification; - if (showNotification) { - let prefs = aInput._prefs; - let now = new Date(); - let date = now.getFullYear() * 10000 + (now.getMonth() + 1) * 100 + now.getDate(); - let previousDate = prefs.getIntPref("lastSuggestionsPromptDate"); - if (previousDate < date) { - let remainingDays = - prefs.getIntPref("daysBeforeHidingSuggestionsPrompt") - 1; - prefs.setIntPref("daysBeforeHidingSuggestionsPrompt", - remainingDays); - prefs.setIntPref("lastSuggestionsPromptDate", date); - if (!remainingDays) - showNotification = false; - } - } - - if (showNotification) { - this._showSearchSuggestionsNotification(); - } else if (this.classList.contains("showSearchSuggestionsNotification")) { - this._hideSearchSuggestionsNotification(); - } - this._openAutocompletePopup(aInput, aElement); ]]> @@ -1634,12 +1716,25 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. this.siteIconStart = undefined; } + try { + let whichNotification = aInput.whichSearchSuggestionsNotification; + if (whichNotification != "none") { + aInput.updateSearchSuggestionsNotificationImpressions(whichNotification); + this._showSearchSuggestionsNotification(whichNotification, popupDirection); + } else if (this.classList.contains("showSearchSuggestionsNotification")) { + this._hideSearchSuggestionsNotification(); + } + } catch (ex) { + // Not critical for the urlbar functionality, just report the error. + Components.utils.reportError(ex); + } + // Position the popup below the navbar. To get the y-coordinate, // which is an offset from the bottom of the input, subtract the // bottom of the navbar from the buttom of the input. let yOffset = - document.getElementById("nav-bar").getBoundingClientRect().bottom - - aInput.getBoundingClientRect().bottom; + this.DOMWindowUtils.getBoundsWithoutFlushing(document.getElementById("nav-bar")).bottom - + this.DOMWindowUtils.getBoundsWithoutFlushing(aInput).bottom; this.openPopup(aElement, "after_start", 0, yOffset, false, false); ]]> @@ -1653,8 +1748,36 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. + + { - Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF); - }); -} - add_task(async function() { let keyword = "test"; @@ -250,7 +241,6 @@ add_task(async function() { }); } - await setup(); await extension.startup(); await SimpleTest.promiseFocus(window); diff --git a/browser/components/extensions/test/browser/browser_ext_webNavigation_urlbar_transitions.js b/browser/components/extensions/test/browser/browser_ext_webNavigation_urlbar_transitions.js index 0d5e1a350650..ea8780deafaa 100644 --- a/browser/components/extensions/test/browser/browser_ext_webNavigation_urlbar_transitions.js +++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_urlbar_transitions.js @@ -60,12 +60,13 @@ function addSearchEngine(basename) { async function prepareSearchEngine() { let oldCurrentEngine = Services.search.currentEngine; + let suggestionsEnabled = Services.prefs.getBoolPref(SUGGEST_URLBAR_PREF); Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, true); let engine = await addSearchEngine(TEST_ENGINE_BASENAME); Services.search.currentEngine = engine; registerCleanupFunction(async function() { - Services.prefs.clearUserPref(SUGGEST_URLBAR_PREF); + Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, suggestionsEnabled); Services.search.currentEngine = oldCurrentEngine; // Make sure the popup is closed for the next test. diff --git a/browser/locales/en-US/chrome/browser/browser.dtd b/browser/locales/en-US/chrome/browser/browser.dtd index daef26732778..36afe55acad4 100644 --- a/browser/locales/en-US/chrome/browser/browser.dtd +++ b/browser/locales/en-US/chrome/browser/browser.dtd @@ -420,7 +420,16 @@ These should match what Safari and other Apple applications use on OS X Lion. -- - + + + + + + + + +