Bug 1536619 [wpt PR 15852] - service worker: Improve WPT tests for async respondWith...
commitcb4fd58842472e1bc98a71b9329b592cfc25fba4
authorBlink WPT Bot <blink-w3c-test-autoroller@chromium.org>
Mon, 15 Apr 2019 14:34:45 +0000 (15 14:34 +0000)
committerJames Graham <james@hoppipolla.co.uk>
Wed, 24 Apr 2019 10:18:10 +0000 (24 11:18 +0100)
tree2031ff9fd74240ea6d8b58e31a95d15d4d437891
parentf5aafb2a05264da1d052bfa312bfd7e5b474ac1b
Bug 1536619 [wpt PR 15852] - service worker: Improve WPT tests for async respondWith/waitUntil., a=testonly

Automatic update from web-platform-tests
service worker: Improve WPT tests for async respondWith/waitUntil. (#15852)

See discussion at [1] and [2].

This makes the following changes.

1.
Adds a test for:

self.addEventListener('fetch', e => {
  Promise.resolve().then(() => {
    e.respondWith(new Response('hi'));
  });
});

This should not throw because respondWith() is called while the event
dispatch flag is still set.

The microtask checkpoint is in "Cleanup After Running Scripts" here:
https://html.spec.whatwg.org/multipage/webappapis.html#clean-up-after-running-script

This is called from step 16.2 here:
https://heycam.github.io/webidl/#call-a-user-objects-operation

Which in turn is called from the DOM spec's "Inner Invoke" to call event
targets:
https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke

2.
Changes the expectation for:

addEventListener('message', event => {
  Promise.resolve().then(event.waitUntil(p));
});

From throws to not throws, for the same reasoning as above.

3.
Changes the expectation for:

addEventListener('message', event => {
  waitPromise = Promise.resolve();
  event.waitUntil(waitPromise);
  waitPromise.then(() => {
    Promise.resolve().then(() => {event.waitUntil();});
  });
});

From throws to not throws. This is subtle. Because all the promises
are just Promise.resolve(), the event dispatch flag is still set
by the time the second waitUntil() is called.

4.
To test what 3. originally intended, a new test is
added which makes waitPromise a promise that does not immediately
resolve.

5.
Changes the expectation for:

addEventListener(‘fetch’, event => {
  response = Promise.resolve(new Response('RESP'));
  event.respondWith(response);
  response.then(() => {
    Promise.resolve().then(() => {event.waitUntil();});
  })
});

Again this is because the promises used resolve immediately,
so the event dispatch flag is still set.

Similarly, a new test is added to cover the original intent.

These WPT changes appear to match the behavior of Safari and Edge while
diverging from Chrome and (partially) Firefox.

[1] https://github.com/w3c/ServiceWorker/issues/1213
[2] https://github.com/w3c/ServiceWorker/issues/1394

Bug: 942414
Change-Id: I9a4a56d71d3919ed614ff78df2bdc6cc0251dadd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1524393
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/master@{#641514}
--

wpt-commits: cecb3eba4dae3d795876f7b4be71bd49afa03356
wpt-pr: 15852
testing/web-platform/tests/service-workers/service-worker/extendable-event-async-waituntil.https.html
testing/web-platform/tests/service-workers/service-worker/fetch-event-async-respond-with.https.html
testing/web-platform/tests/service-workers/service-worker/resources/extendable-event-async-waituntil.js
testing/web-platform/tests/service-workers/service-worker/resources/fetch-event-async-respond-with-worker.js