aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/background-fetch/fetch-uploads.https.window.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wpt/web-platform-tests/background-fetch/fetch-uploads.https.window.js')
-rw-r--r--tests/wpt/web-platform-tests/background-fetch/fetch-uploads.https.window.js31
1 files changed, 27 insertions, 4 deletions
diff --git a/tests/wpt/web-platform-tests/background-fetch/fetch-uploads.https.window.js b/tests/wpt/web-platform-tests/background-fetch/fetch-uploads.https.window.js
index c53b2996645..4ee618a1292 100644
--- a/tests/wpt/web-platform-tests/background-fetch/fetch-uploads.https.window.js
+++ b/tests/wpt/web-platform-tests/background-fetch/fetch-uploads.https.window.js
@@ -9,15 +9,38 @@
backgroundFetchTest(async (test, backgroundFetch) => {
const uploadData = 'Background Fetch!';
const request =
- new Request('resources/upload.py', {method: 'POST', body: uploadData});
+ new Request('resources/upload.py', {method: 'POST', body: uploadData});
- await backgroundFetch.fetch(uniqueId(), request);
- const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+ 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);
+ };
+ });
-}, 'Fetch with an upload should work'); \ No newline at end of file
+ assert_equals(uploaded, uploadData.length);
+}, 'Progress event includes uploaded bytes');