tor-browser

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

browser_sidebar_keys.js (4061B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 async function testSidebarKeyToggle(key, options, expectedSidebarId) {
      5  EventUtils.synthesizeMouseAtCenter(gURLBar, {});
      6  let promiseShown = BrowserTestUtils.waitForEvent(window, "SidebarShown");
      7  EventUtils.synthesizeKey(key, options);
      8  await promiseShown;
      9  Assert.equal(
     10    document.getElementById("sidebar-box").getAttribute("sidebarcommand"),
     11    expectedSidebarId
     12  );
     13  EventUtils.synthesizeKey(key, options);
     14  Assert.ok(!SidebarController.isOpen);
     15 }
     16 
     17 add_task(async function test_sidebar_keys() {
     18  registerCleanupFunction(() => SidebarController.hide());
     19 
     20  await testSidebarKeyToggle("b", { accelKey: true }, "viewBookmarksSidebar");
     21 
     22  let options = { accelKey: true, shiftKey: AppConstants.platform == "macosx" };
     23  await testSidebarKeyToggle("h", options, "viewHistorySidebar");
     24 });
     25 
     26 add_task(async function test_sidebar_in_customize_mode() {
     27  // Test bug 1756385 - widgets to appear unchecked in customize mode. Test that
     28  // the sidebar button widget doesn't appear checked, and that the sidebar
     29  // button toggle is inert while in customize mode.
     30  let { CustomizableUI } = ChromeUtils.importESModule(
     31    "moz-src:///browser/components/customizableui/CustomizableUI.sys.mjs"
     32  );
     33  registerCleanupFunction(() => SidebarController.hide());
     34 
     35  let placement = CustomizableUI.getPlacementOfWidget("sidebar-button");
     36  if (!(placement?.area == CustomizableUI.AREA_NAVBAR)) {
     37    CustomizableUI.addWidgetToArea(
     38      "sidebar-button",
     39      CustomizableUI.AREA_NAVBAR,
     40      0
     41    );
     42    CustomizableUI.ensureWidgetPlacedInWindow("sidebar-button", window);
     43    registerCleanupFunction(function () {
     44      CustomizableUI.removeWidgetFromArea("sidebar-button");
     45    });
     46  }
     47 
     48  if (Services.prefs.getBoolPref("sidebar.revamp", false)) {
     49    Services.prefs.setBoolPref("sidebar.verticalTabs", true);
     50  }
     51 
     52  let widgetIcon = CustomizableUI.getWidget("sidebar-button")
     53    .forWindow(window)
     54    .node?.querySelector(".toolbarbutton-icon");
     55  // Get the alpha value of the sidebar toggle widget's background
     56  let getBGAlpha = () =>
     57    InspectorUtils.colorToRGBA(
     58      getComputedStyle(widgetIcon).getPropertyValue("background-color")
     59    ).a;
     60 
     61  let promiseShown = BrowserTestUtils.waitForEvent(window, "SidebarShown");
     62  SidebarController.show("viewBookmarksSidebar");
     63  await promiseShown;
     64 
     65  if (!Services.prefs.getBoolPref("sidebar.revamp", false)) {
     66    Assert.greater(
     67      getBGAlpha(),
     68      0,
     69      "Sidebar widget background should appear checked"
     70    );
     71  }
     72 
     73  // Enter customize mode. This should disable the toggle and make the sidebar
     74  // toggle widget appear unchecked.
     75  let customizationReadyPromise = BrowserTestUtils.waitForEvent(
     76    gNavToolbox,
     77    "customizationready"
     78  );
     79  gCustomizeMode.enter();
     80  await customizationReadyPromise;
     81 
     82  Assert.equal(
     83    getBGAlpha(),
     84    0,
     85    "Sidebar widget background should appear unchecked"
     86  );
     87 
     88  // Attempt toggle - should fail in customize mode.
     89  await SidebarController.toggle();
     90  ok(SidebarController.isOpen, "Sidebar is still open");
     91 
     92  // Exit customize mode. This should re-enable the toggle and make the sidebar
     93  // toggle widget appear checked again, since toggle() didn't hide the sidebar.
     94  let afterCustomizationPromise = BrowserTestUtils.waitForEvent(
     95    gNavToolbox,
     96    "aftercustomization"
     97  );
     98  gCustomizeMode.exit();
     99  await afterCustomizationPromise;
    100 
    101  if (!Services.prefs.getBoolPref("sidebar.revamp", false)) {
    102    Assert.greater(
    103      getBGAlpha(),
    104      0,
    105      "Sidebar widget background should appear checked again"
    106    );
    107  }
    108 
    109  await SidebarController.toggle();
    110  ok(!SidebarController.isOpen, "Sidebar is closed");
    111  if (!Services.prefs.getBoolPref("sidebar.revamp", false)) {
    112    Assert.equal(
    113      getBGAlpha(),
    114      0,
    115      "Sidebar widget background should appear unchecked"
    116    );
    117  }
    118 
    119  if (Services.prefs.getBoolPref("sidebar.verticalTabs", false)) {
    120    Services.prefs.clearUserPref("sidebar.verticalTabs");
    121  }
    122 });