summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_options_panel_toggle.js
blob: d94f7c14fba8beabc22bc9888a273080da4aec21 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test whether options panel toggled by key event and "Settings" on the meatball menu.

const { Toolbox } = require("resource://devtools/client/framework/toolbox.js");

add_task(async function () {
  const tab = await addTab("about:blank");
  const toolbox = await openToolboxForTab(
    tab,
    "webconsole",
    Toolbox.HostType.BOTTOM
  );

  info("Check the option panel was selected after sending F1 key event");
  await sendOptionsKeyEvent(toolbox);
  is(toolbox.currentToolId, "options", "The options panel should be selected");

  info("Check the last selected panel was selected after sending F1 key event");
  await sendOptionsKeyEvent(toolbox);
  is(
    toolbox.currentToolId,
    "webconsole",
    "The webconsole panel should be selected"
  );

  info("Check the option panel was selected after clicking 'Settings' menu");
  await clickSettingsMenu(toolbox);
  is(toolbox.currentToolId, "options", "The options panel should be selected");

  info(
    "Check the last selected panel was selected after clicking 'Settings' menu"
  );
  await sendOptionsKeyEvent(toolbox);
  is(
    toolbox.currentToolId,
    "webconsole",
    "The webconsole panel should be selected"
  );

  info("Check the combination of key event and 'Settings' menu");
  await sendOptionsKeyEvent(toolbox);
  await clickSettingsMenu(toolbox);
  is(
    toolbox.currentToolId,
    "webconsole",
    "The webconsole panel should be selected"
  );
  await clickSettingsMenu(toolbox);
  await sendOptionsKeyEvent(toolbox);
  is(
    toolbox.currentToolId,
    "webconsole",
    "The webconsole panel should be selected"
  );
});

async function sendOptionsKeyEvent(toolbox) {
  const onReady = toolbox.once("select");
  EventUtils.synthesizeKey("VK_F1", {}, toolbox.win);
  await onReady;
}

async function clickSettingsMenu(toolbox) {
  const onPopupShown = () => {
    toolbox.doc.removeEventListener("popupshown", onPopupShown);
    const menuItem = toolbox.doc.getElementById(
      "toolbox-meatball-menu-settings"
    );
    EventUtils.synthesizeMouseAtCenter(menuItem, {}, menuItem.ownerGlobal);
  };
  toolbox.doc.addEventListener("popupshown", onPopupShown);

  const button = toolbox.doc.getElementById("toolbox-meatball-menu-button");
  await waitUntil(() => button.style.pointerEvents !== "none");
  EventUtils.synthesizeMouseAtCenter(button, {}, button.ownerGlobal);

  await toolbox.once("select");
}