Skip to content

Commit 008a632

Browse files
Uzlopakgithub-actions[bot]
authored andcommitted
chore: update WPT
1 parent c7f3d77 commit 008a632

File tree

47 files changed

+1399
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1399
-204
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
importScripts('./dispatcher.js');
2+
3+
const params = new URLSearchParams(location.search);
4+
const uuid = params.get('uuid');
5+
const executor = new Executor(uuid); // `execute()` is called in constructor.

test/fixtures/wpt/fetch/fetch-later/iframe.tentative.https.window.js

-24
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ async function loadElement(el) {
1515
await loaded;
1616
}
1717

18-
// `host` may be cross-origin
19-
async function loadFetchLaterIframe(host, targetUrl) {
20-
const url = `${host}/fetch/fetch-later/resources/fetch-later.html?url=${
21-
encodeURIComponent(targetUrl)}`;
22-
const iframe = document.createElement('iframe');
23-
iframe.src = url;
24-
await loadElement(iframe);
25-
return iframe;
26-
}
27-
2818
parallelPromiseTest(async t => {
2919
const uuid = token();
3020
const url = generateSetBeaconURL(uuid);
@@ -39,17 +29,3 @@ parallelPromiseTest(async t => {
3929
// The iframe should have sent the request.
4030
await expectBeacon(uuid, {count: 1});
4131
}, 'A blank iframe can trigger fetchLater.');
42-
43-
parallelPromiseTest(async t => {
44-
const uuid = token();
45-
const url = generateSetBeaconURL(uuid);
46-
47-
// Loads a same-origin iframe that fires a fetchLater request.
48-
await loadFetchLaterIframe(HTTPS_ORIGIN, url);
49-
50-
// The iframe should have sent the request.
51-
await expectBeacon(uuid, {count: 1});
52-
}, 'A same-origin iframe can trigger fetchLater.');
53-
54-
// The test to load a cross-origin iframe that fires a fetchLater request is in
55-
// /fetch/fetch-later/permissions-policy/deferred-fetch-default-permissions-policy.tentative.https.window.js

test/fixtures/wpt/fetch/fetch-later/new-window.tentative.https.window.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,32 @@ const {
1111

1212
function fetchLaterPopupUrl(host, targetUrl) {
1313
return `${host}/fetch/fetch-later/resources/fetch-later.html?url=${
14-
encodeURIComponent(targetUrl)}`;
14+
encodeURIComponent(targetUrl)}&activateAfter=0`;
15+
}
16+
17+
async function receiveMessageFromPopup(url) {
18+
const expect =
19+
new FetchLaterIframeExpectation(FetchLaterExpectationType.DONE);
20+
const messageType = await new Promise((resolve, reject) => {
21+
window.addEventListener('message', function handler(e) {
22+
try {
23+
if (expect.run(e, url)) {
24+
window.removeEventListener('message', handler);
25+
resolve(e.data.type);
26+
}
27+
} catch (err) {
28+
reject(err);
29+
}
30+
});
31+
});
32+
33+
assert_equals(messageType, FetchLaterIframeMessageType.DONE);
1534
}
1635

1736
for (const target of ['', '_blank']) {
18-
for (const features in ['', 'popup', 'popup,noopener']) {
37+
// NOTE: noopener popup window cannot communicate back. It will be too
38+
// unreliable to only use `expectBeacon()` to test such window.
39+
for (const features of ['', 'popup']) {
1940
parallelPromiseTest(
2041
async t => {
2142
const uuid = token();
@@ -43,7 +64,7 @@ for (const target of ['', '_blank']) {
4364

4465
// Opens a same-origin popup that fires a fetchLater request.
4566
const w = window.open(popupUrl, target, features);
46-
await new Promise(resolve => w.addEventListener('load', resolve));
67+
await receiveMessageFromPopup(popupUrl);
4768

4869
// The popup should have sent the request.
4970
await expectBeacon(uuid, {count: 1});
@@ -60,10 +81,7 @@ for (const target of ['', '_blank']) {
6081

6182
// Opens a cross-origin popup that fires a fetchLater request.
6283
const w = window.open(popupUrl, target, features);
63-
// As events from cross-origin window is not accessible, waiting for
64-
// its message instead.
65-
await new Promise(
66-
resolve => window.addEventListener('message', resolve));
84+
await receiveMessageFromPopup(popupUrl);
6785

6886
// The popup should have sent the request.
6987
await expectBeacon(uuid, {count: 1});

test/fixtures/wpt/fetch/fetch-later/permissions-policy/deferred-fetch-allowed-by-permissions-policy-attribute-redirect.tentative.https.window.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ const {
1313
} = get_host_info();
1414

1515
const baseUrl = '/permissions-policy/resources/redirect-on-load.html#';
16+
// https://whatpr.org/fetch/1647.html#dom-permissionspolicy-deferred-fetch-minimal
1617
const description = 'Permissions policy allow="deferred-fetch"';
1718

1819
async_test(t => {
1920
test_feature_availability(
2021
'fetchLater()', t,
2122
getDeferredFetchPolicyInIframeHelperUrl(`${baseUrl}${HTTPS_ORIGIN}`),
2223
expect_feature_available_default, /*feature_name=*/ 'deferred-fetch');
23-
}, `${description} allows same-origin navigation in an iframe.`);
24+
}, `${description} allows fetchLater() from a redirected same-origin iframe.`);
2425

26+
// By default, "deferred-fetch" is off for cross-origin iframe.
27+
// It requires a Permissions-Policy header in addition to the allow attribute.
2528
async_test(t => {
2629
test_feature_availability(
2730
'fetchLater()', t,
2831
getDeferredFetchPolicyInIframeHelperUrl(
2932
`${baseUrl}${HTTPS_NOTSAMESITE_ORIGIN}`),
30-
expect_feature_available_default, /*feature_name=*/ 'deferred-fetch');
31-
}, `${description} allows cross-origin navigation in an iframe.`);
33+
expect_feature_unavailable_default, /*feature_name=*/ 'deferred-fetch');
34+
}, `${description} disallows fetchLater() from a redirected cross-origin iframe.`);

test/fixtures/wpt/fetch/fetch-later/permissions-policy/deferred-fetch-default-permissions-policy.tentative.https.window.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ const {
1212
HTTPS_NOTSAMESITE_ORIGIN,
1313
} = get_host_info();
1414

15-
const description = 'Default "deferred-fetch" permissions policy ["self"]';
15+
// https://whatpr.org/fetch/1647.html#dom-permissionspolicy-deferred-fetch
16+
const deferredFetchPolicy =
17+
'Default "deferred-fetch" permissions policy ["self"]';
18+
// https://whatpr.org/fetch/1647.html#dom-permissionspolicy-deferred-fetch-minimal
19+
const deferredFetchMinimalPolicy =
20+
'Default "deferred-fetch-minimal" permissions policy ["*"]';
1621

1722
parallelPromiseTest(async _ => {
1823
const uuid = token();
@@ -22,17 +27,17 @@ parallelPromiseTest(async _ => {
2227
fetchLater(url, {activateAfter: 0});
2328

2429
await expectBeacon(uuid, {count: 1});
25-
}, `${description} allows fetchLater() in the top-level document.`);
30+
}, `${deferredFetchPolicy} allows fetchLater() in the top-level document.`);
2631

2732
async_test(t => {
2833
test_feature_availability(
2934
'fetchLater()', t, getDeferredFetchPolicyInIframeHelperUrl(HTTPS_ORIGIN),
3035
expect_feature_available_default);
31-
}, `${description} allows fetchLater() in the same-origin iframe.`);
36+
}, `${deferredFetchPolicy} allows fetchLater() in the same-origin iframe.`);
3237

3338
async_test(t => {
3439
test_feature_availability(
3540
'fetchLater()', t,
3641
getDeferredFetchPolicyInIframeHelperUrl(HTTPS_NOTSAMESITE_ORIGIN),
3742
expect_feature_available_default);
38-
}, `${description} allows fetchLater() in the cross-origin iframe.`);
43+
}, `${deferredFetchMinimalPolicy} allows fetchLater() in the cross-origin iframe.`);

test/fixtures/wpt/fetch/fetch-later/permissions-policy/deferred-fetch-supported-by-permissions-policy.tentative.window.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
// https://wicg.github.io/local-fonts/#permissions-policy
66
test(() => {
77
assert_in_array('deferred-fetch', document.featurePolicy.features());
8+
assert_in_array('deferred-fetch-minimal', document.featurePolicy.features());
89
}, 'document.featurePolicy.features should advertise deferred-fetch.');

test/fixtures/wpt/fetch/fetch-later/permissions-policy/resources/helper.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
22

33
/**
4-
* Returns an URL to a document that can be used to initialize an iframe to test
5-
* whether the "deferred-fetch"policy is enabled.
4+
* Returns a URL to a document that can be used to initialize an iframe to test
5+
* whether the Permissions Policy "deferred-fetch" or "deferred-fetch-minimal"
6+
* is enabled.
67
*/
78
function getDeferredFetchPolicyInIframeHelperUrl(iframeOrigin) {
89
if (!iframeOrigin.endsWith('/')) {

test/fixtures/wpt/fetch/fetch-later/quota.tentative.https.window.js

-134
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Quota Tests
2+
3+
This folder contains tests to cover the `fetchLater()` API's
4+
per-reporting-origin quota.
5+
6+
See the following links:
7+
8+
- Initial Proposal: https://github.com/WICG/pending-beacon/issues/87#issuecomment-1985358609.
9+
- fetch PR: https://github.com/whatwg/fetch/pull/1647
10+
- html PR: https://github.com/whatwg/html/pull/10903
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// META: script=/common/get-host-info.sub.js
2+
// META: script=/common/utils.js
3+
// META: script=/fetch/fetch-later/resources/fetch-later-helper.js
4+
// META: script=/fetch/fetch-later/quota/resources/helper.js
5+
'use strict';
6+
7+
const {HTTPS_ORIGIN, HTTPS_NOTSAMESITE_ORIGIN} = get_host_info();
8+
9+
// Skips FormData & URLSearchParams, as browser adds extra bytes to them
10+
// in addition to the user-provided content. It is difficult to test a
11+
// request right at the quota limit.
12+
// Skips File & Blob as it's difficult to estimate what additional data are
13+
// added into them.
14+
const dataType = BeaconDataType.String;
15+
16+
// Request headers are counted into total request size.
17+
const headers = new Headers({'Content-Type': 'text/plain;charset=UTF-8'});
18+
19+
const requestUrl = `${HTTPS_ORIGIN}/`;
20+
const quota = getRemainingQuota(QUOTA_PER_ORIGIN, requestUrl, headers);
21+
const halfQuota = Math.ceil(quota / 2);
22+
23+
24+
// Tests that a reporting origin only allow queuing requests within its quota.
25+
test(
26+
() => {
27+
const controller = new AbortController();
28+
29+
// Queues with the 1st call (POST) that sends max/2 quota.
30+
fetchLater(requestUrl, {
31+
method: 'POST',
32+
signal: controller.signal,
33+
body: makeBeaconData(generatePayload(halfQuota), dataType),
34+
// Required, as the size of referrer also take up quota.
35+
referrer: '',
36+
});
37+
38+
// Makes the 2nd call (POST) to the same reporting origin that sends
39+
// max bytes, which should be rejected.
40+
assert_throws_dom('QuotaExceededError', () => {
41+
fetchLater(requestUrl, {
42+
method: 'POST',
43+
signal: controller.signal,
44+
body: makeBeaconData(generatePayload(quota), dataType),
45+
// Required, as the size of referrer also take up quota.
46+
referrer: '',
47+
});
48+
});
49+
50+
// Makes the 3rd call (GET) to the same reporting origin, where its
51+
// request size is len(requestUrl) + headers, which should be accepted.
52+
fetchLater(requestUrl, {
53+
method: 'GET',
54+
signal: controller.signal,
55+
// Required, as the size of referrer also take up quota.
56+
referrer: '',
57+
});
58+
59+
// Release quota taken by the pending requests for subsequent tests.
60+
controller.abort();
61+
},
62+
`The 2nd fetchLater(same-origin) call in the top-level document is not allowed to exceed per-origin quota for its POST body of ${
63+
dataType}.`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Quota Tests for Cross-Origin iframes
2+
3+
This folder contains tests to cover fetchLater() requests from cross-origin
4+
iframe.
5+
6+
According to [spec], up to 16 cross-origin iframes can get a minimal quota (8kb)
7+
to make fetchLater() calls.
8+
9+
[spec]: https://whatpr.org/fetch/1647.html#available-deferred-fetch-quota

0 commit comments

Comments
 (0)