Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / devtools / client / netmonitor / test / browser_net_ws-copy-binary-message.js
blob0e72fb1697a1f5c6ba3f65d4687dd482c7dd7ada
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 binary messages can be copied.
8 */
10 add_task(async function () {
11 const { tab, monitor } = await initNetMonitor(WS_PAGE_URL, {
12 requestCount: 1,
13 });
14 info("Starting test... ");
16 const { document, store, windowRequire } = monitor.panelWin;
17 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
19 store.dispatch(Actions.batchEnable(false));
21 // Wait for WS connections to be established + send message
22 const onNetworkEvents = waitForNetworkEvents(monitor, 1);
23 const data = {
24 text: "something",
25 hex: "736f6d657468696e67",
26 base64: "c29tZXRoaW5n",
28 await SpecialPowers.spawn(tab.linkedBrowser, [data.text], async text => {
29 await content.wrappedJSObject.openConnection(0);
30 content.wrappedJSObject.sendData(text, true);
31 });
32 await onNetworkEvents;
34 const requests = document.querySelectorAll(".request-list-item");
36 // Wait for all sent/received messages to be displayed in DevTools
37 const wait = waitForDOM(
38 document,
39 "#messages-view .message-list-table .message-list-item",
43 // Select the websocket request
44 EventUtils.sendMouseEvent({ type: "mousedown" }, requests[0]);
46 // Test that 'Save Response As' is not in the context menu
47 EventUtils.sendMouseEvent({ type: "contextmenu" }, requests[0]);
49 ok(
50 !getContextMenuItem(monitor, "request-list-context-save-response-as"),
51 "The 'Save Response As' context menu item should be hidden"
54 // Close context menu.
55 const contextMenu = monitor.toolbox.topDoc.querySelector(
56 'popupset menupopup[menu-api="true"]'
58 const popupHiddenPromise = BrowserTestUtils.waitForEvent(
59 contextMenu,
60 "popuphidden"
62 contextMenu.hidePopup();
63 await popupHiddenPromise;
65 // Click on the "Response" panel
66 clickOnSidebarTab(document, "response");
67 await wait;
69 // Get all messages present in the "Response" panel
70 const messages = document.querySelectorAll(
71 "#messages-view .message-list-table .message-list-item"
74 // Test all types for both the sent and received message.
75 for (const message of messages) {
76 for (const [type, expectedValue] of Object.entries(data)) {
77 const menuItemId = `message-list-context-copy-message-${type}`;
78 EventUtils.sendMouseEvent({ type: "contextmenu" }, message);
79 is(
80 !!getContextMenuItem(monitor, menuItemId),
81 true,
82 `Could not find "${type}" copy option.`
85 await waitForClipboardPromise(
86 async function setup() {
87 await selectContextMenuItem(monitor, menuItemId);
89 function validate(result) {
90 return result === expectedValue;
96 // Close WS connection
97 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
98 await content.wrappedJSObject.closeConnection();
99 });
101 await teardown(monitor);