Bug 1789644 - Add a pref toggle for QuickActions, separate from the pref for suggestions. r=mak,daleharvey

Change the behavior of the QuickActions provider, so that setting the
pref `quickactions.enabled` to false will prevent showing quick action
results in all contexts, while setting `suggest.quickactions` to false
will only prevent showing quick action results in the default search
mode (i.e., quick action results will still appear in the Quick Actions
search mode enabled by typing `> ` in the urlbar).

Differential Revision: https://phabricator.services.mozilla.com/D157702
This commit is contained in:
Shane Hughes
2022-09-24 00:00:46 +00:00
parent 26f512bf05
commit 14ba76c156
4 changed files with 78 additions and 4 deletions

View File

@@ -397,6 +397,7 @@ pref("browser.urlbar.suggest.calculator", false);
#if defined(EARLY_BETA_OR_EARLIER)
// Enable QuickActions and its urlbar search mode button.
pref("browser.urlbar.quickactions.enabled", true);
pref("browser.urlbar.suggest.quickactions", true);
pref("browser.urlbar.shortcuts.quickactions", true);
pref("browser.urlbar.quickactions.showPrefs", true);

View File

@@ -229,9 +229,13 @@ const PREF_URLBAR_DEFAULTS = new Map([
// must also be enabled, from Sync preferences.
["suggest.remotetab", true],
// Whether results will include QuickActions.
// Whether results will include QuickActions in the default search mode.
["suggest.quickactions", false],
// If disabled, QuickActions will not be included in either the default search
// mode or the QuickActions search mode.
["quickactions.enabled", false],
// Whether we show the Actions section in about:preferences.
["quickactions.showPrefs", false],

View File

@@ -18,7 +18,8 @@ ChromeUtils.defineESModuleGetters(lazy, {
});
// These prefs are relative to the `browser.urlbar` branch.
const ENABLED_PREF = "suggest.quickactions";
const ENABLED_PREF = "quickactions.enabled";
const SUGGEST_PREF = "suggest.quickactions";
const MATCH_IN_PHRASE_PREF = "quickactions.matchInPhrase";
const SHOW_IN_ZERO_PREFIX_PREF = "quickactions.showInZeroPrefix";
const DYNAMIC_TYPE_NAME = "quickactions";
@@ -85,8 +86,8 @@ class ProviderQuickActions extends UrlbarProvider {
isActive(queryContext) {
return (
lazy.UrlbarPrefs.get(ENABLED_PREF) &&
(!queryContext.searchMode ||
queryContext.searchMode.source == UrlbarUtils.RESULT_SOURCE.ACTIONS)
((lazy.UrlbarPrefs.get(SUGGEST_PREF) && !queryContext.searchMode) ||
queryContext.searchMode?.source == UrlbarUtils.RESULT_SOURCE.ACTIONS)
);
}

View File

@@ -28,6 +28,7 @@ let testActionCalled = 0;
add_setup(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.quickactions.enabled", true],
["browser.urlbar.suggest.quickactions", true],
["browser.urlbar.shortcuts.quickactions", true],
["screenshots.browser.component.enabled", true],
@@ -307,6 +308,73 @@ add_task(async function test_other_search_mode() {
Services.search.setDefault(oldDefaultEngine);
});
add_task(async function test_no_quickactions_suggestions() {
await SpecialPowers.pushPrefEnv({
set: [["browser.urlbar.suggest.quickactions", false]],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "screenshot",
});
Assert.ok(
!window.document.querySelector(
".urlbarView-row[dynamicType=quickactions] .urlbarView-quickaction-row"
),
"Screenshot button is not suggested"
);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "> screenshot",
});
Assert.ok(
window.document.querySelector(
".urlbarView-row[dynamicType=quickactions] .urlbarView-quickaction-row"
),
"Screenshot button is suggested"
);
await UrlbarTestUtils.promisePopupClose(window);
EventUtils.synthesizeKey("KEY_Escape");
await SpecialPowers.popPrefEnv();
});
add_task(async function test_quickactions_disabled() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.urlbar.quickactions.enabled", false],
["browser.urlbar.suggest.quickactions", true],
],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "screenshot",
});
Assert.ok(
!window.document.querySelector(
".urlbarView-row[dynamicType=quickactions] .urlbarView-quickaction-row"
),
"Screenshot button is not suggested"
);
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "> screenshot",
});
Assert.ok(
!window.document.querySelector(
".urlbarView-row[dynamicType=quickactions] .urlbarView-quickaction-row"
),
"Screenshot button is not suggested"
);
await UrlbarTestUtils.promisePopupClose(window);
EventUtils.synthesizeKey("KEY_Escape");
await SpecialPowers.popPrefEnv();
});
let COMMANDS_TESTS = [
{
cmd: "add-ons",