Bug 1465670 P3 Fix dom/cache service worker test harness to call importScripts() during install. r=asuth
authorBen Kelly <ben@wanderview.com>
Tue, 05 Jun 2018 10:49:12 -0700
changeset 421353 8c55a618ddef81d1de47be8ac965578250e21f85
parent 421352 9eb69a99a087f43cf043235ffd3c4bd6799a33b3
child 421354 d9792e276611182498810e1f60d4c6534688f266
push id104035
push userbkelly@mozilla.com
push dateTue, 05 Jun 2018 17:49:21 +0000
treeherdermozilla-inbound@c8103e36d8cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1465670
milestone62.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 1465670 P3 Fix dom/cache service worker test harness to call importScripts() during install. r=asuth
dom/cache/test/mochitest/serviceworker_driver.js
dom/cache/test/mochitest/worker_wrapper.js
--- a/dom/cache/test/mochitest/serviceworker_driver.js
+++ b/dom/cache/test/mochitest/serviceworker_driver.js
@@ -1,37 +1,40 @@
 // Any copyright is dedicated to the Public Domain.
 // http://creativecommons.org/publicdomain/zero/1.0/
 
 function serviceWorkerTestExec(testFile) {
   return new Promise(function(resolve, reject) {
     function setupSW(registration) {
-      var worker = registration.waiting ||
+      var worker = registration.installing ||
+                   registration.waiting ||
                    registration.active;
+      var iframe;
 
       window.addEventListener("message",function onMessage(event) {
         if (event.data.context != "ServiceWorker") {
           return;
         }
         if (event.data.type == 'finish') {
           window.removeEventListener("message", onMessage);
+          iframe.remove();
           registration.unregister()
             .then(resolve)
             .catch(reject);
         } else if (event.data.type == 'status') {
           ok(event.data.status, event.data.context + ": " + event.data.msg);
         }
       });
 
       worker.onerror = reject;
 
-      var iframe = document.createElement("iframe");
+      iframe = document.createElement("iframe");
       iframe.src = "message_receiver.html";
       iframe.onload = function() {
         worker.postMessage({ script: testFile });
       };
       document.body.appendChild(iframe);
     }
 
-    navigator.serviceWorker.ready.then(setupSW);
-    navigator.serviceWorker.register("worker_wrapper.js", {scope: "."});
+    navigator.serviceWorker.register("worker_wrapper.js", {scope: "."})
+      .then(setupSW);
   });
 }
--- a/dom/cache/test/mochitest/worker_wrapper.js
+++ b/dom/cache/test/mochitest/worker_wrapper.js
@@ -87,43 +87,50 @@ function workerTestGetUserAgent(cb) {
     cb(e.data.result);
   });
   client.postMessage({
     context: context,
     type: 'getUserAgent'
   });
 }
 
+var completeInstall = null;
+
 addEventListener('message', function workerWrapperOnMessage(e) {
   removeEventListener('message', workerWrapperOnMessage);
   var data = e.data;
   function runScript() {
     try {
       importScripts(data.script);
     } catch(e) {
       client.postMessage({
         type: 'status',
         status: false,
         context: context,
         msg: 'worker failed to import ' + data.script + "; error: " + e.message
       });
     }
   }
   if ("ServiceWorker" in self) {
-    self.clients.matchAll().then(function(clients) {
+    self.clients.matchAll({ includeUncontrolled: true }).then(function(clients) {
       for (var i = 0; i < clients.length; ++i) {
         if (clients[i].url.indexOf("message_receiver.html") > -1) {
           client = clients[i];
           break;
         }
       }
       if (!client) {
         dump("We couldn't find the message_receiver window, the test will fail\n");
       }
       context = "ServiceWorker";
       runScript();
+      completeInstall();
     });
   } else {
     client = self;
     context = "Worker";
     runScript();
   }
 });
+
+addEventListener("install", e => {
+  e.waitUntil(new Promise(resolve => completeInstall = resolve));
+})