зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1500225
[wpt PR 13603] - [Background Fetch] Fix match() crash., a=testonly
Automatic update from web-platform-tests[Background Fetch] Fix match() crash. Calling `match` was causing crashes in debug mode due to accessing base::Optional<>::value without initialization. Calling match with an unmatched request was crashing due to hitting a DCHECK. This returns undefined now as per the spec. Bug: 896768 Change-Id: I5d82e68ddca157a240ceaaec8990d2553366fbbb Reviewed-on: https://chromium-review.googlesource.com/c/1289269 Commit-Queue: Rayan Kanso <rayankans@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Cr-Commit-Position: refs/heads/master@{#601541} -- wpt-commits: aec4289d8db0aae98d4f171419ed1c8b60bc82d1 wpt-pr: 13603
This commit is contained in:
Родитель
979816d027
Коммит
ff6e70f81d
|
@ -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');
|
|
@ -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(
|
||||
|
|
Загрузка…
Ссылка в новой задаче