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