browser_inspector_highlighter-keybinding_separate-window.js (3899B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 // Test the keybindings for element picker with separate window. 8 9 const { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 10 11 const IS_OSX = Services.appinfo.OS === "Darwin"; 12 const TEST_URL = "data:text/html;charset=utf8,<div></div>"; 13 14 const TEST_MODIFIERS = [ 15 { 16 isOSX: true, 17 description: "OSX and altKey+metaKey", 18 modifier: { altKey: true, metaKey: true }, 19 }, 20 { 21 isOSX: true, 22 description: "OSX and metaKey+shiftKey", 23 modifier: { metaKey: true, shiftKey: true }, 24 }, 25 { 26 description: "ctrlKey+shiftKey", 27 modifier: { ctrlKey: true, shiftKey: true }, 28 }, 29 ]; 30 31 add_task(async () => { 32 info("In order to open the inspector in separate window"); 33 await pushPref("devtools.toolbox.host", "window"); 34 35 info("Open an inspected tab"); 36 await addTab(TEST_URL); 37 38 for (const { description, modifier, isOSX } of TEST_MODIFIERS) { 39 if (!!isOSX !== IS_OSX) { 40 continue; 41 } 42 43 info(`Start the test for ${description}`); 44 45 info("Open the toolbox and the inspecor"); 46 const onToolboxReady = gDevTools.once("toolbox-ready"); 47 EventUtils.synthesizeKey("c", modifier, window); 48 49 info("Check the state of the inspector"); 50 const toolbox = await onToolboxReady; 51 is( 52 toolbox.hostType, 53 Toolbox.HostType.WINDOW, 54 "The toolbox opens in a separate window" 55 ); 56 is(toolbox.currentToolId, "inspector", "The inspector selects"); 57 await assertStatuses(toolbox, true, true); 58 59 info("Toggle the picker mode by the shortcut key on the toolbox"); 60 EventUtils.synthesizeKey("c", modifier, toolbox.win); 61 await assertStatuses(toolbox, false, true); 62 63 info("Focus on main window"); 64 window.focus(); 65 await waitForFocusChanged(document, true); 66 ok(true, "The main window has focus"); 67 68 info("Toggle the picker mode by the shortcut key on the main window"); 69 EventUtils.synthesizeKey("c", modifier, window); 70 await assertStatuses(toolbox, true, false); 71 72 info("Toggle again by the shortcut key on the main window"); 73 EventUtils.synthesizeKey("c", modifier, window); 74 await assertStatuses(toolbox, false, false); 75 76 info("Select a tool other than the inspector"); 77 const onConsoleLoaded = toolbox.once("webconsole-ready"); 78 await toolbox.selectTool("webconsole"); 79 await onConsoleLoaded; 80 await waitForFocusChanged(toolbox.doc, true); 81 82 info("Focus on main window"); 83 window.focus(); 84 await waitForFocusChanged(document, true); 85 86 info("Type the shortcut key again after selecting other tool"); 87 const onInspectorSelected = toolbox.once("inspector-selected"); 88 EventUtils.synthesizeKey("c", modifier, window); 89 await onInspectorSelected; 90 await assertStatuses(toolbox, true, false); 91 92 info("Cancel the picker mode"); 93 EventUtils.synthesizeKey("c", modifier, window); 94 await waitUntil(() => toolbox.pickerButton.isChecked === false); 95 96 info("Close the toolbox"); 97 await toolbox.closeToolbox(); 98 } 99 }); 100 101 async function assertStatuses(toolbox, isPickerMode, isToolboxHavingFocus) { 102 info("Check the state of the picker mode"); 103 await waitUntil(() => toolbox.pickerButton.isChecked === isPickerMode); 104 is( 105 toolbox.pickerButton.isChecked, 106 isPickerMode, 107 "The picker mode is correct" 108 ); 109 110 info("Check whether the toolbox has the focus"); 111 await waitForFocusChanged(toolbox.doc, isToolboxHavingFocus); 112 ok(true, "The focus state of the toolbox is correct"); 113 114 await waitForFocusChanged(document, !isToolboxHavingFocus); 115 ok(true, "The focus state of the main window is correct"); 116 } 117 118 async function waitForFocusChanged(doc, expected) { 119 return waitUntil(() => doc.hasFocus() === expected); 120 }