Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / client / netmonitor / test / browser_net_ws-json-stomp-payload.js
blob74c5d08dd0e05600f6c871a5d9e643b4887e0b85
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 /**
7 * Test that WebSocket payloads containing an array of STOMP messages are parsed
8 * correctly and displayed in a user friendly way
9 */
11 add_task(async function () {
12 const { tab, monitor } = await initNetMonitor(WS_PAGE_URL, {
13 requestCount: 1,
14 });
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\"]`
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 let 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 const waitForData = waitForDOM(document, "#messages-view .properties-view");
60 const [requestFrame] = frames;
61 EventUtils.sendMouseEvent({ type: "mousedown" }, requestFrame);
63 await waitForData;
65 is(
66 document.querySelector("#messages-view .data-label").innerText,
67 "JSON",
68 "The JSON payload panel should be displayed"
71 ok(
72 document.querySelector("#messages-view .treeTable"),
73 "A tree table should be used to display the formatted payload"
76 ok(
77 document.getElementById("/0/command"),
78 "The message 'command' should be displayed"
80 ok(
81 document.getElementById("/0/headers"),
82 "The message 'headers' should be displayed"
84 ok(
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);
95 await wait;
97 is(
98 document.querySelector("#messages-view .data-label").innerText,
99 "Raw Data (79 B)",
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);