1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Test columns' state for WS and SSE connection.
10 function shallowArrayEqual(arr1
, arr2
) {
11 if (arr1
.length
!== arr2
.length
) {
14 for (let i
= 0; i
< arr1
.length
; i
++) {
16 (arr2
[i
] instanceof RegExp
&& !arr2
[i
].test(arr1
[i
])) ||
17 (typeof arr2
[i
] === "string" && arr2
[i
] !== arr1
[i
])
25 function shallowObjectEqual(obj1
, obj2
) {
26 const k1
= Object
.keys(obj1
);
27 const k2
= Object
.keys(obj2
);
29 if (k1
.length
!== k2
.length
) {
33 for (const key
of k1
) {
34 if (obj1
[key
] !== obj2
[key
]) {
42 function shallowEqual(obj1
, obj2
) {
43 if (Array
.isArray(obj1
) && Array
.isArray(obj2
)) {
44 return shallowArrayEqual(obj1
, obj2
);
46 return shallowObjectEqual(obj1
, obj2
);
49 add_task(async
function () {
50 const { tab
, monitor
} = await
initNetMonitor(
51 "http://mochi.test:8888/browser/devtools/client/netmonitor/test/html_ws-sse-test-page.html",
56 info("Starting test... ");
58 const { document
, store
, windowRequire
} = monitor
.panelWin
;
59 const Actions
= windowRequire("devtools/client/netmonitor/src/actions/index");
61 store
.dispatch(Actions
.batchEnable(false));
63 const onNetworkEvents
= waitForNetworkEvents(monitor
, 2);
64 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async () => {
65 await content
.wrappedJSObject
.openWsConnection(1);
66 // Running openSseConnection() here causes intermittent behavior.
68 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async () => {
69 await content
.wrappedJSObject
.openSseConnection();
71 await onNetworkEvents
;
73 const requests
= document
.querySelectorAll(".request-list-item");
74 is(requests
.length
, 2, "There should be two requests");
76 // Select the WS request.
77 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[0]);
79 store
.dispatch(Actions
.toggleMessageColumn("size"));
80 store
.dispatch(Actions
.toggleMessageColumn("opCode"));
81 store
.dispatch(Actions
.toggleMessageColumn("maskBit"));
82 store
.dispatch(Actions
.toggleMessageColumn("finBit"));
83 clickOnSidebarTab(document
, "response");
85 // Get all messages present in the "Response" panel
86 let frames
= await
waitFor(() => {
87 const nodeList
= document
.querySelectorAll(
88 "#messages-view .message-list-table .message-list-item"
90 return nodeList
.length
=== 2 ? nodeList
: null;
93 // Check expected results
95 is(frames
.length
, 2, "There should be two frames");
97 let columnHeaders
= Array
.prototype.map
.call(
98 document
.querySelectorAll(
99 "#messages-view .message-list-headers .button-text"
101 node
=> node
.textContent
105 shallowEqual(columnHeaders
, [
114 "WS Column headers are in correct order"
117 // Get column values of first row for WS.
118 let columnValues
= Array
.prototype.map
.call(frames
, frame
=>
119 Array
.prototype.map
.call(
120 frame
.querySelectorAll(".message-list-column"),
121 column
=> column
.textContent
.trim()
126 shallowEqual(columnValues
, [
132 // Time format is "hh:mm:ss.mmm".
136 "WS Column values are in correct order"
139 // Select the SSE request.
140 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[1]);
142 store
.dispatch(Actions
.toggleMessageColumn("lastEventId"));
143 store
.dispatch(Actions
.toggleMessageColumn("eventName"));
144 store
.dispatch(Actions
.toggleMessageColumn("retry"));
148 document
.querySelectorAll(
149 "#messages-view .message-list-headers .button-text"
152 frames
= document
.querySelectorAll(
153 "#messages-view .message-list-table .message-list-item"
156 columnHeaders
= Array
.prototype.map
.call(
157 document
.querySelectorAll(
158 "#messages-view .message-list-headers .button-text"
160 node
=> node
.textContent
164 shallowEqual(columnHeaders
, [
172 "SSE Column headers are in correct order"
175 // Get column values of first row for SSE.
176 columnValues
= Array
.prototype.map
.call(frames
, frame
=>
177 Array
.prototype.map
.call(
178 frame
.querySelectorAll(".message-list-column"),
179 column
=> column
.textContent
.trim()
184 shallowEqual(columnValues
, [
192 "SSE Column values are in correct order"
195 // Select the WS request again.
196 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[0]);
198 shallowEqual(store
.getState().messages
.columns
, {
207 "WS columns should persist after request switch"
210 // Select the SSE request again.
211 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[1]);
213 shallowEqual(store
.getState().messages
.columns
, {
222 "SSE columns should persist after request switch"
225 // Reset SSE columns.
226 store
.dispatch(Actions
.resetMessageColumns());
228 // Switch to WS request again.
229 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[0]);
231 shallowEqual(store
.getState().messages
.columns
, {
240 "WS columns should not reset after resetting SSE columns"
244 store
.dispatch(Actions
.resetMessageColumns());
246 // Switch to SSE request again.
247 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[1]);
249 shallowEqual(store
.getState().messages
.columns
, {
258 "SSE columns' reset state should persist after request switch"
261 // Switch to WS request again.
262 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[0]);
264 shallowEqual(store
.getState().messages
.columns
, {
273 "WS columns' reset state should persist after request switch"
276 // Close WS connection.
277 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async () => {
278 await content
.wrappedJSObject
.closeWsConnection();
281 return teardown(monitor
);