1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Test that WebSocket payloads containing an array of STOMP messages are parsed
8 * correctly and displayed in a user friendly way
11 add_task(async
function () {
12 const { tab
, monitor
} = await
initNetMonitor(WS_PAGE_URL
, {
15 info("Starting test... ");
17 const { document
, store
, windowRequire
} = monitor
.panelWin
;
18 const Actions
= windowRequire("devtools/client/netmonitor/src/actions/index");
20 store
.dispatch(Actions
.batchEnable(false));
22 // Wait for WS connections to be established + send messages
23 const onNetworkEvents
= waitForNetworkEvents(monitor
, 1);
24 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async () => {
25 await content
.wrappedJSObject
.openConnection(0);
26 content
.wrappedJSObject
.sendData(
27 `[\"SEND\\nx-firefox-test:true\\ncontent-length:17\\n\\n[{\\\"key\\\":\\\"value\\\"}]\\u0000\"]`
30 await onNetworkEvents
;
32 const requests
= document
.querySelectorAll(".request-list-item");
33 is(requests
.length
, 1, "There should be one request");
35 // Wait for all sent/received messages to be displayed in DevTools
36 let wait
= waitForDOM(
38 "#messages-view .message-list-table .message-list-item",
42 // Select the first request
43 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requests
[0]);
45 // Click on the "Response" panel
46 clickOnSidebarTab(document
, "response");
49 // Get all messages present in the "Response" panel
50 const frames
= document
.querySelectorAll(
51 "#messages-view .message-list-table .message-list-item"
54 // Check expected results
55 is(frames
.length
, 2, "There should be two frames");
57 // Wait for next tick to do async stuff (The MessagePayload component uses the async function getMessagePayload)
59 const waitForData
= waitForDOM(document
, "#messages-view .properties-view");
60 const [requestFrame
] = frames
;
61 EventUtils
.sendMouseEvent({ type
: "mousedown" }, requestFrame
);
66 document
.querySelector("#messages-view .data-label").innerText
,
68 "The JSON payload panel should be displayed"
72 document
.querySelector("#messages-view .treeTable"),
73 "A tree table should be used to display the formatted payload"
77 document
.getElementById("/0/command"),
78 "The message 'command' should be displayed"
81 document
.getElementById("/0/headers"),
82 "The message 'headers' should be displayed"
85 document
.getElementById("/0/body"),
86 "The message 'body' should be displayed"
89 // Toggle raw data display
90 wait
= waitForDOM(document
, "#messages-view .message-rawData-payload");
91 const rawDataToggle
= document
.querySelector(
92 "#messages-view .devtools-checkbox-toggle"
94 clickElement(rawDataToggle
, monitor
);
98 document
.querySelector("#messages-view .data-label").innerText
,
100 "The raw data payload info should be displayed"
104 document
.querySelector("#messages-view .message-rawData-payload").value
,
105 `[\"SEND\\nx-firefox-test:true\\ncontent-length:17\\n\\n[{\\\"key\\\":\\\"value\\\"}]\\u0000\"]`,
106 "The raw data must be shown correctly"
109 // Close WS connection
110 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async () => {
111 await content
.wrappedJSObject
.closeConnection();
114 await
teardown(monitor
);