diff --git a/background-fetch/abort.https.window.js b/background-fetch/abort.https.window.js index f08b788dd58b13..b699406a1442b0 100644 --- a/background-fetch/abort.https.window.js +++ b/background-fetch/abort.https.window.js @@ -59,4 +59,16 @@ backgroundFetchTest(async (test, backgroundFetch) => { }; }); -}, 'Calling BackgroundFetchRegistration.abort sets the correct fields and responses are still available'); \ No newline at end of file +}, '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'); \ No newline at end of file diff --git a/background-fetch/service_workers/sw-abort.js b/background-fetch/service_workers/sw-abort.js new file mode 100644 index 00000000000000..c61377758dff76 --- /dev/null +++ b/background-fetch/service_workers/sw-abort.js @@ -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}))); +});