tor-browser

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

browser_net_ws-keep-future-frames.js (2691B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function () {
      7  // Set WS messages limit to a lower value for testing
      8  await pushPref("devtools.netmonitor.msg.displayed-messages.limit", 10);
      9 
     10  const { tab, monitor } = await initNetMonitor(WS_PAGE_URL, {
     11    requestCount: 1,
     12  });
     13  info("Starting test... ");
     14 
     15  const { document, store, windowRequire } = monitor.panelWin;
     16  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     17 
     18  store.dispatch(Actions.batchEnable(false));
     19 
     20  // Wait for WS connections to be established + send messages
     21  const onNetworkEvents = waitForNetworkEvents(monitor, 1);
     22  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     23    await content.wrappedJSObject.openConnection(10);
     24  });
     25  await onNetworkEvents;
     26 
     27  const requests = document.querySelectorAll(".request-list-item");
     28  is(requests.length, 1, "There should be one request");
     29 
     30  // Wait for truncated message notification to appear
     31  const truncatedMessageWait = waitForDOM(
     32    document,
     33    "#messages-view .truncated-message"
     34  );
     35 
     36  // Select the first request
     37  EventUtils.sendMouseEvent({ type: "mousedown" }, requests[0]);
     38 
     39  // Click on the "Response" panel
     40  clickOnSidebarTab(document, "response");
     41  await truncatedMessageWait;
     42 
     43  // Wait for truncated message notification to appear and to have an expected text
     44  await waitFor(() =>
     45    document
     46      .querySelector("#messages-view .truncated-message")
     47      .textContent.includes("10 messages")
     48  );
     49 
     50  // Set on 'Keep all future messages' checkbox
     51  const truncationCheckbox = document.querySelector(
     52    "#messages-view .truncation-checkbox"
     53  );
     54  truncationCheckbox.click();
     55 
     56  // Get rid of all current messages
     57  const clearButton = document.querySelector(
     58    "#messages-view .message-list-clear-button"
     59  );
     60  clearButton.click();
     61 
     62  // And request new messages
     63  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     64    await content.wrappedJSObject.sendFrames(10);
     65  });
     66 
     67  // Wait while they appear in the Response tab
     68  // We should see all requested messages (sometimes more than 20 = 10 sent + 10 received)
     69  await waitForDOM(
     70    document,
     71    "#messages-view .message-list-table .message-list-item",
     72    20
     73  );
     74 
     75  const truncatedMessage = document.querySelector(
     76    "#messages-view .truncated-message"
     77  ).textContent;
     78 
     79  is(truncatedMessage, "0 messages have been truncated to conserve memory");
     80 
     81  // Close WS connection
     82  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     83    await content.wrappedJSObject.closeConnection();
     84  });
     85 
     86  await teardown(monitor);
     87 });