browser_aboutdebugging_devtoolstoolbox_focus.js (4104B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from helper-collapsibilities.js */ 7 Services.scriptloader.loadSubScript( 8 CHROME_URL_ROOT + "helper-collapsibilities.js", 9 this 10 ); 11 12 /** 13 * Test whether the focus transfers to a tab which is already inspected . 14 */ 15 add_task(async function () { 16 info("Force all debug target panes to be expanded"); 17 prepareCollapsibilitiesTest(); 18 19 info( 20 "Select 'performance' panel as the initial tool since the tool does not listen " + 21 "any changes of the document without user action" 22 ); 23 await pushPref("devtools.toolbox.selectedTool", "performance"); 24 25 const { document, tab, window } = await openAboutDebugging(); 26 const { store } = window.AboutDebugging; 27 await selectThisFirefoxPage(document, store); 28 29 const inspectionTarget = "about:debugging"; 30 info(`Open ${inspectionTarget} as inspection target`); 31 await waitUntil(() => findDebugTargetByText(inspectionTarget, document)); 32 info(`Inspect ${inspectionTarget} page in about:devtools-toolbox`); 33 const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox( 34 document, 35 tab, 36 window, 37 inspectionTarget 38 ); 39 40 info( 41 "Check the tab state after clicking inspect button " + 42 "when another tab was selected" 43 ); 44 await updateSelectedTab(gBrowser, tab, store); 45 clickInspectButton(inspectionTarget, document); 46 const devtoolsURL = devtoolsWindow.location.href; 47 assertDevtoolsToolboxTabState(devtoolsURL); 48 49 info( 50 "Check the tab state after clicking inspect button " + 51 "when the toolbox tab is in another window" 52 ); 53 const newNavigator = gBrowser.replaceTabWithWindow(devtoolsTab); 54 await waitUntil( 55 () => 56 newNavigator.gBrowser && 57 newNavigator.gBrowser.selectedTab.linkedBrowser.contentWindow.location 58 .href === devtoolsURL 59 ); 60 61 info( 62 "Create a tab in the window and select the tab " + 63 "so that the about:devtools-toolbox tab loses focus" 64 ); 65 const newTestTab = newNavigator.gBrowser.addTab( 66 "data:text/html,<title>TEST_TAB</title>", 67 { 68 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), 69 } 70 ); 71 await waitUntil(() => findDebugTargetByText("TEST_TAB", document)); 72 73 await updateSelectedTab(newNavigator.gBrowser, newTestTab, store); 74 75 let onTabsSuccess = waitForDispatch(store, "REQUEST_TABS_SUCCESS"); 76 clickInspectButton(inspectionTarget, document); 77 assertDevtoolsToolboxTabState(devtoolsURL); 78 await onTabsSuccess; 79 80 info("Close new navigator and wait until the debug target disappears"); 81 onTabsSuccess = waitForDispatch(store, "REQUEST_TABS_SUCCESS"); 82 const onToolboxDestroyed = gDevTools.once("toolbox-destroyed"); 83 newNavigator.close(); 84 await onToolboxDestroyed; 85 await onTabsSuccess; 86 87 await waitUntil(() => !findDebugTargetByText("Toolbox - ", document)); 88 89 info("Remove test tab"); 90 await removeTab(tab); 91 }); 92 93 function clickInspectButton(inspectionTarget, doc) { 94 const target = findDebugTargetByText(inspectionTarget, doc); 95 const button = target.querySelector(".qa-debug-target-inspect-button"); 96 button.click(); 97 } 98 99 // Check that only one tab is currently opened for the provided URL. 100 // Also check that this tab and the tab's window are focused. 101 function assertDevtoolsToolboxTabState(devtoolsURL) { 102 const existingTabs = []; 103 104 for (const navigator of Services.wm.getEnumerator("navigator:browser")) { 105 for (const browser of navigator.gBrowser.browsers) { 106 if ( 107 browser.contentWindow && 108 browser.contentWindow.location.href === devtoolsURL 109 ) { 110 const tab = navigator.gBrowser.getTabForBrowser(browser); 111 existingTabs.push(tab); 112 } 113 } 114 } 115 116 is(existingTabs.length, 1, `Only one tab is opened for ${devtoolsURL}`); 117 const tab = existingTabs[0]; 118 const navigator = tab.ownerGlobal; 119 is(navigator.gBrowser.selectedTab, tab, "The tab is selected"); 120 const focusedNavigator = Services.wm.getMostRecentBrowserWindow(); 121 is(navigator, focusedNavigator, "The navigator is focused"); 122 }