Bug 1458808 - add test to debug serviceworker from application panel;r=jlast,ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 17 Apr 2018 19:16:56 +0200
changeset 419805 857fce2b698bc4340b600a78a38f352480db18ff
parent 419804 12301019225960647c08823cfc450a396e47a0ae
child 419806 0ef665046a0627777f04209b363a25a94f73bf43
push id64435
push userjdescottes@mozilla.com
push dateFri, 25 May 2018 09:25:45 +0000
treeherderautoland@857fce2b698b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlast, ladybenko
bugs1458808
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458808 - add test to debug serviceworker from application panel;r=jlast,ladybenko MozReview-Commit-ID: EXQAnjycyco
devtools/client/aboutdebugging/test/browser_service_workers_timeout.js
devtools/client/application/src/components/Worker.js
devtools/client/application/test/browser.ini
devtools/client/application/test/browser_application_panel_debug-service-worker.js
devtools/client/application/test/service-workers/debug-sw.js
devtools/client/application/test/service-workers/debug.html
--- a/devtools/client/aboutdebugging/test/browser_service_workers_timeout.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_timeout.js
@@ -34,17 +34,17 @@ add_task(async function() {
   let name = names.filter(element => element.textContent === SERVICE_WORKER)[0];
   ok(name, "Found the service worker in the list");
   let targetElement = name.parentNode.parentNode;
   let debugBtn = targetElement.querySelector(".debug-button");
   ok(debugBtn, "Found its debug button");
 
   // Click on it and wait for the toolbox to be ready
   let onToolboxReady = new Promise(done => {
-    gDevTools.once("toolbox-ready", function(e, toolbox) {
+    gDevTools.once("toolbox-ready", function(toolbox) {
       done(toolbox);
     });
   });
   debugBtn.click();
 
   let toolbox = await onToolboxReady;
 
   // Wait for more than the regular timeout,
--- a/devtools/client/application/src/components/Worker.js
+++ b/devtools/client/application/src/components/Worker.js
@@ -122,17 +122,17 @@ class Worker extends Component {
       },
         Strings.GetStringFromName("unregister"))
       : null;
 
     const debugLinkDisabled = this.isRunning() ? "" : "worker__debug-link--disabled";
     const debugLink = a({
       onClick: this.isRunning() ? this.debug : null,
       title: this.isRunning() ? null : "Only running service workers can be debugged",
-      className: `${debugLinkDisabled} worker__debug-link`
+      className: `${debugLinkDisabled} worker__debug-link js-debug-link`
     },
       Strings.GetStringFromName("debug"));
 
     const startLink = !this.isRunning() ?
       a({ onClick: this.start, className: "worker__start-link" },
         Strings.GetStringFromName("start"))
       : null;
 
--- a/devtools/client/application/test/browser.ini
+++ b/devtools/client/application/test/browser.ini
@@ -1,19 +1,23 @@
 [DEFAULT]
 tags = devtools
 subsuite = devtools
 support-files =
   head.js
+  service-workers/debug-sw.js
+  service-workers/debug.html
   service-workers/dynamic-registration.html
   service-workers/empty.html
   service-workers/empty-sw.js
   service-workers/scope-page.html
   service-workers/simple.html
   service-workers/simple-unicode.html
+  !/devtools/client/debugger/new/test/mochitest/helpers.js
   !/devtools/client/shared/test/frame-script-utils.js
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
+[browser_application_panel_debug-service-worker.js]
 [browser_application_panel_list-domain-workers.js]
 [browser_application_panel_list-several-workers.js]
 [browser_application_panel_list-single-worker.js]
 [browser_application_panel_list-unicode.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/test/browser_application_panel_debug-service-worker.js
@@ -0,0 +1,60 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from ../../debugger/new/test/mochitest/helpers.js */
+Services.scriptloader.loadSubScript(
+  "chrome://mochitests/content/browser/devtools/client/debugger/new/test/mochitest/helpers.js",
+  this);
+
+const TAB_URL = URL_ROOT + "service-workers/debug.html";
+
+add_task(async function() {
+  await enableApplicationPanel();
+
+  let { panel, tab, target } = await openNewTabAndApplicationPanel(TAB_URL);
+  let doc = panel.panelWin.document;
+
+  info("Wait until the service worker appears in the application panel");
+  await waitUntil(() => getWorkerContainers(doc).length === 1);
+
+  let container = getWorkerContainers(doc)[0];
+  info("Wait until the debug link is displayed and enabled");
+  await waitUntil(() =>
+    container.querySelector(".js-debug-link:not(.worker__debug-link--disabled)"));
+
+  info("Click on the debug link and wait for the new toolbox to be ready");
+  let onToolboxReady = gDevTools.once("toolbox-ready");
+
+  let debugLink = container.querySelector(".js-debug-link");
+  debugLink.click();
+
+  let serviceWorkerToolbox = await onToolboxReady;
+  await serviceWorkerToolbox.selectTool("jsdebugger");
+  let debuggerContext = createDebuggerContext(serviceWorkerToolbox);
+
+  await waitForSources(debuggerContext, "debug-sw.js");
+  await selectSource(debuggerContext, "debug-sw.js");
+  await waitForLoadedSource(debuggerContext, "debug-sw.js");
+
+  await addBreakpoint(debuggerContext, "debug-sw.js", 8);
+
+  info("Reload the main tab, expect the service worker script to pause on line 8");
+  tab.linkedBrowser.reload();
+
+  await waitForPaused(debuggerContext);
+  assertPausedLocation(debuggerContext);
+  await resume(debuggerContext);
+
+  const workerScript = findSource(debuggerContext, "debug-sw.js");
+  await removeBreakpoint(debuggerContext, workerScript.id, 8, 0);
+
+  info("Destroy the worker toolbox");
+  await serviceWorkerToolbox.destroy();
+
+  info("Wait until the focus goes back to the main window");
+  await waitUntil(() => gBrowser.selectedBrowser === tab.linkedBrowser);
+
+  await unregisterAllWorkers(target.client);
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/test/service-workers/debug-sw.js
@@ -0,0 +1,10 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Bug 1328293
+self.onfetch = function(event) {
+  let a = 5;
+  console.log(a);
+};
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/test/service-workers/debug.html
@@ -0,0 +1,16 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>Service worker test</title>
+</head>
+<body>
+<script type="text/javascript">
+"use strict";
+window.sw = navigator.serviceWorker.register("debug-sw.js");
+</script>
+</body>
+</html>