Bug 1425975 P8 Fix unregister-then-register-new-script.https.html to not race iframe.remove() and expect resurrection on failed scripts. r=asuth
authorBen Kelly <ben@wanderview.com>
Fri, 05 Jan 2018 12:10:21 -0500
changeset 397965 508a6ad11141b187ccd72ff3c2be8893cde06145
parent 397964 841e106b28101d1762d8c41740f433d19e7def92
child 397966 8449669c2adc5012c05ea09d279d4b57e6df5096
push id98650
push userbkelly@mozilla.com
push dateFri, 05 Jan 2018 17:10:31 +0000
treeherdermozilla-inbound@141238320685 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1425975
milestone59.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 1425975 P8 Fix unregister-then-register-new-script.https.html to not race iframe.remove() and expect resurrection on failed scripts. r=asuth
testing/web-platform/tests/service-workers/service-worker/unregister-then-register-new-script.https.html
--- a/testing/web-platform/tests/service-workers/service-worker/unregister-then-register-new-script.https.html
+++ b/testing/web-platform/tests/service-workers/service-worker/unregister-then-register-new-script.https.html
@@ -85,37 +85,51 @@ async_test(function(t) {
       .then(function() {
           return with_iframe(scope);
         })
       .then(function(frame) {
           iframe = frame;
           return registration.unregister();
         })
       .then(function() {
+          // Step 5.1 of Register clears the uninstall flag before fetching
+          // the script:
+          //
+          //  https://w3c.github.io/ServiceWorker/#register-algorithm
           var promise = navigator.serviceWorker.register('this-will-404',
                                                          { scope: scope });
-          iframe.remove();
           return promise;
         })
       .then(
         function() {
           assert_unreached('register should reject the promise');
         },
         function() {
+          assert_equals(registration.installing, null,
+                        'registration.installing');
+          assert_equals(registration.waiting, null,
+                        'registration.waiting');
+          assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
+                        'registration.active');
+          iframe.remove();
           return with_iframe(scope);
         })
       .then(function(frame) {
-          assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
-                        null,
-                        'document should not load with a controller');
+          assert_equals(
+              frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
+              normalizeURL(worker_url),
+              'the original worker should control a new document');
           frame.remove();
+          return registration.unregister();
+        })
+      .then(function() {
           t.done();
         })
       .catch(unreached_rejection(t));
-}, 'Registering a new script URL that 404s does not resurrect an ' +
+}, 'Registering a new script URL that 404s does resurrect an ' +
        'unregistered registration');
 
 async_test(function(t) {
     var scope = 'resources/scope/unregister-then-register-reject-install-worker';
     var iframe;
     var registration;
 
     service_worker_unregister_and_register(t, worker_url, scope)
@@ -126,34 +140,45 @@ async_test(function(t) {
       .then(function() {
           return with_iframe(scope);
         })
       .then(function(frame) {
           iframe = frame;
           return registration.unregister();
         })
       .then(function() {
+          // Step 5.1 of Register clears the uninstall flag before firing
+          // the install event:
+          //
+          //  https://w3c.github.io/ServiceWorker/#register-algorithm
           var promise = navigator.serviceWorker.register(
               'resources/reject-install-worker.js', { scope: scope });
-          iframe.remove();
           return promise;
         })
       .then(function(r) {
           registration = r;
           return wait_for_state(t, r.installing, 'redundant');
         })
       .then(function() {
+          assert_equals(registration.installing, null,
+                        'registration.installing');
+          assert_equals(registration.waiting, null,
+                        'registration.waiting');
+          assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
+                        'registration.active');
+          iframe.remove();
           return with_iframe(scope);
         })
       .then(function(frame) {
-          assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
-                        null,
-                        'document should not load with a controller');
+          assert_equals(
+              frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
+              normalizeURL(worker_url),
+              'the original worker should control a new document');
           frame.remove();
           return registration.unregister();
         })
       .then(function() {
           t.done();
         })
       .catch(unreached_rejection(t));
-  }, 'Registering a new script URL that fails to install does not resurrect ' +
+  }, 'Registering a new script URL that fails to install does resurrect ' +
        'an unregistered registration');
 </script>