Bug 1789644 - Add a pref toggle for QuickActions, separate from the pref for suggestions. r=mak,daleharvey
authorShane Hughes <shughes@mozilla.com>
Sat, 24 Sep 2022 00:00:46 +0000
changeset 636388 50f72898d7b8b88985dc5d7595007b426a46c93e
parent 636387 c0b9be18630c75c0ef618306e2ea2721efebe868
child 636389 bba85bc0b85e57a9275fb0027176b1b740d6c0df
push id40262
push usermlaza@mozilla.com
push dateSat, 24 Sep 2022 09:33:46 +0000
treeherdermozilla-central@50f72898d7b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, daleharvey
bugs1789644
milestone107.0a1
first release with
nightly linux32
50f72898d7b8 / 107.0a1 / 20220924093346 / files
nightly linux64
50f72898d7b8 / 107.0a1 / 20220924093346 / files
nightly mac
50f72898d7b8 / 107.0a1 / 20220924093346 / files
nightly win32
50f72898d7b8 / 107.0a1 / 20220924093346 / files
nightly win64
50f72898d7b8 / 107.0a1 / 20220924093346 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
browser/app/profile/firefox.js
browser/components/urlbar/UrlbarPrefs.sys.mjs
browser/components/urlbar/UrlbarProviderQuickActions.sys.mjs
browser/components/urlbar/tests/browser/browser_quickactions.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -392,16 +392,17 @@ pref("browser.urlbar.suggest.openpage", 
 pref("browser.urlbar.suggest.remotetab",            true);
 pref("browser.urlbar.suggest.searches",             true);
 pref("browser.urlbar.suggest.topsites",             true);
 pref("browser.urlbar.suggest.engines",              true);
 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);
   pref("browser.urlbar.quickactions.showInZeroPrefix", true);
 #endif
 
 // When `browser.urlbar.bestMatch.enabled` is true, this controls whether best
 // match results are shown in the urlbar. This pref is exposed to the user in
--- a/browser/components/urlbar/UrlbarPrefs.sys.mjs
+++ b/browser/components/urlbar/UrlbarPrefs.sys.mjs
@@ -224,19 +224,23 @@ const PREF_URLBAR_DEFAULTS = new Map([
 
   // Whether results will include switch-to-tab results.
   ["suggest.openpage", true],
 
   // Whether results will include synced tab results. The syncing of open tabs
   // 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],
 
   // Whether we will match QuickActions within a phrase and not only a prefix.
   ["quickactions.matchInPhrase", true],
 
   // Whether we show QuickActions when in zero-prefix.
   ["quickactions.showInZeroPrefix", false],
--- a/browser/components/urlbar/UrlbarProviderQuickActions.sys.mjs
+++ b/browser/components/urlbar/UrlbarProviderQuickActions.sys.mjs
@@ -13,17 +13,18 @@ const lazy = {};
 ChromeUtils.defineESModuleGetters(lazy, {
   QuickActionsLoaderDefault:
     "resource:///modules/QuickActionsLoaderDefault.sys.mjs",
   UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
   UrlbarResult: "resource:///modules/UrlbarResult.sys.mjs",
 });
 
 // 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";
 
 // When the urlbar is first focused and no search term has been
 // entered we show a limited number of results.
 const ACTIONS_SHOWN_FOCUS = 4;
 
@@ -80,18 +81,18 @@ class ProviderQuickActions extends Urlba
    * If this method returns false, the providers manager won't start a query
    * with this provider, to save on resources.
    * @param {UrlbarQueryContext} queryContext The query context object
    * @returns {boolean} Whether this provider should be invoked for the search.
    */
   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)
     );
   }
 
   /**
    * Starts querying.
    * @param {UrlbarQueryContext} queryContext The query context object
    * @param {function} addCallback Callback invoked by the provider to add a new
    *        result. A UrlbarResult should be passed to it.
--- a/browser/components/urlbar/tests/browser/browser_quickactions.js
+++ b/browser/components/urlbar/tests/browser/browser_quickactions.js
@@ -23,16 +23,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
 const DUMMY_PAGE =
   "http://example.com/browser/browser/base/content/test/general/dummy_page.html";
 
 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],
       ["extensions.screenshots.disabled", false],
       // about:addons page holds last visit, as then will open the page if visit
       // about:addons URL, clear it.
       ["extensions.ui.lastCategory", ""],
     ],
@@ -302,16 +303,83 @@ add_task(async function test_other_searc
     entry: "typed",
   });
   await UrlbarTestUtils.promisePopupClose(window, () => {
     EventUtils.synthesizeKey("KEY_Escape");
   });
   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",
     uri: "about:addons",
     testFun: async () => isSelected("button[name=discover]"),
   },
   {
     cmd: "plugins",