commit 70126c608d61b9b40ba5d0cf34ac136b1f3e988f
parent 46633f5e2c5cf65cc610bd0c7b433adf0de8beb7
Author: Moritz Beier <mbeier@mozilla.com>
Date: Thu, 4 Dec 2025 09:25:46 +0000
Bug 2003804 - Make sure new searchbar treats suggestion prefs like the old searchbar. r=dao,urlbar-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D274930
Diffstat:
2 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/browser/components/urlbar/UrlbarController.sys.mjs b/browser/components/urlbar/UrlbarController.sys.mjs
@@ -566,7 +566,8 @@ export class UrlbarController {
if (result.type == lazy.UrlbarUtils.RESULT_TYPE.SEARCH) {
// Speculative connect only if search suggestions are enabled.
if (
- lazy.UrlbarPrefs.get("suggest.searches") &&
+ (lazy.UrlbarPrefs.get("suggest.searches") ||
+ context.sapName == "searchbar") &&
lazy.UrlbarPrefs.get("browser.search.suggest.enabled")
) {
let engine = Services.search.getEngineByName(
diff --git a/browser/components/urlbar/tests/unit/test_UrlbarProviderSearchSuggestions.js b/browser/components/urlbar/tests/unit/test_UrlbarProviderSearchSuggestions.js
@@ -8,6 +8,8 @@ const { UrlbarProviderSearchSuggestions } = ChromeUtils.importESModule(
);
const KEYWORD_ENABLED = "keyword.enabled";
+const SUGGEST_ENABLED = "browser.search.suggest.enabled";
+const URLBAR_SUGGEST = "browser.urlbar.suggest.searches";
add_setup(async function () {
await Services.search.init();
@@ -51,3 +53,76 @@ add_task(async function test_allowRemoteSuggestions() {
Services.prefs.clearUserPref(KEYWORD_ENABLED);
});
+
+add_task(async function test_allowSuggestions() {
+ let suggestionsProvider = new UrlbarProviderSearchSuggestions();
+
+ let context = createContext("bacon eggs", {
+ isPrivate: false,
+ sapName: "urlbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ suggestionsProvider._allowSuggestions(context),
+ "Suggestions in the urlbar should be enabled by default"
+ );
+
+ context = createContext("bacon eggs", {
+ isPrivate: false,
+ sapName: "searchbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ suggestionsProvider._allowSuggestions(context),
+ "Suggestions in the searchbar should be enabled by default"
+ );
+
+ info("Setting " + URLBAR_SUGGEST + "=false");
+ Services.prefs.setBoolPref(URLBAR_SUGGEST, false);
+
+ context = createContext("bacon eggs", {
+ isPrivate: false,
+ sapName: "urlbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ !suggestionsProvider._allowSuggestions(context),
+ "Suggestions in the urlbar should be disabled"
+ );
+
+ context = createContext("bacon eggs", {
+ isPrivate: false,
+ sapName: "searchbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ suggestionsProvider._allowSuggestions(context),
+ "Suggestions in the searchbar should still be enabled"
+ );
+
+ info("Setting " + SUGGEST_ENABLED + "=false");
+ Services.prefs.setBoolPref(SUGGEST_ENABLED, false);
+
+ context = createContext("bacon eggs", {
+ isPrivate: false,
+ sapName: "urlbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ !suggestionsProvider._allowSuggestions(context),
+ "Suggestions in the urlbar should be disabled"
+ );
+
+ context = createContext("bacon eggs", {
+ isPrivate: false,
+ sapName: "searchbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ !suggestionsProvider._allowSuggestions(context),
+ "Suggestions in the urlbar should be disabled"
+ );
+
+ Services.prefs.clearUserPref(SUGGEST_ENABLED);
+ Services.prefs.clearUserPref(URLBAR_SUGGEST);
+});