browser_net_ws-clear.js (2529B)
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 clearing messages works correctly. 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(s) to be established + send messages 22 const onNetworkEvents = waitForNetworkEvents(monitor, 2); 23 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 24 await content.wrappedJSObject.openConnection(2); 25 await content.wrappedJSObject.openConnection(1); 26 }); 27 await onNetworkEvents; 28 29 const requests = document.querySelectorAll(".request-list-item"); 30 is(requests.length, 2, "There should be two requests"); 31 32 // Wait for all sent/received messages to be displayed in DevTools 33 let wait = waitForDOM( 34 document, 35 "#messages-view .message-list-table .message-list-item", 36 4 37 ); 38 39 // Select the first request 40 EventUtils.sendMouseEvent({ type: "mousedown" }, requests[0]); 41 42 // Click on the "Response" panel 43 clickOnSidebarTab(document, "response"); 44 await wait; 45 46 // Get all messages present in the "Response" panel 47 const frames = document.querySelectorAll( 48 "#messages-view .message-list-table .message-list-item" 49 ); 50 51 // Check expected results 52 is(frames.length, 4, "There should be four frames"); 53 54 // Clear messages 55 const clearButton = document.querySelector( 56 "#messages-view .message-list-clear-button" 57 ); 58 clearButton.click(); 59 is( 60 document.querySelectorAll(".message-list-empty-notice").length, 61 1, 62 "Empty notice visible" 63 ); 64 65 // Select the second request and check that the messages are not cleared 66 wait = waitForDOM( 67 document, 68 "#messages-view .message-list-table .message-list-item", 69 2 70 ); 71 EventUtils.sendMouseEvent({ type: "mousedown" }, requests[1]); 72 await wait; 73 const secondRequestFrames = document.querySelectorAll( 74 "#messages-view .message-list-table .message-list-item" 75 ); 76 is(secondRequestFrames.length, 2, "There should be two frames"); 77 78 // Close WS connection 79 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 80 await content.wrappedJSObject.closeConnection(); 81 }); 82 83 await teardown(monitor); 84 });