browser_toolbox_hosts.js (7040B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { 7 gDevToolsBrowser, 8 } = require("resource://devtools/client/framework/devtools-browser.js"); 9 10 const { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 11 const { LEFT, RIGHT, BOTTOM, WINDOW } = Toolbox.HostType; 12 let toolbox; 13 14 // We are opening/close toolboxes many times, 15 // which introduces long GC pauses between each sub task 16 // and requires some more time to run in DEBUG builds. 17 requestLongerTimeout(2); 18 19 const URL = 20 "data:text/html;charset=utf8,test for opening toolbox in different hosts"; 21 22 add_task(async function () { 23 const win = await BrowserTestUtils.openNewBrowserWindow(); 24 win.gBrowser.selectedTab = BrowserTestUtils.addTab(win.gBrowser, URL); 25 26 const tab = win.gBrowser.selectedTab; 27 toolbox = await gDevTools.showToolboxForTab(tab, { 28 toolId: "webconsole", 29 hostType: Toolbox.HostType.WINDOW, 30 }); 31 const onToolboxClosed = toolbox.once("destroyed"); 32 ok( 33 gDevToolsBrowser.hasToolboxOpened(win), 34 "hasToolboxOpened is true before closing the toolbox" 35 ); 36 await BrowserTestUtils.closeWindow(win); 37 ok( 38 !gDevToolsBrowser.hasToolboxOpened(win), 39 "hasToolboxOpened is false after closing the window" 40 ); 41 42 info("Wait for toolbox to be destroyed after browser window is closed"); 43 await onToolboxClosed; 44 toolbox = null; 45 }); 46 47 add_task(async function runTest() { 48 info("Create a test tab and open the toolbox"); 49 const tab = await addTab(URL); 50 toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "webconsole" }); 51 52 await runHostTests(gBrowser); 53 await toolbox.destroy(); 54 55 toolbox = null; 56 gBrowser.removeCurrentTab(); 57 }); 58 59 // We run the same host switching tests in a private window. 60 // See Bug 1581093 for an example of issue specific to private windows. 61 add_task(async function runPrivateWindowTest() { 62 info("Create a private window + tab and open the toolbox"); 63 await runHostTestsFromSeparateWindow({ 64 private: true, 65 }); 66 }); 67 68 // We run the same host switching tests in a non-fission window. 69 // See Bug 1650963 for an example of issue specific to private windows. 70 add_task(async function runNonFissionWindowTest() { 71 info("Create a non-fission window + tab and open the toolbox"); 72 await runHostTestsFromSeparateWindow({ 73 fission: false, 74 }); 75 }); 76 77 async function runHostTestsFromSeparateWindow(options) { 78 const win = await BrowserTestUtils.openNewBrowserWindow(options); 79 const browser = win.gBrowser; 80 browser.selectedTab = BrowserTestUtils.addTab(browser, URL); 81 82 const tab = browser.selectedTab; 83 toolbox = await gDevTools.showToolboxForTab(tab, { toolId: "webconsole" }); 84 85 await runHostTests(browser); 86 await toolbox.destroy(); 87 88 toolbox = null; 89 await BrowserTestUtils.closeWindow(win); 90 } 91 92 async function runHostTests(browser) { 93 await testBottomHost(browser); 94 await testLeftHost(browser); 95 await testRightHost(browser); 96 await testWindowHost(browser); 97 await testToolSelect(); 98 await testDestroy(browser); 99 await testRememberHost(); 100 await testPreviousHost(); 101 } 102 103 function testBottomHost(browser) { 104 checkHostType(toolbox, BOTTOM); 105 106 // test UI presence 107 const panel = browser.getPanel(); 108 const iframe = panel.querySelector(".devtools-toolbox-bottom-iframe"); 109 ok(iframe, "toolbox bottom iframe exists"); 110 111 checkToolboxLoaded(iframe); 112 } 113 114 async function testLeftHost(browser) { 115 await toolbox.switchHost(LEFT); 116 checkHostType(toolbox, LEFT); 117 118 // test UI presence 119 const panel = browser.getPanel(); 120 const bottom = panel.querySelector(".devtools-toolbox-bottom-iframe"); 121 ok(!bottom, "toolbox bottom iframe doesn't exist"); 122 123 const iframe = panel.querySelector(".devtools-toolbox-side-iframe"); 124 ok(iframe, "toolbox side iframe exists"); 125 126 checkToolboxLoaded(iframe); 127 } 128 129 async function testRightHost(browser) { 130 await toolbox.switchHost(RIGHT); 131 checkHostType(toolbox, RIGHT); 132 133 // test UI presence 134 const panel = browser.getPanel(); 135 const bottom = panel.querySelector(".devtools-toolbox-bottom-iframe"); 136 ok(!bottom, "toolbox bottom iframe doesn't exist"); 137 138 const iframe = panel.querySelector(".devtools-toolbox-side-iframe"); 139 ok(iframe, "toolbox side iframe exists"); 140 141 checkToolboxLoaded(iframe); 142 } 143 144 async function testWindowHost(browser) { 145 await toolbox.switchHost(WINDOW); 146 checkHostType(toolbox, WINDOW); 147 148 const panel = browser.getPanel(); 149 const sidebar = panel.querySelector(".devtools-toolbox-side-iframe"); 150 ok(!sidebar, "toolbox sidebar iframe doesn't exist"); 151 152 const win = Services.wm.getMostRecentWindow("devtools:toolbox"); 153 ok(win, "toolbox separate window exists"); 154 155 const iframe = win.document.querySelector(".devtools-toolbox-window-iframe"); 156 checkToolboxLoaded(iframe); 157 } 158 159 async function testToolSelect() { 160 // make sure we can load a tool after switching hosts 161 await toolbox.selectTool("inspector"); 162 } 163 164 async function testDestroy(browser) { 165 await toolbox.destroy(); 166 toolbox = await gDevTools.showToolboxForTab(browser.selectedTab); 167 } 168 169 function testRememberHost() { 170 // last host was the window - make sure it's the same when re-opening 171 is(toolbox.hostType, WINDOW, "host remembered"); 172 173 const win = Services.wm.getMostRecentWindow("devtools:toolbox"); 174 ok(win, "toolbox separate window exists"); 175 } 176 177 async function testPreviousHost() { 178 // last host was the window - make sure it's the same when re-opening 179 is(toolbox.hostType, WINDOW, "host remembered"); 180 181 info("Switching to left"); 182 await toolbox.switchHost(LEFT); 183 checkHostType(toolbox, LEFT, WINDOW); 184 185 info("Switching to right"); 186 await toolbox.switchHost(RIGHT); 187 checkHostType(toolbox, RIGHT, LEFT); 188 189 info("Switching to bottom"); 190 await toolbox.switchHost(BOTTOM); 191 checkHostType(toolbox, BOTTOM, RIGHT); 192 193 info("Switching from bottom to right"); 194 await toolbox.switchToPreviousHost(); 195 checkHostType(toolbox, RIGHT, BOTTOM); 196 197 info("Switching from right to bottom"); 198 await toolbox.switchToPreviousHost(); 199 checkHostType(toolbox, BOTTOM, RIGHT); 200 201 info("Switching to window"); 202 await toolbox.switchHost(WINDOW); 203 checkHostType(toolbox, WINDOW, BOTTOM); 204 205 info("Switching from window to bottom"); 206 await toolbox.switchToPreviousHost(); 207 checkHostType(toolbox, BOTTOM, WINDOW); 208 209 info("Forcing the previous host to match the current (bottom)"); 210 Services.prefs.setCharPref("devtools.toolbox.previousHost", BOTTOM); 211 212 info("Switching from bottom to right (since previous=current=bottom"); 213 await toolbox.switchToPreviousHost(); 214 checkHostType(toolbox, RIGHT, BOTTOM); 215 216 info("Forcing the previous host to match the current (right)"); 217 Services.prefs.setCharPref("devtools.toolbox.previousHost", RIGHT); 218 info("Switching from right to bottom (since previous=current=side"); 219 await toolbox.switchToPreviousHost(); 220 checkHostType(toolbox, BOTTOM, RIGHT); 221 } 222 223 function checkToolboxLoaded(iframe) { 224 const tabs = iframe.contentDocument.querySelector(".toolbox-tabs"); 225 ok(tabs, "toolbox UI has been loaded into iframe"); 226 }