Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ const halfQuota = Math.ceil(quota / 2);

// Tests that a reporting origin only allow queuing requests within its quota.
test(
() => {
(t) => {
const controller = new AbortController();
// Release quota taken by the pending requests for subsequent tests.
t.add_cleanup(() => controller.abort());

// Queues with the 1st call (POST) that sends max/2 quota.
fetchLater(requestUrl, {
Expand All @@ -37,21 +39,15 @@ test(

// Makes the 2nd call (POST) to the same reporting origin that sends
// max bytes, which should be rejected.
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: '',
});
},
// Either no information should be provided, or it should exactly
// be the expected values
(requested) => [QUOTA_PER_ORIGIN, null].includes(requested),
(remaining) => [halfQuota - 1, null].includes(remaining)
);
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: '',
});
}, QUOTA_PER_ORIGIN, halfQuota - 1);

// Makes the 3rd call (GET) to the same reporting origin, where its
// request size is len(requestUrl) + headers, which should be accepted.
Expand All @@ -61,9 +57,6 @@ test(
// Required, as the size of referrer also take up quota.
referrer: '',
});

// Release quota taken by the pending requests for subsequent tests.
controller.abort();
},
`The 2nd fetchLater(same-origin) call in the top-level document is not allowed to exceed per-origin quota for its POST body of ${
dataType}.`);
16 changes: 9 additions & 7 deletions fetch/fetch-later/quota/max-payload.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ promise_test(async _ => {
activateAfter: 0,
method: 'POST',
bodySize: getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers),
referrer: '',
},
{
targetUrl: requestUrl,
Expand All @@ -39,11 +40,12 @@ test(_ => {

assert_throws_quotaexceedederror(() => {
fetchLater(requestUrl, {
activateAfter: 0,
method: 'POST',
body: generatePayload(
getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
dataType),
});
}, null, null);
activateAfter: 0,
method: 'POST',
body: generatePayload(
getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers) + 1,
dataType),
referrer: '',
});
}, QUOTA_PER_ORIGIN + 1, QUOTA_PER_ORIGIN);
}, `fetchLater() rejects max+1 payload in a POST request body of ${dataType}.`);
7 changes: 3 additions & 4 deletions fetch/fetch-later/quota/multiple-origins.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const {HTTPS_ORIGIN, HTTPS_NOTSAMESITE_ORIGIN} = get_host_info();
for (const dataType in BeaconDataType) {
// Tests multiple request reporting origins within same document.
test(
() => {
(t) => {
const controller = new AbortController();
// Release quota taken by the pending requests for subsequent tests.
t.add_cleanup(() => controller.abort());

// Makes the 1st call (POST) that sends max/2+1 quota to `HTTPS_ORIGIN`.
fetchLater(`${HTTPS_ORIGIN}/`, {
Expand All @@ -34,9 +36,6 @@ for (const dataType in BeaconDataType) {
method: 'GET',
signal: controller.signal,
});

// Release quota taken by the pending requests for subsequent tests.
controller.abort();
},
`fetchLater() has per-request-origin quota for its POST body of ${
dataType}.`);
Expand Down
6 changes: 5 additions & 1 deletion fetch/fetch-later/quota/oversized-payload.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ for (const dataType in BeaconDataType) {
method: 'POST',
body: makeBeaconData(
generatePayload(OVERSIZED_REQUEST_BODY_SIZE), dataType),
referrer: '',
});
}, null, null);
// It is difficult to compute the exact requested length, as that depends on
// the datatype. Instead, it should always be more than `OVERSIZED_REQUEST_BODY_SIZE`
// since we count url and referrer as well
}, (requested) => requested > OVERSIZED_REQUEST_BODY_SIZE, QUOTA_PER_ORIGIN);
}, `fetchLater() does not accept payload[size=${
OVERSIZED_REQUEST_BODY_SIZE}] exceeding per-origin quota in a POST request body of ${
dataType}.`);
Expand Down