tor-browser

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

browser_net_block-serviceworker.js (2043B)


      1 /* Any copyright is dedicated to the Public Domain.
      2  http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Service workers only work on https
      7 const URL = EXAMPLE_URL.replace("http:", "https:");
      8 
      9 const TEST_URL = URL + "service-workers/status-codes.html";
     10 
     11 // Test that request blocking works for service worker requests.
     12 add_task(async function () {
     13  const { tab, monitor } = await initNetMonitor(TEST_URL, {
     14    enableCache: true,
     15    requestCount: 1,
     16  });
     17  info("Starting test... ");
     18 
     19  const { document, store, windowRequire } = monitor.panelWin;
     20  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     21 
     22  store.dispatch(Actions.batchEnable(false));
     23 
     24  info("Registering the service worker...");
     25  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
     26    await content.wrappedJSObject.registerServiceWorker();
     27  });
     28 
     29  info("Performing the service worker request");
     30  await performRequests(monitor, tab, 1);
     31 
     32  info("Open the request blocking panel and block service-workers request");
     33  store.dispatch(Actions.toggleRequestBlockingPanel());
     34 
     35  info("Block the image request from the service worker");
     36  await addBlockedRequest("service-workers/test-image.png", monitor);
     37 
     38  await clearNetworkEvents(monitor);
     39 
     40  info("Performing the service worker request again");
     41  await performRequests(monitor, tab, 1);
     42 
     43  // Wait till there are four resources rendered in the results
     44  await waitForDOMIfNeeded(document, ".request-list-item", 4);
     45 
     46  const requestItems = document.querySelectorAll(".request-list-item");
     47  ok(
     48    !checkRequestListItemBlocked(requestItems[0]),
     49    "The first service worker request was not blocked"
     50  );
     51  ok(
     52    checkRequestListItemBlocked(requestItems[requestItems.length - 1]),
     53    "The last service worker request was blocked"
     54  );
     55 
     56  info("Unregistering the service worker...");
     57  await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
     58    await content.wrappedJSObject.unregisterServiceWorker();
     59  });
     60 
     61  await teardown(monitor);
     62 });