summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/test/browser/browser_application_panel_viewsource-service-worker.js
blob: fc6f0819b676aed55a044728bcb098905f9a3ad9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TAB_URL = URL_ROOT + "resources/service-workers/debug.html";
const SW_URL = URL_ROOT + "resources/service-workers/debug-sw.js";

add_task(async function () {
  await enableApplicationPanel();

  // disable service worker debugging
  await pushPref(
    "devtools.debugger.features.windowless-service-workers",
    false
  );

  const { panel, tab, commands } = await openNewTabAndApplicationPanel(TAB_URL);
  const doc = panel.panelWin.document;

  selectPage(panel, "service-workers");

  info("Wait until the service worker appears in the application panel");
  await waitUntil(() => getWorkerContainers(doc).length === 1);

  const container = getWorkerContainers(doc)[0];
  info("Wait until the inspect link is displayed");
  await waitUntil(() => {
    return container.querySelector(".js-inspect-link");
  });

  info("Click on the inspect link and wait for a new view-source: tab open");
  // click on the link and wait for the new tab to open
  const onTabLoaded = BrowserTestUtils.waitForNewTab(
    gBrowser,
    `view-source:${SW_URL}`
  );
  const inspectLink = container.querySelector(".js-inspect-link");
  inspectLink.click();

  const sourceTab = await onTabLoaded;
  ok(sourceTab, "The service worker source was opened in a new tab");

  // clean up
  await unregisterAllWorkers(commands.client, doc);
  // close the tabs
  info("Closing the tabs.");
  await BrowserTestUtils.removeTab(sourceTab);
  await BrowserTestUtils.removeTab(tab);
});