tor-browser

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

browser_net_timing-division.js (2125B)


      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 if timing intervals are divided against seconds when appropriate.
      8 */
      9 add_task(async function () {
     10  // Show only few columns, so there is enough space
     11  // for the waterfall.
     12  await pushPref(
     13    "devtools.netmonitor.visibleColumns",
     14    '["status", "contentSize", "waterfall"]'
     15  );
     16 
     17  const { tab, monitor } = await initNetMonitor(CUSTOM_GET_URL, {
     18    requestCount: 1,
     19  });
     20  info("Starting test... ");
     21 
     22  const { document, store, windowRequire } = monitor.panelWin;
     23  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     24  store.dispatch(Actions.batchEnable(false));
     25 
     26  const wait = waitForNetworkEvents(monitor, 2);
     27  // Timeout needed for having enough divisions on the time scale.
     28  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
     29    content.wrappedJSObject.performRequests(2, null, 3000);
     30  });
     31  await wait;
     32 
     33  const milDivs = document.querySelectorAll(
     34    ".requests-list-timings-division[data-division-scale=millisecond]"
     35  );
     36  const secDivs = document.querySelectorAll(
     37    ".requests-list-timings-division[data-division-scale=second]"
     38  );
     39  const minDivs = document.querySelectorAll(
     40    ".requests-list-timings-division[data-division-scale=minute]"
     41  );
     42 
     43  info("Number of millisecond divisions: " + milDivs.length);
     44  info("Number of second divisions: " + secDivs.length);
     45  info("Number of minute divisions: " + minDivs.length);
     46 
     47  milDivs.forEach(div => info(`Millisecond division: ${div.textContent}`));
     48  secDivs.forEach(div => info(`Second division: ${div.textContent}`));
     49  minDivs.forEach(div => info(`Minute division: ${div.textContent}`));
     50 
     51  is(
     52    store.getState().requests.requests.length,
     53    2,
     54    "There should be only two requests made."
     55  );
     56 
     57  ok(
     58    secDivs.length,
     59    "There should be at least one division on the seconds time scale."
     60  );
     61  ok(
     62    secDivs[0].textContent.match(/\d+\.\d{2}\s\w+/),
     63    "The division on the seconds time scale looks legit."
     64  );
     65 
     66  return teardown(monitor);
     67 });