tor-browser

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

browser_menu_touch.js (5766B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /* This test checks that toolbar menus are in touchmode
      6 * when opened through a touch event. */
      7 
      8 async function openAndCheckMenu(menu, target) {
      9  is(menu.state, "closed", `Menu panel (${menu.id}) is initally closed.`);
     10 
     11  let popupshown = BrowserTestUtils.waitForEvent(menu, "popupshown");
     12  EventUtils.synthesizeNativeTapAtCenter(target);
     13  await popupshown;
     14 
     15  is(menu.state, "open", `Menu panel (${menu.id}) is open.`);
     16  ok(
     17    menu.hasAttribute("touchmode"),
     18    `Menu panel (${menu.id}) is in touchmode.`
     19  );
     20 
     21  menu.hidePopup();
     22 
     23  popupshown = BrowserTestUtils.waitForEvent(menu, "popupshown");
     24  EventUtils.synthesizeMouseAtCenter(target, {});
     25  await popupshown;
     26 
     27  is(menu.state, "open", `Menu panel (${menu.id}) is open.`);
     28  ok(
     29    !menu.hasAttribute("touchmode"),
     30    `Menu panel (${menu.id}) is not in touchmode.`
     31  );
     32 
     33  menu.hidePopup();
     34 }
     35 
     36 async function openAndCheckLazyMenu(id, target) {
     37  let menu = document.getElementById(id);
     38 
     39  EventUtils.synthesizeNativeTapAtCenter(target);
     40  let ev = await BrowserTestUtils.waitForEvent(
     41    window,
     42    "popupshown",
     43    true,
     44    e => e.target.id == id
     45  );
     46  menu = ev.target;
     47 
     48  is(menu.state, "open", `Menu panel (${menu.id}) is open.`);
     49  ok(
     50    menu.hasAttribute("touchmode"),
     51    `Menu panel (${menu.id}) is in touchmode.`
     52  );
     53 
     54  menu.hidePopup();
     55 
     56  let popupshown = BrowserTestUtils.waitForEvent(menu, "popupshown");
     57  EventUtils.synthesizeMouseAtCenter(target, {});
     58  await popupshown;
     59 
     60  is(menu.state, "open", `Menu panel (${menu.id}) is open.`);
     61  ok(
     62    !menu.hasAttribute("touchmode"),
     63    `Menu panel (${menu.id}) is not in touchmode.`
     64  );
     65 
     66  menu.hidePopup();
     67 }
     68 
     69 // The customization UI menu is not attached to the document when it is
     70 // closed and hence requires special attention.
     71 async function openAndCheckCustomizationUIMenu(target) {
     72  EventUtils.synthesizeNativeTapAtCenter(target);
     73 
     74  await BrowserTestUtils.waitForCondition(
     75    () => document.getElementById("customizationui-widget-panel") != null
     76  );
     77  let menu = document.getElementById("customizationui-widget-panel");
     78 
     79  if (menu.state != "open") {
     80    await BrowserTestUtils.waitForEvent(menu, "popupshown");
     81    is(menu.state, "open", `Menu for ${target.id} is open`);
     82  }
     83 
     84  ok(menu.hasAttribute("touchmode"), `Menu for ${target.id} is in touchmode.`);
     85 
     86  menu.hidePopup();
     87 
     88  EventUtils.synthesizeMouseAtCenter(target, {});
     89 
     90  await BrowserTestUtils.waitForCondition(
     91    () => document.getElementById("customizationui-widget-panel") != null
     92  );
     93  menu = document.getElementById("customizationui-widget-panel");
     94 
     95  if (menu.state != "open") {
     96    await BrowserTestUtils.waitForEvent(menu, "popupshown");
     97    is(menu.state, "open", `Menu for ${target.id} is open`);
     98  }
     99 
    100  ok(
    101    !menu.hasAttribute("touchmode"),
    102    `Menu for ${target.id} is not in touchmode.`
    103  );
    104 
    105  menu.hidePopup();
    106 }
    107 
    108 // Ensure that we can run touch events properly for windows
    109 add_setup(async function () {
    110  let isWindows = AppConstants.platform == "win";
    111  await SpecialPowers.pushPrefEnv({
    112    set: [["apz.test.fails_with_native_injection", isWindows]],
    113  });
    114 });
    115 
    116 // Test main ("hamburger") menu.
    117 add_task(async function test_main_menu_touch() {
    118  let mainMenu = document.getElementById("appMenu-popup");
    119  let target = document.getElementById("PanelUI-menu-button");
    120  await openAndCheckMenu(mainMenu, target);
    121 });
    122 
    123 // Test the page action menu.
    124 add_task(async function test_page_action_panel_touch() {
    125  // The page action menu only appears on a web page.
    126  await BrowserTestUtils.withNewTab("https://example.com", async function () {
    127    // The page actions button is not normally visible, so we must
    128    // unhide it.
    129    BrowserPageActions.mainButtonNode.style.display = "flex";
    130    registerCleanupFunction(() => {
    131      BrowserPageActions.mainButtonNode.style.removeProperty("display");
    132    });
    133    let target = document.getElementById("pageActionButton");
    134    await openAndCheckLazyMenu("pageActionPanel", target);
    135  });
    136 });
    137 
    138 // Test the customizationUI panel, which is used for various menus
    139 // such as library, history, sync, developer and encoding.
    140 add_task(async function test_customizationui_panel_touch() {
    141  CustomizableUI.addWidgetToArea("library-button", CustomizableUI.AREA_NAVBAR);
    142  CustomizableUI.addWidgetToArea(
    143    "history-panelmenu",
    144    CustomizableUI.AREA_NAVBAR
    145  );
    146 
    147  await BrowserTestUtils.waitForCondition(
    148    () =>
    149      CustomizableUI.getPlacementOfWidget("library-button").area == "nav-bar"
    150  );
    151 
    152  let target = document.getElementById("library-button");
    153  await openAndCheckCustomizationUIMenu(target);
    154 
    155  target = document.getElementById("history-panelmenu");
    156  await openAndCheckCustomizationUIMenu(target);
    157 
    158  CustomizableUI.reset();
    159 });
    160 
    161 // Test the overflow menu panel.
    162 add_task(async function test_overflow_panel_touch() {
    163  // Move something in the overflow menu to make the button appear.
    164  CustomizableUI.addWidgetToArea(
    165    "library-button",
    166    CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
    167  );
    168  await BrowserTestUtils.waitForCondition(
    169    () =>
    170      CustomizableUI.getPlacementOfWidget("library-button").area ==
    171      CustomizableUI.AREA_FIXED_OVERFLOW_PANEL
    172  );
    173 
    174  let overflowPanel = document.getElementById("widget-overflow");
    175  let target = document.getElementById("nav-bar-overflow-button");
    176  await openAndCheckMenu(overflowPanel, target);
    177 
    178  CustomizableUI.reset();
    179 });
    180 
    181 // Test the list all tabs menu.
    182 add_task(async function test_list_all_tabs_touch() {
    183  let target = document.getElementById("alltabs-button");
    184  await openAndCheckCustomizationUIMenu(target);
    185 });