Bug 1505173 [wpt PR 13955] - [Background Fetch] Reject call to updateUI if event is inactive., a=testonly

Automatic update from web-platform-tests[Background Fetch] Reject call to updateUI if event is inactive.

Spec:
https://wicg.github.io/background-fetch/#background-fetch-update-ui-event-update-ui

Bug: 901909
Change-Id: Ia319cd03e41e65c5a6a1f5e61cde6f4ae7705a32
Reviewed-on: https://chromium-review.googlesource.com/c/1320330
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606118}

--

wpt-commits: 8762072fac59630a7dd6e024dc7ceab71e86ffcc
wpt-pr: 13955
This commit is contained in:
Rayan Kanso 2018-11-13 13:40:09 +00:00 коммит произвёл moz-wptsync-bot
Родитель 997a60523a
Коммит c860ad3488
2 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,4 @@
importScripts('/resources/testharness.js');
importScripts('sw-helpers.js');
async function updateUI(event) {
@ -13,10 +14,20 @@ async function updateUI(event) {
return Promise.all(updateParams.map(param => event.updateUI(param)))
.then(() => 'update success')
.catch(e => e.message);
.catch(e => e.name);
}
self.addEventListener('backgroundfetchsuccess', event => {
if (event.registration.id === 'update-inactive') {
// Post an async task before calling updateUI from the inactive event.
// Any async behaviour outside `waitUntil` should mark the event as
// inactive, and subsequent calls to `updateUI` should fail.
new Promise(r => step_timeout(r, 0))
.then(() => event.updateUI({ title: 'New title' }))
.catch(e => sendMessageToDocument({ update: e.name }));
return;
}
event.waitUntil(updateUI(event)
.then(update => sendMessageToDocument({ type: event.type, update })))
.then(update => sendMessageToDocument({ update })));
});

Просмотреть файл

@ -27,6 +27,17 @@ backgroundFetchTest(async (test, backgroundFetch) => {
assert_equals(registration.id, registrationId);
const message = await getMessageFromServiceWorker();
assert_equals(message.update, 'updateUI may only be called once.');
assert_equals(message.update, 'InvalidStateError');
}, 'Background Fetch updateUI called twice fails', swName);
backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = 'update-inactive';
const registration =
await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
assert_equals(registration.id, registrationId);
const message = await getMessageFromServiceWorker();
assert_equals(message.update, 'InvalidStateError');
}, 'Background Fetch updateUI fails when event is not active', swName);