Bug 1465670 P6 Fix fetch test framework to expect spec-compliant importScripts() behavior. r=asuth
authorBen Kelly <ben@wanderview.com>
Tue, 05 Jun 2018 10:49:12 -0700
changeset 421356 8551bb8503d67dc2d99e8ac93dfa5612e331668c
parent 421355 14c1d777809bbb05619aba08f76bb38b0f430350
child 421357 eab80a391434d02618c5f47a04eb28982dccad0c
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 P6 Fix fetch test framework to expect spec-compliant importScripts() behavior. r=asuth
dom/tests/mochitest/fetch/fetch_test_framework.js
dom/tests/mochitest/fetch/worker_wrapper.js
--- a/dom/tests/mochitest/fetch/fetch_test_framework.js
+++ b/dom/tests/mochitest/fetch/fetch_test_framework.js
@@ -69,45 +69,47 @@ function testScript(script) {
                 /Mobile|Tablet/.test(navigator.userAgent);
     if (isB2G) {
       // TODO B2G doesn't support running service workers for now due to bug 1137683.
       dump("Skipping running the test in SW until bug 1137683 gets fixed.\n");
       return Promise.resolve();
     }
     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: script });
         };
         document.body.appendChild(iframe);
       }
 
       navigator.serviceWorker.register("worker_wrapper.js", {scope: "."})
-        .then(swr => waitForState(swr.installing, 'activated', swr))
         .then(setupSW);
     });
   }
 
   function windowTest() {
     return new Promise(function(resolve, reject) {
       var scriptEl = document.createElement("script");
       scriptEl.setAttribute("src", script);
--- a/dom/tests/mochitest/fetch/worker_wrapper.js
+++ b/dom/tests/mochitest/fetch/worker_wrapper.js
@@ -7,16 +7,18 @@ function ok(a, msg) {
                       msg: a + ": " + msg, context: context});
 }
 
 function is(a, b, msg) {
   client.postMessage({type: 'status', status: a === b,
                       msg: a + " === " + b + ": " + msg, context: context});
 }
 
+var completeInstall;
+
 addEventListener('message', function workerWrapperOnMessage(e) {
   removeEventListener('message', workerWrapperOnMessage);
   var data = e.data;
 
   function loadTest(event) {
     var done = function(res) {
       client.postMessage({ type: 'finish', context: context });
       return res;
@@ -39,27 +41,32 @@ addEventListener('message', function wor
       done();
     }
   }
 
   if ("ServiceWorker" in self) {
     // Fetch requests from a service worker are not intercepted.
     self.isSWPresent = false;
 
-    e.waitUntil(self.clients.matchAll().then(function(clients) {
+    e.waitUntil(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";
       loadTest(e);
+      completeInstall();
     }));
   } else {
     client = self;
     context = "Worker";
     loadTest(e);
   }
 });
+
+addEventListener("install", e => {
+  e.waitUntil(new Promise(resolve => completeInstall = resolve));
+});