diff --git a/dom/workers/ServiceWorkerRegistrationInfo.cpp b/dom/workers/ServiceWorkerRegistrationInfo.cpp index 5fa01bef3c2e..d6a93c1f994c 100644 --- a/dom/workers/ServiceWorkerRegistrationInfo.cpp +++ b/dom/workers/ServiceWorkerRegistrationInfo.cpp @@ -240,10 +240,8 @@ ServiceWorkerRegistrationInfo::Activate() // FIXME(nsm): Unlink appcache if there is one. - RefPtr swm = ServiceWorkerManager::GetInstance(); - swm->CheckPendingReadyPromises(); - // "Queue a task to fire a simple event named controllerchange..." + RefPtr swm = ServiceWorkerManager::GetInstance(); nsCOMPtr controllerChangeRunnable = NewRunnableMethod>( swm, &ServiceWorkerManager::FireControllerChange, this); @@ -319,6 +317,10 @@ ServiceWorkerRegistrationInfo::AsyncUpdateRegistrationStateProperties(WhichServi } else { MOZ_ASSERT(aTransition == TransitionToNextState); swm->TransitionServiceWorkerRegistrationWorker(this, aWorker); + + if (aWorker == WhichServiceWorker::WAITING_WORKER) { + swm->CheckPendingReadyPromises(); + } } } diff --git a/dom/workers/test/serviceworkers/test_worker_reference_gc_timeout.html b/dom/workers/test/serviceworkers/test_worker_reference_gc_timeout.html index a94eb2310cf8..8666495ac8c9 100644 --- a/dom/workers/test/serviceworkers/test_worker_reference_gc_timeout.html +++ b/dom/workers/test/serviceworkers/test_worker_reference_gc_timeout.html @@ -28,7 +28,6 @@ add_task(function setupPrefs() { ]}); }); -//var worker; add_task(function* test_worker_ref_gc() { let registration = yield navigator.serviceWorker.register( "lazy_worker.js", { scope: "./lazy_worker_scope_timeout"} ) @@ -45,10 +44,32 @@ add_task(function* test_worker_ref_gc() { }); }); }); - ok(true, "Got activated event!"); yield registration.unregister(); +}); + +add_task(function* test_worker_ref_gc_ready_promise() { + let wait_active = navigator.serviceWorker.ready.then(function(reg) { + SpecialPowers.exactGC(); + ok(reg.active, "Got active worker."); + ok(reg.active.state === "activating", "Worker is in activating state"); + return new Promise(function(res) { + reg.active.onstatechange = function(e) { + reg.active.onstatechange = null; + ok(reg.active.state === "activated", "Worker was activated"); + res(); + } + }); + }); + + let registration = yield navigator.serviceWorker.register( + "lazy_worker.js", { scope: "."} ); + yield wait_active; + yield registration.unregister(); +}); + +add_task(function* cleanup() { yield SpecialPowers.popPrefEnv(); });