Bug 1899500 - Implement explicit resource management in Baseline compiler. r=arai
[gecko.git] / browser / components / preferences / tests / browser_search_quickactions.js
blob70799b5002f1711249915e0f8a54d37a25cfb557
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
4 // This tests the Privacy pane's Firefox QuickActions UI.
6 "use strict";
8 ChromeUtils.defineESModuleGetters(this, {
9   ActionsProviderQuickActions:
10     "resource:///modules/ActionsProviderQuickActions.sys.mjs",
11   UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs",
12 });
14 add_setup(async function setup() {
15   await SpecialPowers.pushPrefEnv({
16     set: [
17       ["browser.urlbar.secondaryActions.featureGate", true],
18       ["browser.urlbar.quickactions.enabled", true],
19     ],
20   });
22   ActionsProviderQuickActions.addAction("testaction", {
23     commands: ["testaction"],
24     label: "quickactions-downloads2",
25   });
27   registerCleanupFunction(() => {
28     ActionsProviderQuickActions.removeAction("testaction");
29   });
30 });
32 async function isGroupHidden(tab) {
33   return SpecialPowers.spawn(
34     tab.linkedBrowser,
35     [],
36     async () => content.document.getElementById("quickActionsBox").hidden
37   );
40 add_task(async function test_show_prefs() {
41   Services.prefs.setBoolPref("browser.urlbar.quickactions.showPrefs", false);
43   let tab = await BrowserTestUtils.openNewForegroundTab(
44     gBrowser,
45     "about:preferences#search"
46   );
48   Assert.ok(
49     await isGroupHidden(tab),
50     "The preferences are hidden when pref disabled"
51   );
53   Services.prefs.setBoolPref("browser.urlbar.quickactions.showPrefs", true);
55   Assert.ok(
56     !(await isGroupHidden(tab)),
57     "The preferences are shown when pref enabled"
58   );
60   Services.prefs.clearUserPref("browser.urlbar.quickactions.showPrefs");
61   await BrowserTestUtils.removeTab(tab);
62 });
64 async function testActionIsShown(window, name) {
65   await UrlbarTestUtils.promiseAutocompleteResultPopup({
66     window,
67     value: "testact",
68     waitForFocus: SimpleTest.waitForFocus,
69   });
70   try {
71     await BrowserTestUtils.waitForMutationCondition(
72       window.document,
73       {},
74       () =>
75         !!window.document.querySelector(
76           `.urlbarView-action-btn[data-action=${name}]`
77         )
78     );
79     Assert.ok(true, `We found action "${name}"`);
80     return true;
81   } catch (e) {
82     return false;
83   }
86 add_task(async function test_prefs() {
87   Services.prefs.setBoolPref("browser.urlbar.quickactions.showPrefs", true);
88   Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
90   let tab = await BrowserTestUtils.openNewForegroundTab(
91     gBrowser,
92     "about:preferences#search"
93   );
95   Assert.ok(
96     !(await testActionIsShown(window)),
97     "Actions are not shown while pref disabled"
98   );
100   await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
101     let checkbox = content.document.getElementById("enableQuickActions");
102     is(
103       checkbox.checked,
104       false,
105       "Checkbox is not checked while feature is disabled"
106     );
107     checkbox.click();
108   });
110   Assert.ok(
111     await testActionIsShown(window, "testaction"),
112     "Actions are shown after user clicks checkbox"
113   );
115   Services.prefs.clearUserPref("browser.urlbar.quickactions.showPrefs");
116   Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
117   await BrowserTestUtils.removeTab(tab);