browser_toolbox_raise.js (1948B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const TEST_URL = "data:text/html,test for opening toolbox in different hosts"; 5 6 var { Toolbox } = require("resource://devtools/client/framework/toolbox.js"); 7 8 add_task(async function () { 9 const tab1 = await addTab(TEST_URL); 10 const tab2 = BrowserTestUtils.addTab(gBrowser); 11 12 const toolbox = await gDevTools.showToolboxForTab(tab1); 13 await testBottomHost(toolbox, tab1, tab2); 14 15 await testWindowHost(toolbox); 16 17 Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM); 18 19 await toolbox.destroy(); 20 gBrowser.removeCurrentTab(); 21 gBrowser.removeCurrentTab(); 22 }); 23 24 async function testBottomHost(toolbox, tab1, tab2) { 25 // switch to another tab and test toolbox.raise() 26 gBrowser.selectedTab = tab2; 27 await new Promise(executeSoon); 28 is( 29 gBrowser.selectedTab, 30 tab2, 31 "Correct tab is selected before calling raise" 32 ); 33 34 await toolbox.raise(); 35 is( 36 gBrowser.selectedTab, 37 tab1, 38 "Correct tab was selected after calling raise" 39 ); 40 } 41 42 async function testWindowHost(toolbox) { 43 await toolbox.switchHost(Toolbox.HostType.WINDOW); 44 45 info("Wait for the toolbox to be focused when switching to window host"); 46 // We can't wait for the "focus" event on toolbox.win.parent as this document is created while calling switchHost. 47 await waitFor(() => { 48 return Services.focus.activeWindow == toolbox.topWindow; 49 }); 50 51 const onBrowserWindowFocused = new Promise(resolve => 52 window.addEventListener("focus", resolve, { once: true, capture: true }) 53 ); 54 55 info("Focusing the browser window"); 56 window.focus(); 57 58 info("Wait for the browser window to be focused"); 59 await onBrowserWindowFocused; 60 61 // Now raise toolbox. 62 await toolbox.raise(); 63 is( 64 Services.focus.activeWindow, 65 toolbox.topWindow, 66 "the toolbox window is immediately focused after raise resolution" 67 ); 68 }