Bug 1465670 P5 Fix test_serviceworker_interfaces.html to expect spec importScript behavior. r=asuth
authorBen Kelly <ben@wanderview.com>
Tue, 05 Jun 2018 10:49:12 -0700
changeset 421355 14c1d777809bbb05619aba08f76bb38b0f430350
parent 421354 d9792e276611182498810e1f60d4c6534688f266
child 421356 8551bb8503d67dc2d99e8ac93dfa5612e331668c
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 P5 Fix test_serviceworker_interfaces.html to expect spec importScript behavior. r=asuth
dom/serviceworkers/test/serviceworker_wrapper.js
dom/serviceworkers/test/test_serviceworker_interfaces.html
--- a/dom/serviceworkers/test/serviceworker_wrapper.js
+++ b/dom/serviceworkers/test/serviceworker_wrapper.js
@@ -78,24 +78,36 @@ function workerTestGetStorageManager(cb)
     removeEventListener('message', workerTestGetStorageManagerCB);
     cb(e.data.result);
   });
   client.postMessage({
     type: 'getStorageManager'
   });
 }
 
+var completeInstall;
+
 addEventListener('message', function workerWrapperOnMessage(e) {
   removeEventListener('message', workerWrapperOnMessage);
   var data = e.data;
-  self.clients.matchAll().then(function(clients) {
-    client = clients[0];
+  self.clients.matchAll({ includeUncontrolled: true }).then(function(clients) {
+    for (var i = 0; i < clients.length; ++i) {
+      if (clients[i].url.includes("message_receiver.html")) {
+        client = clients[i];
+        break;
+      }
+    }
     try {
       importScripts(data.script);
     } catch(e) {
       client.postMessage({
         type: 'status',
         status: false,
         msg: 'worker failed to import ' + data.script + "; error: " + e.message
       });
     }
+    completeInstall();
   });
 });
+
+addEventListener('install', e => {
+  e.waitUntil(new Promise(resolve => completeInstall = resolve));
+});
--- a/dom/serviceworkers/test/test_serviceworker_interfaces.html
+++ b/dom/serviceworkers/test/test_serviceworker_interfaces.html
@@ -7,20 +7,23 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
   <script type="text/javascript" src="../worker_driver.js"></script>
 </head>
 <body>
 <script class="testbody" type="text/javascript">
 
   function setupSW(registration) {
-    var worker = registration.waiting ||
+    var iframe;
+    var worker = registration.installing ||
+                 registration.waiting ||
                  registration.active;
     window.onmessage = function(event) {
       if (event.data.type == 'finish') {
+        iframe.remove();
         registration.unregister().then(function(success) {
           ok(success, "The service worker should be unregistered successfully");
 
           SimpleTest.finish();
         }, function(e) {
           dump("Unregistering the SW failed with " + e + "\n");
           SimpleTest.finish();
         });
@@ -58,27 +61,27 @@
       }
     }
 
     worker.onerror = function(event) {
       ok(false, 'Worker had an error: ' + event.data);
       SimpleTest.finish();
     };
 
-    var iframe = document.createElement("iframe");
+    iframe = document.createElement("iframe");
     iframe.src = "message_receiver.html";
     iframe.onload = function() {
       worker.postMessage({ script: "test_serviceworker_interfaces.js" });
     };
     document.body.appendChild(iframe);
   }
 
   function runTest() {
-    navigator.serviceWorker.ready.then(setupSW);
-    navigator.serviceWorker.register("serviceworker_wrapper.js", {scope: "."});
+    navigator.serviceWorker.register("serviceworker_wrapper.js", {scope: "."})
+      .then(setupSW);
   }
 
   SimpleTest.waitForExplicitFinish();
   onload = function() {
     // The handling of "dom.caches.enabled" here is a bit complicated.  What we
     // want to happen is that Cache is always enabled in service workers.  So
     // if service workers are disabled by default we want to force on both
     // service workers and "dom.caches.enabled".  But if service workers are