tor-browser

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

browser_net_ws-early-connection.js (2038B)


      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 created while the page is still loading
      8 * is properly tracked and there are WS frames displayed in the
      9 * Messages side panel.
     10 */
     11 add_task(async function () {
     12  const { monitor } = await initNetMonitor(SIMPLE_URL, { 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  // Make the WS Messages side panel the default so, we avoid
     22  // request headers from the backend by selecting the Headers
     23  // panel
     24  store.dispatch(Actions.selectDetailsPanelTab("response"));
     25 
     26  // Load page that opens WS connection during the load time.
     27  const waitForEvents = waitForNetworkEvents(monitor, 3);
     28  await navigateTo(WS_PAGE_EARLY_CONNECTION_URL);
     29  await waitForEvents;
     30 
     31  const requests = document.querySelectorAll(
     32    ".request-list-item .requests-list-file"
     33  );
     34  is(requests.length, 3, "There should be three requests");
     35 
     36  // Get index of the WS connection request.
     37  const index = Array.from(requests).findIndex(element => {
     38    return element.textContent === "file_ws_backend";
     39  });
     40 
     41  Assert.notStrictEqual(index, -1, "There must be one WS connection request");
     42 
     43  // Select the connection request to see WS frames in the side panel.
     44  EventUtils.sendMouseEvent({ type: "mousedown" }, requests[index]);
     45 
     46  info("Waiting for WS frames...");
     47 
     48  // Wait for two frames to be displayed in the panel
     49  await waitForDOMIfNeeded(
     50    document,
     51    "#messages-view .message-list-table .message-list-item",
     52    2
     53  );
     54 
     55  // Check the payload of the first frame.
     56  const firstFramePayload = document.querySelector(
     57    "#messages-view .message-list-table .message-list-item .message-list-payload"
     58  );
     59  is(firstFramePayload.textContent.trim(), "readyState:loading");
     60 
     61  await teardown(monitor);
     62 });