tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_search_quickactions.js (3674B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // This tests the Privacy pane's Firefox QuickActions UI.
      5 
      6 "use strict";
      7 
      8 ChromeUtils.defineESModuleGetters(this, {
      9  ActionsProviderQuickActions:
     10    "moz-src:///browser/components/urlbar/ActionsProviderQuickActions.sys.mjs",
     11  UrlbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs",
     12 });
     13 
     14 add_setup(async function setup() {
     15  await SpecialPowers.pushPrefEnv({
     16    set: [["browser.urlbar.secondaryActions.featureGate", true]],
     17  });
     18 
     19  ActionsProviderQuickActions.addAction("testaction", {
     20    commands: ["testaction"],
     21    label: "quickactions-downloads2",
     22  });
     23 
     24  registerCleanupFunction(() => {
     25    ActionsProviderQuickActions.removeAction("testaction");
     26  });
     27 });
     28 
     29 add_task(async function test_show_prefs() {
     30  Services.prefs.setBoolPref(
     31    "browser.urlbar.scotchBonnet.enableOverride",
     32    false
     33  );
     34  Services.prefs.setBoolPref("browser.urlbar.quickactions.showPrefs", false);
     35 
     36  await openPreferencesViaOpenPreferencesAPI("search", { leaveOpen: true });
     37  let doc = gBrowser.selectedBrowser.contentDocument;
     38  let quickActionsCheckbox = doc.getElementById("enableQuickActions");
     39  Assert.ok(
     40    !BrowserTestUtils.isVisible(quickActionsCheckbox),
     41    "Quick actions checkbox should be hidden when both prefs are false"
     42  );
     43 
     44  Services.prefs.setBoolPref("browser.urlbar.quickactions.showPrefs", true);
     45  await quickActionsCheckbox.parentElement.updateComplete;
     46  Assert.ok(
     47    BrowserTestUtils.isVisible(quickActionsCheckbox),
     48    "Quick actions checkbox should be shown again"
     49  );
     50 
     51  Services.prefs.setBoolPref("browser.urlbar.quickactions.showPrefs", false);
     52  Services.prefs.setBoolPref(
     53    "browser.urlbar.scotchBonnet.enableOverride",
     54    true
     55  );
     56  await quickActionsCheckbox.parentElement.updateComplete;
     57  Assert.ok(
     58    BrowserTestUtils.isVisible(quickActionsCheckbox),
     59    "Quick actions checkbox should still be shown"
     60  );
     61 
     62  Services.prefs.clearUserPref("browser.urlbar.scotchBonnet.enableOverride");
     63  Services.prefs.clearUserPref("browser.urlbar.quickactions.showPrefs");
     64  gBrowser.removeCurrentTab();
     65 });
     66 
     67 async function testActionIsShown(window, name) {
     68  await UrlbarTestUtils.promiseAutocompleteResultPopup({
     69    window,
     70    value: "testact",
     71    waitForFocus: SimpleTest.waitForFocus,
     72  });
     73  try {
     74    await BrowserTestUtils.waitForMutationCondition(
     75      window.document,
     76      {},
     77      () =>
     78        !!window.document.querySelector(
     79          `.urlbarView-action-btn[data-action=${name}]`
     80        )
     81    );
     82    Assert.ok(true, `We found action "${name}"`);
     83    return true;
     84  } catch (e) {
     85    return false;
     86  }
     87 }
     88 
     89 add_task(async function test_prefs() {
     90  Services.prefs.setBoolPref("browser.urlbar.quickactions.showPrefs", true);
     91  Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false);
     92 
     93  let tab = await BrowserTestUtils.openNewForegroundTab(
     94    gBrowser,
     95    "about:preferences#search"
     96  );
     97 
     98  Assert.ok(
     99    !(await testActionIsShown(window)),
    100    "Actions are not shown while pref disabled"
    101  );
    102 
    103  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
    104    let checkbox = content.document.getElementById("enableQuickActions");
    105    is(
    106      checkbox.checked,
    107      false,
    108      "Checkbox is not checked while feature is disabled"
    109    );
    110    checkbox.click();
    111  });
    112 
    113  Assert.ok(
    114    await testActionIsShown(window, "testaction"),
    115    "Actions are shown after user clicks checkbox"
    116  );
    117 
    118  Services.prefs.clearUserPref("browser.urlbar.quickactions.showPrefs");
    119  Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions");
    120  await BrowserTestUtils.removeTab(tab);
    121 });