fune/testing/web-platform/tests/background-fetch/fetch-uploads.https.window.js
Rayan Kanso 1731253ca5 Bug 1523562 [wpt PR 14970] - [Background Fetch] Enable creating registrations with duplicate requests, a=testonly
Automatic update from web-platform-tests
[Background Fetch] Enable creating registrations with duplicate requests

Remove check in renderer and add WP test for uploads.

Bug: 871174
Change-Id: Id225cc05b6f3c065962e1481c98562ca96d87322
Reviewed-on: https://chromium-review.googlesource.com/c/1424821
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: Mugdha Lakhani <nator@google.com>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625640}

--

wpt-commits: 14577a3e19422fd99a3c57fb568a48b8291d0768
wpt-pr: 14970
2019-02-07 21:51:01 +00:00

64 lines
2.5 KiB
JavaScript

// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
// META: script=resources/utils.js
'use strict';
// Covers basic functionality provided by BackgroundFetchManager.fetch().
// Specifically, when `fetch` contains request uploads.
// https://wicg.github.io/background-fetch/#background-fetch-manager-fetch
backgroundFetchTest(async (test, backgroundFetch) => {
const uploadData = 'Background Fetch!';
const request =
new Request('resources/upload.py', {method: 'POST', body: uploadData});
const registration = await backgroundFetch.fetch(uniqueId(), request);
assert_equals(registration.uploadTotal, uploadData.length);
const {type, eventRegistration, results} = await getMessageFromServiceWorker();
assert_equals(type, 'backgroundfetchsuccess');
assert_equals(results.length, 1);
assert_equals(eventRegistration.result, 'success');
assert_equals(eventRegistration.failureReason, '');
assert_equals(eventRegistration.uploaded, uploadData.length);
assert_equals(results[0].text, uploadData);
}, 'Fetch with an upload should work');
backgroundFetchTest(async (test, backgroundFetch) => {
const uploadData = 'Background Fetch!';
const uploadRequest =
new Request('resources/upload.py', {method: 'POST', body: uploadData});
const registration = await backgroundFetch.fetch(
uniqueId(),
[uploadRequest, '/common/slow.py']);
const uploaded = await new Promise(resolve => {
registration.onprogress = event => {
if (event.target.downloaded === 0)
return;
// If a progress event with downloaded bytes was received, then
// everything was uploaded.
resolve(event.target.uploaded);
};
});
assert_equals(uploaded, uploadData.length);
}, 'Progress event includes uploaded bytes');
backgroundFetchTest(async (test, backgroundFetch) => {
const uploadRequest1 =
new Request('resources/upload.py', {method: 'POST', body: 'upload1'});
const uploadRequest2 =
new Request('resources/upload.py', {method: 'POST', body: 'upload2'});
await backgroundFetch.fetch(uniqueId(), [uploadRequest1, uploadRequest2]);
const {type, eventRegistration, results} = await getMessageFromServiceWorker();
assert_equals(type, 'backgroundfetchsuccess');
assert_equals(results.length, 2);
assert_equals(eventRegistration.result, 'success');
assert_equals(eventRegistration.failureReason, '');
assert_array_equals([results[0].text, results[1].text].sort(),
['upload1', 'upload2']);
}, 'Duplicate upload requests work and can be distinguished.');