Update web-platform-tests to revision ab64b78a8f6777a1d95d8d1d4bba9ccdbecf94ea

This commit is contained in:
WPT Sync Bot 2018-08-26 21:31:58 -04:00
parent da36740f0b
commit 394aced19f
713 changed files with 12430 additions and 12632 deletions

View file

@ -73,12 +73,18 @@ backgroundFetchTest(async (test, backgroundFetch) => {
assert_equals(registration.uploadTotal, 0);
assert_equals(registration.uploaded, 0);
assert_equals(registration.downloadTotal, 0);
assert_equals(registration.state, "pending");
assert_equals(registration.failureReason, "");
// Skip `downloaded`, as the transfer may have started already.
const {type, results} = await getMessageFromServiceWorker();
const {type, eventRegistration, results} = await getMessageFromServiceWorker();
assert_equals('backgroundfetchsuccess', type);
assert_equals(results.length, 1);
assert_equals(eventRegistration.id, registration.id);
assert_equals(eventRegistration.state, "success");
assert_equals(eventRegistration.failureReason, "");
assert_true(results[0].url.includes('resources/feature-name.txt'));
assert_equals(results[0].status, 200);
assert_equals(results[0].text, 'Background Fetch');

View file

@ -41,6 +41,8 @@ backgroundFetchTest(async (test, backgroundFetch) => {
assert_equals(registration.uploadTotal, 0);
assert_equals(registration.uploaded, 0);
assert_equals(registration.downloadTotal, 1234);
assert_equals(registration.state, "pending");
assert_equals(registration.failureReason, "");
// Skip `downloaded`, as the transfer may have started already.
const secondRegistration = await backgroundFetch.get(registrationId);

View file

@ -5,6 +5,25 @@ function sendMessageToDocument(msg) {
source.postMessage(msg);
}
// This is needed to create a local javascript object identical to the
// one returned by a BackgroundFetchEvent, so that it can be serialized
// and transmitted from the service worker context to the document.
function cloneRegistration(registration) {
function deepCopy(src) {
if (typeof src !== 'object' || src === null)
return src;
var dst = Array.isArray(src) ? [] : {};
for (var property in src) {
if (typeof src[property] === 'function')
continue;
dst[property] = deepCopy(src[property]);
}
return dst;
}
return deepCopy(registration);
}
// Notify the document that the SW is registered and ready.
self.addEventListener('message', event => {
source = event.source;

View file

@ -1,20 +1,24 @@
importScripts('sw-helpers.js');
async function getFetchResult(settledFetch) {
if (!settledFetch.response)
async function getFetchResult(record) {
response = await record.responseReady;
if (!response)
return Promise.resolve(null);
return {
url: settledFetch.response.url,
status: settledFetch.response.status,
text: await settledFetch.response.text(),
url: response.url,
status: response.status,
text: await response.text(),
};
}
self.addEventListener('backgroundfetchsuccess', event => {
event.waitUntil(
event.fetches.values()
.then(fetches => Promise.all(fetches.map(fetch => getFetchResult(fetch))))
.then(results => sendMessageToDocument({ type: event.type, results })));
event.registration.matchAll()
.then(records => Promise.all(records.map(record => getFetchResult(record))))
.then(results => {
const registrationCopy = cloneRegistration(event.registration);
sendMessageToDocument({ type: event.type, eventRegistration: registrationCopy, results })
}));
});