Update web-platform-tests to revision 2b758296541cf4f2209b8c2352cf6c7890c97be3

This commit is contained in:
WPT Sync Bot 2018-10-22 21:28:54 -04:00
parent 2304f02123
commit 835d593cd0
118 changed files with 3269 additions and 703 deletions

View file

@ -282,3 +282,41 @@ backgroundFetchTest(async (test, backgroundFetch) => {
assert_equals(nullResponse, null);
}, 'Fetches with mixed content should fail.');
backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = 'matchexistingrequest';
const registration =
await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
assert_equals(registration.id, registrationId);
const {type, eventRegistration, results} = await getMessageFromServiceWorker();
assert_equals('backgroundfetchsuccess', type);
assert_equals(results.length, 1);
assert_equals(eventRegistration.id, registration.id);
assert_equals(eventRegistration.result, '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');
}, 'Matching to a single request should work');
backgroundFetchTest(async (test, backgroundFetch) => {
const registrationId = 'matchmissingrequest';
const registration =
await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
assert_equals(registration.id, registrationId);
const {type, eventRegistration, results} = await getMessageFromServiceWorker();
assert_equals('backgroundfetchsuccess', type);
assert_equals(results.length, 0);
assert_equals(eventRegistration.id, registration.id);
assert_equals(eventRegistration.result, 'success');
assert_equals(eventRegistration.failureReason, '');
}, 'Matching to a non-existing request should work');

View file

@ -13,10 +13,33 @@ async function getFetchResult(record) {
}
function handleBackgroundFetchEvent(event) {
let matchFunction = null;
switch (event.registration.id) {
case 'matchexistingrequest':
matchFunction = event.registration.match.bind(
event.registration, '/background-fetch/resources/feature-name.txt');
break;
case 'matchmissingrequest':
matchFunction = event.registration.match.bind(
event.registration, '/background-fetch/resources/missing.txt');
break;
default:
matchFunction = event.registration.matchAll.bind(event.registration);
break;
}
event.waitUntil(
event.registration.matchAll()
matchFunction()
// Format `match(All)?` function results.
.then(records => {
if (!records) return []; // Nothing was matched.
if (!records.map) return [records]; // One entry was returned.
return records; // Already in a list.
})
// Extract responses.
.then(records =>
Promise.all(records.map(record => getFetchResult(record))))
// Clone registration and send message.
.then(results => {
const registrationCopy = cloneRegistration(event.registration);
sendMessageToDocument(