Skip to content

Commit dcf82a7

Browse files
chore: update WPT (#4172)
Co-authored-by: Uzlopak <[email protected]>
1 parent 2ed2a8a commit dcf82a7

29 files changed

+1083
-121
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
features:
2+
- name: fetch-priority
3+
files:
4+
- request-init-priority.any.js

test/fixtures/wpt/fetch/http-cache/no-vary-search.tentative.any.js

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
// META: script=http-cache.js
77
/*
88
NOTE for testing No-Vary-Search-Header:
9-
If `params` is set to true, `expect=("dispatch" "uuid")` must be specified.
10-
Otherwise:
11-
- The same HTTP Cache will be used by other tests, which are supposed
12-
to be distinguished by uuid.
13-
- The test utility cannot get the server's states because UA will use the HTTP
14-
Cache instead of sending a new request to server to ask for the latest state.
9+
- If `params` is set to true, `expect=("dispatch" "uuid")` must be specified.
10+
Otherwise:
11+
- The same HTTP Cache will be used by other tests, which are supposed
12+
to be distinguished by uuid.
13+
- The test utility cannot get the server's states because UA will use the HTTP
14+
Cache instead of sending a new request to server to ask for the latest state.
15+
- Do not test not_cached cases and cached cases within one test. Test infra
16+
checks the number of requests and responses without considering if the
17+
previous responses should be served from cache or not.
1518
*/
1619
var tests = [
1720
{
@@ -28,6 +31,61 @@ var tests = [
2831
expected_type: "cached"
2932
}
3033
]
34+
},
35+
{
36+
name: "Ground truth: When key-order is not set, URLs should be compared in an order-sensitive way.",
37+
requests: [
38+
{
39+
url_params: "a=1&b=2",
40+
response_headers: [
41+
["Cache-Control", "max-age=10000"],
42+
],
43+
},
44+
{
45+
url_params: "b=2&a=1",
46+
expected_type: "not_cached"
47+
}
48+
]
49+
},
50+
{
51+
name: "When key-order is set , URLs should be compared in an order-insensitive way. Matched cases:",
52+
requests: [
53+
{
54+
url_params: "a=1&b=2",
55+
response_headers: [
56+
["Cache-Control", "max-age=10000"],
57+
["No-Vary-Search", "key-order"],
58+
],
59+
},
60+
{
61+
url_params: "b=2&a=1",
62+
expected_type: "cached"
63+
}
64+
]
65+
},
66+
{
67+
name: "When key-order is set , URLs should be compared in an order-insensitive way. Not matched cases",
68+
requests: [
69+
{
70+
url_params: "a=1&b=2",
71+
response_headers: [
72+
["Cache-Control", "max-age=10000"],
73+
["No-Vary-Search", "key-order"],
74+
],
75+
},
76+
{
77+
url_params: "b=2",
78+
expected_type: "not_cached"
79+
},
80+
{
81+
url_params: "a=2&b=2",
82+
expected_type: "not_cached"
83+
},
84+
{
85+
url_params: "a=1&b=2&c=3",
86+
expected_type: "not_cached"
87+
}
88+
]
3189
}
3290
];
3391
run_tests(tests);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>HTTP Cache: Cache-Control with Pragma: no-cache</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<body>
7+
<script>
8+
promise_test(async t => {
9+
// According to https://www.rfc-editor.org/rfc/rfc9111.html#name-pragma
10+
// the pragma header is deprecated.
11+
// When there's a mismatch between pragma and Cache-Control then the latter
12+
// should be respected, and the resource should be cached.
13+
const url = 'resources/cached_pragma_rand.py'
14+
15+
// First fetch to populate the cache
16+
const response1 = await fetch(url, { cache: 'default' });
17+
assert_true(response1.ok, 'First fetch should succeed');
18+
const text1 = await response1.text();
19+
20+
// Second fetch should be served from cache
21+
const response2 = await fetch(url, { cache: 'default' });
22+
assert_true(response2.ok, 'Second fetch should succeed');
23+
const text2 = await response2.text();
24+
25+
assert_equals(text1, text2, 'Responses should be identical, indicating caching');
26+
}, 'Response with Cache-Control: max-age=2592000, public and Pragma: no-cache should be cached');
27+
</script>
28+
</body>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def main(request, response):
2+
# Disable non-standard XSS protection
3+
response.headers.set(b"X-XSS-Protection", b"0")
4+
response.headers.set(b"Content-Type", b"text/html")
5+
6+
# Set caching headers
7+
# According to rfc9111 Pragma: no-cache is deprecated, so we expect
8+
# Cache-Control to take precedence when there's a mismatch.
9+
response.headers.set(b"Cache-Control", b"max-age=2592000, public")
10+
response.headers.set(b"Pragma", b"no-cache")
11+
12+
# Include a timestamp to verify caching behavior
13+
import time
14+
response.content = f"Timestamp: {time.time()}".encode('utf-8')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spec: https://wicg.github.io/local-network-access/
2+
suggested_reviewers:
3+
- cthomp
4+
- camillelamy
5+
- hchao
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Local Network Access tests
2+
3+
This directory contains tests for Local Network Access' integration with
4+
the Fetch specification.
5+
6+
See also:
7+
8+
* [Explainer](https://github.com/explainers-by-googlers/local-network-access)
9+
10+
Local Network Access replaced [Private Network
11+
Access](https://wicg.github.io/local-network-access/).
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>LNA Fetch tests: HTTPS </title>
4+
<body>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
<script src="/resources/testdriver.js"></script>
8+
<script src="/resources/testdriver-vendor.js"></script>
9+
<script src="resources/support.sub.js"></script>
10+
<script>
11+
"use strict";
12+
13+
promise_test(t => {
14+
const sourceUrl = resolveUrl("resources/fetch-private.html",
15+
sourceResolveOptions({ server: Server.HTTPS_PUBLIC }));
16+
17+
function checkResult(evt) {
18+
checkTestResult(evt.data, FetchTestResult.SUCCESS);
19+
t.done();
20+
}
21+
22+
const promise = new Promise((resolve) => {
23+
window.addEventListener('message', resolve, {once: true});
24+
}).then(checkResult);
25+
const popup = window.open(sourceUrl);
26+
t.add_cleanup(() => popup.close());
27+
28+
return promise;
29+
}, 'LNA Public to private with permission');
30+
31+
promise_test(t => {
32+
// TODO(crbug.com/406991278): consider moving permission url param into
33+
// options
34+
const sourceUrl = resolveUrl("resources/fetch-private.html?permission=denied",
35+
sourceResolveOptions({ server: Server.HTTPS_PUBLIC }));
36+
37+
function checkResult(evt) {
38+
checkTestResult(evt.data, FetchTestResult.FAILURE);
39+
t.done();
40+
}
41+
42+
const promise = new Promise((resolve) => {
43+
window.addEventListener('message', resolve, {once: true});
44+
}).then(checkResult);
45+
const popup = window.open(sourceUrl);
46+
t.add_cleanup(() => popup.close());
47+
48+
return promise;
49+
}, 'LNA Public to private with permission denied');
50+
</script>
51+
</body>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>Fetch Private resource</title>
4+
5+
<script src="/resources/testdriver.js"></script>
6+
<script src="/resources/testdriver-vendor.js"></script>
7+
<script src="support.sub.js"></script>
8+
<script>
9+
"use strict";
10+
11+
// Set the 'local-network-access' permission then attempt to fetch a resource
12+
// in the private address space.
13+
//
14+
// By default, 'local-network-access' permission is set to 'granted'. This can
15+
// be changed by passing in a different value via the 'permission' URL parameter.
16+
// Valid values:
17+
//
18+
// * granted
19+
// * denied
20+
// * prompt
21+
Promise.resolve().then(async () => {
22+
23+
const window_url = new URL(window.location.href);
24+
let permission_value = 'granted';
25+
if (window_url.searchParams.has('permission')) {
26+
permission_value = window_url.searchParams.get('permission');
27+
}
28+
29+
test_driver.set_test_context(opener);
30+
await test_driver.set_permission({ name: 'local-network-access' }, permission_value);
31+
32+
const target = {
33+
server: Server.HTTPS_PRIVATE,
34+
behavior: { response: ResponseBehavior.allowCrossOrigin() },
35+
};
36+
const targetUrl = resolveTargetUrl(target);
37+
38+
fetch(targetUrl)
39+
.then(async function(response) {
40+
const body = await response.text();
41+
const message = {
42+
ok: response.ok,
43+
type: response.type,
44+
body: body,
45+
};
46+
opener.postMessage(message, "*");
47+
})
48+
.catch(error => {
49+
opener.postMessage({ error: error.toString() }, "*");
50+
});
51+
});
52+
</script>

0 commit comments

Comments
 (0)