From 9a5b791909fbbd07a8c72e44df2fb3474b4df807 Mon Sep 17 00:00:00 2001 From: Rayan Kanso Date: Thu, 22 Nov 2018 10:34:18 +0000 Subject: [PATCH] Bug 1508360 [wpt PR 14128] - [Background Fetch] Remove chromium specific WPT code, a=testonly Automatic update from web-platform-tests[Background Fetch] Remove chromium specific WPT code Also add an upload endpoint to test Background Fetch uploads. Bug: 774054 Change-Id: I305e9f43b5d2e77a8e78e9e460e8398d771b03e0 Reviewed-on: https://chromium-review.googlesource.com/c/1341923 Commit-Queue: Rayan Kanso Reviewed-by: Peter Beverloo Cr-Commit-Position: refs/heads/master@{#609394} -- wpt-commits: dcda413dc629781f75684101e9f8ec7d122fa30b wpt-pr: 14128 --- .../background-fetch/abort.https.window.js | 6 ++--- .../fetch-uploads.https.window.js | 23 ++++++++++++++++++ .../background-fetch/fetch.https.window.js | 24 ++----------------- .../background-fetch/resources/upload.py | 3 +++ 4 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 testing/web-platform/tests/background-fetch/fetch-uploads.https.window.js create mode 100644 testing/web-platform/tests/background-fetch/resources/upload.py diff --git a/testing/web-platform/tests/background-fetch/abort.https.window.js b/testing/web-platform/tests/background-fetch/abort.https.window.js index b699406a1442..9cc8c25f7a41 100644 --- a/testing/web-platform/tests/background-fetch/abort.https.window.js +++ b/testing/web-platform/tests/background-fetch/abort.https.window.js @@ -8,7 +8,7 @@ backgroundFetchTest(async (test, backgroundFetch) => { const registration = await backgroundFetch.fetch( uniqueId(), - ['resources/feature-name.txt', '/serviceworker/resources/slow-response.php']); + ['resources/feature-name.txt', '/common/slow.py']); assert_true(await registration.abort()); assert_false(await registration.abort()); @@ -18,7 +18,7 @@ backgroundFetchTest(async (test, backgroundFetch) => { backgroundFetchTest(async (test, backgroundFetch) => { const registration = await backgroundFetch.fetch( uniqueId(), - ['resources/feature-name.txt', '/serviceworker/resources/slow-response.php']); + ['resources/feature-name.txt', '/common/slow.py']); await new Promise(resolve => { let aborted = false; @@ -63,7 +63,7 @@ backgroundFetchTest(async (test, backgroundFetch) => { backgroundFetchTest(async (test, backgroundFetch) => { const registration = await backgroundFetch.fetch( - uniqueId(), '/serviceworker/resources/slow-response.php'); + uniqueId(), '/common/slow.py'); assert_true(await registration.abort()); const {results} = await getMessageFromServiceWorker(); diff --git a/testing/web-platform/tests/background-fetch/fetch-uploads.https.window.js b/testing/web-platform/tests/background-fetch/fetch-uploads.https.window.js new file mode 100644 index 000000000000..c53b29966458 --- /dev/null +++ b/testing/web-platform/tests/background-fetch/fetch-uploads.https.window.js @@ -0,0 +1,23 @@ +// 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}); + + await backgroundFetch.fetch(uniqueId(), request); + 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(results[0].text, uploadData); + +}, 'Fetch with an upload should work'); \ No newline at end of file diff --git a/testing/web-platform/tests/background-fetch/fetch.https.window.js b/testing/web-platform/tests/background-fetch/fetch.https.window.js index aee777d986e4..52d29db5dc4f 100644 --- a/testing/web-platform/tests/background-fetch/fetch.https.window.js +++ b/testing/web-platform/tests/background-fetch/fetch.https.window.js @@ -195,27 +195,6 @@ backgroundFetchTest(async (test, backgroundFetch) => { }, 'Fetches can have requests with duplicate URLs'); -backgroundFetchTest(async (test, backgroundFetch) => { - const request = - new Request('resources/feature-name.txt', - {method: 'POST', body: 'TestBody'}); - - const registration = await backgroundFetch.fetch('my-id', request); - - const {type, eventRegistration, results} = await getMessageFromServiceWorker(); - assert_equals('backgroundfetchsuccess', type); - assert_equals(results.length, 1); - - assert_equals(eventRegistration.id, registration.id); - assert_equals(eventRegistration.failureReason, ''); - - assert_true(results[0].url.includes('resources/feature-name.txt')); - assert_equals(results[0].status, 200); - assert_equals(results[0].text, 'Background Fetch'); - - -}, 'Fetches can have requests with a body'); - backgroundFetchTest(async (test, backgroundFetch) => { const registrationId = uniqueId(); const registration = @@ -319,4 +298,5 @@ backgroundFetchTest(async (test, backgroundFetch) => { assert_equals(eventRegistration.result, 'success'); assert_equals(eventRegistration.failureReason, ''); -}, 'Matching to a non-existing request should work'); \ No newline at end of file +}, 'Matching to a non-existing request should work'); + diff --git a/testing/web-platform/tests/background-fetch/resources/upload.py b/testing/web-platform/tests/background-fetch/resources/upload.py new file mode 100644 index 000000000000..585144efa6ba --- /dev/null +++ b/testing/web-platform/tests/background-fetch/resources/upload.py @@ -0,0 +1,3 @@ +# Simply returns the request body to check if the upload succeeded. +def main(request, response): + return 200, [("Content-Type", request.headers['content-type'])], request.body