Bug 1495944: Add a test for shortcut keys on about:devtools-toolbox page. r=jdescottes
☠☠ backed out by fd6b8be34aed ☠ ☠
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Fri, 18 Jan 2019 00:38:49 +0000
changeset 511477 f365b9fa9697d6700adf1ea5db66f541001a78f8
parent 511476 cd627a79a250c209f157d30d1a5a9ea6c4e978d0
child 511478 9aa3456410843b6ae80f75c6d668c96dfd31b5fd
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1495944
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1495944: Add a test for shortcut keys on about:devtools-toolbox page. r=jdescottes Depends on D16687 Differential Revision: https://phabricator.services.mozilla.com/D16788
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_devtoolstoolbox_shortcuts.js
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -33,16 +33,17 @@ skip-if = (os == 'linux' && bits == 32) 
 [browser_aboutdebugging_connection_prompt_setting.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
 [browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
 [browser_aboutdebugging_debug-target-pane_empty.js]
 [browser_aboutdebugging_debug-target-pane_usb_runtime.js]
 [browser_aboutdebugging_devtools.js]
 [browser_aboutdebugging_devtoolstoolbox_contextmenu.js]
 [browser_aboutdebugging_devtoolstoolbox_menubar.js]
+[browser_aboutdebugging_devtoolstoolbox_shortcuts.js]
 [browser_aboutdebugging_navigate.js]
 [browser_aboutdebugging_persist_connection.js]
 [browser_aboutdebugging_routes.js]
 [browser_aboutdebugging_runtime_connection-prompt.js]
 [browser_aboutdebugging_runtime_usbclient_closed.js]
 [browser_aboutdebugging_select_network_runtime.js]
 [browser_aboutdebugging_select_page_with_serviceworker.js]
 [browser_aboutdebugging_serviceworker_multie10s.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_devtoolstoolbox_shortcuts.js
@@ -0,0 +1,91 @@
+/* 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();
+
+  info("Show about:devtools-toolbox page");
+  const target = findDebugTargetByText("about:debugging", document);
+  ok(target, "about:debugging tab target appeared");
+  const inspectButton = target.querySelector(".js-debug-target-inspect-button");
+  ok(inspectButton, "Inspect button for about:debugging appeared");
+  inspectButton.click();
+  await Promise.all([
+    waitUntil(() => tab.nextElementSibling),
+    waitForRequestsToSettle(window.AboutDebugging.store),
+    gDevTools.once("toolbox-ready"),
+  ]);
+
+  info("Wait for about:devtools-toolbox tab will be selected");
+  const devtoolsTab = tab.nextElementSibling;
+  await waitUntil(() => gBrowser.selectedTab === devtoolsTab);
+  info("Check whether the shortcut keys which opens devtools is disabled");
+  await assertShortcutKeys(gBrowser.selectedBrowser, false);
+
+  info("Force to select about:debugging page");
+  gBrowser.selectedTab = tab;
+  info("Check whether the shortcut keys which opens devtools is enabled");
+  await assertShortcutKeys(gBrowser.selectedBrowser, true);
+
+  await removeTab(devtoolsTab);
+  await waitForRequestsToSettle(window.AboutDebugging.store);
+  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 }`);
+}