tor-browser

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

browser_884402_customize_from_overflow.js (3967B)


      1 "use strict";
      2 
      3 var overflowPanel, originalWindowWidth;
      4 
      5 add_setup(function () {
      6  overflowPanel = document.getElementById("widget-overflow");
      7  originalWindowWidth = ensureToolbarOverflow(window);
      8 });
      9 
     10 registerCleanupFunction(function () {
     11  overflowPanel.removeAttribute("animate");
     12  window.resizeTo(originalWindowWidth, window.outerHeight);
     13  let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
     14  return TestUtils.waitForCondition(() => !navbar.hasAttribute("overflowing"));
     15 });
     16 
     17 // Right-click on an item within the overflow panel should
     18 // show a context menu with options to move it.
     19 add_task(async function () {
     20  overflowPanel.setAttribute("animate", "false");
     21  let fxaButton = document.getElementById("fxa-toolbar-menu-button");
     22  if (BrowserTestUtils.isHidden(fxaButton)) {
     23    // FxA button is likely hidden since the user is logged out.
     24    let initialFxaStatus = document.documentElement.getAttribute("fxastatus");
     25    document.documentElement.setAttribute("fxastatus", "signed_in");
     26    registerCleanupFunction(() =>
     27      document.documentElement.setAttribute("fxastatus", initialFxaStatus)
     28    );
     29    ok(BrowserTestUtils.isVisible(fxaButton), "FxA button is now visible");
     30  }
     31 
     32  let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
     33  ok(
     34    !navbar.hasAttribute("overflowing"),
     35    "Should start with a non-overflowing toolbar."
     36  );
     37  window.resizeTo(kForceOverflowWidthPx, window.outerHeight);
     38 
     39  await TestUtils.waitForCondition(() => navbar.hasAttribute("overflowing"));
     40  ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
     41 
     42  let chevron = document.getElementById("nav-bar-overflow-button");
     43  let shownPanelPromise = promisePanelElementShown(window, overflowPanel);
     44  chevron.click();
     45  await shownPanelPromise;
     46 
     47  let contextMenu = document.getElementById(
     48    "customizationPanelItemContextMenu"
     49  );
     50  let shownContextPromise = popupShown(contextMenu);
     51  ok(fxaButton, "fxa-toolbar-menu-button was found");
     52  is(
     53    fxaButton.getAttribute("overflowedItem"),
     54    "true",
     55    "FxA button is overflowing"
     56  );
     57  EventUtils.synthesizeMouse(fxaButton, 2, 2, {
     58    type: "contextmenu",
     59    button: 2,
     60  });
     61  await shownContextPromise;
     62 
     63  is(
     64    overflowPanel.state,
     65    "open",
     66    "The widget overflow panel should still be open."
     67  );
     68 
     69  let expectedEntries = [
     70    [".customize-context-moveToPanel", true],
     71    [".customize-context-removeFromPanel", true],
     72    ["---"],
     73    [".viewCustomizeToolbar", true],
     74  ];
     75  checkContextMenu(contextMenu, expectedEntries);
     76 
     77  let hiddenContextPromise = popupHidden(contextMenu);
     78  let hiddenPromise = promisePanelElementHidden(window, overflowPanel);
     79  let moveToPanel = contextMenu.querySelector(".customize-context-moveToPanel");
     80  if (moveToPanel) {
     81    contextMenu.activateItem(moveToPanel);
     82  } else {
     83    contextMenu.hidePopup();
     84  }
     85  await hiddenContextPromise;
     86  await hiddenPromise;
     87 
     88  let fxaButtonPlacement = CustomizableUI.getPlacementOfWidget(
     89    "fxa-toolbar-menu-button"
     90  );
     91  ok(fxaButtonPlacement, "FxA button should still have a placement");
     92  is(
     93    fxaButtonPlacement && fxaButtonPlacement.area,
     94    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL,
     95    "FxA button should be pinned now"
     96  );
     97  CustomizableUI.reset();
     98  ensureToolbarOverflow(window, false);
     99 
    100  // In some cases, it can take a tick for the navbar to overflow again. Wait for it:
    101  await TestUtils.waitForCondition(() =>
    102    fxaButton.hasAttribute("overflowedItem")
    103  );
    104  ok(navbar.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
    105 
    106  fxaButtonPlacement = CustomizableUI.getPlacementOfWidget(
    107    "fxa-toolbar-menu-button"
    108  );
    109  ok(fxaButtonPlacement, "FxA button should still have a placement");
    110  is(
    111    fxaButtonPlacement && fxaButtonPlacement.area,
    112    "nav-bar",
    113    "FxA button should be back in the navbar now"
    114  );
    115 
    116  is(
    117    fxaButton.getAttribute("overflowedItem"),
    118    "true",
    119    "FxA button should still be overflowed"
    120  );
    121 });