Bug 1924993 - [devtools] Debugger tests wait before typing in conditional panel r...
[gecko.git] / devtools / client / netmonitor / test / browser_net_search-results.js
blobb3fd21ec986ea81989af5ee140b661ee18e9922f
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 /**
7 * Test search match functionality.
8 * Search panel is visible and clicking matches shows them in the request details.
9 */
11 add_task(async function () {
12 await pushPref("devtools.netmonitor.features.search", true);
14 const { tab, monitor } = await initNetMonitor(HTTPS_CUSTOM_GET_URL, {
15 requestCount: 1,
16 });
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.
27 const URLS = [
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);
34 await wait;
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(
46 document,
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(
61 document,
62 ".search-panel-content .treeRow.resultRow",
66 // Check the matches
67 const matches = document.querySelectorAll(
68 ".search-panel-content .treeRow.resultRow"
71 await checkSearchResult(
72 monitor,
73 matches[0],
74 "#headers-panel",
75 ".url-preview .properties-view",
76 ".treeRow",
77 [SEARCH_STRING]
79 await checkSearchResult(
80 monitor,
81 matches[1],
82 "#headers-panel",
83 "#responseHeaders .properties-view",
84 ".treeRow.selected",
85 [SEARCH_STRING]
87 await checkSearchResult(
88 monitor,
89 matches[2],
90 "#headers-panel",
91 "#requestHeaders .properties-view",
92 ".treeRow.selected",
93 [SEARCH_STRING]
95 await checkSearchResult(
96 monitor,
97 matches[3],
98 "#cookies-panel",
99 "#responseCookies .properties-view",
100 ".treeRow.selected",
101 [SEARCH_STRING]
103 await checkSearchResult(
104 monitor,
105 matches[4],
106 "#response-panel",
107 ".CodeMirror-code",
108 ".CodeMirror-activeline",
109 [SEARCH_STRING]
111 await checkSearchResult(
112 monitor,
113 matches[5],
114 "#headers-panel",
115 ".url-preview .properties-view",
116 ".treeRow",
117 [SEARCH_STRING]
119 await checkSearchResult(
120 monitor,
121 matches[6],
122 "#headers-panel",
123 "#responseHeaders .properties-view",
124 ".treeRow.selected",
125 [SEARCH_STRING]
127 await checkSearchResult(
128 monitor,
129 matches[7],
130 "#headers-panel",
131 "#requestHeaders .properties-view",
132 ".treeRow.selected",
133 [SEARCH_STRING]
135 await checkSearchResult(
136 monitor,
137 matches[8],
138 "#headers-panel",
139 "#requestHeaders .properties-view",
140 ".treeRow.selected",
141 [SEARCH_STRING]
143 await checkSearchResult(
144 monitor,
145 matches[9],
146 "#cookies-panel",
147 "#responseCookies .properties-view",
148 ".treeRow.selected",
149 [SEARCH_STRING]
151 await checkSearchResult(
152 monitor,
153 matches[10],
154 "#cookies-panel",
155 "#requestCookies .properties-view",
156 ".treeRow.selected",
157 [SEARCH_STRING]
159 await checkSearchResult(
160 monitor,
161 matches[11],
162 "#response-panel",
163 ".CodeMirror-code",
164 ".CodeMirror-activeline",
165 [SEARCH_STRING]
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(
181 monitor,
182 match,
183 panelSelector,
184 panelContentSelector,
185 panelDetailSelector,
186 expected
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}`);
197 await waitFor(() =>
198 document.querySelector(`${panelSelector} ${panelContentSelector}`)
201 const tabpanel = document.querySelector(panelSelector);
202 const content = tabpanel.querySelectorAll(
203 `${panelContentSelector} ${panelDetailSelector}`
207 content.length,
208 expected.length,
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]),
228 true,
229 `Content must include ${expected[i]}`