mirror of
https://github.com/servo/servo.git
synced 2025-08-15 18:35:33 +01:00
Update web-platform-tests to revision b382ac7192087da0a7439902e20be76ab7587ee8
This commit is contained in:
parent
3e96a322ae
commit
defee2aae0
45 changed files with 645 additions and 189 deletions
|
@ -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');
|
||||
});
|
|
@ -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 })))
|
||||
});
|
|
@ -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 })));
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue