browser_aboutdebugging_devtoolstoolbox_shortcuts.js (3207B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from helper-collapsibilities.js */ 7 Services.scriptloader.loadSubScript( 8 CHROME_URL_ROOT + "helper-collapsibilities.js", 9 this 10 ); 11 12 /** 13 * Test shortcut keys on about:devtools-toolbox page. 14 */ 15 add_task(async function () { 16 info("Force all debug target panes to be expanded"); 17 prepareCollapsibilitiesTest(); 18 19 const { document, tab, window } = await openAboutDebugging(); 20 await selectThisFirefoxPage(document, window.AboutDebugging.store); 21 const { devtoolsBrowser, devtoolsTab, devtoolsWindow } = 22 await openAboutDevtoolsToolbox(document, tab, window); 23 24 info("Check whether the shortcut keys which opens devtools is disabled"); 25 await assertShortcutKeys(devtoolsBrowser, false); 26 27 info("Switch to the inspector programmatically"); 28 const toolbox = getToolbox(devtoolsWindow); 29 await toolbox.selectTool("inspector"); 30 31 info( 32 "Use the Webconsole keyboard shortcut and wait for the panel to be selected" 33 ); 34 const onToolReady = toolbox.once("webconsole-ready"); 35 EventUtils.synthesizeKey( 36 "K", 37 { 38 accelKey: true, 39 shiftKey: !navigator.userAgent.match(/Mac/), 40 altKey: navigator.userAgent.match(/Mac/), 41 }, 42 devtoolsWindow 43 ); 44 await onToolReady; 45 46 info("Force to select about:debugging page"); 47 await updateSelectedTab(gBrowser, tab, window.AboutDebugging.store); 48 49 info("Check whether the shortcut keys which opens devtools is enabled"); 50 await assertShortcutKeys(tab.linkedBrowser, true); 51 52 await closeAboutDevtoolsToolbox(document, devtoolsTab, window); 53 await removeTab(tab); 54 }); 55 56 async function assertShortcutKeys(browser, shouldBeEnabled) { 57 await assertShortcutKey(browser.contentWindow, "VK_F12", {}, shouldBeEnabled); 58 await assertShortcutKey( 59 browser.contentWindow, 60 "I", 61 { 62 accelKey: true, 63 shiftKey: !navigator.userAgent.match(/Mac/), 64 altKey: navigator.userAgent.match(/Mac/), 65 }, 66 shouldBeEnabled 67 ); 68 } 69 70 async function assertShortcutKey(win, key, modifiers, shouldBeEnabled) { 71 info(`Assert shortcut key [${key}]`); 72 73 if (shouldBeEnabled) { 74 await assertShortcutKeyEnabled(win, key, modifiers); 75 } else { 76 await assertShortcutKeyDisabled(win, key, modifiers); 77 } 78 } 79 80 async function assertShortcutKeyDisabled(win, key, modifiers) { 81 let isReadyCalled = false; 82 const toolboxListener = () => { 83 isReadyCalled = true; 84 }; 85 gDevTools.on("toolbox-ready", toolboxListener); 86 87 EventUtils.synthesizeKey(key, modifiers, win); 88 await wait(1000); 89 ok(!isReadyCalled, `Devtools should not be opened by ${key}`); 90 91 gDevTools.off("toolbox-ready", toolboxListener); 92 } 93 94 async function assertShortcutKeyEnabled(win, key, modifiers) { 95 // Open devtools 96 const onToolboxReady = gDevTools.once("toolbox-ready"); 97 EventUtils.synthesizeKey(key, modifiers, win); 98 await onToolboxReady; 99 ok(true, `Devtools should be opened by ${key}`); 100 101 // Close devtools 102 const onToolboxDestroyed = gDevTools.once("toolbox-destroyed"); 103 EventUtils.synthesizeKey(key, modifiers, win); 104 await onToolboxDestroyed; 105 ok(true, `Devtopls should be closed by ${key}`); 106 }