Support serviceWorkerRegistration.update() inside service workers
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Dec 2017 02:32:42 +0000 (02:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Dec 2017 02:32:42 +0000 (02:32 +0000)
commit49db0ef67dcbce1f0d599c8762cba4e0bb6261f8
treec7b5e8265a7a8f7da98f6f46450ccfbe84af5985
parent5f773baa7ba0046786677452fe7a295e69189908
Support serviceWorkerRegistration.update() inside service workers
https://bugs.webkit.org/show_bug.cgi?id=180215

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaseline WPT test that no longer times out. The test still fails even
though we support update(). The issue is that the second frame load
uses the new worker (because of the update()) instead of the old one.
The test seems to expect that the new service worker is still in
waiting state at the point the second frame is loaded. However, for us
it is already activated.

* web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt:

Source/WebCore:

Support serviceWorkerRegistration.update() inside service workers. The code paths
for job scheduling and resolution have been made thread safe by hopping to the right
thread when necessary. In particular, ServiceWorkerContainer always makes sure to to
a callOnMainThread() before calling methods on the SWClientConnection. Also, the
SWClientConnection relies on a new postTaskTo() method before calling methods on the
job.

Test: http/tests/workers/service/self_registration_update.html

* workers/service/SWClientConnection.cpp:
(WebCore::SWClientConnection::scheduleJob):
(WebCore::SWClientConnection::finishedFetchingScript):
(WebCore::SWClientConnection::failedFetchingScript):
(WebCore::SWClientConnection::jobRejectedInServer):
(WebCore::SWClientConnection::registrationJobResolvedInServer):
(WebCore::SWClientConnection::unregistrationJobResolvedInServer):
(WebCore::SWClientConnection::startScriptFetchForServer):
(WebCore::SWClientConnection::postMessageToServiceWorkerClient):
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::SWClientConnection::updateWorkerState):
(WebCore::SWClientConnection::fireUpdateFoundEvent):
(WebCore::SWClientConnection::notifyClientsOfControllerChange):
(WebCore::SWClientConnection::clearPendingJobs):
(WebCore::SWClientConnection::postTaskTo):
* workers/service/SWClientConnection.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::scheduleJob):
(WebCore::ServiceWorkerContainer::jobFailedWithException):
(WebCore::ServiceWorkerContainer::scheduleTaskToFireUpdateFoundEvent):
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
(WebCore::ServiceWorkerContainer::jobResolvedWithUnregistrationResult):
(WebCore::ServiceWorkerContainer::startScriptFetchForJob):
(WebCore::ServiceWorkerContainer::jobFinishedLoadingScript):
(WebCore::ServiceWorkerContainer::jobFailedLoadingScript):
(WebCore::ServiceWorkerContainer::jobDidFinish):
(WebCore::ServiceWorkerContainer::addRegistration):
(WebCore::ServiceWorkerContainer::removeRegistration):
(WebCore::ServiceWorkerContainer::scheduleTaskToFireControllerChangeEvent):
(WebCore::ServiceWorkerContainer::contextIdentifier):
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::ServiceWorkerJob):
* workers/service/ServiceWorkerJob.h:
(WebCore::ServiceWorkerJob::contextIdentifier):
* workers/service/ServiceWorkerJobClient.h:
* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::update):
* workers/service/ServiceWorkerTypes.h:

LayoutTests:

Add layout test coverage and unskip WPT test that no longer times out.

* TestExpectations:
* http/tests/workers/service/resources/self_registration_update-worker.js: Added.
* http/tests/workers/service/self_registration_update-expected.txt: Added.
* http/tests/workers/service/self_registration_update.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225455 268f45cc-cd09-0410-ab3c-d52691b4dbfc
17 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/http/tests/workers/service/resources/self_registration_update-worker.js [new file with mode: 0644]
LayoutTests/http/tests/workers/service/self_registration_update-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/workers/service/self_registration_update.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/ServiceWorkerGlobalScope/update.https-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/workers/service/SWClientConnection.cpp
Source/WebCore/workers/service/SWClientConnection.h
Source/WebCore/workers/service/ServiceWorkerContainer.cpp
Source/WebCore/workers/service/ServiceWorkerContainer.h
Source/WebCore/workers/service/ServiceWorkerJob.cpp
Source/WebCore/workers/service/ServiceWorkerJob.h
Source/WebCore/workers/service/ServiceWorkerJobClient.h
Source/WebCore/workers/service/ServiceWorkerRegistration.cpp
Source/WebCore/workers/service/ServiceWorkerTypes.h