tor-browser

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

browser_application_panel_debug-service-worker.js (2016B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 Services.scriptloader.loadSubScript(
      7  "chrome://mochitests/content/browser/devtools/client/debugger/test/mochitest/shared-head.js",
      8  this
      9 );
     10 
     11 const TAB_URL = URL_ROOT + "resources/service-workers/debug.html";
     12 
     13 add_task(async function () {
     14  await enableApplicationPanel();
     15 
     16  const { panel, tab, toolbox, commands } =
     17    await openNewTabAndApplicationPanel(TAB_URL);
     18 
     19  const doc = panel.panelWin.document;
     20 
     21  selectPage(panel, "service-workers");
     22 
     23  info("Wait until the service worker appears in the application panel");
     24  await waitUntil(() => getWorkerContainers(doc).length === 1);
     25 
     26  const container = getWorkerContainers(doc)[0];
     27  info("Wait until the inspect link is displayed");
     28  await waitUntil(() => {
     29    return container.querySelector(".js-inspect-link");
     30  });
     31 
     32  info("Click on the inspect link and wait for debugger to be ready");
     33  const debugLink = container.querySelector(".js-inspect-link");
     34  debugLink.click();
     35  await waitFor(() => toolbox.getPanel("jsdebugger"));
     36 
     37  // add a breakpoint at line 11
     38  const debuggerContext = createDebuggerContext(toolbox);
     39  await waitForLoadedSource(debuggerContext, "debug-sw.js");
     40  await addBreakpoint(debuggerContext, "debug-sw.js", 11);
     41 
     42  // force a pause at the breakpoint
     43  info("Invoke fetch, expect the service worker script to pause on line 11");
     44  await ContentTask.spawn(tab.linkedBrowser, {}, async function () {
     45    content.wrappedJSObject.fetchFromWorker();
     46  });
     47  await waitForPaused(debuggerContext);
     48  const workerScript = findSource(debuggerContext, "debug-sw.js");
     49  await assertPausedAtSourceAndLine(debuggerContext, workerScript.id, 11);
     50  await resume(debuggerContext);
     51 
     52  // remove breakpoint
     53  await removeBreakpoint(debuggerContext, workerScript.id, 11);
     54 
     55  await unregisterAllWorkers(commands.client, doc);
     56 
     57  // close the tab
     58  info("Closing the tab.");
     59  await BrowserTestUtils.removeTab(tab);
     60 });