author | Rayan Kanso <rayankans@chromium.org> |
Thu, 11 Oct 2018 09:30:57 +0000 | |
changeset 441022 | ad04238da3b66b40bbf8c0609e8d55469652b974 |
parent 441021 | b4124072ce413dd778e0d1780ea71283b1c698ce |
child 441023 | bcd7b358b492a08052588e078fb11a8c371c01d1 |
push id | 34842 |
push user | aciure@mozilla.com |
push date | Sat, 13 Oct 2018 09:36:47 +0000 |
treeherder | mozilla-central@94a62c1aad52 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | testonly |
bugs | 1496784, 13390, 1261477, 1264640, 597106 |
milestone | 64.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
new file mode 100644 --- /dev/null +++ b/testing/web-platform/tests/background-fetch/abort.https.window.js @@ -0,0 +1,50 @@ +// 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']); + const resultPromise = getMessageFromServiceWorker(); + + await new Promise(resolve => { + registration.onprogress = async (e) => { + // The size of the first file. + if (e.target.downloaded < 16) + return; + + // At this point the first file is downloaded. + + assert_true(await registration.abort()); + + const {type, eventRegistration, results} = await resultPromise; + + assert_equals(eventRegistration.result, 'failure'); + assert_equals(eventRegistration.failureReason, 'aborted'); + + assert_equals(type, 'backgroundfetchabort'); + assert_equals(results.length, 1); + + assert_true(results[0].url.includes('resources/feature-name.txt')); + assert_equals(results[0].status, 200); + assert_equals(results[0].text, 'Background Fetch'); + + resolve(); + }; + }); + +}, 'Calling BackgroundFetchRegistration.abort sets the correct fields and responses are still available'); \ No newline at end of file
--- a/testing/web-platform/tests/background-fetch/service_workers/sw.js +++ b/testing/web-platform/tests/background-fetch/service_workers/sw.js @@ -22,8 +22,9 @@ function handleBackgroundFetchUpdateEven const registrationCopy = cloneRegistration(event.registration); sendMessageToDocument( { type: event.type, eventRegistration: registrationCopy, results }) })); } self.addEventListener('backgroundfetchsuccess', handleBackgroundFetchUpdateEvent); self.addEventListener('backgroundfetchfail', handleBackgroundFetchUpdateEvent); +self.addEventListener('backgroundfetchabort', handleBackgroundFetchUpdateEvent);