Bug 1924993 - [devtools] Debugger tests wait before typing in conditional panel r...
[gecko.git] / devtools / client / netmonitor / test / browser_net_ws-limit-payload.js
blob8a3082810afe1852c1bc92ff91493ef9876faf79
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 /**
7 * Test that WS connection is established successfully and the truncated payload is correct.
8 */
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, {
15 requestCount: 1,
16 });
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
29 });
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(
37 document,
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");
47 await wait;
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)
58 await waitForTick();
59 EventUtils.sendMouseEvent({ type: "mousedown" }, frames[0]);
61 await waitForDOM(document, "#messages-view .truncated-data-message");
63 ok(
64 document.querySelector("#messages-view .truncated-data-message"),
65 "Truncated data header shown"
67 is(
68 document.querySelector("#messages-view .message-rawData-payload")
69 .textContent.length,
70 100,
71 "Payload size is kept to the limit"
74 // Close WS connection
75 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
76 await content.wrappedJSObject.closeConnection();
77 });
79 await teardown(monitor);
80 });