tor-browser

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

browser_net_service-worker-timings.js (2355B)


      1 "use strict";
      2 
      3 /**
      4 * Tests that timings for requests from the service workers are displayed correctly.
      5 */
      6 add_task(async function testServiceWorkerTimings() {
      7  // Service workers only work on https
      8  const TEST_URL = HTTPS_EXAMPLE_URL + "service-workers/status-codes.html";
      9  const { tab, monitor } = await initNetMonitor(TEST_URL, {
     10    enableCache: true,
     11    requestCount: 1,
     12  });
     13  info("Starting test... ");
     14 
     15  const { document, store, windowRequire } = monitor.panelWin;
     16  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     17 
     18  store.dispatch(Actions.batchEnable(false));
     19 
     20  info("Registering the service worker...");
     21  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
     22    await content.wrappedJSObject.registerServiceWorker();
     23  });
     24 
     25  info("Performing requests which are intercepted by service worker...");
     26  await performRequests(monitor, tab, 1);
     27 
     28  const timingsSelector =
     29    "#timings-panel .tabpanel-summary-container.service-worker";
     30  wait = waitForDOM(document, timingsSelector, 3);
     31 
     32  AccessibilityUtils.setEnv({
     33    // Keyboard users will will see the sidebar when the request row is
     34    // selected. Accessibility is handled on the container level.
     35    actionCountRule: false,
     36    interactiveRule: false,
     37    labelRule: false,
     38  });
     39  EventUtils.sendMouseEvent(
     40    { type: "click" },
     41    document.querySelectorAll(".request-list-item")[0]
     42  );
     43  AccessibilityUtils.resetEnv();
     44 
     45  store.dispatch(Actions.toggleNetworkDetails());
     46 
     47  clickOnSidebarTab(document, "timings");
     48  await wait;
     49 
     50  const timings = document.querySelectorAll(timingsSelector, 3);
     51  // Note: The specific timing numbers change so this only asserts that the
     52  // timings are visible
     53  ok(
     54    timings[0].textContent.includes("Startup"),
     55    "The service worker timing for launch of the service worker is visible"
     56  );
     57  ok(
     58    timings[1].textContent.includes("Dispatch fetch:"),
     59    "The service worker timing for dispatching the fetch event is visible"
     60  );
     61  ok(
     62    timings[2].textContent.includes("Handle fetch:"),
     63    "The service worker timing for handling the fetch event is visible"
     64  );
     65 
     66  info("Unregistering the service worker...");
     67  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
     68    await content.wrappedJSObject.unregisterServiceWorker();
     69  });
     70 
     71  await teardown(monitor);
     72 });