browser_toolbox_tabsswitch_shortcuts.js (2124B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 requestLongerTimeout(2); 7 8 var { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 9 10 const L10N = new LocalizationHelper( 11 "devtools/client/locales/toolbox.properties" 12 ); 13 14 add_task(async function () { 15 const tab = await addTab("about:blank"); 16 17 const toolIDs = (await getSupportedToolIds(tab)).filter( 18 id => id != "options" 19 ); 20 const toolbox = await gDevTools.showToolboxForTab(tab, { 21 hostType: Toolbox.HostType.BOTTOM, 22 toolId: toolIDs[0], 23 }); 24 const nextShortcut = L10N.getStr("toolbox.nextTool.key"); 25 const prevShortcut = L10N.getStr("toolbox.previousTool.key"); 26 27 // Iterate over all tools, starting from options to netmonitor, in normal 28 // order. 29 for (let i = 1; i < toolIDs.length; i++) { 30 await testShortcuts(toolbox, i, nextShortcut, toolIDs); 31 } 32 33 // Iterate again, in the same order, starting from netmonitor (so next one is 34 // 0: options). 35 for (let i = 0; i < toolIDs.length; i++) { 36 await testShortcuts(toolbox, i, nextShortcut, toolIDs); 37 } 38 39 // Iterate over all tools in reverse order, starting from netmonitor to 40 // options. 41 for (let i = toolIDs.length - 2; i >= 0; i--) { 42 await testShortcuts(toolbox, i, prevShortcut, toolIDs); 43 } 44 45 // Iterate again, in reverse order again, starting from options (so next one 46 // is length-1: netmonitor). 47 for (let i = toolIDs.length - 1; i >= 0; i--) { 48 await testShortcuts(toolbox, i, prevShortcut, toolIDs); 49 } 50 51 await toolbox.destroy(); 52 gBrowser.removeCurrentTab(); 53 }); 54 55 async function testShortcuts(toolbox, index, shortcut, toolIDs) { 56 info( 57 "Testing shortcut to switch to tool " + 58 index + 59 ":" + 60 toolIDs[index] + 61 " using shortcut " + 62 shortcut 63 ); 64 65 const onToolSelected = toolbox.once("select"); 66 synthesizeKeyShortcut(shortcut); 67 const id = await onToolSelected; 68 69 info("toolbox-select event from " + id); 70 71 is( 72 toolIDs.indexOf(id), 73 index, 74 "Correct tool is selected on pressing the shortcut for " + id 75 ); 76 }