Bug 1328293 - Add test for new entry in about:debugging#workers. r=jdescottes
☠☠ backed out by 14b3fa51bb12 ☠ ☠
authorCatalin Badea <catalin.badea392@gmail.com>
Sat, 21 Jan 2017 21:19:35 +0200
changeset 377834 a76a454541fc9a40f46129e960e4eb3f74af6389
parent 377833 42823a93cd1600cbb59e7eafa97a7ad82f0cbb85
child 377835 14b3fa51bb1261b74b50f440d7410f46c7960d2c
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1328293
milestone53.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 1328293 - Add test for new entry in about:debugging#workers. r=jdescottes
devtools/client/aboutdebugging/test/browser.ini
devtools/client/aboutdebugging/test/browser_service_workers_fetch_flag.js
devtools/client/aboutdebugging/test/service-workers/fetch-sw.html
devtools/client/aboutdebugging/test/service-workers/fetch-sw.js
--- a/devtools/client/aboutdebugging/test/browser.ini
+++ b/devtools/client/aboutdebugging/test/browser.ini
@@ -8,16 +8,18 @@ support-files =
   addons/bad/manifest.json
   addons/bug1273184.xpi
   addons/test-devtools-webextension/*
   addons/test-devtools-webextension-nobg/*
   service-workers/delay-sw.html
   service-workers/delay-sw.js
   service-workers/empty-sw.html
   service-workers/empty-sw.js
+  service-workers/fetch-sw.html
+  service-workers/fetch-sw.js
   service-workers/push-sw.html
   service-workers/push-sw.js
   !/devtools/client/framework/test/shared-head.js
 
 [browser_addons_debug_bootstrapped.js]
 [browser_addons_debug_webextension.js]
 tags = webextensions
 [browser_addons_debug_webextension_inspector.js]
@@ -27,16 +29,17 @@ tags = webextensions
 [browser_addons_debug_webextension_popup.js]
 tags = webextensions
 [browser_addons_debugging_initial_state.js]
 [browser_addons_install.js]
 [browser_addons_reload.js]
 [browser_addons_toggle_debug.js]
 [browser_page_not_found.js]
 [browser_service_workers.js]
+[browser_service_workers_fetch_flag.js]
 [browser_service_workers_not_compatible.js]
 [browser_service_workers_push.js]
 [browser_service_workers_push_service.js]
 [browser_service_workers_start.js]
 [browser_service_workers_status.js]
 [browser_service_workers_timeout.js]
 skip-if = true # Bug 1232931
 [browser_service_workers_unregister.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_fetch_flag.js
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Service workers can't be loaded from chrome://,
+// but http:// is ok with dom.serviceWorkers.testing.enabled turned on.
+const EMPTY_SW_TAB_URL = URL_ROOT + "service-workers/empty-sw.html";
+const FETCH_SW_TAB_URL = URL_ROOT + "service-workers/fetch-sw.html";
+
+function* testBody(url, expecting) {
+  yield new Promise(done => {
+    let options = {"set": [
+      ["dom.serviceWorkers.enabled", true],
+      ["dom.serviceWorkers.testing.enabled", true],
+    ]};
+    SpecialPowers.pushPrefEnv(options, done);
+  });
+
+  let { tab, document } = yield openAboutDebugging("workers");
+
+  let swTab = yield addTab(url);
+
+  let serviceWorkersElement = getServiceWorkerList(document);
+  yield waitForMutation(serviceWorkersElement, { childList: true });
+
+  let fetchFlags = [...document.querySelectorAll("#service-workers .service-worker-fetch-flag")];
+  fetchFlags = fetchFlags.map(element => element.textContent);
+  ok(fetchFlags.includes(expecting), "Found correct fetch flag.");
+
+  try {
+    yield unregisterServiceWorker(swTab, serviceWorkersElement);
+    ok(true, "Service worker registration unregistered");
+  } catch (e) {
+    ok(false, "SW not unregistered; " + e);
+  }
+
+  // Check that the service worker disappeared from the UI
+  let names = [...document.querySelectorAll("#service-workers .target-name")];
+  names = names.map(element => element.textContent);
+  ok(names.length == 0, "All service workers were removed from the list.");
+
+  yield removeTab(swTab);
+  yield closeAboutDebugging(tab);
+}
+
+add_task(function* () {
+  yield testBody(FETCH_SW_TAB_URL, "Listening for fetch events.");
+  yield testBody(EMPTY_SW_TAB_URL, "Not listening for fetch events.");
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/service-workers/fetch-sw.html
@@ -0,0 +1,22 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="UTF-8">
+  <title>Service worker test</title>
+</head>
+<body>
+<script type="text/javascript">
+"use strict";
+
+var sw = navigator.serviceWorker.register("fetch-sw.js", {scope: "fetch-sw/"});
+sw.then(
+  function () {
+    dump("SW registered\n");
+  },
+  function (e) {
+    dump("SW not registered: " + e + "\n");
+  }
+);
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/service-workers/fetch-sw.js
@@ -0,0 +1,4 @@
+// Bug 1328293
+onfetch = function(event) {
+  // do nothing.
+}