mirror of
https://github.com/servo/servo.git
synced 2025-08-18 03:45:33 +01:00
Update web-platform-tests to revision d647a1bc742a533186d8297cae2a2bee669c7780
This commit is contained in:
parent
bf192caf4b
commit
4cf0a092d0
41 changed files with 897 additions and 487 deletions
|
@ -0,0 +1,59 @@
|
|||
// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
|
||||
// META: script=resources/utils.js
|
||||
'use strict';
|
||||
|
||||
// Covers basic functionality provided by BackgroundFetchManager.abort().
|
||||
// https://wicg.github.io/background-fetch/#background-fetch-registration-abort
|
||||
|
||||
backgroundFetchTest(async (test, backgroundFetch) => {
|
||||
const registration = await backgroundFetch.fetch(
|
||||
uniqueId(),
|
||||
['resources/feature-name.txt', '/serviceworker/resources/slow-response.php']);
|
||||
|
||||
assert_true(await registration.abort());
|
||||
assert_false(await registration.abort());
|
||||
|
||||
}, 'Aborting the same registration twice fails');
|
||||
|
||||
backgroundFetchTest(async (test, backgroundFetch) => {
|
||||
const registration = await backgroundFetch.fetch(
|
||||
uniqueId(),
|
||||
['resources/feature-name.txt', '/serviceworker/resources/slow-response.php']);
|
||||
|
||||
await new Promise(resolve => {
|
||||
let aborted = false;
|
||||
const expectedResultText = 'Background Fetch';
|
||||
|
||||
registration.onprogress = async event => {
|
||||
if (event.target.downloaded < expectedResultText.length)
|
||||
return;
|
||||
|
||||
if (aborted)
|
||||
return;
|
||||
|
||||
// Abort after the first file has been downloaded and check the results.
|
||||
|
||||
aborted = true;
|
||||
assert_true(await registration.abort());
|
||||
|
||||
const {type, eventRegistration, results} = await getMessageFromServiceWorker();
|
||||
|
||||
assert_equals(eventRegistration.result, 'failure');
|
||||
assert_equals(eventRegistration.failureReason, 'aborted');
|
||||
assert_equals(registration.result, 'failure');
|
||||
assert_equals(registration.failureReason, 'aborted');
|
||||
|
||||
assert_equals(type, 'backgroundfetchabort');
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
|
||||
}, 'Calling BackgroundFetchRegistration.abort sets the correct fields and responses are still available');
|
|
@ -145,6 +145,24 @@ backgroundFetchTest(async (test, backgroundFetch) => {
|
|||
|
||||
}, 'Using Background Fetch to successfully fetch a single resource');
|
||||
|
||||
backgroundFetchTest(async (test, backgroundFetch) => {
|
||||
const registrationId = uniqueId();
|
||||
const registration =
|
||||
await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
|
||||
|
||||
assert_equals(registration.result, '');
|
||||
assert_equals(registration.failureReason, '');
|
||||
|
||||
const {type, eventRegistration, results} =
|
||||
await getMessageFromServiceWorker();
|
||||
assert_equals('backgroundfetchsuccess', type);
|
||||
|
||||
assert_equals(eventRegistration.id, registration.id);
|
||||
assert_equals(registration.result, 'success');
|
||||
assert_equals(registration.failureReason, '');
|
||||
|
||||
}, 'Registration object gets updated values when a background fetch completes.');
|
||||
|
||||
backgroundFetchTest(async (test, backgroundFetch) => {
|
||||
const registrationId = uniqueId();
|
||||
|
||||
|
@ -240,6 +258,9 @@ backgroundFetchTest(async (test, backgroundFetch) => {
|
|||
assert_equals(eventRegistration.result, 'failure');
|
||||
assert_equals(eventRegistration.failureReason, 'bad-status');
|
||||
|
||||
assert_equals(registration.result, 'failure');
|
||||
assert_equals(registration.failureReason, 'bad-status');
|
||||
|
||||
}, 'Using Background Fetch to fetch a non-existent resource should fail.');
|
||||
|
||||
backgroundFetchTest(async (test, backgroundFetch) => {
|
||||
|
|
|
@ -27,3 +27,4 @@ function handleBackgroundFetchUpdateEvent(event) {
|
|||
|
||||
self.addEventListener('backgroundfetchsuccess', handleBackgroundFetchUpdateEvent);
|
||||
self.addEventListener('backgroundfetchfail', handleBackgroundFetchUpdateEvent);
|
||||
self.addEventListener('backgroundfetchabort', handleBackgroundFetchUpdateEvent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue