Bug 1273920 P2 Fix register-wait-forever-in-install-worker.https.html to expect new unified service worker job queue behavior. r=asuth
authorBen Kelly <ben@wanderview.com>
Tue, 24 May 2016 14:08:20 -0700
changeset 337821 be3124589d82e31f292fcee8ef04546f9e1627c1
parent 337820 5e7f47c7f2b9d3f2af92369c26e91e6de94d9eab
child 337822 013b6cecd6ead3f2ef504202cbd240ae95d60541
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1273920
milestone49.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 1273920 P2 Fix register-wait-forever-in-install-worker.https.html to expect new unified service worker job queue behavior. r=asuth
testing/web-platform/tests/service-workers/service-worker/register-wait-forever-in-install-worker.https.html
testing/web-platform/tests/service-workers/service-worker/resources/wait-forever-in-install-worker.js
--- a/testing/web-platform/tests/service-workers/service-worker/register-wait-forever-in-install-worker.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/register-wait-forever-in-install-worker.https.html
@@ -5,23 +5,49 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="resources/test-helpers.sub.js"></script>
 <script>
 
 promise_test(function(t) {
     var bad_script = 'resources/wait-forever-in-install-worker.js';
     var good_script = 'resources/empty-worker.js';
     var scope = 'resources/wait-forever-in-install-worker';
+    var other_scope = 'resources/wait-forever-in-install-worker-other';
+    var registration;
+    var registerPromise;
+
     return navigator.serviceWorker.register(bad_script, {scope: scope})
-      .then(function(registration) {
+      .then(function(r) {
+          registration = r;
           assert_equals(registration.installing.scriptURL,
                         normalizeURL(bad_script));
-          return navigator.serviceWorker.register(good_script, {scope: scope});
+
+          // This register job should not start until the first
+          // register for the same scope completes.
+          registerPromise =
+            navigator.serviceWorker.register(good_script, {scope: scope});
+
+          // In order to test that the above register does not complete
+          // we will perform a register() on a different scope.  The
+          // assumption here is that the previous register call would
+          // have completed in the same timeframe if it was able to do
+          // so.
+          return navigator.serviceWorker.register(good_script,
+                                                  {scope: other_scope});
         })
-      .then(function(registration) {
+      .then(function(swr) {
+          return swr.unregister();
+        })
+      .then(function() {
+          assert_equals(registration.installing.scriptURL,
+                        normalizeURL(bad_script));
+          registration.installing.postMessage('STOP_WAITING');
+          return registerPromise;
+        })
+      .then(function(swr) {
           assert_equals(registration.installing.scriptURL,
                         normalizeURL(good_script));
           return wait_for_state(t, registration.installing, 'activated');
         })
       .then(function() {
           return service_worker_unregister_and_done(t, scope);
         })
   }, 'register worker that calls waitUntil with a promise that never ' +
--- a/testing/web-platform/tests/service-workers/service-worker/resources/wait-forever-in-install-worker.js
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/wait-forever-in-install-worker.js
@@ -1,3 +1,12 @@
+var waitUntilResolve;
 self.addEventListener('install', function(event) {
-    event.waitUntil(new Promise(function() {}));
+    event.waitUntil(new Promise(function(resolve) {
+        waitUntilResolve = resolve;
+      }));
   });
+
+self.addEventListener('message', function(event) {
+    if (event.data === 'STOP_WAITING') {
+      waitUntilResolve();
+    }
+  });