1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 * Test that WS connection is established successfully and the truncated payload is correct.
10 add_task(async
function () {
11 // Set WS message payload limit to a lower value for testing
12 await
pushPref("devtools.netmonitor.msg.messageDataLimit", 100);
14 const { tab
, monitor
} = await
initNetMonitor(WS_PAGE_URL
, {
17 info("Starting test... ");
19 const { document
, store
, windowRequire
} = monitor
.panelWin
;
20 const Actions
= windowRequire("devtools/client/netmonitor/src/actions/index");
22 store
.dispatch(Actions
.batchEnable(false));
24 // Wait for WS connections to be established + send messages
25 const onNetworkEvents
= waitForNetworkEvents(monitor
, 1);
26 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async () => {
27 await content
.wrappedJSObject
.openConnection(0);
28 content
.wrappedJSObject
.sendData(new Array(10 * 11).toString()); // > 100B payload
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 const 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 EventUtils
.sendMouseEvent({ type
: "mousedown" }, frames
[0]);
61 await
waitForDOM(document
, "#messages-view .truncated-data-message");
64 document
.querySelector("#messages-view .truncated-data-message"),
65 "Truncated data header shown"
68 document
.querySelector("#messages-view .message-rawData-payload")
71 "Payload size is kept to the limit"
74 // Close WS connection
75 await SpecialPowers
.spawn(tab
.linkedBrowser
, [], async () => {
76 await content
.wrappedJSObject
.closeConnection();
79 await
teardown(monitor
);