tor-browser

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

browser_aboutdebugging_serviceworker_start.js (2616B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /* import-globals-from helper-serviceworker.js */
      7 Services.scriptloader.loadSubScript(
      8  CHROME_URL_ROOT + "helper-serviceworker.js",
      9  this
     10 );
     11 
     12 const SW_TAB_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.html";
     13 const SW_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.worker.js";
     14 
     15 /**
     16 * Test that service workers can be started using about:debugging.
     17 */
     18 add_task(async function () {
     19  await enableServiceWorkerDebugging();
     20 
     21  // Setting a low idle_timeout and idle_extended_timeout will allow the service worker
     22  // to reach the STOPPED state quickly, which will allow us to test the start button.
     23  // The default value is 30000 milliseconds.
     24  info("Set a low service worker idle timeout");
     25  await pushPref("dom.serviceWorkers.idle_timeout", 1000);
     26  await pushPref("dom.serviceWorkers.idle_extended_timeout", 1000);
     27 
     28  const { document, tab, window } = await openAboutDebugging({
     29    enableWorkerUpdates: true,
     30  });
     31  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     32 
     33  // Open a tab that registers a basic service worker.
     34  const swTab = await addTab(SW_TAB_URL);
     35 
     36  // Wait for the registration to make sure service worker has been started, and that we
     37  // are not just reading STOPPED as the initial state.
     38  await waitForRegistration(swTab);
     39 
     40  info("Wait until the service worker stops");
     41  const targetElement = await waitForServiceWorkerStopped(SW_URL, document);
     42 
     43  // Retrieve the Start button for the worker.
     44  const startButton = targetElement.querySelector(".qa-start-button");
     45  ok(startButton, "Found its start button");
     46 
     47  info(
     48    "Click on the start button and wait for the service worker to be running"
     49  );
     50  const onServiceWorkerRunning = waitForServiceWorkerRunning(SW_URL, document);
     51  startButton.click();
     52  const updatedTarget = await onServiceWorkerRunning;
     53 
     54  // Check that the buttons are displayed as expected.
     55  const hasInspectButton = updatedTarget.querySelector(
     56    ".qa-debug-target-inspect-button"
     57  );
     58  const hasStartButton = updatedTarget.querySelector(".qa-start-button");
     59  ok(hasInspectButton, "Service worker has an inspect button");
     60  ok(!hasStartButton, "Service worker does not have a start button");
     61 
     62  info("Unregister service worker");
     63  await unregisterServiceWorker(swTab);
     64 
     65  info("Wait until the service worker disappears from about:debugging");
     66  await waitUntil(() => !findDebugTargetByText(SW_URL, document));
     67 
     68  info("Remove tabs");
     69  await removeTab(swTab);
     70  await removeTab(tab);
     71 });