Bug 1367427 - The one-offs bar is not displayed in the Awesome Bar while search suggestions hint is displayed. r=adw

MozReview-Commit-ID: KpVwQ3XzivB

--HG--
extra : rebase_source : 194f4cf265d543eeee99e844a15681479812c284
This commit is contained in:
Marco Bonardo 2017-05-24 17:14:33 +02:00
parent 70e0807e88
commit 8b3d4db681
2 changed files with 42 additions and 39 deletions

View File

@ -5,6 +5,7 @@ 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);
@ -16,13 +17,15 @@ add_task(async function prepare() {
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");
@ -39,6 +42,7 @@ add_task(async function 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.
@ -48,6 +52,7 @@ add_task(async function focus() {
await promiseSearchComplete();
Assert.ok(suggestionsPresent());
assertVisible(true);
assertFooterVisible(true);
// Check the Change Options link.
let changeOptionsLink = document.getElementById("search-suggestions-change-settings");
@ -65,6 +70,7 @@ add_task(async function privateWindow() {
let win = await BrowserTestUtils.openNewBrowserWindow({ private: true });
await promiseAutocompleteResultPopup("foo", win);
assertVisible(false, win);
assertFooterVisible(true, win);
win.gURLBar.blur();
await BrowserTestUtils.closeWindow(win);
});
@ -76,6 +82,7 @@ add_task(async function enableOutsideNotification() {
Services.prefs.setBoolPref(SUGGEST_URLBAR_PREF, false);
await promiseAutocompleteResultPopup("foo");
assertVisible(false);
assertFooterVisible(true);
});
add_task(async function userMadeChoice() {
@ -84,6 +91,7 @@ add_task(async function userMadeChoice() {
Services.prefs.setBoolPref(CHOICE_PREF, true);
await promiseAutocompleteResultPopup("foo");
assertVisible(false);
assertFooterVisible(true);
});
function setupVisibleHint() {
@ -116,3 +124,7 @@ function assertVisible(visible, win = window) {
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");
}

View File

@ -1345,9 +1345,6 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
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");
@ -1423,34 +1420,31 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
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;
}
}
}
@ -1871,14 +1865,6 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
]]></body>
</method>
<method name="_updateFooterVisibility">
<body>
<![CDATA[
this.footer.collapsed = this._matchCount == 0;
]]>
</body>
</method>
<method name="_showSearchSuggestionsNotification">
<parameter name="whichNotification"/>
<parameter name="popupDirection"/>
@ -1923,7 +1909,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.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) {
@ -2102,6 +2090,9 @@ file, You can obtain one at http://mozilla.org/MPL/2.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();
]]>