browser_toolbox_toggle.js (3411B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test toggling the toolbox with ACCEL+SHIFT+I / ACCEL+ALT+I and F12 in docked 7 // and detached (window) modes. 8 9 const URL = "data:text/html;charset=utf-8,Toggling devtools using shortcuts"; 10 11 var { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 12 13 add_task(async function () { 14 // Test with ACCEL+SHIFT+I / ACCEL+ALT+I (MacOSX) ; modifiers should match : 15 // - toolbox-key-toggle in devtools/client/framework/toolbox-window.xhtml 16 // - key_devToolboxMenuItem in browser/base/content/browser.xhtml 17 info("Test toggle using CTRL+SHIFT+I/CMD+ALT+I"); 18 await testToggle("I", { 19 accelKey: true, 20 shiftKey: !navigator.userAgent.match(/Mac/), 21 altKey: navigator.userAgent.match(/Mac/), 22 }); 23 24 // Test with F12 ; no modifiers 25 info("Test toggle using F12"); 26 await testToggle("VK_F12", {}); 27 }); 28 29 async function testToggle(key, modifiers) { 30 const tab = await addTab(URL + " ; key : '" + key + "'"); 31 await gDevTools.showToolboxForTab(tab); 32 33 await testToggleDockedToolbox(tab, key, modifiers); 34 await testToggleDetachedToolbox(tab, key, modifiers); 35 36 await cleanup(); 37 } 38 39 async function testToggleDockedToolbox(tab, key, modifiers) { 40 const toolbox = gDevTools.getToolboxForTab(tab); 41 42 isnot( 43 toolbox.hostType, 44 Toolbox.HostType.WINDOW, 45 "Toolbox is docked in the main window" 46 ); 47 48 info("verify docked toolbox is destroyed when using toggle key"); 49 const onToolboxDestroyed = gDevTools.once("toolbox-destroyed"); 50 EventUtils.synthesizeKey(key, modifiers); 51 await onToolboxDestroyed; 52 ok(true, "Docked toolbox is destroyed when using a toggle key"); 53 54 info("verify new toolbox is created when using toggle key"); 55 const onToolboxReady = gDevTools.once("toolbox-ready"); 56 EventUtils.synthesizeKey(key, modifiers); 57 await onToolboxReady; 58 ok(true, "Toolbox is created by using when toggle key"); 59 } 60 61 async function testToggleDetachedToolbox(tab, key, modifiers) { 62 const toolbox = gDevTools.getToolboxForTab(tab); 63 64 info("change the toolbox hostType to WINDOW"); 65 66 await toolbox.switchHost(Toolbox.HostType.WINDOW); 67 is( 68 toolbox.hostType, 69 Toolbox.HostType.WINDOW, 70 "Toolbox opened on separate window" 71 ); 72 73 info("Wait for focus on the toolbox window"); 74 await new Promise(res => waitForFocus(res, toolbox.win)); 75 76 info("Focus main window to put the toolbox window in the background"); 77 78 const onMainWindowFocus = once(window, "focus"); 79 window.focus(); 80 await onMainWindowFocus; 81 ok(true, "Main window focused"); 82 83 info( 84 "Verify windowed toolbox is focused instead of closed when using " + 85 "toggle key from the main window" 86 ); 87 const toolboxWindow = toolbox.topWindow; 88 const onToolboxWindowFocus = once(toolboxWindow, "focus", true); 89 EventUtils.synthesizeKey(key, modifiers); 90 await onToolboxWindowFocus; 91 ok(true, "Toolbox focused and not destroyed"); 92 93 info( 94 "Verify windowed toolbox is destroyed when using toggle key from its " + 95 "own window" 96 ); 97 98 const onToolboxDestroyed = gDevTools.once("toolbox-destroyed"); 99 EventUtils.synthesizeKey(key, modifiers, toolboxWindow); 100 await onToolboxDestroyed; 101 ok(true, "Toolbox destroyed"); 102 } 103 104 function cleanup() { 105 Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM); 106 gBrowser.removeCurrentTab(); 107 }