1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Test search match functionality.
8 * Search panel is visible and clicking matches shows them in the request details.
11 add_task(async
function () {
12 await
pushPref("devtools.netmonitor.features.search", true);
14 const { tab
, monitor
} = await
initNetMonitor(HTTPS_CUSTOM_GET_URL
, {
17 info("Starting test... ");
19 const { document
, store
, windowRequire
} = monitor
.panelWin
;
21 // Action should be processed synchronously in tests.
22 const Actions
= windowRequire("devtools/client/netmonitor/src/actions/index");
23 store
.dispatch(Actions
.batchEnable(false));
25 const SEARCH_STRING
= "test";
26 // Execute two XHRs and wait until they are finished.
28 HTTPS_SEARCH_SJS
+ "?value=test1",
29 HTTPS_SEARCH_SJS
+ "?value=test2",
32 const wait
= waitForNetworkEvents(monitor
, 2);
33 await SpecialPowers
.spawn(tab
.linkedBrowser
, [URLS
], makeRequests
);
36 // Open the Search panel
37 await store
.dispatch(Actions
.openSearch());
39 // Fill Filter input with text and check displayed messages.
40 // The filter should be focused automatically.
41 typeInNetmonitor(SEARCH_STRING
, monitor
);
42 EventUtils
.synthesizeKey("KEY_Enter");
44 // Wait until there are two resources rendered in the results
45 await
waitForDOMIfNeeded(
47 ".search-panel-content .treeRow.resourceRow",
51 const searchMatchContents
= document
.querySelectorAll(
52 ".search-panel-content .treeRow .treeIcon"
55 for (let i
= searchMatchContents
.length
- 1; i
>= 0; i
--) {
56 clickElement(searchMatchContents
[i
], monitor
);
59 // Wait until there are two resources rendered in the results
60 await
waitForDOMIfNeeded(
62 ".search-panel-content .treeRow.resultRow",
67 const matches
= document
.querySelectorAll(
68 ".search-panel-content .treeRow.resultRow"
71 await
checkSearchResult(
75 ".url-preview .properties-view",
79 await
checkSearchResult(
83 "#responseHeaders .properties-view",
87 await
checkSearchResult(
91 "#requestHeaders .properties-view",
95 await
checkSearchResult(
99 "#responseCookies .properties-view",
103 await
checkSearchResult(
108 ".CodeMirror-activeline",
111 await
checkSearchResult(
115 ".url-preview .properties-view",
119 await
checkSearchResult(
123 "#responseHeaders .properties-view",
127 await
checkSearchResult(
131 "#requestHeaders .properties-view",
135 await
checkSearchResult(
139 "#requestHeaders .properties-view",
143 await
checkSearchResult(
147 "#responseCookies .properties-view",
151 await
checkSearchResult(
155 "#requestCookies .properties-view",
159 await
checkSearchResult(
164 ".CodeMirror-activeline",
168 await
teardown(monitor
);
171 async
function makeRequests(urls
) {
172 await content
.wrappedJSObject
.get(urls
[0]);
173 await content
.wrappedJSObject
.get(urls
[1]);
174 info("XHR Requests executed");
178 * Check whether the search result is correctly linked with the related information
180 async
function checkSearchResult(
184 panelContentSelector
,
188 const { document
} = monitor
.panelWin
;
190 // Scroll the match into view so that it's clickable
191 match
.scrollIntoView();
193 // Click on the match to show it
194 clickElement(match
, monitor
);
196 console
.log(`${panelSelector} ${panelContentSelector}`);
198 document
.querySelector(`${panelSelector} ${panelContentSelector}`)
201 const tabpanel
= document
.querySelector(panelSelector
);
202 const content
= tabpanel
.querySelectorAll(
203 `${panelContentSelector} ${panelDetailSelector}`
209 `There should be ${expected.length} item${
210 expected.length === 1 ? "" : "s"
211 } displayed in this tabpanel`
214 // Make sure only 1 item is selected
215 if (panelDetailSelector
=== ".treeRow.selected") {
216 const selectedElements
= tabpanel
.querySelectorAll(panelDetailSelector
);
218 selectedElements
.length
,
220 `There should be only 1 item selected, found ${selectedElements.length} items selected`
224 if (content
.length
=== expected
.length
) {
225 for (let i
= 0; i
< expected
.length
; i
++) {
227 content
[i
].textContent
.includes(expected
[i
]),
229 `Content must include ${expected[i]}`