Skip to content

Update WPT #4358

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 1 commit into
base: main
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
2 changes: 2 additions & 0 deletions test/fixtures/wpt/common/get-host-info.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function get_host_info() {
var REMOTE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('www1.' + ORIGINAL_HOST);
var OTHER_HOST = '{{domains[www2]}}';
var NOTSAMESITE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('{{hosts[alt][]}}');
var OTHER_NOTSAMESITE_HOST = '{{hosts[alt][www2]}}';

return {
HTTP_PORT: HTTP_PORT,
Expand All @@ -45,6 +46,7 @@ function get_host_info() {
HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + HTTPS_PORT_ELIDED,
HTTPS_REMOTE_ORIGIN_WITH_CREDS: 'https://foo:bar@' + REMOTE_HOST + HTTPS_PORT_ELIDED,
HTTPS_NOTSAMESITE_ORIGIN: 'https://' + NOTSAMESITE_HOST + HTTPS_PORT_ELIDED,
HTTPS_OTHER_NOTSAMESITE_ORIGIN: 'https://' + OTHER_NOTSAMESITE_HOST + HTTPS_PORT_ELIDED,
UNAUTHENTICATED_ORIGIN: 'http://' + OTHER_HOST + HTTP_PORT_ELIDED,
AUTHENTICATED_ORIGIN: 'https://' + OTHER_HOST + HTTPS_PORT_ELIDED
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ test(

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

// Makes the 3rd call (GET) to the same reporting origin, where its
// request size is len(requestUrl) + headers, which should be accepted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ 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),
}));

assert_throws_quotaexceedederror(() => {
fetchLater(requestUrl, {
activateAfter: 0,
method: 'POST',
body: generatePayload(
getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
dataType),
});
}, null, null);
}, `fetchLater() rejects max+1 payload in a POST request body of ${dataType}.`);
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ 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(() => {
assert_throws_quotaexceedederror(() => {
fetchLater('/', {
activateAfter: 0,
method: 'POST',
body: makeBeaconData(
generatePayload(OVERSIZED_REQUEST_BODY_SIZE), dataType),
});
}, null, null);
}, `fetchLater() does not accept payload[size=${
OVERSIZED_REQUEST_BODY_SIZE}] exceeding per-origin quota in a POST request body of ${
dataType}.`);
}
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
4 changes: 2 additions & 2 deletions test/fixtures/wpt/fetch/local-network-access/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ the Fetch specification.

See also:

* [Explainer](https://github.com/explainers-by-googlers/local-network-access)
* [Spec](https://wicg.github.io/local-network-access/)

Local Network Access replaced [Private Network
Access](https://wicg.github.io/local-network-access/).
Access](https://wicg.github.io/private-network-access/).
191 changes: 188 additions & 3 deletions test/fixtures/wpt/resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,54 @@
});
}

/**
* Assert that a `Promise` is rejected with a `QuotaExceededError` with the
* expected values.
*
* For the remaining arguments, there are two ways of calling
* `promise_rejects_quotaexceedederror`:
*
* 1) If the `QuotaExceededError` is expected to come from the
* current global, the second argument should be the promise
* expected to reject, the third and a fourth the expected
* `requested` and `quota` property values, and the fifth,
* optional, argument is the assertion description.
*
* 2) If the `QuotaExceededError` is expected to come from some
* other global, the second argument should be the
* `QuotaExceededError` constructor from that global, the third
* argument should be the promise expected to reject, the fourth
* and fifth the expected `requested` and `quota` property
* values, and the sixth, optional, argument is the assertion
* description.
*
*/
function promise_rejects_quotaexceedederror(test, promiseOrConstructor, requestedOrPromise, quotaOrRequested, descriptionOrQuota, maybeDescription)
{
let constructor, promise, requested, quota, description;
if (typeof promiseOrConstructor === "function" &&
promiseOrConstructor.name === "QuotaExceededError") {
constructor = promiseOrConstructor;
promise = requestedOrPromise;
requested = quotaOrRequested;
quota = descriptionOrQuota;
description = maybeDescription;
} else {
constructor = self.QuotaExceededError;
promise = promiseOrConstructor;
requested = requestedOrPromise;
quota = quotaOrRequested;
description = descriptionOrQuota;
assert(maybeDescription === undefined,
"Too many args passed to no-constructor version of promise_rejects_quotaexceedederror");
}
return bring_promise_to_current_realm(promise)
.then(test.unreached_func("Should have rejected: " + description))
.catch(function(e) {
assert_throws_quotaexceedederror_impl(function() { throw e; }, requested, quota, description, "promise_rejects_quotaexceedederror", constructor);
});
}

/**
* Assert that a Promise is rejected with the provided value.
*
Expand Down Expand Up @@ -1240,6 +1288,7 @@
expose(promise_test, 'promise_test');
expose(promise_rejects_js, 'promise_rejects_js');
expose(promise_rejects_dom, 'promise_rejects_dom');
expose(promise_rejects_quotaexceedederror, 'promise_rejects_quotaexceedederror');
expose(promise_rejects_exactly, 'promise_rejects_exactly');
expose(generate_tests, 'generate_tests');
expose(setup, 'setup');
Expand Down Expand Up @@ -2296,7 +2345,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 +2369,6 @@
NetworkError: 19,
AbortError: 20,
URLMismatchError: 21,
QuotaExceededError: 22,
TimeoutError: 23,
InvalidNodeTypeError: 24,
DataCloneError: 25,
Expand Down Expand Up @@ -2352,12 +2399,19 @@
if (typeof type === "number") {
if (type === 0) {
throw new AssertionError('Test bug: ambiguous DOMException code 0 passed to assert_throws_dom()');
} else if (!(type in code_name_map)) {
}
if (type === 22) {
throw new AssertionError('Test bug: QuotaExceededError needs to be tested for using assert_throws_quotaexceedederror()');
}
if (!(type in code_name_map)) {
throw new AssertionError('Test bug: unrecognized DOMException code "' + type + '" passed to assert_throws_dom()');
}
name = code_name_map[type];
required_props.code = type;
} else if (typeof type === "string") {
if (name === "QuotaExceededError") {
throw new AssertionError('Test bug: QuotaExceededError needs to be tested for using assert_throws_quotaexceedederror()');
}
name = type in codename_name_map ? codename_name_map[type] : type;
if (!(name in name_code_map)) {
throw new AssertionError('Test bug: unrecognized DOMException code name or name "' + type + '" passed to assert_throws_dom()');
Expand Down Expand Up @@ -2392,6 +2446,137 @@
}
}

/**
* Assert a `QuotaExceededError` with the expected values is thrown.
*
* There are two ways of calling `assert_throws_quotaexceedederror`:
*
* 1) If the `QuotaExceededError` is expected to come from the
* current global, the first argument should be the function
* expected to throw, the second and a third the expected
* `requested` and `quota` property values, and the fourth,
* optional, argument is the assertion description.
*
* 2) If the `QuotaExceededError` is expected to come from some
* other global, the first argument should be the
* `QuotaExceededError` constructor from that global, the second
* argument should be the function expected to throw, the third
* and fourth the expected `requested` and `quota` property
* values, and the fifth, optional, argument is the assertion
* description.
*
* For the `requested` and `quota` values, instead of `null` or a
* number, the caller can provide a function which determines
* whether the value is acceptable by returning a boolean.
*
*/
function assert_throws_quotaexceedederror(funcOrConstructor, requestedOrFunc, quotaOrRequested, descriptionOrQuota, maybeDescription)
{
let constructor, func, requested, quota, description;
if (funcOrConstructor.name === "QuotaExceededError") {
constructor = funcOrConstructor;
func = requestedOrFunc;
requested = quotaOrRequested;
quota = descriptionOrQuota;
description = maybeDescription;
} else {
constructor = self.QuotaExceededError;
func = funcOrConstructor;
requested = requestedOrFunc;
quota = quotaOrRequested;
description = descriptionOrQuota;
assert(maybeDescription === undefined,
"Too many args passed to no-constructor version of assert_throws_quotaexceedederror");
}
assert_throws_quotaexceedederror_impl(func, requested, quota, description, "assert_throws_quotaexceedederror", constructor);
}
expose_assert(assert_throws_quotaexceedederror, "assert_throws_quotaexceedederror");

/**
* Similar to `assert_throws_quotaexceedederror` but allows
* specifying the assertion type
* (`"assert_throws_quotaexceedederror"` or
* `"promise_rejects_quotaexceedederror"`, in practice). The
* `constructor` argument must be the `QuotaExceededError`
* constructor from the global we expect the exception to come from.
*/
function assert_throws_quotaexceedederror_impl(func, requested, quota, description, assertion_type, constructor)
{
try {
func.call(this);
assert(false, assertion_type, description, "${func} did not throw",
{func});
} catch (e) {
if (e instanceof AssertionError) {
throw e;
}

// Basic sanity-checks on the thrown exception.
assert(typeof e === "object",
assertion_type, description,
"${func} threw ${e} with type ${type}, not an object",
{func, e, type:typeof e});

assert(e !== null,
assertion_type, description,
"${func} threw null, not an object",
{func});

// Sanity-check our requested and quota.
assert(requested === null ||
typeof requested === "number" ||
typeof requested === "function",
assertion_type, description,
"${requested} is not null, a number, or a function",
{requested});
assert(quota === null ||
typeof quota === "number" ||
typeof quota === "function",
assertion_type, description,
"${quota} is not null or a number",
{quota});

const required_props = {
code: 22,
name: "QuotaExceededError"
};
if (typeof requested !== "function") {
required_props.requested = requested;
}
if (typeof quota !== "function") {
required_props.quota = quota;
}

for (const [prop, expected] of Object.entries(required_props)) {
assert(prop in e && e[prop] == expected,
assertion_type, description,
"${func} threw ${e} that is not a correct QuotaExceededError: property ${prop} is equal to ${actual}, expected ${expected}",
{func, e, prop, actual:e[prop], expected});
}

if (typeof requested === "function") {
assert(requested(e.requested),
assertion_type, description,
"${func} threw ${e} that is not a correct QuotaExceededError: requested value ${requested} did not pass the requested predicate",
{func, e, requested});
}
if (typeof quota === "function") {
assert(quota(e.quota),
assertion_type, description,
"${func} threw ${e} that is not a correct QuotaExceededError: quota value ${quota} did not pass the quota predicate",
{func, e, quota});
}

// Check that the exception is from the right global. This check is last
// so more specific, and more informative, checks on the properties can
// happen in case a totally incorrect exception is thrown.
assert(e.constructor === constructor,
assertion_type, description,
"${func} threw an exception from the wrong global",
{func});
}
}

/**
* Assert the provided value is thrown.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ promise_test(async t => {
await indexedDbOpenRequest(t, bucket.indexedDB, dbname, (db_to_upgrade) => {
db_to_upgrade.createObjectStore(objectStoreName);
});
t.add_cleanup(() => {
db.close();
});

const txn = db.transaction(objectStoreName, 'readwrite');
const buffer = new ArrayBuffer(arraySize);
Expand All @@ -34,8 +37,5 @@ promise_test(async t => {
type: 'binary/random'
}), 2);

await promise_rejects_dom(
t, 'QuotaExceededError', transactionPromise(txn));

db.close();
await promise_rejects_quotaexceedederror(t, transactionPromise(txn), null, null);
}, 'IDB respects bucket quota');
Loading