Commit c137e2ae authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[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: default avatarMugdha Lakhani <nator@google.com>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625640}
parent c6d2c8c3
......@@ -245,24 +245,8 @@ ScriptPromise BackgroundFetchManager::fetch(
kurls.insert(request_url);
}
const bool has_duplicate_requests = kurls.size() != fetch_api_requests.size();
UMA_HISTOGRAM_BOOLEAN("BackgroundFetch.HasDuplicateRequests",
has_duplicate_requests);
// Note: This is a proprietary check, due to the way Chrome currently handles
// storing background fetch records. Entries are keyed by the URL, so if two
// requests have the same URL, and different responses, the first response
// will be lost when the second request/response pair is stored.
if (has_duplicate_requests) {
return ScriptPromise::Reject(
script_state,
V8ThrowException::CreateTypeError(
script_state->GetIsolate(),
"Fetches with duplicate requests are not yet supported. "
"Consider adding query params to make the requests unique. "
"For updates check http://crbug.com/871174"));
}
kurls.size() != fetch_api_requests.size());
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
ScriptPromise promise = resolver->Promise();
......
......@@ -44,3 +44,21 @@ backgroundFetchTest(async (test, backgroundFetch) => {
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.');
......@@ -8,7 +8,7 @@ FAIL Requests with text/json content type require CORS Preflight and succeed. as
PASS Using Background Fetch to successfully fetch a single resource
PASS Registration object gets updated values when a background fetch completes.
PASS Background Fetch that exceeds the quota throws a QuotaExceededError
FAIL Fetches can have requests with duplicate URLs promise_test: Unhandled rejection with value: object "TypeError: Fetches with duplicate requests are not yet supported. Consider adding query params to make the requests unique. For updates check http://crbug.com/871174"
PASS Fetches can have requests with duplicate URLs
PASS recordsAvailable is false after onbackgroundfetchsuccess finishes execution.
PASS Using Background Fetch to fetch a non-existent resource should fail.
PASS Fetches with mixed content should fail.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment