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) {
CreateRegistration(registration_id,
std::vector<ServiceWorkerFetchRequest>(),
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.
......@@ -841,7 +842,8 @@ TEST_F(BackgroundFetchDataManagerTest, RegistrationLimitIsEnforced) {
CreateRegistration(registration_id,
std::vector<ServiceWorkerFetchRequest>(),
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(
DCHECK_EQ(error, blink::mojom::BackgroundFetchError::NONE);
if (!can_create) {
// TODO(crbug.com/889401): Report a more descriptive storage error.
FinishWithError(blink::mojom::BackgroundFetchError::QUOTA_EXCEEDED);
FinishWithError(
blink::mojom::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED);
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 {
STORAGE_ERROR,
SERVICE_WORKER_UNAVAILABLE,
QUOTA_EXCEEDED,
PERMISSION_DENIED
PERMISSION_DENIED,
REGISTRATION_LIMIT_EXCEEDED
};
// Struct representing completed Background Fetch requests, along with their
......
......@@ -342,6 +342,11 @@ void BackgroundFetchManager::DidFetch(
resolver->Reject(DOMException::Create(
DOMExceptionCode::kQuotaExceededError, "Quota exceeded."));
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_ID:
// Not applicable for this callback.
......@@ -477,6 +482,7 @@ void BackgroundFetchManager::DidGetRegistration(
case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT:
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback.
break;
}
......@@ -528,6 +534,7 @@ void BackgroundFetchManager::DidGetDeveloperIds(
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback.
break;
}
......
......@@ -275,6 +275,7 @@ void BackgroundFetchRegistration::DidAbort(
case mojom::blink::BackgroundFetchError::INVALID_ARGUMENT:
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback.
break;
}
......
......@@ -117,6 +117,7 @@ void BackgroundFetchUpdateUIEvent::DidUpdateUI(
case mojom::blink::BackgroundFetchError::SERVICE_WORKER_UNAVAILABLE:
case mojom::blink::BackgroundFetchError::PERMISSION_DENIED:
case mojom::blink::BackgroundFetchError::QUOTA_EXCEEDED:
case mojom::blink::BackgroundFetchError::REGISTRATION_LIMIT_EXCEEDED:
// Not applicable for this callback.
break;
}
......
......@@ -3209,6 +3209,7 @@ uploading your change for review. These are checked by presubmit scripts.
<int value="5" label="Service Worker unavailable"/>
<int value="6" label="Quota exceeded"/>
<int value="7" label="Permission denied"/>
<int value="8" label="Registration Limit Exceeded"/>
</enum>
<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