tor-browser

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

browser_net_throttle.js (1881B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Network throttling integration test.
      5 
      6 "use strict";
      7 
      8 requestLongerTimeout(2);
      9 
     10 add_task(async function () {
     11  await throttleTest({ throttle: true, addLatency: true });
     12  await throttleTest({ throttle: true, addLatency: false });
     13  await throttleTest({ throttle: false, addLatency: false });
     14 });
     15 
     16 async function throttleTest(options) {
     17  const { throttle, addLatency } = options;
     18  const { monitor } = await initNetMonitor(SIMPLE_URL, { requestCount: 1 });
     19  const { store, windowRequire, connector } = monitor.panelWin;
     20  const { ACTIVITY_TYPE } = windowRequire(
     21    "devtools/client/netmonitor/src/constants"
     22  );
     23  const { updateNetworkThrottling, triggerActivity } = connector;
     24  const { getSortedRequests } = windowRequire(
     25    "devtools/client/netmonitor/src/selectors/index"
     26  );
     27 
     28  info(`Starting test... (throttle = ${throttle}, addLatency = ${addLatency})`);
     29 
     30  // When throttling, must be smaller than the length of the content
     31  // of SIMPLE_URL in bytes.
     32  const size = throttle ? 200 : 0;
     33  const latency = addLatency ? 100 : 0;
     34 
     35  const throttleProfile = {
     36    latency,
     37    download: size,
     38    upload: 10000,
     39  };
     40 
     41  info("sending throttle request");
     42 
     43  await updateNetworkThrottling(true, throttleProfile);
     44 
     45  const wait = waitForNetworkEvents(monitor, 1);
     46  await triggerActivity(ACTIVITY_TYPE.RELOAD.WITH_CACHE_DISABLED);
     47  await wait;
     48 
     49  await waitForRequestData(store, ["eventTimings"]);
     50 
     51  const requestItem = getSortedRequests(store.getState())[0];
     52  const reportedOneSecond = requestItem.eventTimings.timings.receive > 1000;
     53  if (throttle) {
     54    ok(reportedOneSecond, "download reported as taking more than one second");
     55  } else {
     56    ok(!reportedOneSecond, "download reported as taking less than one second");
     57  }
     58 
     59  await teardown(monitor);
     60 }