1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Test if sorting columns in the network table works correctly.
10 add_task(async
function () {
13 } = require("resource://devtools/client/netmonitor/src/utils/l10n.js");
15 const { monitor
} = await
initNetMonitor(SORTING_URL
, { requestCount
: 1 });
16 info("Starting test... ");
18 // It seems that this test may be slow on debug builds. This could be because
19 // of the heavy dom manipulation associated with sorting.
20 requestLongerTimeout(2);
22 const { document
, store
, windowRequire
} = monitor
.panelWin
;
23 const Actions
= windowRequire("devtools/client/netmonitor/src/actions/index");
24 const { getDisplayedRequests
, getSelectedRequest
, getSortedRequests
} =
25 windowRequire("devtools/client/netmonitor/src/selectors/index");
27 store
.dispatch(Actions
.batchEnable(false));
29 // Loading the frame script and preparing the xhr request URLs so we can
30 // generate some requests later.
33 url
: "sjs_sorting-test-server.sjs?index=1&" + Math
.random(),
37 url
: "sjs_sorting-test-server.sjs?index=5&" + Math
.random(),
41 url
: "sjs_sorting-test-server.sjs?index=2&" + Math
.random(),
45 url
: "sjs_sorting-test-server.sjs?index=4&" + Math
.random(),
49 url
: "sjs_sorting-test-server.sjs?index=3&" + Math
.random(),
54 const wait
= waitForNetworkEvents(monitor
, 5);
55 await
performRequestsInContent(requests
);
58 store
.dispatch(Actions
.toggleNetworkDetails());
61 getSelectedRequest(store
.getState()),
63 "There should be a selected item in the requests menu."
66 getSelectedIndex(store
.getState()),
68 "The first item should be selected in the requests menu."
71 !!document
.querySelector(".network-details-bar"),
73 "The network details panel should be visible after toggle button was pressed."
77 await
testContents([0, 2, 4, 3, 1]);
79 info("Testing status sort, ascending.");
80 EventUtils
.sendMouseEvent(
82 document
.querySelector("#requests-list-status-button")
84 testHeaders("status", "ascending");
85 await
testContents([0, 1, 2, 3, 4]);
87 info("Testing status sort, descending.");
88 EventUtils
.sendMouseEvent(
90 document
.querySelector("#requests-list-status-button")
92 testHeaders("status", "descending");
93 await
testContents([4, 3, 2, 1, 0]);
95 info("Testing status sort, ascending. Checking sort loops correctly.");
96 EventUtils
.sendMouseEvent(
98 document
.querySelector("#requests-list-status-button")
100 testHeaders("status", "ascending");
101 await
testContents([0, 1, 2, 3, 4]);
103 info("Testing method sort, ascending.");
104 EventUtils
.sendMouseEvent(
106 document
.querySelector("#requests-list-method-button")
108 testHeaders("method", "ascending");
109 await
testContents([0, 1, 2, 3, 4]);
111 info("Testing method sort, descending.");
112 EventUtils
.sendMouseEvent(
114 document
.querySelector("#requests-list-method-button")
116 testHeaders("method", "descending");
117 await
testContents([4, 3, 2, 1, 0]);
119 info("Testing method sort, ascending. Checking sort loops correctly.");
120 EventUtils
.sendMouseEvent(
122 document
.querySelector("#requests-list-method-button")
124 testHeaders("method", "ascending");
125 await
testContents([0, 1, 2, 3, 4]);
127 info("Testing file sort, ascending.");
128 EventUtils
.sendMouseEvent(
130 document
.querySelector("#requests-list-file-button")
132 testHeaders("file", "ascending");
133 await
testContents([0, 1, 2, 3, 4]);
135 info("Testing file sort, descending.");
136 EventUtils
.sendMouseEvent(
138 document
.querySelector("#requests-list-file-button")
140 testHeaders("file", "descending");
141 await
testContents([4, 3, 2, 1, 0]);
143 info("Testing file sort, ascending. Checking sort loops correctly.");
144 EventUtils
.sendMouseEvent(
146 document
.querySelector("#requests-list-file-button")
148 testHeaders("file", "ascending");
149 await
testContents([0, 1, 2, 3, 4]);
151 info("Testing URL sort, ascending.");
152 EventUtils
.sendMouseEvent(
154 document
.querySelector("#requests-list-url-button")
156 testHeaders("url", "ascending");
157 await
testContents([0, 1, 2, 3, 4]);
159 info("Testing URL sort, descending.");
160 EventUtils
.sendMouseEvent(
162 document
.querySelector("#requests-list-url-button")
164 testHeaders("url", "descending");
165 await
testContents([4, 3, 2, 1, 0]);
167 info("Testing URL sort, ascending. Checking sort loops correctly.");
168 EventUtils
.sendMouseEvent(
170 document
.querySelector("#requests-list-url-button")
172 testHeaders("url", "ascending");
173 await
testContents([0, 1, 2, 3, 4]);
175 info("Testing type sort, ascending.");
176 EventUtils
.sendMouseEvent(
178 document
.querySelector("#requests-list-type-button")
180 testHeaders("type", "ascending");
181 await
testContents([0, 1, 2, 3, 4]);
183 info("Testing type sort, descending.");
184 EventUtils
.sendMouseEvent(
186 document
.querySelector("#requests-list-type-button")
188 testHeaders("type", "descending");
189 await
testContents([4, 3, 2, 1, 0]);
191 info("Testing type sort, ascending. Checking sort loops correctly.");
192 EventUtils
.sendMouseEvent(
194 document
.querySelector("#requests-list-type-button")
196 testHeaders("type", "ascending");
197 await
testContents([0, 1, 2, 3, 4]);
199 info("Testing transferred sort, ascending.");
200 EventUtils
.sendMouseEvent(
202 document
.querySelector("#requests-list-transferred-button")
204 testHeaders("transferred", "ascending");
205 await
testContents([0, 1, 2, 3, 4]);
207 info("Testing transferred sort, descending.");
208 EventUtils
.sendMouseEvent(
210 document
.querySelector("#requests-list-transferred-button")
212 testHeaders("transferred", "descending");
213 await
testContents([4, 3, 2, 1, 0]);
215 info("Testing transferred sort, ascending. Checking sort loops correctly.");
216 EventUtils
.sendMouseEvent(
218 document
.querySelector("#requests-list-transferred-button")
220 testHeaders("transferred", "ascending");
221 await
testContents([0, 1, 2, 3, 4]);
223 info("Testing size sort, ascending.");
224 EventUtils
.sendMouseEvent(
226 document
.querySelector("#requests-list-contentSize-button")
228 testHeaders("contentSize", "ascending");
229 await
testContents([0, 1, 2, 3, 4]);
231 info("Testing size sort, descending.");
232 EventUtils
.sendMouseEvent(
234 document
.querySelector("#requests-list-contentSize-button")
236 testHeaders("contentSize", "descending");
237 await
testContents([4, 3, 2, 1, 0]);
239 info("Testing size sort, ascending. Checking sort loops correctly.");
240 EventUtils
.sendMouseEvent(
242 document
.querySelector("#requests-list-contentSize-button")
244 testHeaders("contentSize", "ascending");
245 await
testContents([0, 1, 2, 3, 4]);
247 info("Testing waterfall sort, ascending.");
249 // Because the waterfall column is hidden when the network details panel is
250 // opened, the waterfall button is not visible. Therefore we hide the network
252 await store
.dispatch(Actions
.toggleNetworkDetails());
253 EventUtils
.sendMouseEvent(
255 document
.querySelector("#requests-list-waterfall-button")
257 await store
.dispatch(Actions
.toggleNetworkDetails());
258 testHeaders("waterfall", "ascending");
259 await
testContents([0, 2, 4, 3, 1]);
261 info("Testing waterfall sort, descending.");
262 await store
.dispatch(Actions
.toggleNetworkDetails());
263 EventUtils
.sendMouseEvent(
265 document
.querySelector("#requests-list-waterfall-button")
267 testHeaders("waterfall", "descending");
268 await store
.dispatch(Actions
.toggleNetworkDetails());
269 await
testContents([4, 2, 0, 1, 3], true);
271 info("Testing waterfall sort, ascending. Checking sort loops correctly.");
272 await store
.dispatch(Actions
.toggleNetworkDetails());
273 EventUtils
.sendMouseEvent(
275 document
.querySelector("#requests-list-waterfall-button")
277 testHeaders("waterfall", "ascending");
278 await store
.dispatch(Actions
.toggleNetworkDetails());
279 await
testContents([0, 2, 4, 3, 1]);
281 return teardown(monitor
);
283 function getSelectedIndex(state
) {
284 if (!state
.requests
.selectedId
) {
287 return getSortedRequests(state
).findIndex(
288 r
=> r
.id
=== state
.requests
.selectedId
292 function testHeaders(sortType
, direction
) {
293 const doc
= monitor
.panelWin
.document
;
294 const target
= doc
.querySelector("#requests-list-" + sortType
+ "-button");
295 const headers
= doc
.querySelectorAll(".requests-list-header-button");
297 for (const header
of headers
) {
298 if (header
!= target
) {
300 !header
.hasAttribute("data-sorted"),
303 " header does not have a 'data-sorted' attribute."
307 .getAttribute("title")
308 .includes(L10N
.getStr("networkMenu.sortedAsc")) &&
310 .getAttribute("title")
311 .includes(L10N
.getStr("networkMenu.sortedDesc")),
314 " header does not include any sorting in the 'title' attribute."
318 header
.getAttribute("data-sorted"),
320 "The " + header
.id
+ " header has a correct 'data-sorted' attribute."
323 direction
== "ascending"
324 ? L10N
.getStr("networkMenu.sortedAsc")
325 : L10N
.getStr("networkMenu.sortedDesc");
327 header
.getAttribute("title").includes(sorted
),
330 " header includes the used sorting in the 'title' attribute."
336 async
function testContents([a
, b
, c
, d
, e
], waterfall
= false) {
338 getSelectedRequest(store
.getState()),
340 "There should still be a selected item after sorting."
344 getSelectedIndex(store
.getState()),
346 "The first item should be still selected after sorting."
350 !!document
.querySelector(".network-details-bar"),
352 "The network details panel should still be visible after sorting."
356 getSortedRequests(store
.getState()).length
,
358 "There should be a total of 5 items in the requests menu."
361 getDisplayedRequests(store
.getState()).length
,
363 "There should be a total of 5 visible items in the requests menu."
366 document
.querySelectorAll(".request-list-item").length
,
368 "The visible items in the requests menu are, in fact, visible!"
371 const requestItems
= document
.querySelectorAll(".request-list-item");
372 for (const requestItem
of requestItems
) {
373 requestItem
.scrollIntoView();
374 const requestsListStatus
= requestItem
.querySelector(".status-code");
375 EventUtils
.sendMouseEvent({ type
: "mouseover" }, requestsListStatus
);
376 await
waitUntil(() => requestsListStatus
.title
);
379 verifyRequestItemTarget(
381 getDisplayedRequests(store
.getState()),
382 getSortedRequests(store
.getState())[a
],
384 SORTING_SJS
+ "?index=1",
390 fullMimeType
: "text/1",
391 transferred
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 198),
392 size
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 0),
395 verifyRequestItemTarget(
397 getDisplayedRequests(store
.getState()),
398 getSortedRequests(store
.getState())[b
],
400 SORTING_SJS
+ "?index=2",
406 fullMimeType
: "text/2",
407 transferred
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 217),
408 size
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 19),
411 verifyRequestItemTarget(
413 getDisplayedRequests(store
.getState()),
414 getSortedRequests(store
.getState())[c
],
416 SORTING_SJS
+ "?index=3",
422 fullMimeType
: "text/3",
423 transferred
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 227),
424 size
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 29),
427 verifyRequestItemTarget(
429 getDisplayedRequests(store
.getState()),
430 getSortedRequests(store
.getState())[d
],
432 SORTING_SJS
+ "?index=4",
438 fullMimeType
: "text/4",
439 transferred
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 237),
440 size
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 39),
443 verifyRequestItemTarget(
445 getDisplayedRequests(store
.getState()),
446 getSortedRequests(store
.getState())[e
],
448 SORTING_SJS
+ "?index=5",
454 fullMimeType
: "text/5",
455 transferred
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 247),
456 size
: L10N
.getFormatStrWithNumbers("networkMenu.sizeB", 49),