tor-browser

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

browser_net_telemetry_select_ws_frame.js (2318B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Tests the select_ws_frame telemetry event.
      8 */
      9 const { TelemetryTestUtils } = ChromeUtils.importESModule(
     10  "resource://testing-common/TelemetryTestUtils.sys.mjs"
     11 );
     12 
     13 add_task(async function () {
     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  // Clear all events.
     25  Services.telemetry.clearEvents();
     26 
     27  // Ensure no events have been logged.
     28  TelemetryTestUtils.assertNumberOfEvents(0);
     29 
     30  // Wait for WS connection to be established + send messages.
     31  const onNetworkEvents = waitForNetworkEvents(monitor, 1);
     32  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
     33    await content.wrappedJSObject.openConnection(1);
     34  });
     35  await onNetworkEvents;
     36 
     37  const requests = document.querySelectorAll(".request-list-item");
     38  is(requests.length, 1, "There should be one request");
     39 
     40  // Select the request to open the side panel.
     41  EventUtils.sendMouseEvent({ type: "mousedown" }, requests[0]);
     42 
     43  // Wait for all sent/received messages to be displayed in DevTools.
     44  const wait = waitForDOM(
     45    document,
     46    "#messages-view .message-list-table .message-list-item",
     47    2
     48  );
     49 
     50  // Click on the "Response" panel.
     51  clickOnSidebarTab(document, "response");
     52  await wait;
     53 
     54  // Get all messages present in the "Response" panel.
     55  const frames = document.querySelectorAll(
     56    "#messages-view .message-list-table .message-list-item"
     57  );
     58 
     59  // Check expected results.
     60  is(frames.length, 2, "There should be two frames");
     61 
     62  // Wait for tick, so the `mousedown` event works.
     63  await waitForTick();
     64 
     65  // Wait for the payload to be resolved (LongString)
     66  const payloadResolved = monitor.panelWin.api.once(
     67    TEST_EVENTS.LONGSTRING_RESOLVED
     68  );
     69 
     70  // Select frame
     71  EventUtils.sendMouseEvent({ type: "mousedown" }, frames[0]);
     72  await payloadResolved;
     73 
     74  // Verify existence of the telemetry event.
     75  checkTelemetryEvent(
     76    {},
     77    {
     78      method: "select_ws_frame",
     79    }
     80  );
     81 
     82  return teardown(monitor);
     83 });