Bug 1153292 - part 8: wait for aboutdebugging ui update after unregistering sw;r=janx draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 07 Sep 2016 15:06:48 +0200
changeset 411119 5736b3cf50d077adfe413e23d10bf21f2c1e07a9
parent 411118 0d0554452655d2537429043932d73f74f8379b24
child 530676 922f6aac4c91f4f48d2e7c2f0c748034b59419a0
push id28840
push userjdescottes@mozilla.com
push dateWed, 07 Sep 2016 16:50:43 +0000
reviewersjanx
bugs1153292
milestone51.0a1
Bug 1153292 - part 8: wait for aboutdebugging ui update after unregistering sw;r=janx MozReview-Commit-ID: 7IjTx15VeUB
devtools/client/aboutdebugging/test/browser_service_workers.js
devtools/client/aboutdebugging/test/browser_service_workers_push.js
devtools/client/aboutdebugging/test/browser_service_workers_push_service.js
devtools/client/aboutdebugging/test/browser_service_workers_start.js
devtools/client/aboutdebugging/test/browser_service_workers_status.js
devtools/client/aboutdebugging/test/browser_service_workers_timeout.js
devtools/client/aboutdebugging/test/head.js
devtools/server/actors/worker.js
--- a/devtools/client/aboutdebugging/test/browser_service_workers.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers.js
@@ -26,29 +26,23 @@ add_task(function* () {
   yield waitForMutation(serviceWorkersElement, { childList: true });
 
   // Check that the service worker appears in the UI
   let names = [...document.querySelectorAll("#service-workers .target-name")];
   names = names.map(element => element.textContent);
   ok(names.includes(SERVICE_WORKER),
     "The service worker url appears in the list: " + names);
 
-  // Finally, unregister the service worker itself
-  let aboutDebuggingUpdate = waitForMutation(serviceWorkersElement,
-    { childList: true });
-
   try {
-    yield unregisterServiceWorker(swTab);
+    yield unregisterServiceWorker(swTab, serviceWorkersElement);
     ok(true, "Service worker registration unregistered");
   } catch (e) {
     ok(false, "SW not unregistered; " + e);
   }
 
-  yield aboutDebuggingUpdate;
-
   // Check that the service worker disappeared from the UI
   names = [...document.querySelectorAll("#service-workers .target-name")];
   names = names.map(element => element.textContent);
   ok(!names.includes(SERVICE_WORKER),
     "The service worker url is no longer in the list: " + names);
 
   yield removeTab(swTab);
   yield closeAboutDebugging(tab);
--- a/devtools/client/aboutdebugging/test/browser_service_workers_push.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_push.js
@@ -87,17 +87,17 @@ add_task(function* () {
     });
   });
   pushBtn.click();
   yield onPushNotification;
   ok(true, "Service worker received a push notification");
 
   // Finally, unregister the service worker itself.
   try {
-    yield unregisterServiceWorker(swTab);
+    yield unregisterServiceWorker(swTab, serviceWorkersElement);
     ok(true, "Service worker registration unregistered");
   } catch (e) {
     ok(false, "SW not unregistered; " + e);
   }
 
   yield removeTab(swTab);
   yield closeAboutDebugging(tab);
 });
--- a/devtools/client/aboutdebugging/test/browser_service_workers_push_service.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_push_service.js
@@ -96,20 +96,21 @@ add_task(function* () {
   });
 
   // Wait for the service worker details to update again.
   yield waitForMutation(targetDetailsElement, { childList: true });
   ok(!targetContainer.querySelector(".service-worker-push-url"),
     "The push service URL should be removed");
 
   // Finally, unregister the service worker itself.
-  yield unregisterServiceWorker(swTab).then(() => {
+  try {
+    yield unregisterServiceWorker(swTab, serviceWorkersElement);
     ok(true, "Service worker registration unregistered");
-  }).catch(function (e) {
-    ok(false, "Service worker not unregistered; " + e);
-  });
+  } catch (e) {
+    ok(false, "SW not unregistered; " + e);
+  }
 
   info("Unmock the push service");
   PushService.service = null;
 
   yield removeTab(swTab);
   yield closeAboutDebugging(tab);
 });
--- a/devtools/client/aboutdebugging/test/browser_service_workers_start.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_start.js
@@ -79,17 +79,17 @@ add_task(function* () {
   yield onStarted;
 
   // Check that we have a Debug button but not a Start button again.
   ok(targetElement.querySelector(".debug-button"), "Found its debug button");
   ok(!targetElement.querySelector(".start-button"), "No start button");
 
   // Finally, unregister the service worker itself.
   try {
-    yield unregisterServiceWorker(swTab);
+    yield unregisterServiceWorker(swTab, serviceWorkersElement);
     ok(true, "Service worker registration unregistered");
   } catch (e) {
     ok(false, "SW not unregistered; " + e);
   }
 
   yield removeTab(swTab);
   yield closeAboutDebugging(tab);
 });
--- a/devtools/client/aboutdebugging/test/browser_service_workers_status.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_status.js
@@ -4,16 +4,18 @@
 "use strict";
 
 // Service workers can't be loaded from chrome://,
 // but http:// is ok with dom.serviceWorkers.testing.enabled turned on.
 const SERVICE_WORKER = URL_ROOT + "service-workers/delay-sw.js";
 const TAB_URL = URL_ROOT + "service-workers/delay-sw.html";
 const SW_TIMEOUT = 2000;
 
+requestLongerTimeout(2);
+
 add_task(function* () {
   yield SpecialPowers.pushPrefEnv({
     "set": [
       // Accept workers from mochitest's http.
       ["dom.serviceWorkers.testing.enabled", true],
       ["dom.serviceWorkers.idle_timeout", SW_TIMEOUT],
       ["dom.serviceWorkers.idle_extended_timeout", SW_TIMEOUT],
     ]
@@ -47,29 +49,23 @@ add_task(function* () {
   is(status.textContent, "Registering", "Service worker is currently registering");
 
   yield waitForMutation(serviceWorkersElement, { childList: true, subtree: true });
   is(status.textContent, "Running", "Service worker is currently running");
 
   yield waitForMutation(serviceWorkersElement, { attributes: true, subtree: true });
   is(status.textContent, "Stopped", "Service worker is currently stopped");
 
-  // Finally, unregister the service worker itself
-  let aboutDebuggingUpdate = waitForMutation(serviceWorkersElement,
-    { childList: true });
-
   try {
-    yield unregisterServiceWorker(swTab);
+    yield unregisterServiceWorker(swTab, serviceWorkersElement);
     ok(true, "Service worker unregistered");
   } catch (e) {
     ok(false, "Service worker not unregistered; " + e);
   }
 
-  yield aboutDebuggingUpdate;
-
   // Check that the service worker disappeared from the UI
   names = [...document.querySelectorAll("#service-workers .target-name")];
   names = names.map(element => element.textContent);
   ok(!names.includes(SERVICE_WORKER),
     "The service worker url is no longer in the list: " + names);
 
   yield removeTab(swTab);
   yield closeAboutDebugging(tab);
--- a/devtools/client/aboutdebugging/test/browser_service_workers_timeout.js
+++ b/devtools/client/aboutdebugging/test/browser_service_workers_timeout.js
@@ -72,22 +72,19 @@ add_task(function* () {
   // after we destroy the toolbox.
   // The DEBUG button should disappear once the worker is destroyed.
   yield waitForMutation(targetElement, { childList: true });
   ok(!targetElement.querySelector(".debug-button"),
     "The debug button was removed when the worker was killed");
 
   // Finally, unregister the service worker itself.
   try {
-    yield unregisterServiceWorker(swTab);
+    yield unregisterServiceWorker(swTab, serviceWorkersElement);
     ok(true, "Service worker registration unregistered");
   } catch (e) {
     ok(false, "SW not unregistered; " + e);
   }
 
-  // Now ensure that the worker registration is correctly removed.
-  // The list should update once the registration is destroyed.
-  yield waitForMutation(serviceWorkersElement, { childList: true });
   assertHasTarget(false, document, "service-workers", SERVICE_WORKER);
 
   yield removeTab(swTab);
   yield closeAboutDebugging(tab);
 });
--- a/devtools/client/aboutdebugging/test/head.js
+++ b/devtools/client/aboutdebugging/test/head.js
@@ -295,27 +295,32 @@ function waitForServiceWorkerRegistered(
     // Retrieve the `sw` promise created in the html page.
     let { sw } = content.wrappedJSObject;
     yield sw;
   });
 }
 
 /**
  * Asks the service worker within the test page to unregister, and returns a
- * promise that will resolve when it has successfully unregistered itself.
+ * promise that will resolve when it has successfully unregistered itself and the
+ * about:debugging UI has fully processed this update.
+ *
  * @param {Tab} tab
+ * @param {Node} serviceWorkersElement
  * @return {Promise} Resolves when the service worker is unregistered.
  */
-function unregisterServiceWorker(tab) {
-  return ContentTask.spawn(tab.linkedBrowser, {}, function* () {
+function* unregisterServiceWorker(tab, serviceWorkersElement) {
+  let onMutation = waitForMutation(serviceWorkersElement, { childList: true });
+  yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
     // Retrieve the `sw` promise created in the html page
     let { sw } = content.wrappedJSObject;
     let registration = yield sw;
     yield registration.unregister();
   });
+  return onMutation;
 }
 
 /**
  * Waits for the creation of a new window, usually used with create private
  * browsing window.
  * Returns a promise that will resolve when the window is successfully created.
  * @param {window} win
  */
--- a/devtools/server/actors/worker.js
+++ b/devtools/server/actors/worker.js
@@ -376,16 +376,18 @@ protocol.ActorClassWithSpec(serviceWorke
    * @param ServiceWorkerRegistrationInfo registration
    *   The registration's information.
    */
   initialize(conn, registration) {
     protocol.Actor.prototype.initialize.call(this, conn);
     this._conn = conn;
     this._registration = registration;
     this._pushSubscriptionActor = null;
+    console.log("@@@@ SHOULD BE ADDING REGISTRATION HERE for:" + registration.scriptSpec);
+
     this._registration.addListener(this);
 
     let {installingWorker, waitingWorker, activeWorker} = registration;
     this._installingWorker = new ServiceWorkerActor(conn, installingWorker);
     this._activeWorker = new ServiceWorkerActor(conn, activeWorker);
     this._waitingWorker = new ServiceWorkerActor(conn, waitingWorker);
 
     Services.obs.addObserver(this, PushService.subscriptionModifiedTopic, false);
@@ -417,16 +419,17 @@ protocol.ActorClassWithSpec(serviceWorke
       activeWorker: this._activeWorker.form(),
       waitingWorker: this._waitingWorker.form(),
     };
   },
 
   destroy() {
     protocol.Actor.prototype.destroy.call(this);
     Services.obs.removeObserver(this, PushService.subscriptionModifiedTopic, false);
+    console.log("@@@@ SHOULD BE REMOVING REGISTRATION HERE for:" + this._registration.scriptSpec);
     this._registration.removeListener(this);
     this._registration = null;
     if (this._pushSubscriptionActor) {
       this._pushSubscriptionActor.destroy();
     }
     this._pushSubscriptionActor = null;
 
     this._installingWorker.destroy();
@@ -528,18 +531,20 @@ ServiceWorkerRegistrationActorList.proto
     let registrations = new Set();
     let array = swm.getAllRegistrations();
     for (let index = 0; index < array.length; ++index) {
       registrations.add(
         array.queryElementAt(index, Ci.nsIServiceWorkerRegistrationInfo));
     }
 
     // Delete each actor for which we don't have a registration.
-    for (let [registration, ] of this._actors) {
+    for (let [registration] of this._actors) {
       if (!registrations.has(registration)) {
+        console.log("@@@@ REMOVING REGISTRATION for " + registration.scriptSpec);
+        // this._actors.get(registration).destroy();
         this._actors.delete(registration);
       }
     }
 
     // Create an actor for each registration for which we don't have one.
     for (let registration of registrations) {
       if (!this._actors.has(registration)) {
         this._actors.set(registration,