Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f7edecd

Browse files
mingycchromium-wpt-export-bot
authored andcommittedMar 21, 2024·
[fetch-later] Define new permissions policy deferred-fetch
1-Pager: https://docs.google.com/document/d/1P70kdENIByy3qWabN5rUPmBVkkANNSOM_jZynLnqINY/edit This CL follows the [guide] to define a new permissions policy `deferred-fetch`, which is used to gate the new `fetchLater()` API. Relevant WPT are added in this CL, and the subsequent CL will further use this policy to adjust the request quota. In this CL, `deferred-fetch` is not added to chrome://settings/content page. And no permission prompt for it. - webappsec request: w3c/webappsec-permissions-policy#544 - "deferred-fetch" usage in fetchLater draft spec: https://whatpr.org/fetch/1647.html#request-a-deferred-fetch - "deferred-fetch" policy discussion: WICG/pending-beacon#87 (comment) - FetchLater Explainer: https://github.com/WICG/pending-beacon/blob/main/docs/fetch-later-api.md [guide]: https://chromium.googlesource.com/chromium/src/+/main/components/permissions/add_new_permission.md Bug: b:40276121 Change-Id: I2db4dd7484610fefb50c463552155b220f13ac5d
1 parent cda4b9f commit f7edecd

13 files changed

+234
-4
lines changed
 

Diff for: ‎fetch/fetch-later/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# FetchLater Tests
22

3-
These tests cover [FetchLater method](https://whatpr.org/fetch/1647/094ea69...152d725.html#fetch-later-method) related behaviors.
3+
These tests cover [FetchLater method](https://whatpr.org/fetch/1647.html#dom-window-fetchlater) related behaviors.

Diff for: ‎fetch/fetch-later/iframe.tentative.https.window.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ parallelPromiseTest(async t => {
5858
// Loads a same-origin iframe that fires a fetchLater request.
5959
await loadFetchLaterIframe(HTTPS_NOTSAMESITE_ORIGIN, url);
6060

61-
// The iframe should have sent the request.
62-
await expectBeacon(uuid, {count: 1});
63-
}, 'A cross-origin iframe can trigger fetchLater.');
61+
// See also
62+
// /fetch/fetch-later/permissions-policy/deferred-fetch-default-permissions-policy.tentative.https.window.js
63+
await expectBeacon(uuid, {count: 0});
64+
}, 'A cross-origin iframe cannot trigger fetchLater.');

Diff for: ‎fetch/fetch-later/permissions-policy/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Permissions Policy: "deferred-fetch" Tests
2+
3+
This folder contains tests to cover the permissions policy "deferred-fetch",
4+
which is used to gate the `fetchLater()` API.
5+
6+
The tests follow the patterns from
7+
//permissions-policy/README.md to cover
8+
all use cases of permissions policy for a new feature.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// META: title=Permissions Policy "deferred-fetch" is allowed to redirect by allow attribute
2+
// META: script=/permissions-policy/resources/permissions-policy.js
3+
// META: script=/common/utils.js
4+
// META: script=/common/get-host-info.sub.js
5+
// META: script=/fetch/fetch-later/resources/fetch-later-helper.js
6+
// META: script=/fetch/fetch-later/permissions-policy/resources/helper.js
7+
// META: timeout=long
8+
'use strict';
9+
10+
const {
11+
HTTPS_ORIGIN,
12+
HTTPS_NOTSAMESITE_ORIGIN,
13+
} = get_host_info();
14+
15+
const baseUrl = '/permissions-policy/resources/redirect-on-load.html#';
16+
const description = 'Permissions policy allow="deferred-fetch"';
17+
18+
async_test(t => {
19+
test_feature_availability(
20+
'fetchLater()', t,
21+
getDeferredFetchPolicyInIframeHelperUrl(`${baseUrl}${HTTPS_ORIGIN}`),
22+
expect_feature_available_default, /*feature_name=*/ 'deferred-fetch');
23+
}, `${description} allows same-origin navigation in an iframe.`);
24+
25+
async_test(t => {
26+
test_feature_availability(
27+
'fetchLater()', t,
28+
getDeferredFetchPolicyInIframeHelperUrl(
29+
`${baseUrl}${HTTPS_NOTSAMESITE_ORIGIN}`),
30+
expect_feature_unavailable_default, /*feature_name=*/ 'deferred-fetch');
31+
}, `${description} disallows cross-origin navigation in an iframe.`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// META: title=Permissions Policy "deferred-fetch" is allowed by allow attribute
2+
// META: script=/permissions-policy/resources/permissions-policy.js
3+
// META: script=/common/utils.js
4+
// META: script=/common/get-host-info.sub.js
5+
// META: script=/fetch/fetch-later/resources/fetch-later-helper.js
6+
// META: script=/fetch/fetch-later/permissions-policy/resources/helper.js
7+
// META: timeout=long
8+
'use strict';
9+
10+
const {
11+
HTTPS_ORIGIN,
12+
HTTPS_NOTSAMESITE_ORIGIN,
13+
} = get_host_info();
14+
15+
const description = 'Permissions policy "deferred-fetch"';
16+
const attribute = 'allow="deferred-fetch" attribute';
17+
18+
async_test(
19+
t => {
20+
test_feature_availability(
21+
'fetchLater()', t,
22+
getDeferredFetchPolicyInIframeHelperUrl(HTTPS_ORIGIN),
23+
expect_feature_available_default, /*feature_name=*/ 'deferred-fetch');
24+
},
25+
`${description} can be enabled in the same-origin iframe using ${
26+
attribute}.`);
27+
28+
async_test(
29+
t => {
30+
test_feature_availability(
31+
'fetchLater()', t,
32+
getDeferredFetchPolicyInIframeHelperUrl(HTTPS_NOTSAMESITE_ORIGIN),
33+
expect_feature_available_default, /*feature_name=*/ 'deferred-fetch');
34+
},
35+
`${description} can be enabled in the cross-origin iframe using ${
36+
attribute}.`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// META: title=Permissions Policy "deferred-fetch" is allowed
2+
// META: script=/permissions-policy/resources/permissions-policy.js
3+
// META: script=/common/utils.js
4+
// META: script=/common/get-host-info.sub.js
5+
// META: script=/fetch/fetch-later/resources/fetch-later-helper.js
6+
// META: script=/fetch/fetch-later/permissions-policy/resources/helper.js
7+
// META: timeout=long
8+
'use strict';
9+
10+
const {
11+
HTTPS_ORIGIN,
12+
HTTPS_NOTSAMESITE_ORIGIN,
13+
} = get_host_info();
14+
15+
const description = 'Permissions policy header: "deferred-fetch=*"';
16+
17+
parallelPromiseTest(async _ => {
18+
const uuid = token();
19+
const url = generateSetBeaconURL(uuid);
20+
21+
// Request the browser to fetchLater() immediately.
22+
fetchLater(url, {activateAfter: 0});
23+
24+
await expectBeacon(uuid, {count: 1});
25+
}, `${description} allows fetchLater() in the top-level document.`);
26+
27+
async_test(t => {
28+
test_feature_availability(
29+
'fetchLater()', t, getDeferredFetchPolicyInIframeHelperUrl(HTTPS_ORIGIN),
30+
expect_feature_available_default);
31+
}, `${description} allows fetchLater() in the same-origin iframe.`);
32+
33+
async_test(t => {
34+
test_feature_availability(
35+
'fetchLater()', t,
36+
getDeferredFetchPolicyInIframeHelperUrl(HTTPS_NOTSAMESITE_ORIGIN),
37+
expect_feature_unavailable_default);
38+
}, `${description} disallows fetchLater() in the cross-origin iframe.`);
39+
40+
async_test(t => {
41+
test_feature_availability(
42+
'fetchLater()', t,
43+
getDeferredFetchPolicyInIframeHelperUrl(HTTPS_NOTSAMESITE_ORIGIN),
44+
expect_feature_available_default, /*feature_name=*/ 'deferred-fetch');
45+
}, `${description} allow="deferred-fetch" allows fetchLater() in the cross-origin iframe.`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Permissions-Policy: deferred-fetch=*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// META: title=Permissions Policy "deferred-fetch" default behavior
2+
// META: script=/permissions-policy/resources/permissions-policy.js
3+
// META: script=/common/utils.js
4+
// META: script=/common/get-host-info.sub.js
5+
// META: script=/fetch/fetch-later/resources/fetch-later-helper.js
6+
// META: script=/fetch/fetch-later/permissions-policy/resources/helper.js
7+
// META: timeout=long
8+
'use strict';
9+
10+
const {
11+
HTTPS_ORIGIN,
12+
HTTPS_NOTSAMESITE_ORIGIN,
13+
} = get_host_info();
14+
15+
const description = 'Default "deferred-fetch" permissions policy ["self"]';
16+
17+
parallelPromiseTest(async _ => {
18+
const uuid = token();
19+
const url = generateSetBeaconURL(uuid);
20+
21+
// Request the browser to fetchLater() immediately.
22+
fetchLater(url, {activateAfter: 0});
23+
24+
await expectBeacon(uuid, {count: 1});
25+
}, `${description} allows fetchLater() in the top-level document.`);
26+
27+
async_test(t => {
28+
test_feature_availability(
29+
'fetchLater()', t, getDeferredFetchPolicyInIframeHelperUrl(HTTPS_ORIGIN),
30+
expect_feature_available_default);
31+
}, `${description} allows fetchLater() in the same-origin iframe.`);
32+
33+
async_test(t => {
34+
test_feature_availability(
35+
'fetchLater()', t,
36+
getDeferredFetchPolicyInIframeHelperUrl(HTTPS_NOTSAMESITE_ORIGIN),
37+
expect_feature_unavailable_default);
38+
}, `${description} disallows fetchLater() in the cross-origin iframe.`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// META: title=Permissions Policy "deferred-fetch" is disabled
2+
// META: script=/permissions-policy/resources/permissions-policy.js
3+
// META: script=/common/utils.js
4+
// META: script=/common/get-host-info.sub.js
5+
// META: script=/fetch/fetch-later/resources/fetch-later-helper.js
6+
// META: script=/fetch/fetch-later/permissions-policy/resources/helper.js
7+
// META: timeout=long
8+
'use strict';
9+
10+
const {
11+
HTTPS_ORIGIN,
12+
HTTPS_NOTSAMESITE_ORIGIN,
13+
} = get_host_info();
14+
15+
const description = 'Permissions policy header: "deferred-fetch=()"';
16+
17+
parallelPromiseTest(async _ => {
18+
// Request the browser to fetchLater() immediately, which is not allowed.
19+
assert_throws_dom(
20+
'NotAllowedError', () => fetchLater('/', {activateAfter: 0}));
21+
}, `${description} disallows fetchLater() in the top-level document.`);
22+
23+
async_test(t => {
24+
test_feature_availability(
25+
'fetchLater()', t, getDeferredFetchPolicyInIframeHelperUrl(HTTPS_ORIGIN),
26+
expect_feature_unavailable_default);
27+
}, `${description} disallows fetchLater() in the same-origin iframe.`);
28+
29+
async_test(t => {
30+
test_feature_availability(
31+
'fetchLater()', t,
32+
getDeferredFetchPolicyInIframeHelperUrl(HTTPS_NOTSAMESITE_ORIGIN),
33+
expect_feature_unavailable_default);
34+
}, `${description} disallows fetchLater() in the cross-origin iframe.`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Permissions-Policy: deferred-fetch=()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// META: title=The feature list should advertise deferred-fetch
2+
'use strict';
3+
4+
// https://w3c.github.io/webappsec-permissions-policy/#dom-permissions-policy-features
5+
// https://wicg.github.io/local-fonts/#permissions-policy
6+
test(() => {
7+
assert_in_array('deferred-fetch', document.featurePolicy.features());
8+
}, 'document.featurePolicy.features should advertise deferred-fetch.');
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
/**
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.
6+
*/
7+
function getDeferredFetchPolicyInIframeHelperUrl(iframeOrigin) {
8+
if (!iframeOrigin.endsWith('/')) {
9+
iframeOrigin += '/';
10+
}
11+
return `${
12+
iframeOrigin}fetch/fetch-later/permissions-policy/resources/permissions-policy-deferred-fetch.html`;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<script>
3+
'use strict';
4+
5+
window.onload = () => {
6+
let enabled = true;
7+
try {
8+
fetchLater('/', {activateAfter: 0});
9+
} catch (e) {
10+
enabled = false;
11+
}
12+
parent.postMessage({ type: 'availability-result', enabled }, '*');
13+
}
14+
</script>

0 commit comments

Comments
 (0)
Please sign in to comment.