tor-browser

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

browser_net_ws-limit-payload.js (2532B)


      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 the truncated payload is correct.
      8 */
      9 
     10 add_task(async function () {
     11  // Set WS message payload limit to a lower value for testing
     12  await pushPref("devtools.netmonitor.msg.messageDataLimit", 100);
     13 
     14  const { tab, monitor } = await initNetMonitor(WS_PAGE_URL, {
     15    requestCount: 1,
     16  });
     17  info("Starting test... ");
     18 
     19  const { document, store, windowRequire } = monitor.panelWin;
     20  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     21 
     22  store.dispatch(Actions.batchEnable(false));
     23 
     24  // Wait for WS connections to be established + send messages
     25  const onNetworkEvents = waitForNetworkEvents(monitor, 1);
     26  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     27    await content.wrappedJSObject.openConnection(0);
     28    content.wrappedJSObject.sendData(new Array(10 * 11).toString()); // > 100B payload
     29  });
     30  await onNetworkEvents;
     31 
     32  const requests = document.querySelectorAll(".request-list-item");
     33  is(requests.length, 1, "There should be one request");
     34 
     35  // Wait for all sent/received messages to be displayed in DevTools
     36  const wait = waitForDOM(
     37    document,
     38    "#messages-view .message-list-table .message-list-item",
     39    2
     40  );
     41 
     42  // Select the first request
     43  EventUtils.sendMouseEvent({ type: "mousedown" }, requests[0]);
     44 
     45  // Click on the "Response" panel
     46  clickOnSidebarTab(document, "response");
     47  await wait;
     48 
     49  // Get all messages present in the "Response" panel
     50  const frames = document.querySelectorAll(
     51    "#messages-view .message-list-table .message-list-item"
     52  );
     53 
     54  // Check expected results
     55  is(frames.length, 2, "There should be two frames");
     56 
     57  // Wait for next tick to do async stuff (The MessagePayload component uses the async function getMessagePayload)
     58  await waitForTick();
     59  EventUtils.sendMouseEvent({ type: "mousedown" }, frames[0]);
     60 
     61  await waitForDOM(document, "#messages-view .truncated-data-message");
     62 
     63  ok(
     64    document.querySelector("#messages-view .truncated-data-message"),
     65    "Truncated data header shown"
     66  );
     67  is(
     68    document.querySelector("#messages-view .message-rawData-payload")
     69      .textContent.length,
     70    100,
     71    "Payload size is kept to the limit"
     72  );
     73 
     74  // Close WS connection
     75  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     76    await content.wrappedJSObject.closeConnection();
     77  });
     78 
     79  await teardown(monitor);
     80 });