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
4 changes: 4 additions & 0 deletions test/fixtures/wpt/fetch/api/request/WEB_FEATURES.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
features:
- name: fetch-priority
files:
- request-init-priority.any.js
70 changes: 64 additions & 6 deletions test/fixtures/wpt/fetch/http-cache/no-vary-search.tentative.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
// META: script=http-cache.js
/*
NOTE for testing No-Vary-Search-Header:
If `params` is set to true, `expect=("dispatch" "uuid")` must be specified.
Otherwise:
- The same HTTP Cache will be used by other tests, which are supposed
to be distinguished by uuid.
- The test utility cannot get the server's states because UA will use the HTTP
Cache instead of sending a new request to server to ask for the latest state.
- If `params` is set to true, `expect=("dispatch" "uuid")` must be specified.
Otherwise:
- The same HTTP Cache will be used by other tests, which are supposed
to be distinguished by uuid.
- The test utility cannot get the server's states because UA will use the HTTP
Cache instead of sending a new request to server to ask for the latest state.
- Do not test not_cached cases and cached cases within one test. Test infra
checks the number of requests and responses without considering if the
previous responses should be served from cache or not.
*/
var tests = [
{
Expand All @@ -28,6 +31,61 @@ var tests = [
expected_type: "cached"
}
]
},
{
name: "Ground truth: When key-order is not set, URLs should be compared in an order-sensitive way.",
requests: [
{
url_params: "a=1&b=2",
response_headers: [
["Cache-Control", "max-age=10000"],
],
},
{
url_params: "b=2&a=1",
expected_type: "not_cached"
}
]
},
{
name: "When key-order is set , URLs should be compared in an order-insensitive way. Matched cases:",
requests: [
{
url_params: "a=1&b=2",
response_headers: [
["Cache-Control", "max-age=10000"],
["No-Vary-Search", "key-order"],
],
},
{
url_params: "b=2&a=1",
expected_type: "cached"
}
]
},
{
name: "When key-order is set , URLs should be compared in an order-insensitive way. Not matched cases",
requests: [
{
url_params: "a=1&b=2",
response_headers: [
["Cache-Control", "max-age=10000"],
["No-Vary-Search", "key-order"],
],
},
{
url_params: "b=2",
expected_type: "not_cached"
},
{
url_params: "a=2&b=2",
expected_type: "not_cached"
},
{
url_params: "a=1&b=2&c=3",
expected_type: "not_cached"
}
]
}
];
run_tests(tests);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>HTTP Cache: Cache-Control with Pragma: no-cache</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
promise_test(async t => {
// According to https://www.rfc-editor.org/rfc/rfc9111.html#name-pragma
// the pragma header is deprecated.
// When there's a mismatch between pragma and Cache-Control then the latter
// should be respected, and the resource should be cached.
const url = 'resources/cached_pragma_rand.py'

// First fetch to populate the cache
const response1 = await fetch(url, { cache: 'default' });
assert_true(response1.ok, 'First fetch should succeed');
const text1 = await response1.text();

// Second fetch should be served from cache
const response2 = await fetch(url, { cache: 'default' });
assert_true(response2.ok, 'Second fetch should succeed');
const text2 = await response2.text();

assert_equals(text1, text2, 'Responses should be identical, indicating caching');
}, 'Response with Cache-Control: max-age=2592000, public and Pragma: no-cache should be cached');
</script>
</body>
14 changes: 14 additions & 0 deletions test/fixtures/wpt/fetch/http-cache/resources/cached_pragma_rand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def main(request, response):
# Disable non-standard XSS protection
response.headers.set(b"X-XSS-Protection", b"0")
response.headers.set(b"Content-Type", b"text/html")

# Set caching headers
# According to rfc9111 Pragma: no-cache is deprecated, so we expect
# Cache-Control to take precedence when there's a mismatch.
response.headers.set(b"Cache-Control", b"max-age=2592000, public")
response.headers.set(b"Pragma", b"no-cache")

# Include a timestamp to verify caching behavior
import time
response.content = f"Timestamp: {time.time()}".encode('utf-8')
5 changes: 5 additions & 0 deletions test/fixtures/wpt/fetch/local-network-access/META.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spec: https://wicg.github.io/local-network-access/
suggested_reviewers:
- cthomp
- camillelamy
- hchao
11 changes: 11 additions & 0 deletions test/fixtures/wpt/fetch/local-network-access/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Local Network Access tests

This directory contains tests for Local Network Access' integration with
the Fetch specification.

See also:

* [Explainer](https://github.com/explainers-by-googlers/local-network-access)

Local Network Access replaced [Private Network
Access](https://wicg.github.io/local-network-access/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>LNA Fetch tests: HTTPS </title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/support.sub.js"></script>
<script>
"use strict";

promise_test(t => {
const sourceUrl = resolveUrl("resources/fetch-private.html",
sourceResolveOptions({ server: Server.HTTPS_PUBLIC }));

function checkResult(evt) {
checkTestResult(evt.data, FetchTestResult.SUCCESS);
t.done();
}

const promise = new Promise((resolve) => {
window.addEventListener('message', resolve, {once: true});
}).then(checkResult);
const popup = window.open(sourceUrl);
t.add_cleanup(() => popup.close());

return promise;
}, 'LNA Public to private with permission');

promise_test(t => {
// TODO(crbug.com/406991278): consider moving permission url param into
// options
const sourceUrl = resolveUrl("resources/fetch-private.html?permission=denied",
sourceResolveOptions({ server: Server.HTTPS_PUBLIC }));

function checkResult(evt) {
checkTestResult(evt.data, FetchTestResult.FAILURE);
t.done();
}

const promise = new Promise((resolve) => {
window.addEventListener('message', resolve, {once: true});
}).then(checkResult);
const popup = window.open(sourceUrl);
t.add_cleanup(() => popup.close());

return promise;
}, 'LNA Public to private with permission denied');
</script>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Fetch Private resource</title>

<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="support.sub.js"></script>
<script>
"use strict";

// Set the 'local-network-access' permission then attempt to fetch a resource
// in the private address space.
//
// By default, 'local-network-access' permission is set to 'granted'. This can
// be changed by passing in a different value via the 'permission' URL parameter.
// Valid values:
//
// * granted
// * denied
// * prompt
Promise.resolve().then(async () => {

const window_url = new URL(window.location.href);
let permission_value = 'granted';
if (window_url.searchParams.has('permission')) {
permission_value = window_url.searchParams.get('permission');
}

test_driver.set_test_context(opener);
await test_driver.set_permission({ name: 'local-network-access' }, permission_value);

const target = {
server: Server.HTTPS_PRIVATE,
behavior: { response: ResponseBehavior.allowCrossOrigin() },
};
const targetUrl = resolveTargetUrl(target);

fetch(targetUrl)
.then(async function(response) {
const body = await response.text();
const message = {
ok: response.ok,
type: response.type,
body: body,
};
opener.postMessage(message, "*");
})
.catch(error => {
opener.postMessage({ error: error.toString() }, "*");
});
});
</script>
Loading