Skip to content

Update QuotaExceededError expectations #53645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions WebCryptoAPI/getRandomValues.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ for (const array of arrays) {

test(function() {
const maxlength = 65536 / ctor.BYTES_PER_ELEMENT;
assert_throws_dom("QuotaExceededError", function() {
self.crypto.getRandomValues(new ctor(maxlength + 1))
}, "crypto.getRandomValues length over 65536")

try {
self.crypto.getRandomValues(new ctor(maxlength + 1));
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError, "QuotaExceededError constructor match");
assert_equals(e.quota, null, "quota");
assert_equals(e.requested, null, "requested");
}
}, "Large length: " + array);

test(function() {
Expand Down
9 changes: 8 additions & 1 deletion ai/language_detection/detector.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ promise_test(async t => {
const detectPromise = detector.detect(text);

if (inputUsage >= detector.inputQuota) {
await promise_rejects_dom(t, 'QuotaExceededError', detectPromise);
try {
await detectPromise;
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError,
'QuotaExceededError constructor match');
assert_equals(e.quota, detector.inputQuota, 'quota');
assert_not_equals(e.requested, null, 'requested');
}
} else {
await detectPromise;
}
Expand Down
10 changes: 8 additions & 2 deletions ai/translator/translator.optional.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@ promise_test(async t => {
if (inputUsage < translator.inputQuota) {
assert_equals(await translator.translate(text), 'こんにちは');
} else {
await promise_rejects_dom(
t, 'QuotaExceededError', translator.translate(text));
try {
await translator.translate(text);
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError,
'QuotaExceededError constructor match');
assert_equals(e.quota, translator.inputQuota, 'quota');
assert_not_equals(e.requested, null, 'requested');
}
}
}, 'Translator.measureInputUsage() and inputQuota basic usage.');

Expand Down
12 changes: 8 additions & 4 deletions background-fetch/fetch.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ backgroundFetchTest(async (test, backgroundFetch) => {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function runTest(config, qualifier) {
assert_equals(_video2.mediaKeys, _mediaKeys);
return Promise.resolve();
}, function(error) {
assert_equals(error.name, 'QuotaExceededError');
assert_equals(error.constructor, globalThis.QuotaExceededError, 'QuotaExceededError constructor match');
assert_equals(error.quota, null, 'quota');
assert_equals(error.requested, null, 'requested');
assert_not_equals(error.message, '');
// Return something so the promise resolves properly.
return Promise.resolve();
Expand All @@ -51,4 +53,4 @@ function runTest(config, qualifier) {
test.done();
}).catch(onFailure);
}, testname);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ test(

// Makes the 2nd call (POST) to the same reporting origin that sends
// max bytes, which should be rejected.
assert_throws_dom('QuotaExceededError', () => {
try {
fetchLater(requestUrl, {
method: 'POST',
signal: controller.signal,
body: makeBeaconData(generatePayload(quota), dataType),
// Required, as the size of referrer also take up quota.
referrer: '',
});
});
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError,
'QuotaExceededError constructor match');
assert_equals(e.quota, null, 'quota');
assert_equals(e.requested, null, 'requested');
}

// Makes the 3rd call (GET) to the same reporting origin, where its
// request size is len(requestUrl) + headers, which should be accepted.
Expand Down
23 changes: 14 additions & 9 deletions fetch/fetch-later/quota/max-payload.tentative.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ promise_test(async _ => {
test(_ => {
const uuid = token();
const requestUrl = generateSetBeaconURL(uuid, {host: HTTPS_ORIGIN});
assert_throws_dom(
'QuotaExceededError',
() => fetchLater(requestUrl, {
activateAfter: 0,
method: 'POST',
body: generatePayload(
getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
dataType),
}));
try {
fetchLater(requestUrl, {
activateAfter: 0,
method: 'POST',
body: generatePayload(
getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
dataType),
});
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError,
'QuotaExceededError constructor match');
assert_equals(e.quota, null, 'quota');
assert_equals(e.requested, null, 'requested');
}
}, `fetchLater() rejects max+1 payload in a POST request body of ${dataType}.`);
25 changes: 15 additions & 10 deletions fetch/fetch-later/quota/oversized-payload.tentative.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ const OVERSIZED_REQUEST_BODY_SIZE = QUOTA_PER_ORIGIN + 1;
for (const dataType in BeaconDataType) {
// Test making a POST request with oversized payload, which should be rejected
// by fetchLater API.
test(
() => assert_throws_dom(
'QuotaExceededError',
() => fetchLater('/', {
activateAfter: 0,
method: 'POST',
body: makeBeaconData(
generatePayload(OVERSIZED_REQUEST_BODY_SIZE), dataType),
})),
`fetchLater() does not accept payload[size=${
test(() => {
try {
fetchLater('/', {
activateAfter: 0,
method: 'POST',
body: makeBeaconData(
generatePayload(OVERSIZED_REQUEST_BODY_SIZE), dataType),
});
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError,
'QuotaExceededError constructor match');
assert_equals(e.quota, null, 'quota');
assert_equals(e.requested, null, 'requested');
}
}, `fetchLater() does not accept payload[size=${
OVERSIZED_REQUEST_BODY_SIZE}] exceeding per-origin quota in a POST request body of ${
dataType}.`);
}
6 changes: 0 additions & 6 deletions fetch/fetch-later/resources/fetch-later.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
fetchLater(TARGET_URL, REQUEST_INIT);
postMessageBack({type: FetchLaterIframeMessageType.DONE});
} catch (e) {
if (e.name == "QuotaExceededError" &&
e instanceof DOMException) {
// PostMessage is unable to serialize the QuotExceededError object.
// Therefore do basic checks here and pass error name if successful.
e = {name: e.name};
}
postMessageBack({type: FetchLaterIframeMessageType.ERROR, error: e});
}
</script>
Expand Down
13 changes: 9 additions & 4 deletions fs/script-tests/FileSystemBaseHandle-buckets.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ directory_test(async (t, root_dir) => {
await createFileWithContents('mtime.txt', 'short file', inboxRootDir);

// Longer file fails.
return promise_rejects_dom(
t, 'QuotaExceededError',
createFileWithContents(
try {
await createFileWithContents(
'mtime2.txt',
'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',
inboxRootDir));
inboxRootDir);
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError,
'QuotaExceededError constructor match');
assert_equals(e.quota, null, 'quota');
assert_equals(e.requested, null, 'requested');
}
}, 'Bucket quota restricts the size of a file that can be created');
5 changes: 4 additions & 1 deletion media-source/mediasource-appendbuffer-quota-exceeded.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
sourceBuffer.appendBuffer(dataAudio);
},
function (ex, previousBufferedStart, previousBufferedEnd) { // onCaughtExceptionCallback
assert_equals(ex.name, 'QuotaExceededError');
assert_equals(ex.constructor, globalThis.QuotaExceededError, 'QuotaExceededError constructor match');
assert_equals(ex.quota, null, 'quota');
assert_equals(ex.requested, null, 'requested');

// Verify that the state looks like appendBuffer stops executing its steps if the prepare append
// algorithm aborts after throwing `QuotaExceededError`.

Expand Down
5 changes: 2 additions & 3 deletions resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,6 @@
NETWORK_ERR: 'NetworkError',
ABORT_ERR: 'AbortError',
URL_MISMATCH_ERR: 'URLMismatchError',
QUOTA_EXCEEDED_ERR: 'QuotaExceededError',
TIMEOUT_ERR: 'TimeoutError',
INVALID_NODE_TYPE_ERR: 'InvalidNodeTypeError',
DATA_CLONE_ERR: 'DataCloneError'
Expand All @@ -2321,7 +2320,6 @@
NetworkError: 19,
AbortError: 20,
URLMismatchError: 21,
QuotaExceededError: 22,
TimeoutError: 23,
InvalidNodeTypeError: 24,
DataCloneError: 25,
Expand All @@ -2336,7 +2334,8 @@
VersionError: 0,
OperationError: 0,
NotAllowedError: 0,
OptOutError: 0
OptOutError: 0,
QuotaExceededError: 0
};

var code_name_map = {};
Expand Down
10 changes: 8 additions & 2 deletions storage/buckets/bucket-quota-indexeddb.tentative.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ promise_test(async t => {
type: 'binary/random'
}), 2);

await promise_rejects_dom(
t, 'QuotaExceededError', transactionPromise(txn));
try {
await transactionPromise(txn);
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError,
'QuotaExceededError constructor match');
assert_equals(e.quota, null, 'quota');
assert_equals(e.requested, null, 'requested');
}

db.close();
}, 'IDB respects bucket quota');
5 changes: 2 additions & 3 deletions wasm/core/js/harness/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,6 @@ policies and contribution forms [3].
NETWORK_ERR: 'NetworkError',
ABORT_ERR: 'AbortError',
URL_MISMATCH_ERR: 'URLMismatchError',
QUOTA_EXCEEDED_ERR: 'QuotaExceededError',
TIMEOUT_ERR: 'TimeoutError',
INVALID_NODE_TYPE_ERR: 'InvalidNodeTypeError',
DATA_CLONE_ERR: 'DataCloneError'
Expand All @@ -1237,7 +1236,6 @@ policies and contribution forms [3].
NetworkError: 19,
AbortError: 20,
URLMismatchError: 21,
QuotaExceededError: 22,
TimeoutError: 23,
InvalidNodeTypeError: 24,
DataCloneError: 25,
Expand All @@ -1251,7 +1249,8 @@ policies and contribution forms [3].
ReadOnlyError: 0,
VersionError: 0,
OperationError: 0,
NotAllowedError: 0
NotAllowedError: 0,
QuotaExceededError: 0
};

if (!(name in name_code_map)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ test(function() {
{name: "NetworkError", code: 19},
{name: "AbortError", code: 20},
{name: "URLMismatchError", code: 21},
{name: "QuotaExceededError", code: 22},
{name: "TimeoutError", code: 23},
{name: "InvalidNodeTypeError", code: 24},
{name: "DataCloneError", code: 25},
Expand All @@ -128,7 +127,9 @@ test(function() {
{name: "ReadOnlyError", code: 0},
{name: "VersionError", code: 0},
{name: "OperationError", code: 0},
{name: "NotAllowedError", code: 0}
{name: "NotAllowedError", code: 0},
// See https://github.com/whatwg/webidl/pull/1465.
{name: "QuotaExceededError", code: 0}
].forEach(function(test_case) {
test(function() {
var ex = new DOMException("msg", test_case.name);
Expand Down
15 changes: 11 additions & 4 deletions webstorage/storage_local_setitem_quotaexceedederr.window.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
test(function() {
test(t => {
localStorage.clear();

var index = 0;
var key = "name";
var val = "x".repeat(1024);

assert_throws_dom("QUOTA_EXCEEDED_ERR", function() {
t.add_cleanup(() => {
localStorage.clear();
});

try {
while (true) {
index++;
localStorage.setItem("" + key + index, "" + val + index);
}
});
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError, "QuotaExceededError constructor match");
assert_equals(e.quota, null, "quota");
assert_equals(e.requested, null, "requested");
}

localStorage.clear();
}, "Throws QuotaExceededError when the quota has been exceeded");
15 changes: 11 additions & 4 deletions webstorage/storage_session_setitem_quotaexceedederr.window.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
test(function() {
test(t => {
sessionStorage.clear();

var index = 0;
var key = "name";
var val = "x".repeat(1024);

assert_throws_dom("QUOTA_EXCEEDED_ERR", function() {
t.add_cleanup(() => {
sessionStorage.clear();
});

try {
while (true) {
index++;
sessionStorage.setItem("" + key + index, "" + val + index);
}
});
} catch (e) {
assert_equals(e.constructor, globalThis.QuotaExceededError, "QuotaExceededError constructor match");
assert_equals(e.quota, null, "quota");
assert_equals(e.requested, null, "requested");
}

sessionStorage.clear();
}, "Throws QuotaExceededError when the quota has been exceeded");