Bug 1450064 - Add test for showing service workers from the current domain only. r=jdescottes
authorBelén Albeza <balbeza@mozilla.com>
Fri, 27 Apr 2018 12:21:04 +0200
changeset 416795 e840531c844fa7e7a811a37da9d8889b5860a308
parent 416794 ee5fa77bd63b9a9d1d3c6fc571ca25de2d4578db
child 416796 0ec4c004635096307b1a8e6d787046ca1fbf9d49
push id33938
push useraciure@mozilla.com
push dateThu, 03 May 2018 21:51:21 +0000
treeherdermozilla-central@06915b0dce57 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1450064
milestone61.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 1450064 - Add test for showing service workers from the current domain only. r=jdescottes MozReview-Commit-ID: 6aulfLwLjR6
devtools/client/application/test/browser.ini
devtools/client/application/test/browser_application_panel_list-domain-workers.js
--- a/devtools/client/application/test/browser.ini
+++ b/devtools/client/application/test/browser.ini
@@ -5,10 +5,11 @@ support-files =
   head.js
   service-workers/dynamic-registration.html
   service-workers/empty-sw.js
   service-workers/scope-page.html
   service-workers/simple.html
   !/devtools/client/shared/test/frame-script-utils.js
   !/devtools/client/shared/test/shared-head.js
 
+[browser_application_panel_list-domain-workers.js]
 [browser_application_panel_list-several-workers.js]
 [browser_application_panel_list-single-worker.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/application/test/browser_application_panel_list-domain-workers.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Check that the application panel only displays service workers from the
+ * current domain.
+ */
+
+const SIMPLE_URL = URL_ROOT + "service-workers/simple.html";
+const OTHER_URL = SIMPLE_URL.replace("example.com", "test1.example.com");
+const EMPTY_URL = (URL_ROOT + "service-workers/empty.html")
+  .replace("example.com", "test2.example.com");
+
+add_task(async function() {
+  await enableApplicationPanel();
+
+  let { panel, target } = await openNewTabAndApplicationPanel(SIMPLE_URL);
+  let doc = panel.panelWin.document;
+
+  info("Wait until the service worker appears in the application panel");
+  await waitUntil(() => getWorkerContainers(doc).length === 1);
+
+  let scopeEl = getWorkerContainers(doc)[0].querySelector(".service-worker-scope");
+  ok(scopeEl.textContent.startsWith("example.com"),
+    "First service worker registration is displayed for the correct domain");
+
+  info(
+    "Navigate to another page for a different domain with no service worker");
+
+  await navigate(target, EMPTY_URL);
+  await waitUntil(() => doc.querySelector(".worker-list-empty") !== null);
+  ok(true, "No service workers are shown for an empty page in a different domain.");
+
+  info(
+    "Navigate to another page for a different domain with another service worker");
+  await navigate(target, OTHER_URL);
+
+  info("Wait until the service worker appears in the application panel");
+  await waitUntil(() => getWorkerContainers(doc).length === 1);
+
+  scopeEl = getWorkerContainers(doc)[0].querySelector(".service-worker-scope");
+  ok(scopeEl.textContent.startsWith("test1.example.com"),
+    "Second service worker registration is displayed for the correct domain");
+
+  let unregisterWorkers = async function() {
+    while (getWorkerContainers(doc).length > 0) {
+      let count = getWorkerContainers(doc).length;
+
+      await waitUntil(() => getWorkerContainers(doc)[0]
+        .querySelector(".unregister-button"));
+
+      info("Click on the unregister button for the first service worker");
+      getWorkerContainers(doc)[0]
+        .querySelector(".unregister-button")
+        .click();
+
+      info("Wait until the service worker is removed from the application panel");
+      await waitUntil(() => getWorkerContainers(doc).length == count - 1);
+    }
+  };
+
+  await unregisterWorkers();
+  await navigate(target, SIMPLE_URL);
+  await unregisterWorkers();
+});