Commit 933c4c53 authored by Rayan Kanso's avatar Rayan Kanso Committed by Commit Bot

[Background Fetch] Report registration limit error to developers.

Adds a BackgroundFetchError which is propagated to the developer.

Bug: 889401
Change-Id: Ie4505cd0f50ab263cce5d66c854094133bc3539c
Reviewed-on: https://chromium-review.googlesource.com/1246102
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Reviewed-by: default avatarMugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595933}
parent 6c9478ff
...@@ -831,7 +831,8 @@ TEST_F(BackgroundFetchDataManagerTest, RegistrationLimitIsEnforced) { ...@@ -831,7 +831,8 @@ TEST_F(BackgroundFetchDataManagerTest, RegistrationLimitIsEnforced) {
CreateRegistration(registration_id, CreateRegistration(registration_id,
std::vector<ServiceWorkerFetchRequest>(), std::vector<ServiceWorkerFetchRequest>(),
BackgroundFetchOptions(), SkBitmap(), &error); BackgroundFetchOptions(), SkBitmap(), &error);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::QUOTA_EXCEEDED); ASSERT_EQ(error,
blink::mojom::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED);
} }
// The registration should also fail for the other Service Worker. // The registration should also fail for the other Service Worker.
...@@ -841,7 +842,8 @@ TEST_F(BackgroundFetchDataManagerTest, RegistrationLimitIsEnforced) { ...@@ -841,7 +842,8 @@ TEST_F(BackgroundFetchDataManagerTest, RegistrationLimitIsEnforced) {
CreateRegistration(registration_id, CreateRegistration(registration_id,
std::vector<ServiceWorkerFetchRequest>(), std::vector<ServiceWorkerFetchRequest>(),
BackgroundFetchOptions(), SkBitmap(), &error); BackgroundFetchOptions(), SkBitmap(), &error);
ASSERT_EQ(error, blink::mojom::BackgroundFetchError::QUOTA_EXCEEDED); ASSERT_EQ(error,
blink::mojom::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED);
} }
} }
......
...@@ -156,8 +156,8 @@ void CreateMetadataTask::DidGetCanCreateRegistration( ...@@ -156,8 +156,8 @@ void CreateMetadataTask::DidGetCanCreateRegistration(
DCHECK_EQ(error, blink::mojom::BackgroundFetchError::NONE); DCHECK_EQ(error, blink::mojom::BackgroundFetchError::NONE);
if (!can_create) { if (!can_create) {
// TODO(crbug.com/889401): Report a more descriptive storage error. FinishWithError(
FinishWithError(blink::mojom::BackgroundFetchError::QUOTA_EXCEEDED); blink::mojom::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED);
return; return;
} }
......
<!doctype html>
<meta charset="utf-8">
<title>Background Fetch API: CORS preflight blocking test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/serviceworker/resources/test-helpers.js"></script>
<script src="resources/utils.js"></script>
<script>
'use strict';
// https://crbug.com/889401
backgroundFetchTest(async (t, bgFetch) => {
const registrationPromises = [];
for (let i = 0; i < 6; i++) {
const registrationPromise = bgFetch.fetch(
`my-fetch-${i}`,
'/serviceworker/resources/slow-response.php');
registrationPromises.push(registrationPromise);
}
try {
await Promise.all(registrationPromises);
assert_unreached('Should have rejected the registration exceeding the limit');
} catch (e) {
assert_equals(e.message, 'There are too many active fetches for this origin.');
}
}, 'Registration rejected after limit exceeded');
</script>
\ No newline at end of file
...@@ -19,7 +19,8 @@ enum BackgroundFetchError { ...@@ -19,7 +19,8 @@ enum BackgroundFetchError {
STORAGE_ERROR, STORAGE_ERROR,
SERVICE_WORKER_UNAVAILABLE, SERVICE_WORKER_UNAVAILABLE,
QUOTA_EXCEEDED, QUOTA_EXCEEDED,
PERMISSION_DENIED PERMISSION_DENIED,
REGISTRATION_LIMIT_EXCEEDED
}; };
// Struct representing completed Background Fetch requests, along with their // Struct representing completed Background Fetch requests, along with their
......
...@@ -342,6 +342,11 @@ void BackgroundFetchManager::DidFetch( ...@@ -342,6 +342,11 @@ void BackgroundFetchManager::DidFetch(
resolver->Reject(DOMException::Create( resolver->Reject(DOMException::Create(
DOMExceptionCode::kQuotaExceededError, "Quota exceeded.")); DOMExceptionCode::kQuotaExceededError, "Quota exceeded."));
return; return;
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
resolver->Reject(V8ThrowException::CreateTypeError(
script_state->GetIsolate(),
"There are too many active fetches for this origin."));
return;
case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT: case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT:
case mojom::blink::BackgroundFetchError::INVALID_ID: case mojom::blink::BackgroundFetchError::INVALID_ID:
// Not applicable for this callback. // Not applicable for this callback.
...@@ -477,6 +482,7 @@ void BackgroundFetchManager::DidGetRegistration( ...@@ -477,6 +482,7 @@ void BackgroundFetchManager::DidGetRegistration(
case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT: case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT:
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED: case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED: case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback. // Not applicable for this callback.
break; break;
} }
...@@ -528,6 +534,7 @@ void BackgroundFetchManager::DidGetDeveloperIds( ...@@ -528,6 +534,7 @@ void BackgroundFetchManager::DidGetDeveloperIds(
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED: case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE: case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED: case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback. // Not applicable for this callback.
break; break;
} }
......
...@@ -275,6 +275,7 @@ void BackgroundFetchRegistration::DidAbort( ...@@ -275,6 +275,7 @@ void BackgroundFetchRegistration::DidAbort(
case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT: case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT:
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED: case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED: case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback. // Not applicable for this callback.
break; break;
} }
......
...@@ -117,6 +117,7 @@ void BackgroundFetchUpdateUIEvent::DidUpdateUI( ...@@ -117,6 +117,7 @@ void BackgroundFetchUpdateUIEvent::DidUpdateUI(
case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE: case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE:
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED: case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED: case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback. // Not applicable for this callback.
break; break;
} }
......
...@@ -3209,6 +3209,7 @@ uploading your change for review. These are checked by presubmit scripts. ...@@ -3209,6 +3209,7 @@ uploading your change for review. These are checked by presubmit scripts.
<int value="5" label="Service Worker unavailable"/> <int value="5" label="Service Worker unavailable"/>
<int value="6" label="Quota exceeded"/> <int value="6" label="Quota exceeded"/>
<int value="7" label="Permission denied"/> <int value="7" label="Permission denied"/>
<int value="8" label="Registration Limit Exceeded"/>
</enum> </enum>
<enum name="BackgroundFetchEventDispatchResult"> <enum name="BackgroundFetchEventDispatchResult">
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