From d9c0acb19f49a33b745895174248d5d394d53332 Mon Sep 17 00:00:00 2001 From: Eddy Bruel Date: Fri, 13 Nov 2015 21:54:54 +0100 Subject: [PATCH] Bug 1220740 - nsIServiceWorkerRegistrationInfo should emit an event when its worker properties change;r=amarchesini --- dom/workers/ServiceWorkerManager.cpp | 3 ++ .../test_serviceworkerregistrationinfo.xul | 44 ++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 25aef40baaf0..e9816149a1b3 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -1193,6 +1193,7 @@ public: mRegistration->mInstallingWorker = mUpdateAndInstallInfo.forget(); mRegistration->mInstallingWorker->UpdateState(ServiceWorkerState::Installing); + mRegistration->NotifyListenersOnChange(); Succeed(); // The job should NOT call fail from this point on. @@ -1360,6 +1361,7 @@ private: mRegistration->mWaitingWorker = mRegistration->mInstallingWorker.forget(); mRegistration->mWaitingWorker->UpdateState(ServiceWorkerState::Installed); + mRegistration->NotifyListenersOnChange(); swm->InvalidateServiceWorkerRegistrationWorker(mRegistration, WhichServiceWorker::INSTALLING_WORKER | WhichServiceWorker::WAITING_WORKER); @@ -1679,6 +1681,7 @@ ServiceWorkerRegistrationInfo::Activate() mActiveWorker = activatingWorker.forget(); mWaitingWorker = nullptr; mActiveWorker->UpdateState(ServiceWorkerState::Activating); + NotifyListenersOnChange(); // FIXME(nsm): Unlink appcache if there is one. diff --git a/dom/workers/test/serviceworkers/test_serviceworkerregistrationinfo.xul b/dom/workers/test/serviceworkers/test_serviceworkerregistrationinfo.xul index 58e52b8c25ba..f46657215a0a 100644 --- a/dom/workers/test/serviceworkers/test_serviceworkerregistrationinfo.xul +++ b/dom/workers/test/serviceworkers/test_serviceworkerregistrationinfo.xul @@ -41,11 +41,32 @@ "listeners when its state changes."); promise = waitForRegister(EXAMPLE_URL, function (registration) { is(registration.scriptSpec, ""); + ok(registration.installingWorker === null); + ok(registration.waitingWorker === null); + ok(registration.activeWorker === null); return waitForServiceWorkerRegistrationChange(registration, function () { is(registration.scriptSpec, EXAMPLE_URL + "worker.js"); - return registration; + return waitForServiceWorkerRegistrationChange(registration, function () { + ok(registration.installingWorker !== null); + ok(registration.waitingWorker === null); + ok(registration.activeWorker === null); + + return waitForServiceWorkerRegistrationChange(registration, function () { + ok(registration.installingWorker === null); + ok(registration.waitingWorker !== null); + ok(registration.activeWorker === null); + + return waitForServiceWorkerRegistrationChange(registration, function () { + ok(registration.installingWorker === null); + ok(registration.waitingWorker === null); + ok(registration.activeWorker !== null); + + return registration; + }); + }); + }); }); }); iframe.contentWindow.postMessage("register", "*"); @@ -54,7 +75,26 @@ promise = waitForServiceWorkerRegistrationChange(registration, function () { is(registration.scriptSpec, EXAMPLE_URL + "worker2.js"); - return registration; + return waitForServiceWorkerRegistrationChange(registration, function () { + ok(registration.installingWorker !== null); + ok(registration.waitingWorker === null); + ok(registration.activeWorker !== null); + + return waitForServiceWorkerRegistrationChange(registration, function () { + ok(registration.installingWorker === null); + ok(registration.waitingWorker !== null); + ok(registration.activeWorker !== null); + + return waitForServiceWorkerRegistrationChange(registration, function () { + ok(registration.installingWorker === null); + ok(registration.waitingWorker === null); + ok(registration.activeWorker !== null); + + return registration; + }); + }); + + }); }); iframe.contentWindow.postMessage("register", "*"); yield promise;