Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Background Fetch] Throw DOMException for responseReady on abort. #13549

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion background-fetch/abort.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@ backgroundFetchTest(async (test, backgroundFetch) => {
};
});

}, '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');
23 changes: 23 additions & 0 deletions background-fetch/service_workers/sw-abort.js
Original file line number Diff line number Diff line change
@@ -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})));
});