tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_net_ws-connection-closed.js (1562B)


      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 message is displayed when the connection is closed.
      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 ContentTask.spawn(tab.linkedBrowser, {}, async () => {
     24    await content.wrappedJSObject.openConnection(1);
     25  });
     26  await onNetworkEvents;
     27 
     28  const requests = document.querySelectorAll(".request-list-item");
     29 
     30  // Select the request to open the side panel.
     31  EventUtils.sendMouseEvent({ type: "mousedown" }, requests[0]);
     32 
     33  // Click on the "Response" panel
     34  clickOnSidebarTab(document, "response");
     35 
     36  const wait = waitForDOM(
     37    document,
     38    "#messages-view .msg-connection-closed-message"
     39  );
     40 
     41  // Close WS connection
     42  await ContentTask.spawn(tab.linkedBrowser, {}, async () => {
     43    await content.wrappedJSObject.closeConnection();
     44  });
     45  await wait;
     46 
     47  is(
     48    !!document.querySelector("#messages-view .msg-connection-closed-message"),
     49    true,
     50    "Connection closed message should be displayed"
     51  );
     52 
     53  await teardown(monitor);
     54 });