Bug 1367427 - The one-offs bar is not displayed in the Awesome Bar while search suggestions hint is displayed. r=past
MozReview-Commit-ID: KpVwQ3XzivB
--- a/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js
+++ b/browser/base/content/test/urlbar/browser_urlbarSearchSuggestions_opt-out.js
@@ -1,58 +1,63 @@
// 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";
+const ONEOFF_PREF = "browser.urlbar.oneOffSearches";
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);
+ let oneOffs = Services.prefs.getBoolPref(ONEOFF_PREF);
+ Services.prefs.setBoolPref(ONEOFF_PREF, true);
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);
-
+ Services.prefs.setBoolPref(ONEOFF_PREF, oneOffs);
// 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);
+ assertFooterVisible(false);
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);
+ assertFooterVisible(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");
});
@@ -60,35 +65,38 @@ add_task(async function focus() {
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);
+ assertFooterVisible(true, 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);
+ assertFooterVisible(true);
});
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);
+ assertFooterVisible(true);
});
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);
@@ -111,8 +119,12 @@ function suggestionsPresent() {
return false;
}
function assertVisible(visible, win = window) {
let style =
win.getComputedStyle(win.gURLBar.popup.searchSuggestionsNotification);
Assert.equal(style.visibility, visible ? "visible" : "collapse");
}
+function assertFooterVisible(visible, win = window) {
+ let style = win.getComputedStyle(win.gURLBar.popup.footer);
+ Assert.equal(style.visibility, visible ? "visible" : "collapse");
+}
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -1340,19 +1340,16 @@ file, You can obtain one at http://mozil
// If available, use the cached value, rather than running all of the
// checks again at every locationbar focus.
if (this._whichSearchSuggestionsNotification) {
return this._whichSearchSuggestionsNotification;
}
if (Services.prefs.getBoolPref("browser.search.suggest.enabled") &&
!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 &&
// In any case, if the user made a choice we should not nag him.
!this._userMadeSearchSuggestionsChoice) {
let enabledByDefault = this._defaultPrefs.getBoolPref("suggest.searches");
if (!enabledByDefault &&
this._prefs.getIntPref("daysBeforeHidingSuggestionsPrompt")) {
return "opt-in";
}
if (enabledByDefault &&
@@ -1418,44 +1415,41 @@ file, You can obtain one at http://mozil
<handler event="focus"><![CDATA[
if (event.originalTarget == this.inputField) {
this._hideURLTooltip();
this.formatValue();
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;
- }
+ // 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";
- }
+ // 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;
- }
+ if (whichNotification == "opt-out") {
+ try {
+ this.popup.openAutocompletePopup(this, this);
+ } finally {
+ if (mouseFocused) {
+ delete this._whichSearchSuggestionsNotification;
+ this._showSearchSuggestionNotificationOnMouseFocus = false;
}
}
}
}
]]></handler>
<handler event="blur"><![CDATA[
if (event.originalTarget == this.inputField) {
@@ -1866,24 +1860,16 @@ file, You can obtain one at http://mozil
// bottom of the navbar from the buttom of the input.
let yOffset =
this.DOMWindowUtils.getBoundsWithoutFlushing(document.getElementById("nav-bar")).bottom -
this.DOMWindowUtils.getBoundsWithoutFlushing(aInput).bottom;
this.openPopup(aElement, "after_start", 0, yOffset, false, false);
]]></body>
</method>
- <method name="_updateFooterVisibility">
- <body>
- <![CDATA[
- this.footer.collapsed = this._matchCount == 0;
- ]]>
- </body>
- </method>
-
<method name="_showSearchSuggestionsNotification">
<parameter name="whichNotification"/>
<parameter name="popupDirection"/>
<body>
<![CDATA[
let deckIndex = 0;
if (whichNotification == "opt-out") {
deckIndex = 1;
@@ -1918,17 +1904,19 @@ file, You can obtain one at http://mozil
//
// But without flexing the listbox, the listbox's height animation
// sometimes fails to complete, leaving the popup too tall. Work
// around that problem by disabling the listbox animation.
this.richlistbox.flex = 0;
this.setAttribute("dontanimate", "true");
this.classList.add("showSearchSuggestionsNotification");
- this._updateFooterVisibility();
+ // Don't show the one-off buttons if we are showing onboarding and
+ // there's no result, since it would be ugly and pointless.
+ this.footer.collapsed = this._matchCount == 0;
// This event allows accessibility APIs to see the notification.
if (!this.popupOpen) {
let event = document.createEvent("Events");
event.initEvent("AlertActive", true, true);
this.searchSuggestionsNotification.dispatchEvent(event);
}
]]>
@@ -2097,16 +2085,19 @@ file, You can obtain one at http://mozil
if (this.selectedIndex == -1 && this._isFirstResultHeuristic) {
// Don't fire DOMMenuItemActive so that screen readers still see
// the input as being focused.
this.richlistbox.suppressMenuItemEvent = true;
this.input.controller.setInitiallySelectedIndex(0);
this.richlistbox.suppressMenuItemEvent = false;
}
+ // When a result is present the footer should always be visible.
+ this.footer.collapsed = false;
+
this.input.gotResultForCurrentQuery = true;
this.input.maybeReplayDeferredKeyEvents();
]]>
</body>
</method>
<method name="_onSearchBegin">
<body><![CDATA[