Bug 178985

Summary: [Service Workers] Fire updatefound event after resolving the registration promise
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: beidson, buildbot, commit-queue, dbates, esprehn+autocc, ggaren, japhet, kangil.han, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=179018
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Archive of layout-test-results from ews126 for ios-simulator-wk2
none
Patch
none
Patch
none
Patch
none
Archive of layout-test-results from ews121 for ios-simulator-wk2
none
Patch
none
Archive of layout-test-results from ews121 for ios-simulator-wk2
none
Patch
none
Patch
none
Patch
none
Patch
none
Archive of layout-test-results from ews125 for ios-simulator-wk2
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2017-10-28 16:23:43 PDT
Fire updatefound event after resolving the registration promise and populate ServiceWorkerRegistration.installing to unblock some web-platform-tests.
Comment 1 Chris Dumez 2017-10-29 13:49:59 PDT
Created attachment 325290 [details]
Patch
Comment 2 Chris Dumez 2017-10-29 13:54:42 PDT
Created attachment 325291 [details]
Patch
Comment 3 Chris Dumez 2017-10-29 14:46:40 PDT
Created attachment 325293 [details]
Patch
Comment 4 Build Bot 2017-10-29 16:16:35 PDT
Comment on attachment 325293 [details]
Patch

Attachment 325293 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5033790

New failing tests:
imported/w3c/web-platform-tests/service-workers/service-worker/fetch-event.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/websocket.https.html
Comment 5 Build Bot 2017-10-29 16:16:36 PDT
Created attachment 325295 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 6 Chris Dumez 2017-10-29 16:34:16 PDT
Created attachment 325297 [details]
Patch
Comment 7 Chris Dumez 2017-10-29 16:42:07 PDT
Created attachment 325299 [details]
Patch
Comment 8 Chris Dumez 2017-10-29 17:07:28 PDT
Created attachment 325303 [details]
Patch
Comment 9 Build Bot 2017-10-29 18:35:50 PDT
Comment on attachment 325303 [details]
Patch

Attachment 325303 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5034825

New failing tests:
imported/w3c/web-platform-tests/service-workers/service-worker/unregister-controller.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https.html
Comment 10 Build Bot 2017-10-29 18:35:51 PDT
Created attachment 325308 [details]
Archive of layout-test-results from ews121 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 11 Chris Dumez 2017-10-29 18:41:25 PDT
Created attachment 325309 [details]
Patch
Comment 12 Build Bot 2017-10-29 20:04:21 PDT
Comment on attachment 325309 [details]
Patch

Attachment 325309 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5035365

New failing tests:
imported/w3c/web-platform-tests/service-workers/service-worker/fetch-frame-resource.https.html
Comment 13 Build Bot 2017-10-29 20:04:23 PDT
Created attachment 325313 [details]
Archive of layout-test-results from ews121 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 14 Chris Dumez 2017-10-29 20:42:46 PDT
Created attachment 325318 [details]
Patch
Comment 15 Chris Dumez 2017-10-30 14:03:09 PDT
Created attachment 325376 [details]
Patch
Comment 16 youenn fablet 2017-10-30 14:33:29 PDT
Comment on attachment 325376 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=325376&action=review

> Source/WebCore/workers/service/ServiceWorker.cpp:41
> +ServiceWorker::ServiceWorker(ScriptExecutionContext& context, uint64_t serviceWorkerIdentifier, const URL& scriptURL)

URL&& probably

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:77
>  ServiceWorker* ServiceWorkerContainer::controller() const

CallWith=ScriptExecutionContext might be better.

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:216
> +        context->setActiveServiceWorker(ServiceWorker::create(*context, data.identifier, data.scriptURL));

We should probably not create a ServiceWorker here.
Probably we should get it from the selected ServiceWorkerRegistration that we create below.
I guess the above FIXME might cover this though.
Or maybe some refactoring would get us closer to the end target?

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:225
> +    // a few events to make it look like we are installing and activing the service worker.

Let's hope we can remove that code and FIXME soon.
But end result in terms of testing is great!

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:254
> +        context->setActiveServiceWorker(nullptr);

I would prefer clearActiveServiceWorker and setActiveServiceWorker take a Ref<>. Both might be inlined anyway.

> Source/WebCore/workers/service/ServiceWorkerRegistration.cpp:54
>      return nullptr;

Do we not do it in the other way usually by returning nullptr early?

> Source/WebCore/workers/service/ServiceWorkerRegistration.h:74
> +    RefPtr<ServiceWorker> m_serviceWorker;

Right now I guess it can it be a Ref<> but in the future it may not. Would use a Ref<> though if possible now.
Comment 17 Chris Dumez 2017-10-30 14:40:50 PDT
Comment on attachment 325376 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=325376&action=review

>> Source/WebCore/workers/service/ServiceWorker.cpp:41
>> +ServiceWorker::ServiceWorker(ScriptExecutionContext& context, uint64_t serviceWorkerIdentifier, const URL& scriptURL)
> 
> URL&& probably

My call site is not able to transfer ownership so it would not be helpful and it would make that call site looks slightly worse.

>> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:77
>>  ServiceWorker* ServiceWorkerContainer::controller() const
> 
> CallWith=ScriptExecutionContext might be better.

This would be a behavior change I believe. I want the script execution context of the ServiceWorkerContainer object, not the one of the caller.

>> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:216
>> +        context->setActiveServiceWorker(ServiceWorker::create(*context, data.identifier, data.scriptURL));
> 
> We should probably not create a ServiceWorker here.
> Probably we should get it from the selected ServiceWorkerRegistration that we create below.
> I guess the above FIXME might cover this though.
> Or maybe some refactoring would get us closer to the end target?

What do you mean? I need to see the selected / active service worker, like the previous code used to. do. It used to be just am identifier, now it is a ServiceWorker object.

>> Source/WebCore/workers/service/ServiceWorkerRegistration.cpp:54
>>      return nullptr;
> 
> Do we not do it in the other way usually by returning nullptr early?

Sure.

>> Source/WebCore/workers/service/ServiceWorkerRegistration.h:74
>> +    RefPtr<ServiceWorker> m_serviceWorker;
> 
> Right now I guess it can it be a Ref<> but in the future it may not. Would use a Ref<> though if possible now.

My thought also. Ok, I'll try Ref<> for now.
Comment 18 Chris Dumez 2017-10-30 14:43:43 PDT
Created attachment 325379 [details]
Patch
Comment 19 Chris Dumez 2017-10-30 14:51:39 PDT
https://bugs.webkit.org/show_bug.cgi?id=179018 will allow us to unskip even more tests.
Comment 20 Chris Dumez 2017-10-30 14:54:58 PDT
Created attachment 325381 [details]
Patch
Comment 21 Build Bot 2017-10-30 16:15:54 PDT
Comment on attachment 325381 [details]
Patch

Attachment 325381 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5043692

New failing tests:
imported/w3c/web-platform-tests/service-workers/service-worker/fetch-request-css-images.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/register-same-scope-different-script-url.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/multiple-register.https.html
imported/w3c/web-platform-tests/service-workers/service-worker/unregister-then-register.https.html
Comment 22 Build Bot 2017-10-30 16:15:55 PDT
Created attachment 325385 [details]
Archive of layout-test-results from ews125 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews125  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 23 Chris Dumez 2017-10-30 16:55:29 PDT
Created attachment 325389 [details]
Patch
Comment 24 Chris Dumez 2017-10-30 18:31:33 PDT
Created attachment 325403 [details]
Patch
Comment 25 Chris Dumez 2017-10-30 19:07:14 PDT
Created attachment 325409 [details]
Patch
Comment 26 WebKit Commit Bot 2017-10-30 20:13:09 PDT
Comment on attachment 325409 [details]
Patch

Clearing flags on attachment: 325409

Committed r224218: <https://trac.webkit.org/changeset/224218>
Comment 27 WebKit Commit Bot 2017-10-30 20:13:11 PDT
All reviewed patches have been landed.  Closing bug.
Comment 28 youenn fablet 2017-10-30 21:42:49 PDT
> >> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:77
> >>  ServiceWorker* ServiceWorkerContainer::controller() const
> > 
> > CallWith=ScriptExecutionContext might be better.
> 
> This would be a behavior change I believe. I want the script execution
> context of the ServiceWorkerContainer object, not the one of the caller.

Is there a case where they would not be the same thing?

> >> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:216
> >> +        context->setActiveServiceWorker(ServiceWorker::create(*context, data.identifier, data.scriptURL));
> > 
> > We should probably not create a ServiceWorker here.
> > Probably we should get it from the selected ServiceWorkerRegistration that we create below.
> > I guess the above FIXME might cover this though.
> > Or maybe some refactoring would get us closer to the end target?
> 
> What do you mean? I need to see the selected / active service worker, like
> the previous code used to. do. It used to be just am identifier, now it is a
> ServiceWorker object.

As per the spec, a page selects a registration.
Then, the active worker of the selected registration becomes the page active worker.

It would therefore be closer to spec to do something like either have the selected registration retrieved from the ScriptExecutionContext or the selected registration to set the ServiceWorker of the ScriptExecutionContext when registration state is changing.
Comment 29 Radar WebKit Bug Importer 2017-11-15 12:35:50 PST
<rdar://problem/35567842>