Bug 1328293 - Add test for new entry in about:debugging#workers. r=jdescottes
authorCatalin Badea <catalin.badea392@gmail.com>
Sun, 22 Jan 2017 09:03:00 +0200
changeset 377852 b108c67ae38528b3140e342dde1a41c05ef24f4f
parent 377851 abe4ae295d864e60824018314be1ad9ca702b66a
child 377853 80d47de5e1bf04fd59ba08df1e438ee4640e04d1
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,51 @@
+/* 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,6 @@
+"use strict";
+
+// Bug 1328293
+self.onfetch = function (event) {
+  // do nothing.
+};