Bug 1251510 Wait for service worker to be active before continuing test_xslt.html tests. r=ehsan
authorBen Kelly <ben@wanderview.com>
Mon, 29 Feb 2016 14:17:46 -0500
changeset 322480 195d3130e0bfce13404d16e241373ffde7453854
parent 322479 7f425c877b1fe7bb7f3d18eb6e5c98ba857c8937
child 322481 90cef80ab3099df78dca2d48f55fb6bd23db7eaf
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1251510
milestone47.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 1251510 Wait for service worker to be active before continuing test_xslt.html tests. r=ehsan
dom/workers/test/serviceworkers/test_xslt.html
--- a/dom/workers/test/serviceworkers/test_xslt.html
+++ b/dom/workers/test/serviceworkers/test_xslt.html
@@ -15,17 +15,33 @@
 <pre id="test"></pre>
 <script class="testbody" type="text/javascript">
   var registration;
   var worker;
 
   function start() {
     return navigator.serviceWorker.register("xslt_worker.js",
                                             { scope: "./" })
-      .then((swr) => registration = swr);
+      .then((swr) => {
+        registration = swr;
+
+        // Ensure the registration is active before continuing
+        var worker = registration.installing;
+        return new Promise((resolve) => {
+          if (worker.state === 'activated') {
+            resolve();
+            return;
+          }
+          worker.addEventListener('statechange', () => {
+            if (worker.state === 'activated') {
+              resolve();
+            }
+          });
+        });
+      });
   }
 
   function unregister() {
     return registration.unregister().then(function(result) {
       ok(result, "Unregister should return true.");
     }, function(e) {
       dump("Unregistering the SW failed with " + e + "\n");
     });