summaryrefslogtreecommitdiffstats
path: root/browser/components/customizableui/test/browser_ctrl_click_panel_opening.js
blob: 9377c289508126f287db7af2a56b6a0ccc34d8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_appMenu_mainView() {
  // On macOS, ctrl-click shouldn't open the panel because this normally opens
  // the context menu. This happens via the `contextmenu` event which is created
  // by widget code, so our simulated clicks do not do so, so we can't test
  // anything on macOS:
  if (AppConstants.platform == "macosx") {
    ok(true, "The test is ignored on Mac");
    return;
  }

  let mainViewID = "appMenu-protonMainView";
  const mainView = document.getElementById(mainViewID);

  let shownPromise = BrowserTestUtils.waitForEvent(mainView, "ViewShown");
  // Should still open the panel when Ctrl key is pressed.
  EventUtils.synthesizeMouseAtCenter(PanelUI.menuButton, { ctrlKey: true });
  await shownPromise;
  ok(true, "Main menu shown after button pressed");

  // Close the main panel.
  let hiddenPromise = BrowserTestUtils.waitForEvent(document, "popuphidden");
  mainView.closest("panel").hidePopup();
  await hiddenPromise;
});

add_task(async function test_appMenu_libraryView() {
  // On macOS, ctrl-click shouldn't open the panel because this normally opens
  // the context menu. This happens via the `contextmenu` event which is created
  // by widget code, so our simulated clicks do not do so, so we can't test
  // anything on macOS:
  if (AppConstants.platform == "macosx") {
    ok(true, "The test is ignored on Mac");
    return;
  }

  CustomizableUI.addWidgetToArea("library-button", "nav-bar");
  const button = document.getElementById("library-button");
  await waitForElementShown(button);

  // Should still open the panel when Ctrl key is pressed.
  EventUtils.synthesizeMouseAtCenter(button, { ctrlKey: true });
  const libraryView = document.getElementById("appMenu-libraryView");
  let shownPromise = BrowserTestUtils.waitForEvent(libraryView, "ViewShown");
  await shownPromise;
  ok(true, "Library menu shown after button pressed");

  // Close the Library panel.
  let hiddenPromise = BrowserTestUtils.waitForEvent(document, "popuphidden");
  libraryView.closest("panel").hidePopup();
  await hiddenPromise;
});