Bug 1500388 - Migrate test:browser_service_workers.js r=daisuke,Ola
authorBelén Albeza <balbeza@mozilla.com>
Tue, 22 Jan 2019 09:07:05 +0000
changeset 514802 435aedf3116a52051fc3355b45e9ae07addca589
parent 514801 58e82b793e1cedafc925c346d407f6dfe9b6781c
child 514803 f10300d5ef4e95aac0aeb495cd9cf80aa5d11521
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke, Ola
bugs1500388
milestone66.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 1500388 - Migrate test:browser_service_workers.js r=daisuke,Ola Differential Revision: https://phabricator.services.mozilla.com/D16965
devtools/client/aboutdebugging-new/test/browser/browser.ini
devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_serviceworker_runtime-page.js
devtools/client/aboutdebugging-new/test/browser/head.js
--- a/devtools/client/aboutdebugging-new/test/browser/browser.ini
+++ b/devtools/client/aboutdebugging-new/test/browser/browser.ini
@@ -49,16 +49,17 @@ skip-if = (os == "win" && ccov) # Bug 15
 [browser_aboutdebugging_routes.js]
 [browser_aboutdebugging_runtime_connection-prompt.js]
 [browser_aboutdebugging_runtime_usbclient_closed.js]
 [browser_aboutdebugging_select_network_runtime.js]
 [browser_aboutdebugging_select_page_with_serviceworker.js]
 [browser_aboutdebugging_serviceworker_multie10s.js]
 [browser_aboutdebugging_serviceworker_push.js]
 [browser_aboutdebugging_serviceworker_pushservice_url.js]
+[browser_aboutdebugging_serviceworker_runtime-page.js]
 [browser_aboutdebugging_sidebar_network_runtimes.js]
 [browser_aboutdebugging_sidebar_usb_runtime.js]
 [browser_aboutdebugging_sidebar_usb_runtime_connect.js]
 [browser_aboutdebugging_sidebar_usb_runtime_refresh.js]
 [browser_aboutdebugging_sidebar_usb_runtime_select.js]
 [browser_aboutdebugging_sidebar_usb_status.js]
 skip-if = (os == 'linux' && bits == 32) # ADB start() fails on linux 32, see Bug 1499638
 [browser_aboutdebugging_sidebar_usb_unknown_runtime.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging-new/test/browser/browser_aboutdebugging_serviceworker_runtime-page.js
@@ -0,0 +1,63 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-serviceworker.js", this);
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-collapsibilities.js", this);
+
+const SW_TAB_URL = URL_ROOT + "resources/service-workers/push-sw.html";
+const SW_URL = URL_ROOT + "resources/service-workers/push-sw.js";
+
+// This is a migration from:
+// https://searchfox.org/mozilla-central/source/devtools/client/aboutdebugging/test/browser_service_workers.js
+
+/**
+ * Test that service workers appear and dissapear from the runtime page when they
+ * are registered / unregistered.
+ */
+add_task(async function() {
+  prepareCollapsibilitiesTest();
+  await enableServiceWorkerDebugging();
+  const { document, tab, window } = await openAboutDebugging();
+  const store = window.AboutDebugging.store;
+
+  await selectThisFirefoxPage(document, store);
+
+  // check that SW list is empty
+  info("Check that the SW pane is empty");
+  let swPane = getDebugTargetPane("Service Workers", document);
+  ok(!swPane.querySelector(".js-debug-target-item"),
+    "SW list is empty");
+
+  // open a tab and register service worker
+  info("Register a service worker");
+  const swTab = await addTab(SW_TAB_URL);
+  // check that service worker is rendered
+  info("Wait for sw to appear in the debug pane list");
+  await waitUntil(() => {
+    swPane = getDebugTargetPane("Service Workers", document);
+    return swPane.querySelectorAll(".js-debug-target-item").length > 0;
+  });
+  swPane = getDebugTargetPane("Service Workers", document);
+  ok(swPane.querySelectorAll(".js-debug-target-item").length === 1,
+    "Service worker list has one element");
+  ok(swPane.querySelector(".js-debug-target-item").textContent.includes(SW_URL),
+    "Service worker list is the one we registered");
+
+  // unregister the service worker
+  info("Unregister service worker");
+  await unregisterServiceWorker(swTab);
+  // check that service worker is not rendered anymore
+  info("Wait for service worker to disappear");
+  await waitUntil(() => {
+    swPane = getDebugTargetPane("Service Workers", document);
+    return swPane.querySelectorAll(".js-debug-target-item").length === 0;
+  });
+
+  info("Remove tabs");
+  await removeTab(swTab);
+  await removeTab(tab);
+});
--- a/devtools/client/aboutdebugging-new/test/browser/head.js
+++ b/devtools/client/aboutdebugging-new/test/browser/head.js
@@ -125,16 +125,28 @@ function waitForDispatch(store, type) {
       run: (dispatch, getState, action) => {
         resolve(action);
       },
     });
   });
 }
 
 /**
+ * Navigate to "This Firefox"
+ */
+async function selectThisFirefoxPage(doc, store) {
+  info("Select This Firefox page");
+  doc.location.hash = "#/runtime/this-firefox";
+  info("Wait for requests to settle");
+  await waitForRequestsToSettle(store);
+  info("Wait for runtime page to be rendered");
+  await waitUntil(() => doc.querySelector(".js-runtime-page"));
+}
+
+/**
  * Navigate to the Connect page. Resolves when the Connect page is rendered.
  */
 async function selectConnectPage(doc) {
   const sidebarItems = doc.querySelectorAll(".js-sidebar-item");
   const connectSidebarItem = [...sidebarItems].find(element => {
     return element.textContent === "Connect";
   });
   ok(connectSidebarItem, "Sidebar contains a Connect item");