tor-browser

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

browser_network_throttling.js (2092B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const {
      7  profiles,
      8 } = require("resource://devtools/client/shared/components/throttling/profiles.js");
      9 
     10 // Tests changing network throttling
     11 const TEST_URL = "data:text/html;charset=utf-8,Network throttling test";
     12 
     13 addRDMTask(TEST_URL, async function ({ ui }) {
     14  // Test defaults
     15  testNetworkThrottlingSelectorLabel(ui, "No Throttling", "No Throttling");
     16  await testNetworkThrottlingState(ui, null);
     17 
     18  // Test a fast profile
     19  await testThrottlingProfile(
     20    ui,
     21    "Wi-Fi",
     22    "download 30Mbps, upload 15Mbps, latency 2ms"
     23  );
     24 
     25  // Test a slower profile
     26  await testThrottlingProfile(
     27    ui,
     28    "Regular 3G",
     29    "download 750Kbps, upload 250Kbps, latency 100ms"
     30  );
     31 
     32  // Test switching back to no throttling
     33  await selectNetworkThrottling(ui, "No Throttling");
     34  testNetworkThrottlingSelectorLabel(ui, "No Throttling", "No Throttling");
     35  await testNetworkThrottlingState(ui, null);
     36 });
     37 
     38 function testNetworkThrottlingSelectorLabel(
     39  ui,
     40  expectedLabel,
     41  expectedTooltip
     42 ) {
     43  const menu = ui.toolWindow.document.querySelector("#network-throttling");
     44  is(
     45    menu.textContent,
     46    expectedLabel,
     47    `Button label should be changed to ${expectedLabel}`
     48  );
     49  is(
     50    menu.getAttribute("title"),
     51    expectedTooltip,
     52    `Button tooltip should be changed to ${expectedTooltip}`
     53  );
     54 }
     55 
     56 var testNetworkThrottlingState = async function (ui, expected) {
     57  const state = await ui.networkFront.getNetworkThrottling();
     58  Assert.deepEqual(
     59    state,
     60    expected,
     61    "Network throttling state should be " + JSON.stringify(expected, null, 2)
     62  );
     63 };
     64 
     65 var testThrottlingProfile = async function (ui, profile, tooltip) {
     66  await selectNetworkThrottling(ui, profile);
     67  testNetworkThrottlingSelectorLabel(ui, profile, tooltip);
     68  const data = profiles.find(({ id }) => id == profile);
     69  const { download, upload, latency } = data;
     70  await testNetworkThrottlingState(ui, {
     71    downloadThroughput: download,
     72    uploadThroughput: upload,
     73    latency,
     74  });
     75 };