mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Update web-platform-tests to revision 824f0c1df556305042b8aa8073c32e9ef86c3efa
This commit is contained in:
parent
bcafe4188f
commit
d0eccdba1a
131 changed files with 3087 additions and 705 deletions
|
@ -45,15 +45,30 @@ backgroundFetchTest(async (test, backgroundFetch) => {
|
|||
|
||||
assert_equals(type, 'backgroundfetchabort');
|
||||
|
||||
assert_equals(results.length, 2);
|
||||
|
||||
const completedResult = results[0] || results[1];
|
||||
// The abort might have gone through before the first result was persisted.
|
||||
if (results.length === 1) {
|
||||
assert_true(results[0].url.includes('resources/feature-name.txt'));
|
||||
assert_equals(results[0].status, 200);
|
||||
assert_equals(results[0].text, expectedResultText);
|
||||
if (completedResult) {
|
||||
assert_true(completedResult.url.includes('resources/feature-name.txt'));
|
||||
assert_equals(completedResult.status, 200);
|
||||
assert_equals(completedResult.text, expectedResultText);
|
||||
}
|
||||
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
}, 'Calling BackgroundFetchRegistration.abort sets the correct fields and responses are still available');
|
||||
}, 'Calling BackgroundFetchRegistration.abort sets the correct fields and responses are still available');
|
||||
|
||||
backgroundFetchTest(async (test, backgroundFetch) => {
|
||||
const registration = await backgroundFetch.fetch(
|
||||
uniqueId(), '/serviceworker/resources/slow-response.php');
|
||||
assert_true(await registration.abort());
|
||||
|
||||
const {results} = await getMessageFromServiceWorker();
|
||||
assert_equals(results.length, 1);
|
||||
assert_false(results[0].response);
|
||||
assert_equals(results[0].name, 'AbortError');
|
||||
|
||||
}, 'An aborted fetch throws a DOM exception when accessing an incomplete record', 'sw-abort.js');
|
|
@ -265,8 +265,8 @@ backgroundFetchTest(async (test, backgroundFetch) => {
|
|||
|
||||
backgroundFetchTest(async (test, backgroundFetch) => {
|
||||
const registration = await backgroundFetch.fetch(
|
||||
'my-id',
|
||||
['https://example.com', 'http://example.com']);
|
||||
'my-id',
|
||||
[location.origin, location.origin.replace('https', 'http')]);
|
||||
|
||||
const {type, eventRegistration, results} = await getMessageFromServiceWorker();
|
||||
|
||||
|
@ -274,7 +274,11 @@ backgroundFetchTest(async (test, backgroundFetch) => {
|
|||
assert_equals(eventRegistration.failureReason, 'fetch-error');
|
||||
|
||||
assert_equals(results.length, 2);
|
||||
assert_true(results[0].url.includes('https://example.com'));
|
||||
assert_equals(results[1].url, '');
|
||||
|
||||
const validResponse = results[0] ? results[0] : results[1];
|
||||
const nullResponse = !results[0] ? results[0] : results[1];
|
||||
|
||||
assert_true(validResponse.url.includes(location.origin));
|
||||
assert_equals(nullResponse, null);
|
||||
|
||||
}, 'Fetches with mixed content should fail.');
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
importScripts('sw-helpers.js');
|
||||
|
||||
async function getFetchResult(record) {
|
||||
try {
|
||||
await record.responseReady;
|
||||
} catch (e) {
|
||||
return {
|
||||
response: false,
|
||||
name: e.name,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
response: true,
|
||||
};
|
||||
}
|
||||
self.addEventListener('backgroundfetchabort', event => {
|
||||
event.waitUntil(
|
||||
event.registration.matchAll()
|
||||
.then(records =>
|
||||
Promise.all(records.map(record => getFetchResult(record))))
|
||||
.then(results => sendMessageToDocument({results})));
|
||||
});
|
|
@ -2,9 +2,8 @@
|
|||
importScripts('sw-helpers.js');
|
||||
|
||||
async function getFetchResult(record) {
|
||||
response = await record.responseReady;
|
||||
if (!response)
|
||||
return Promise.resolve(null);
|
||||
const response = await record.responseReady.catch(() => null);
|
||||
if (!response) return null;
|
||||
|
||||
return {
|
||||
url: response.url,
|
||||
|
@ -13,7 +12,7 @@ async function getFetchResult(record) {
|
|||
};
|
||||
}
|
||||
|
||||
function handleBackgroundFetchUpdateEvent(event) {
|
||||
function handleBackgroundFetchEvent(event) {
|
||||
event.waitUntil(
|
||||
event.registration.matchAll()
|
||||
.then(records =>
|
||||
|
@ -25,6 +24,6 @@ function handleBackgroundFetchUpdateEvent(event) {
|
|||
}));
|
||||
}
|
||||
|
||||
self.addEventListener('backgroundfetchsuccess', handleBackgroundFetchUpdateEvent);
|
||||
self.addEventListener('backgroundfetchfail', handleBackgroundFetchUpdateEvent);
|
||||
self.addEventListener('backgroundfetchabort', handleBackgroundFetchUpdateEvent);
|
||||
self.addEventListener('backgroundfetchsuccess', handleBackgroundFetchEvent);
|
||||
self.addEventListener('backgroundfetchfail', handleBackgroundFetchEvent);
|
||||
self.addEventListener('backgroundfetchabort', handleBackgroundFetchEvent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue