browser_net_ws-basic.js (2249B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Test that WS connection is established successfully and sent/received messages are correct. 8 */ 9 10 add_task(async function () { 11 const { tab, monitor } = await initNetMonitor(WS_PAGE_URL, { 12 requestCount: 1, 13 }); 14 info("Starting test... "); 15 16 const { document, store, windowRequire } = monitor.panelWin; 17 const Actions = windowRequire("devtools/client/netmonitor/src/actions/index"); 18 19 store.dispatch(Actions.batchEnable(false)); 20 21 // Wait for WS connection to be established + send messages 22 const onNetworkEvents = waitForNetworkEvents(monitor, 1); 23 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 24 await content.wrappedJSObject.openConnection(1); 25 }); 26 await onNetworkEvents; 27 28 const requests = document.querySelectorAll(".request-list-item"); 29 is(requests.length, 1, "There should be one request"); 30 31 // Select the request to open the side panel. 32 EventUtils.sendMouseEvent({ type: "mousedown" }, requests[0]); 33 34 // Wait for all sent/received messages to be displayed in DevTools 35 const wait = waitForDOM( 36 document, 37 "#messages-view .message-list-table .message-list-item", 38 2 39 ); 40 41 // Click on the "Response" panel 42 clickOnSidebarTab(document, "response"); 43 await wait; 44 45 // Get all messages present in the "Response" panel 46 const frames = document.querySelectorAll( 47 "#messages-view .message-list-table .message-list-item" 48 ); 49 50 // Check expected results 51 is(frames.length, 2, "There should be two frames"); 52 53 // Sent frame 54 is( 55 frames[0].children[0].textContent, 56 " Payload 0", 57 "The correct sent payload should be displayed" 58 ); 59 is(frames[0].classList.contains("sent"), true, "The payload type is 'Sent'"); 60 61 // Received frame 62 is( 63 frames[1].children[0].textContent, 64 " Payload 0", 65 "The correct received payload should be displayed" 66 ); 67 is( 68 frames[1].classList.contains("received"), 69 true, 70 "The payload type is 'Received'" 71 ); 72 73 // Close WS connection 74 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 75 await content.wrappedJSObject.closeConnection(); 76 }); 77 78 await teardown(monitor); 79 });