summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_shortcuts.js
blob: b03a206350708efdf5aac3d492b0e7f828413656 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/* import-globals-from helper-collapsibilities.js */
Services.scriptloader.loadSubScript(
  CHROME_URL_ROOT + "helper-collapsibilities.js",
  this
);

/**
 * Test shortcut keys on about:devtools-toolbox page.
 */
add_task(async function () {
  info("Force all debug target panes to be expanded");
  prepareCollapsibilitiesTest();

  const { document, tab, window } = await openAboutDebugging();
  await selectThisFirefoxPage(document, window.AboutDebugging.store);
  const { devtoolsBrowser, devtoolsTab, devtoolsWindow } =
    await openAboutDevtoolsToolbox(document, tab, window);

  info("Check whether the shortcut keys which opens devtools is disabled");
  await assertShortcutKeys(devtoolsBrowser, false);

  info("Switch to the inspector programmatically");
  const toolbox = getToolbox(devtoolsWindow);
  await toolbox.selectTool("inspector");

  info(
    "Use the Webconsole keyboard shortcut and wait for the panel to be selected"
  );
  const onToolReady = toolbox.once("webconsole-ready");
  EventUtils.synthesizeKey(
    "K",
    {
      accelKey: true,
      shiftKey: !navigator.userAgent.match(/Mac/),
      altKey: navigator.userAgent.match(/Mac/),
    },
    devtoolsWindow
  );
  await onToolReady;

  info("Force to select about:debugging page");
  await updateSelectedTab(gBrowser, tab, window.AboutDebugging.store);

  info("Check whether the shortcut keys which opens devtools is enabled");
  await assertShortcutKeys(tab.linkedBrowser, true);

  await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
  await removeTab(tab);
});

async function assertShortcutKeys(browser, shouldBeEnabled) {
  await assertShortcutKey(browser.contentWindow, "VK_F12", {}, shouldBeEnabled);
  await assertShortcutKey(
    browser.contentWindow,
    "I",
    {
      accelKey: true,
      shiftKey: !navigator.userAgent.match(/Mac/),
      altKey: navigator.userAgent.match(/Mac/),
    },
    shouldBeEnabled
  );
}

async function assertShortcutKey(win, key, modifiers, shouldBeEnabled) {
  info(`Assert shortcut key [${key}]`);

  if (shouldBeEnabled) {
    await assertShortcutKeyEnabled(win, key, modifiers);
  } else {
    await assertShortcutKeyDisabled(win, key, modifiers);
  }
}

async function assertShortcutKeyDisabled(win, key, modifiers) {
  let isReadyCalled = false;
  const toolboxListener = () => {
    isReadyCalled = true;
  };
  gDevTools.on("toolbox-ready", toolboxListener);

  EventUtils.synthesizeKey(key, modifiers, win);
  await wait(1000);
  ok(!isReadyCalled, `Devtools should not be opened by ${key}`);

  gDevTools.off("toolbox-ready", toolboxListener);
}

async function assertShortcutKeyEnabled(win, key, modifiers) {
  // Open devtools
  const onToolboxReady = gDevTools.once("toolbox-ready");
  EventUtils.synthesizeKey(key, modifiers, win);
  await onToolboxReady;
  ok(true, `Devtools should be opened by ${key}`);

  // Close devtools
  const onToolboxDestroyed = gDevTools.once("toolbox-destroyed");
  EventUtils.synthesizeKey(key, modifiers, win);
  await onToolboxDestroyed;
  ok(true, `Devtopls should be closed by ${key}`);
}