tor-browser

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

browser_net_duration.js (2074B)


      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 if pending requests are labeled as "" (empty string) in the Duration column.
      8 */
      9 
     10 add_task(async function () {
     11  const { monitor } = await initNetMonitor(SLOW_REQUESTS_URL, {
     12    requestCount: 1,
     13  });
     14  const { document, store, windowRequire } = monitor.panelWin;
     15  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     16  const { getDisplayedRequests } = windowRequire(
     17    "devtools/client/netmonitor/src/selectors/index"
     18  );
     19  store.dispatch(Actions.batchEnable(false));
     20 
     21  const waitForFullRequest = waitForNetworkEvents(monitor, 1);
     22  const waitForPartialPending = waitForNetworkEvents(monitor, 1, {
     23    expectedPayloadReady: 0,
     24    expectedEventTimings: 0,
     25  });
     26  info("Starting test... ");
     27  performRequestsInContent([
     28    {
     29      url: "sjs_long-polling-server.sjs",
     30      method: "GET",
     31    },
     32  ]);
     33  // Wait for the first request to be partially retrieve
     34  await waitForPartialPending;
     35  const pendingArr = getDurations();
     36 
     37  const waitForRequest = waitForNetworkEvents(monitor, 1);
     38  performRequestsInContent([
     39    {
     40      url: "sjs_long-polling-server.sjs?unblock",
     41      method: "GET",
     42    },
     43  ]);
     44  // Wait for the full retrieval of the second request
     45  await waitForRequest;
     46  // Also wait for full retrieval of the first request which has been unblocked by the second
     47  await waitForFullRequest;
     48 
     49  const resolvedArr = getDurations();
     50 
     51  is(pendingArr[0], "", "Duration should be listed as '' until resolved.");
     52 
     53  is(
     54    resolvedArr[0],
     55    `${getDisplayedRequests(store.getState())[0].totalTime} ms`,
     56    "Duration of resolved request should be displayed correctly."
     57  );
     58 
     59  function getDurations() {
     60    const items = document.querySelectorAll(".request-list-item");
     61    const result = [];
     62 
     63    for (const item of items) {
     64      const duration = item.querySelector(
     65        ".requests-list-duration-time"
     66      ).textContent;
     67 
     68      result.push(duration);
     69    }
     70 
     71    return result;
     72  }
     73 });