Bug 1863530 - Remove browser.search.widget.inNavBar pref. r=dao,settings-reviewers,search-reviewers,omc-reviewers,urlbar-reviewers,Gijs,aminomancer

Differential Revision: https://phabricator.services.mozilla.com/D215607
This commit is contained in:
Moritz Beier 2024-07-23 17:29:00 +00:00
parent 8154dbd319
commit 3e5fce6039
28 changed files with 124 additions and 234 deletions

View File

@ -3,20 +3,14 @@
/* import-globals-from ../../mochitest/role.js */
loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
// eslint-disable-next-line camelcase
add_task(async function test_searchbar_a11y_tree() {
await SpecialPowers.pushPrefEnv({
set: [["browser.search.widget.inNavBar", true]],
});
// This used to rely on the implied 100ms initial timer of
// TestUtils.waitForCondition. See bug 1700735.
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
await new Promise(resolve => setTimeout(resolve, 100));
let searchbar = await TestUtils.waitForCondition(
() => document.getElementById("searchbar"),
"wait for search bar to appear"
);
let searchbar = await gCUITestUtils.addSearchBar();
// Make sure the popup has been rendered so it shows up in the a11y tree.
let popup = document.getElementById("PopupSearchAutoComplete");

View File

@ -739,9 +739,6 @@ pref("browser.search.openintab", false);
// context menu searches open in the foreground
pref("browser.search.context.loadInBackground", false);
// Mirrors whether the search-container widget is in the navigation toolbar.
pref("browser.search.widget.inNavBar", false);
// Enables display of the options for the user using a separate default search
// engine in private browsing mode.
pref("browser.search.separatePrivateDefault.ui.enabled", false);

View File

@ -9,6 +9,11 @@
* otherwise specified.
*/
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
const PERMISSIONS_PAGE =
"https://example.com/browser/browser/base/content/test/permissions/permissions.html";
const afterUrlBarButton = "save-to-pocket-button";
@ -619,9 +624,7 @@ add_task(async function testCharacterInPanelMultiView() {
// Test tab stops after the search bar is added.
add_task(async function testTabStopsAfterSearchBarAdded() {
AddOldMenuSideButtons();
await SpecialPowers.pushPrefEnv({
set: [["browser.search.widget.inNavBar", 1]],
});
await gCUITestUtils.addSearchBar();
await withNewBlankTab(async function () {
startFromUrlBar();
await expectFocusAfterKey("Tab", "searchbar", true);
@ -631,7 +634,7 @@ add_task(async function testTabStopsAfterSearchBarAdded() {
await expectFocusAfterKey("Shift+Tab", "searchbar", true);
await expectFocusAfterKey("Shift+Tab", gURLBar.inputField);
});
await SpecialPowers.popPrefEnv();
gCUITestUtils.removeSearchBar();
RemoveOldMenuSideButtons();
});

View File

@ -3,99 +3,31 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Keeps the "browser.search.widget.inNavBar" preference synchronized,
* and ensures persisted widths are updated if the search bar is removed.
* Updates persisted widths when the search bar is removed,
* and removes the search bar based on usage.
*/
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { CustomizableUI } from "resource:///modules/CustomizableUI.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
BrowserUsageTelemetry: "resource:///modules/BrowserUsageTelemetry.sys.mjs",
});
const WIDGET_ID = "search-container";
const PREF_NAME = "browser.search.widget.inNavBar";
export const SearchWidgetTracker = {
init() {
this.onWidgetReset = this.onWidgetUndoMove = node => {
if (node.id == WIDGET_ID) {
this.syncPreferenceWithWidget();
this.removePersistedWidths();
}
};
CustomizableUI.addListener(this);
Services.prefs.addObserver(PREF_NAME, () =>
this.syncWidgetWithPreference()
);
this._updateSearchBarVisibilityBasedOnUsage();
},
onWidgetAdded(widgetId, area) {
if (widgetId == WIDGET_ID && area == CustomizableUI.AREA_NAVBAR) {
this.syncPreferenceWithWidget();
}
},
onWidgetRemoved(aWidgetId, aArea) {
if (aWidgetId == WIDGET_ID && aArea == CustomizableUI.AREA_NAVBAR) {
this.syncPreferenceWithWidget();
onWidgetAfterDOMChange(node, _nextNode, _container, wasRemoval) {
if (wasRemoval && node.id == WIDGET_ID) {
this.removePersistedWidths();
}
},
onAreaNodeRegistered(aArea) {
// The placement of the widget always takes priority, and the preference
// should always match the actual placement when the browser starts up - i.e.
// once the navigation bar has been registered.
if (aArea == CustomizableUI.AREA_NAVBAR) {
this.syncPreferenceWithWidget();
}
},
onCustomizeEnd() {
// onWidgetUndoMove does not fire when the search container is moved back to
// the customization palette as a result of an undo, so we sync again here.
this.syncPreferenceWithWidget();
},
syncPreferenceWithWidget() {
Services.prefs.setBoolPref(PREF_NAME, this.widgetIsInNavBar);
},
syncWidgetWithPreference() {
let newValue = Services.prefs.getBoolPref(PREF_NAME);
if (newValue == this.widgetIsInNavBar) {
_updateSearchBarVisibilityBasedOnUsage() {
if (!this._widgetIsInNavBar) {
return;
}
if (newValue) {
// The URL bar widget is always present in the navigation toolbar, so we
// can simply read its position to place the search bar right after it.
CustomizableUI.addWidgetToArea(
WIDGET_ID,
CustomizableUI.AREA_NAVBAR,
CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1
);
lazy.BrowserUsageTelemetry.recordWidgetChange(
WIDGET_ID,
CustomizableUI.AREA_NAVBAR,
"searchpref"
);
} else {
CustomizableUI.removeWidgetFromArea(WIDGET_ID);
lazy.BrowserUsageTelemetry.recordWidgetChange(
WIDGET_ID,
null,
"searchpref"
);
}
},
_updateSearchBarVisibilityBasedOnUsage() {
let searchBarLastUsed = Services.prefs.getStringPref(
"browser.search.widget.lastUsed",
""
@ -107,7 +39,7 @@ export const SearchWidgetTracker = {
let saerchBarUnusedThreshold =
removeAfterDaysUnused * 24 * 60 * 60 * 1000;
if (new Date() - new Date(searchBarLastUsed) > saerchBarUnusedThreshold) {
Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
CustomizableUI.removeWidgetFromArea(WIDGET_ID);
}
}
},
@ -127,7 +59,7 @@ export const SearchWidgetTracker = {
}
},
get widgetIsInNavBar() {
get _widgetIsInNavBar() {
let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
return placement?.area == CustomizableUI.AREA_NAVBAR;
},

View File

@ -46,8 +46,6 @@ skip-if = ["os == 'mac' && debug"]
["browser_1880230_hideInNonPrivateBrowsing.js"]
["browser_694291_searchbar_preference.js"]
["browser_873501_handle_specials.js"]
["browser_876926_customize_mode_wrapping.js"]

View File

@ -7,7 +7,6 @@ const WIDGET_ID = "search-container";
registerCleanupFunction(() => {
CustomizableUI.reset();
Services.prefs.clearUserPref("browser.search.widget.inNavBar");
});
add_task(async function test_syncPreferenceWithWidget() {

View File

@ -1,48 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const WIDGET_ID = "search-container";
const PREF_NAME = "browser.search.widget.inNavBar";
function checkDefaults() {
ok(!Services.prefs.getBoolPref(PREF_NAME));
is(CustomizableUI.getPlacementOfWidget(WIDGET_ID), null);
}
add_task(async function test_defaults() {
// Verify the default state before the first test.
checkDefaults();
});
add_task(async function test_syncPreferenceWithWidget() {
// Moving the widget to any position in the navigation toolbar should turn the
// preference to true.
CustomizableUI.addWidgetToArea(WIDGET_ID, CustomizableUI.AREA_NAVBAR);
ok(Services.prefs.getBoolPref(PREF_NAME));
// Moving the widget to any position outside of the navigation toolbar should
// turn the preference back to false.
CustomizableUI.addWidgetToArea(
WIDGET_ID,
CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
);
ok(!Services.prefs.getBoolPref(PREF_NAME));
});
add_task(async function test_syncWidgetWithPreference() {
// setting the preference should move the widget to the navigation toolbar and
// place it right after the location bar.
Services.prefs.setBoolPref(PREF_NAME, true);
let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
is(placement.area, CustomizableUI.AREA_NAVBAR);
is(
placement.position,
CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1
);
// This should move the widget back to the customization palette.
Services.prefs.setBoolPref(PREF_NAME, false);
checkDefaults();
});

View File

@ -62,7 +62,7 @@ add_task(async function check_shortcut_when_in_overflow() {
);
ok(CustomizableUI.inDefaultState, "Should start in default state.");
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
await gCUITestUtils.addSearchBar();
window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
await TestUtils.waitForCondition(() => {
@ -89,7 +89,7 @@ add_task(async function check_shortcut_when_in_overflow() {
EventUtils.synthesizeKey("KEY_Escape");
await hiddenPanelPromise;
Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
gCUITestUtils.removeSearchBar();
navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
window.resizeTo(this.originalWindowWidth, window.outerHeight);
@ -102,7 +102,7 @@ add_task(async function check_shortcut_when_in_overflow() {
// Ctrl+K should focus the search bar if it is in the navbar and not overflowing.
add_task(async function check_shortcut_when_not_in_overflow() {
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
await gCUITestUtils.addSearchBar();
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in nav-bar");
@ -112,7 +112,7 @@ add_task(async function check_shortcut_when_not_in_overflow() {
// from the nav bar even with the original window width.
await waitForSearchBarFocus();
Services.prefs.setBoolPref("browser.search.widget.inNavBar", false);
gCUITestUtils.removeSearchBar();
});
function sendWebSearchKeyCommand() {

View File

@ -204,9 +204,7 @@ add_task(async function searchbar_context_move_to_panel_and_back() {
// This is specifically testing the addToPanel function for the search bar, so
// we have to move it to its correct position in the navigation toolbar first.
// The preference will be restored when the customizations are reset later.
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
let searchbar = document.getElementById("searchbar");
let searchbar = await gCUITestUtils.addSearchBar();
// This fails if the screen resolution is small and the search bar overflows
// from the nav bar.
await gCustomizeMode.addToPanel(searchbar);

View File

@ -7,11 +7,10 @@ const { SearchWidgetTracker } = ChromeUtils.importESModule(
"resource:///modules/SearchWidgetTracker.sys.mjs"
);
const SEARCH_BAR_PREF_NAME = "browser.search.widget.inNavBar";
const SEARCH_BAR_LAST_USED_PREF_NAME = "browser.search.widget.lastUsed";
add_task(async function checkSearchBarPresent() {
Services.prefs.setBoolPref(SEARCH_BAR_PREF_NAME, true);
await gCUITestUtils.addSearchBar();
Services.prefs.setStringPref(
SEARCH_BAR_LAST_USED_PREF_NAME,
new Date("2022").toISOString()
@ -26,11 +25,10 @@ add_task(async function checkSearchBarPresent() {
!BrowserSearch.searchBar,
"Search bar should not be present in the Nav bar"
);
Assert.equal(
Services.prefs.getBoolPref(SEARCH_BAR_PREF_NAME),
false,
Assert.ok(
!CustomizableUI.getPlacementOfWidget("search-container"),
"Should remove the search bar"
);
Services.prefs.clearUserPref(SEARCH_BAR_LAST_USED_PREF_NAME);
Services.prefs.clearUserPref(SEARCH_BAR_PREF_NAME);
gCUITestUtils.removeSearchBar();
});

View File

@ -11,6 +11,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
SearchUIUtils: "resource:///modules/SearchUIUtils.sys.mjs",
SearchUtils: "resource://gre/modules/SearchUtils.sys.mjs",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
});
const PREF_URLBAR_QUICKSUGGEST_BLOCKLIST =
@ -21,7 +22,6 @@ Preferences.addAll([
{ id: "browser.search.suggest.enabled", type: "bool" },
{ id: "browser.urlbar.suggest.searches", type: "bool" },
{ id: "browser.search.suggest.enabled.private", type: "bool" },
{ id: "browser.search.widget.inNavBar", type: "bool" },
{ id: "browser.urlbar.showSearchSuggestionsFirst", type: "bool" },
{ id: "browser.urlbar.showSearchTerms.enabled", type: "bool" },
{ id: "browser.search.separatePrivateDefault", type: "bool" },
@ -79,7 +79,6 @@ var gSearchPane = {
let suggestsPref = Preferences.get("browser.search.suggest.enabled");
let urlbarSuggestsPref = Preferences.get("browser.urlbar.suggest.searches");
let searchBarPref = Preferences.get("browser.search.widget.inNavBar");
let privateSuggestsPref = Preferences.get(
"browser.search.suggest.enabled.private"
);
@ -88,7 +87,14 @@ var gSearchPane = {
this._updateSuggestionCheckboxes.bind(this);
suggestsPref.on("change", updateSuggestionCheckboxes);
urlbarSuggestsPref.on("change", updateSuggestionCheckboxes);
searchBarPref.on("change", updateSuggestionCheckboxes);
let customizableUIListener = {
onWidgetAfterDOMChange: updateSuggestionCheckboxes,
};
lazy.CustomizableUI.addListener(customizableUIListener);
window.addEventListener("unload", () => {
lazy.CustomizableUI.removeListener(customizableUIListener);
});
let urlbarSuggests = document.getElementById("urlBarSuggestion");
urlbarSuggests.addEventListener("command", () => {
urlbarSuggestsPref.value = urlbarSuggests.checked;
@ -100,7 +106,7 @@ var gSearchPane = {
// all prefs.
suggestionsInSearchFieldsCheckbox.addEventListener("command", () => {
this._skipUpdateSuggestionCheckboxesFromPrefChanges = true;
if (!searchBarPref.value) {
if (!lazy.CustomizableUI.getPlacementOfWidget("search-container")) {
urlbarSuggestsPref.value = suggestionsInSearchFieldsCheckbox.checked;
}
suggestsPref.value = suggestionsInSearchFieldsCheckbox.checked;
@ -163,14 +169,18 @@ var gSearchPane = {
};
NimbusFeatures.urlbar.onUpdate(onNimbus);
// Add observer of Search Bar preference as showSearchTerms
// can't be shown/hidden while Search Bar is enabled.
let searchBarPref = Preferences.get("browser.search.widget.inNavBar");
let updateCheckboxHidden = () => {
checkbox.hidden =
!UrlbarPrefs.get("showSearchTermsFeatureGate") || searchBarPref.value;
!UrlbarPrefs.get("showSearchTermsFeatureGate") ||
!!lazy.CustomizableUI.getPlacementOfWidget("search-container");
};
searchBarPref.on("change", updateCheckboxHidden);
// Add observer of CustomizableUI as showSearchTerms
// can't be shown/hidden while Search Bar is enabled.
let customizableUIListener = {
onWidgetAfterDOMChange: updateCheckboxHidden,
};
lazy.CustomizableUI.addListener(customizableUIListener);
// Fire once to initialize.
onNimbus();
@ -178,6 +188,7 @@ var gSearchPane = {
window.addEventListener("unload", () => {
NimbusFeatures.urlbar.offUpdate(onNimbus);
lazy.CustomizableUI.removeListener(customizableUIListener);
});
},
@ -215,14 +226,14 @@ var gSearchPane = {
"showSearchSuggestionsPrivateWindows"
);
let urlbarSuggestsPref = Preferences.get("browser.urlbar.suggest.searches");
let searchBarPref = Preferences.get("browser.search.widget.inNavBar");
let searchBarVisible =
!!lazy.CustomizableUI.getPlacementOfWidget("search-container");
suggestionsInSearchFieldsCheckbox.checked =
suggestsPref.value &&
(searchBarPref.value ? true : urlbarSuggestsPref.value);
suggestsPref.value && (searchBarVisible || urlbarSuggestsPref.value);
urlbarSuggests.disabled = !suggestsPref.value || permanentPB;
urlbarSuggests.hidden = !searchBarPref.value;
urlbarSuggests.hidden = !searchBarVisible;
privateWindowCheckbox.disabled = !suggestsPref.value;
privateWindowCheckbox.checked = Preferences.get(
@ -249,7 +260,7 @@ var gSearchPane = {
}
if (
suggestionsInSearchFieldsCheckbox.checked &&
!searchBarPref.value &&
!searchBarVisible &&
!urlbarSuggests.checked
) {
urlbarSuggestsPref.value = true;

View File

@ -1,10 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
const MAIN_PREF = "browser.search.suggest.enabled";
const URLBAR_PREF = "browser.urlbar.suggest.searches";
const FIRST_PREF = "browser.urlbar.showSearchSuggestionsFirst";
const SEARCHBAR_PREF = "browser.search.widget.inNavBar";
const FIRST_CHECKBOX_ID = "showSearchSuggestionsFirstCheckbox";
add_setup(async function () {
@ -123,7 +127,7 @@ add_task(async function superprefInteraction() {
Assert.ok(checkbox.checked, "Checkbox should be checked");
Assert.ok(!checkbox.disabled, "Checkbox should be enabled");
Services.prefs.setBoolPref(SEARCHBAR_PREF, true);
await gCUITestUtils.addSearchBar();
// Two superior prefs control the show-suggestion-first pref: URLBAR_PREF and
// MAIN_PREF. Toggle each and make sure the show-suggestion-first checkbox
@ -240,5 +244,5 @@ add_task(async function superprefInteraction() {
Services.prefs.clearUserPref(FIRST_PREF);
Services.prefs.clearUserPref(URLBAR_PREF);
Services.prefs.clearUserPref(MAIN_PREF);
Services.prefs.clearUserPref(SEARCHBAR_PREF);
gCUITestUtils.removeSearchBar();
});

View File

@ -15,6 +15,11 @@ ChromeUtils.defineLazyGetter(this, "QuickSuggestTestUtils", () => {
return module;
});
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
const CHECKBOX_ID = "searchShowSearchTermCheckbox";
const PREF_SEARCHTERMS = "browser.urlbar.showSearchTerms.enabled";
const PREF_FEATUREGATE = "browser.urlbar.showSearchTerms.featureGate";
@ -145,11 +150,9 @@ add_task(async function showSearchTerms_checkbox() {
add_task(async function showSearchTerms_and_searchBar_preference_load() {
// Enable the feature.
await SpecialPowers.pushPrefEnv({
set: [
[PREF_FEATUREGATE, true],
["browser.search.widget.inNavBar", true],
],
set: [[PREF_FEATUREGATE, true]],
});
await gCUITestUtils.addSearchBar();
await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
let doc = gBrowser.selectedBrowser.contentDocument;
@ -163,6 +166,7 @@ add_task(async function showSearchTerms_and_searchBar_preference_load() {
// Clean-up.
gBrowser.removeCurrentTab();
await SpecialPowers.popPrefEnv();
gCUITestUtils.removeSearchBar();
});
/*
@ -182,9 +186,7 @@ add_task(async function showSearchTerms_and_searchBar_preference_change() {
let checkbox = doc.getElementById(CHECKBOX_ID);
Assert.ok(!checkbox.hidden, "showSearchTerms checkbox should be shown.");
await SpecialPowers.pushPrefEnv({
set: [["browser.search.widget.inNavBar", true]],
});
await gCUITestUtils.addSearchBar();
Assert.ok(
checkbox.hidden,
"showSearchTerms checkbox should be hidden when search bar is enabled."
@ -192,6 +194,7 @@ add_task(async function showSearchTerms_and_searchBar_preference_change() {
// Clean-up.
await SpecialPowers.popPrefEnv();
gCUITestUtils.removeSearchBar();
Assert.ok(!checkbox.hidden, "showSearchTerms checkbox should be shown.");
gBrowser.removeCurrentTab();

View File

@ -1,7 +1,11 @@
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
const SUGGEST_PREF_NAME = "browser.search.suggest.enabled";
const URLBAR_SUGGEST_PREF_NAME = "browser.urlbar.suggest.searches";
const PRIVATE_PREF_NAME = "browser.search.suggest.enabled.private";
const SEARCHBAR_PREF_NAME = "browser.search.widget.inNavBar";
let initialUrlbarSuggestValue;
let initialSuggestionsInPrivateValue;
@ -80,7 +84,7 @@ async function toggleElement(
// Open with suggestions enabled
add_task(async function test_suggestions_start_enabled() {
Services.prefs.setBoolPref(SUGGEST_PREF_NAME, true);
Services.prefs.setBoolPref(SEARCHBAR_PREF_NAME, true);
await gCUITestUtils.addSearchBar();
await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
@ -128,7 +132,7 @@ add_task(async function test_suggestions_start_enabled() {
Services.prefs.setBoolPref(SUGGEST_PREF_NAME, false);
ok(!urlbarBox.checked, "Should have unchecked the urlbar box");
ok(urlbarBox.disabled, "Should have disabled the urlbar box");
Services.prefs.setBoolPref(SEARCHBAR_PREF_NAME, false);
gCUITestUtils.removeSearchBar();
ok(urlbarBox.hidden, "Should have hidden the urlbar box");
ok(!privateBox.checked, "Should have unchecked the private suggestions box");
ok(privateBox.disabled, "Should have disabled the private suggestions box");
@ -158,7 +162,7 @@ add_task(async function test_suggestions_start_disabled() {
add_task(async function test_sync_search_suggestions_prefs() {
info("Adding the search bar to the toolbar");
Services.prefs.setBoolPref(SEARCHBAR_PREF_NAME, true);
await gCUITestUtils.addSearchBar();
Services.prefs.setBoolPref(SUGGEST_PREF_NAME, true);
Services.prefs.setBoolPref(URLBAR_SUGGEST_PREF_NAME, false);
await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
@ -196,7 +200,7 @@ add_task(async function test_sync_search_suggestions_prefs() {
);
info("Removing the search bar from the toolbar");
Services.prefs.setBoolPref(SEARCHBAR_PREF_NAME, false);
gCUITestUtils.removeSearchBar();
const suggestsPref = [true, false];
const urlbarSuggestsPref = [true, false];
@ -225,7 +229,6 @@ add_task(async function test_sync_search_suggestions_prefs() {
}
gBrowser.removeCurrentTab();
Services.prefs.clearUserPref(SEARCHBAR_PREF_NAME);
Services.prefs.clearUserPref(URLBAR_SUGGEST_PREF_NAME);
Services.prefs.clearUserPref(SUGGEST_PREF_NAME);
});

View File

@ -5,13 +5,6 @@ This document describes preferences affecting Firefox's Search UI code. For info
on the toolkit search service, see the :doc:`/toolkit/search/Preferences` document.
Preferences that are generated and updated by code won't be described here.
User Exposed
------------
These preferences are exposed through the Firefox UI
browser.search.widget.inNavBar (boolean, default: false)
Whether the search bar widget is displayed in the navigation bar.
Hidden
------
These preferences are normally hidden, and should not be used unless you really

View File

@ -24,11 +24,11 @@ SERP
A search engine results page.
Persisted Search
When a user has the following preference values:
When a user has the following preference values (only applies
when the search bar isn't present in any toolbar or overflow panel):
- ``browser.urlbar.showSearchTerms.enabled``: ``true``
- ``browser.urlbar.showSearchTerms.featureGate``: ``true``
- ``browser.search.widget.inNavBar``: ``false``
and does the following:

View File

@ -25,13 +25,14 @@ add_setup(async function () {
set: [
["browser.search.separatePrivateDefault.ui.enabled", true],
["browser.search.separatePrivateDefault", true],
["browser.search.widget.inNavBar", true],
],
});
await gCUITestUtils.addSearchBar();
originalEngine = await Services.search.getDefault();
originalPrivateEngine = await Services.search.getDefaultPrivate();
registerCleanupFunction(async () => {
await resetEngines();
gCUITestUtils.removeSearchBar();
});
await SearchTestUtils.installOpenSearchEngine({

View File

@ -82,4 +82,3 @@ tags = "os_integration"
["browser_openPreferences.js"]
["browser_openSearchPanel.js"]
skip-if = ["true"] # Bug 1113038 - Intermittent "Popup was opened"

View File

@ -12,8 +12,12 @@ ChromeUtils.defineESModuleGetters(this, {
"resource://testing-common/TelemetryArchiveTesting.sys.mjs",
TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.sys.mjs",
UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs",
CustomizableUITestUtils:
"resource://testing-common/CustomizableUITestUtils.sys.mjs",
});
let gCUITestUtils = new CustomizableUITestUtils(window);
function test() {
UITourTest();
}
@ -476,9 +480,7 @@ var tests = [
is(buttons.hasChildNodes(), false, "Popup should have no buttons");
// Place the search bar in the navigation toolbar temporarily.
await SpecialPowers.pushPrefEnv({
set: [["browser.search.widget.inNavBar", true]],
});
await gCUITestUtils.addSearchBar();
await showInfoPromise("search", "search title", "search text");
@ -494,7 +496,7 @@ var tests = [
"Popup should have correct description text"
);
await SpecialPowers.popPrefEnv();
gCUITestUtils.removeSearchBar();
}),
function test_getConfigurationVersion(done) {
function callback(result) {

View File

@ -279,14 +279,11 @@ add_UITour_task(async function test_getConfiguration_selectedSearchEngine() {
add_UITour_task(async function test_setSearchTerm() {
// Place the search bar in the navigation toolbar temporarily.
await SpecialPowers.pushPrefEnv({
set: [["browser.search.widget.inNavBar", true]],
});
let searchbar = await gCUITestUtils.addSearchBar();
const TERM = "UITour Search Term";
await gContentAPI.setSearchTerm(TERM);
let searchbar = document.getElementById("searchbar");
// The UITour gets to the searchbar element through a promise, so the value setting
// only happens after a tick.
await waitForConditionPromise(
@ -294,18 +291,15 @@ add_UITour_task(async function test_setSearchTerm() {
"Correct term set"
);
await SpecialPowers.popPrefEnv();
gCUITestUtils.removeSearchBar();
});
add_UITour_task(async function test_clearSearchTerm() {
// Place the search bar in the navigation toolbar temporarily.
await SpecialPowers.pushPrefEnv({
set: [["browser.search.widget.inNavBar", true]],
});
let searchbar = await gCUITestUtils.addSearchBar();
await gContentAPI.setSearchTerm("");
let searchbar = document.getElementById("searchbar");
// The UITour gets to the searchbar element through a promise, so the value setting
// only happens after a tick.
await waitForConditionPromise(
@ -313,5 +307,5 @@ add_UITour_task(async function test_clearSearchTerm() {
"Search term cleared"
);
await SpecialPowers.popPrefEnv();
gCUITestUtils.removeSearchBar();
});

View File

@ -1,5 +1,11 @@
"use strict";
ChromeUtils.defineESModuleGetters(this, {
CustomizableUITestUtils:
"resource://testing-common/CustomizableUITestUtils.sys.mjs",
});
let gCUITestUtils = new CustomizableUITestUtils(window);
var gTestTab;
var gContentAPI;
@ -61,14 +67,14 @@ add_UITour_task(async function test_availableTargets_changeWidgets() {
});
add_UITour_task(async function test_availableTargets_search() {
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
await gCUITestUtils.addSearchBar();
try {
let data = await getConfigurationPromise("availableTargets");
let expecteds = getExpectedTargets();
expecteds = ["search", "searchIcon", ...expecteds];
ok_targets(data, expecteds);
} finally {
Services.prefs.clearUserPref("browser.search.widget.inNavBar");
gCUITestUtils.removeSearchBar();
}
});

View File

@ -3,6 +3,11 @@
"use strict";
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
var gTestTab;
var gContentAPI;
@ -11,23 +16,22 @@ function test() {
}
var tests = [
function test_openSearchPanel(done) {
async function test_openSearchPanel(done) {
// If suggestions are enabled, the panel will attempt to use the network to
// connect to the suggestions provider, causing the test suite to fail. We
// also change the preference to display the search bar during the test.
Services.prefs.setBoolPref("browser.search.widget.inNavBar", true);
Services.prefs.setBoolPref("browser.search.suggest.enabled", false);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.search.widget.inNavBar");
gCUITestUtils.removeSearchBar();
Services.prefs.clearUserPref("browser.search.suggest.enabled");
});
let searchbar = document.getElementById("searchbar");
ok(!searchbar.textbox.open, "Popup starts as closed");
let searchbar = await gCUITestUtils.addSearchBar();
ok(!searchbar.textbox.popupOpen, "Popup starts as closed");
gContentAPI.openSearchPanel(() => {
ok(searchbar.textbox.open, "Popup was opened");
ok(searchbar.textbox.popupOpen, "Popup was opened");
searchbar.textbox.closePopup();
ok(!searchbar.textbox.open, "Popup was closed");
ok(!searchbar.textbox.popupOpen, "Popup was closed");
done();
});
},

View File

@ -15,6 +15,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
Region: "resource://gre/modules/Region.sys.mjs",
TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.sys.mjs",
UrlbarUtils: "resource:///modules/UrlbarUtils.sys.mjs",
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
});
const PREF_URLBAR_BRANCH = "browser.urlbar.";
@ -523,7 +524,6 @@ const PREF_OTHER_DEFAULTS = new Map([
["browser.fixup.dns_first_for_single_words", false],
["browser.search.suggest.enabled", true],
["browser.search.suggest.enabled.private", false],
["browser.search.widget.inNavBar", false],
["keyword.enabled", true],
["security.insecure_connection_text.enabled", false],
["ui.popup.disable_autohide", false],
@ -1689,7 +1689,7 @@ class Preferences {
return (
this.get("showSearchTermsFeatureGate") &&
this.get("showSearchTerms.enabled") &&
!this.get("browser.search.widget.inNavBar")
!lazy.CustomizableUI.getPlacementOfWidget("search-container")
);
}

View File

@ -14,11 +14,9 @@ const SEARCH_STRING = "example_string";
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
["browser.search.widget.inNavBar", true],
["browser.urlbar.showSearchTerms.featureGate", true],
],
set: [["browser.urlbar.showSearchTerms.featureGate", true]],
});
await gCUITestUtils.addSearchBar();
await SearchTestUtils.installSearchExtension(
{

View File

@ -17,7 +17,6 @@ add_setup(async function () {
set: [
["browser.urlbar.showSearchTerms.featureGate", true],
["browser.urlbar.showSearchTerms.enabled", true],
["browser.search.widget.inNavBar", false],
],
});
});

View File

@ -17,7 +17,6 @@ add_setup(async function () {
set: [
["browser.urlbar.showSearchTerms.featureGate", true],
["browser.urlbar.showSearchTerms.enabled", true],
["browser.search.widget.inNavBar", false],
],
});
});

View File

@ -1,3 +1,8 @@
const { CustomizableUITestUtils } = ChromeUtils.importESModule(
"resource://testing-common/CustomizableUITestUtils.sys.mjs"
);
let gCUITestUtils = new CustomizableUITestUtils(window);
add_task(async function () {
// Even if modifier of a shortcut key same as modifier of content access key,
// the shortcut key should be executed if (remote) content doesn't handle it.
@ -12,17 +17,16 @@ add_task(async function () {
["ui.key.generalAccessKey", -1],
["ui.key.chromeAccess", 0 /* disabled */],
["ui.key.contentAccess", 4 /* Alt */],
["browser.search.widget.inNavBar", true],
],
},
resolve
);
});
let searchBar = await gCUITestUtils.addSearchBar();
const kTestPage = "data:text/html,<body>simple web page</body>";
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kTestPage);
let searchBar = BrowserSearch.searchBar;
searchBar.focus();
function promiseURLBarHasFocus() {

View File

@ -241,7 +241,6 @@ const DEFAULT_ENVIRONMENT_PREFS = new Map([
["browser.shell.checkDefaultBrowser", { what: RECORD_PREF_VALUE }],
["browser.search.region", { what: RECORD_PREF_VALUE }],
["browser.search.suggest.enabled", { what: RECORD_PREF_VALUE }],
["browser.search.widget.inNavBar", { what: RECORD_DEFAULTPREF_VALUE }],
["browser.startup.homepage", { what: RECORD_PREF_STATE }],
["browser.startup.page", { what: RECORD_PREF_VALUE }],
["browser.urlbar.autoFill", { what: RECORD_DEFAULTPREF_VALUE }],