Update web-platform-tests to revision b382ac7192087da0a7439902e20be76ab7587ee8

This commit is contained in:
WPT Sync Bot 2018-08-10 21:31:07 -04:00
parent 3e96a322ae
commit defee2aae0
45 changed files with 645 additions and 189 deletions

View file

@ -0,0 +1,12 @@
// The source to post setup and completion results to.
let source = null;
function sendMessageToDocument(msg) {
source.postMessage(msg);
}
// Notify the document that the SW is registered and ready.
self.addEventListener('message', event => {
source = event.source;
sendMessageToDocument('ready');
});

View file

@ -0,0 +1,22 @@
importScripts('sw-helpers.js');
async function updateUI(event) {
let updateParams = [];
switch (event.id) {
case 'update-once':
updateParams = [{title: 'Title1'}];
break;
case 'update-twice':
updateParams = [{title: 'Title1'}, {title: 'Title2'}];
break;
}
return Promise.all(updateParams.map(param => event.updateUI(param)))
.then(() => 'update success')
.catch(e => e.message);
}
self.addEventListener('backgroundfetched', event => {
event.waitUntil(updateUI(event)
.then(update => sendMessageToDocument({ type: event.type, update })))
});

View file

@ -0,0 +1,19 @@
importScripts('sw-helpers.js');
async function getFetchResult(settledFetch) {
if (!settledFetch.response)
return Promise.resolve(null);
return {
url: settledFetch.response.url,
status: settledFetch.response.status,
text: await settledFetch.response.text(),
};
}
self.addEventListener('backgroundfetched', event => {
event.waitUntil(
event.fetches.values()
.then(fetches => Promise.all(fetches.map(fetch => getFetchResult(fetch))))
.then(results => sendMessageToDocument({ type: event.type, results })));
});