mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1498415 [wpt PR 13473] - [Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort, a=testonly
Automatic update from web-platform-tests[Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort Re-resubmit cr/1261477 The issue was that there is a race condition between the abort going through, and the downloaded file being persisted on disk. I added an extra check in the WPT test. Change-Id: I98aa005b4637c08f60a126a6c7c896c1c0edfddf Reviewed-on: https://chromium-review.googlesource.com/c/1276557 Commit-Queue: Rayan Kanso <rayankans@chromium.org> Reviewed-by: Mugdha Lakhani <nator@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Cr-Commit-Position: refs/heads/master@{#598848} -- wpt-commits: c54a084daf22377e9c9ac3b50f9220ad0df27858 wpt-pr: 13473
This commit is contained in:
parent
2c9a1fc659
commit
50c48d53cd
@ -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');
|
@ -27,3 +27,4 @@ function handleBackgroundFetchUpdateEvent(event) {
|
||||
|
||||
self.addEventListener('backgroundfetchsuccess', handleBackgroundFetchUpdateEvent);
|
||||
self.addEventListener('backgroundfetchfail', handleBackgroundFetchUpdateEvent);
|
||||
self.addEventListener('backgroundfetchabort', handleBackgroundFetchUpdateEvent);
|
||||
|
Loading…
Reference in New Issue
Block a user