Bug 1186856 - ServiceWorker .register() should always stop current registration from uninstalling. r=jdm, a=ritu
authorBen Kelly <ben@wanderview.com>
Thu, 19 Nov 2015 17:42:09 -0800
changeset 305619 ffdc3e33fc9ebab045a21dbb444b441b9756b7b2
parent 305618 527f7615ef42091d9d6f12959b2819f6b88c5202
child 305620 8a55efc59eae6de1e53d240cdb81c37e8816c5c1
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm, ritu
bugs1186856
milestone44.0a2
Bug 1186856 - ServiceWorker .register() should always stop current registration from uninstalling. r=jdm, a=ritu
dom/workers/ServiceWorkerManager.cpp
testing/web-platform/mozilla/meta/service-workers/service-worker/unregister-then-register-new-script.https.html.ini
testing/web-platform/mozilla/tests/service-workers/service-worker/unregister-then-register-new-script.https.html
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -858,20 +858,20 @@ public:
       swm->AppendPendingOperation(runnable);
       return;
     }
 
     if (mJobType == REGISTER_JOB) {
       mRegistration = swm->GetRegistration(mPrincipal, mScope);
 
       if (mRegistration) {
+        mRegistration->mPendingUninstall = false;
         RefPtr<ServiceWorkerInfo> newest = mRegistration->Newest();
         if (newest && mScriptSpec.Equals(newest->ScriptSpec()) &&
             mScriptSpec.Equals(mRegistration->mScriptSpec)) {
-          mRegistration->mPendingUninstall = false;
           swm->StoreRegistration(mPrincipal, mRegistration);
           Succeed();
 
           // Done() must always be called async from Start()
           nsCOMPtr<nsIRunnable> runnable =
             NS_NewRunnableMethodWithArg<nsresult>(
               this,
               &ServiceWorkerRegisterJob::Done,
deleted file mode 100644
--- a/testing/web-platform/mozilla/meta/service-workers/service-worker/unregister-then-register-new-script.https.html.ini
+++ /dev/null
@@ -1,8 +0,0 @@
-[unregister-then-register-new-script.https.html]
-  type: testharness
-  [Registering a new script URL while an unregistered registration is in use]
-    expected: FAIL
-
-  [Registering a new script URL that fails to install does not resurrect an unregistered registration]
-    expected: FAIL
-
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/unregister-then-register-new-script.https.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/unregister-then-register-new-script.https.html
@@ -98,24 +98,24 @@ async_test(function(t) {
       .then(
         function() {
           assert_unreached('register should reject the promise');
         },
         function() {
           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),
+                        'register() should always abort uninstalling the registration');
           frame.remove();
           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)
@@ -139,21 +139,21 @@ async_test(function(t) {
       .then(function(r) {
           registration = r;
           return wait_for_state(t, r.installing, 'redundant');
         })
       .then(function() {
           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),
+                        'register() should always abort uninstalling the registration');
           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>