Skip to content

Commit aa7246b

Browse files
committed
Correct other QuotaExceededError expectations
1 parent 4c7520e commit aa7246b

15 files changed

+109
-56
lines changed

WebCryptoAPI/getRandomValues.any.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ for (const array of arrays) {
6060

6161
test(function() {
6262
const maxlength = 65536 / ctor.BYTES_PER_ELEMENT;
63-
assert_throws_dom("QuotaExceededError", function() {
64-
self.crypto.getRandomValues(new ctor(maxlength + 1))
65-
}, "crypto.getRandomValues length over 65536")
63+
64+
try {
65+
self.crypto.getRandomValues(new ctor(maxlength + 1));
66+
} catch (e) {
67+
assert_equals(e.constructor, globalThis.QuotaExceededError, "QuotaExceededError constructor match");
68+
assert_equals(e.quota, null, "quota");
69+
assert_equals(e.requested, null, "requested");
70+
}
6671
}, "Large length: " + array);
6772

6873
test(function() {

ai/language_detection/detector.https.window.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ promise_test(async t => {
133133
const detectPromise = detector.detect(text);
134134

135135
if (inputUsage >= detector.inputQuota) {
136-
await promise_rejects_dom(t, 'QuotaExceededError', detectPromise);
136+
try {
137+
await detectPromise;
138+
} catch (e) {
139+
assert_equals(e.constructor, globalThis.QuotaExceededError,
140+
'QuotaExceededError constructor match');
141+
assert_equals(e.quota, detector.inputQuota, 'quota');
142+
assert_not_equals(e.requested, null, 'requested');
143+
}
137144
} else {
138145
await detectPromise;
139146
}

ai/translator/translator.optional.https.window.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,14 @@ promise_test(async t => {
189189
if (inputUsage < translator.inputQuota) {
190190
assert_equals(await translator.translate(text), 'こんにちは');
191191
} else {
192-
await promise_rejects_dom(
193-
t, 'QuotaExceededError', translator.translate(text));
192+
try {
193+
await translator.translate(text);
194+
} catch (e) {
195+
assert_equals(e.constructor, globalThis.QuotaExceededError,
196+
'QuotaExceededError constructor match');
197+
assert_equals(e.quota, translator.inputQuota, 'quota');
198+
assert_not_equals(e.requested, null, 'requested');
199+
}
194200
}
195201
}, 'Translator.measureInputUsage() and inputQuota basic usage.');
196202

background-fetch/fetch.https.window.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,14 @@ backgroundFetchTest(async (test, backgroundFetch) => {
170170

171171
// Very large download total that will definitely exceed the quota.
172172
const options = {downloadTotal: Number.MAX_SAFE_INTEGER};
173-
await promise_rejects_dom(
174-
test, 'QUOTA_EXCEEDED_ERR',
175-
backgroundFetch.fetch(registrationId, 'resources/feature-name.txt', options),
176-
'This fetch should have thrown a quota exceeded error');
173+
try {
174+
await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt', options);
175+
} catch (e) {
176+
assert_equals(e.constructor, globalThis.QuotaExceededError,
177+
'QuotaExceededError constructor match');
178+
assert_equals(e.quota, null, 'quota');
179+
assert_equals(e.requested, null, 'requested');
180+
}
177181

178182
}, 'Background Fetch that exceeds the quota throws a QuotaExceededError');
179183

encrypted-media/scripts/setmediakeys-to-multiple-video-elements.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ function runTest(config, qualifier) {
3535
assert_equals(_video2.mediaKeys, _mediaKeys);
3636
return Promise.resolve();
3737
}, function(error) {
38-
assert_equals(error.name, 'QuotaExceededError');
38+
assert_equals(error.constructor, globalThis.QuotaExceededError, 'QuotaExceededError constructor match');
39+
assert_equals(error.quota, null, 'quota');
40+
assert_equals(error.requested, null, 'requested');
3941
assert_not_equals(error.message, '');
4042
// Return something so the promise resolves properly.
4143
return Promise.resolve();
@@ -51,4 +53,4 @@ function runTest(config, qualifier) {
5153
test.done();
5254
}).catch(onFailure);
5355
}, testname);
54-
}
56+
}

fetch/fetch-later/quota/accumulated-oversized-payload.tentative.https.window.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,20 @@ test(
3737

3838
// Makes the 2nd call (POST) to the same reporting origin that sends
3939
// max bytes, which should be rejected.
40-
assert_throws_dom('QuotaExceededError', () => {
40+
try {
4141
fetchLater(requestUrl, {
4242
method: 'POST',
4343
signal: controller.signal,
4444
body: makeBeaconData(generatePayload(quota), dataType),
4545
// Required, as the size of referrer also take up quota.
4646
referrer: '',
4747
});
48-
});
48+
} catch (e) {
49+
assert_equals(e.constructor, globalThis.QuotaExceededError,
50+
'QuotaExceededError constructor match');
51+
assert_equals(e.quota, null, 'quota');
52+
assert_equals(e.requested, null, 'requested');
53+
}
4954

5055
// Makes the 3rd call (GET) to the same reporting origin, where its
5156
// request size is len(requestUrl) + headers, which should be accepted.

fetch/fetch-later/quota/max-payload.tentative.https.window.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ promise_test(async _ => {
3636
test(_ => {
3737
const uuid = token();
3838
const requestUrl = generateSetBeaconURL(uuid, {host: HTTPS_ORIGIN});
39-
assert_throws_dom(
40-
'QuotaExceededError',
41-
() => fetchLater(requestUrl, {
42-
activateAfter: 0,
43-
method: 'POST',
44-
body: generatePayload(
45-
getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
46-
dataType),
47-
}));
39+
try {
40+
fetchLater(requestUrl, {
41+
activateAfter: 0,
42+
method: 'POST',
43+
body: generatePayload(
44+
getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
45+
dataType),
46+
});
47+
} catch (e) {
48+
assert_equals(e.constructor, globalThis.QuotaExceededError,
49+
'QuotaExceededError constructor match');
50+
assert_equals(e.quota, null, 'quota');
51+
assert_equals(e.requested, null, 'requested');
52+
}
4853
}, `fetchLater() rejects max+1 payload in a POST request body of ${dataType}.`);

fetch/fetch-later/quota/oversized-payload.tentative.https.window.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ const OVERSIZED_REQUEST_BODY_SIZE = QUOTA_PER_ORIGIN + 1;
99
for (const dataType in BeaconDataType) {
1010
// Test making a POST request with oversized payload, which should be rejected
1111
// by fetchLater API.
12-
test(
13-
() => assert_throws_dom(
14-
'QuotaExceededError',
15-
() => fetchLater('/', {
16-
activateAfter: 0,
17-
method: 'POST',
18-
body: makeBeaconData(
19-
generatePayload(OVERSIZED_REQUEST_BODY_SIZE), dataType),
20-
})),
21-
`fetchLater() does not accept payload[size=${
12+
test(() => {
13+
try {
14+
fetchLater('/', {
15+
activateAfter: 0,
16+
method: 'POST',
17+
body: makeBeaconData(
18+
generatePayload(OVERSIZED_REQUEST_BODY_SIZE), dataType),
19+
});
20+
} catch (e) {
21+
assert_equals(e.constructor, globalThis.QuotaExceededError,
22+
'QuotaExceededError constructor match');
23+
assert_equals(e.quota, null, 'quota');
24+
assert_equals(e.requested, null, 'requested');
25+
}
26+
}, `fetchLater() does not accept payload[size=${
2227
OVERSIZED_REQUEST_BODY_SIZE}] exceeding per-origin quota in a POST request body of ${
2328
dataType}.`);
2429
}

fetch/fetch-later/resources/fetch-later.html

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030
fetchLater(TARGET_URL, REQUEST_INIT);
3131
postMessageBack({type: FetchLaterIframeMessageType.DONE});
3232
} catch (e) {
33-
if (e.name == "QuotaExceededError" &&
34-
e instanceof DOMException) {
35-
// PostMessage is unable to serialize the QuotExceededError object.
36-
// Therefore do basic checks here and pass error name if successful.
37-
e = {name: e.name};
38-
}
3933
postMessageBack({type: FetchLaterIframeMessageType.ERROR, error: e});
4034
}
4135
</script>

fs/script-tests/FileSystemBaseHandle-buckets.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ directory_test(async (t, root_dir) => {
3434
await createFileWithContents('mtime.txt', 'short file', inboxRootDir);
3535

3636
// Longer file fails.
37-
return promise_rejects_dom(
38-
t, 'QuotaExceededError',
39-
createFileWithContents(
37+
try {
38+
await createFileWithContents(
4039
'mtime2.txt',
4140
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum',
42-
inboxRootDir));
41+
inboxRootDir);
42+
} catch (e) {
43+
assert_equals(e.constructor, globalThis.QuotaExceededError,
44+
'QuotaExceededError constructor match');
45+
assert_equals(e.quota, null, 'quota');
46+
assert_equals(e.requested, null, 'requested');
47+
}
4348
}, 'Bucket quota restricts the size of a file that can be created');

0 commit comments

Comments
 (0)