Skip to content

Commit 608d5f6

Browse files
chore: update WPT (nodejs#4028)
Co-authored-by: Uzlopak <[email protected]>
1 parent 4269dab commit 608d5f6

File tree

55 files changed

+1489
-228
lines changed

Some content is hidden

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

55 files changed

+1489
-228
lines changed
Lines changed: 5 additions & 0 deletions
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/common/dispatcher/remote-executor.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
<meta charset="utf-8">
44
<body>
55
</body>
6-
<script src="./dispatcher.js"></script>
6+
<script src="./dispatcher.js"
7+
crossorigin
8+
integrity="sha256-daCATx8B9i1s6ixqZvCGcGQOv3a+VMoor6aS9UNUoiY=">
9+
</script>
710
<script>
811
const params = new URLSearchParams(window.location.search);
912
const uuid = params.get('uuid');

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

Lines changed: 0 additions & 24 deletions
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

Lines changed: 25 additions & 7 deletions
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 9 additions & 4 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 0 additions & 134 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
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

0 commit comments

Comments
 (0)