Commit 960dfcbf authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

WPT tests for http-equiv accept-ch header

This CL adds WPT tests for http-equiv accept-ch header:
(1) The header is not honored on HTTP pages
(2) Malformed header is not honored
(3) When the header is present, client hints are attached only
    on the same-origin subresources, and not on cross-origin
    subresources in the same navigation.
(4) When the header is present, client hints are attached only
    on the same origin subresources, and not on subresources in
    a new navigation.

Bug: 856700
Change-Id: I3f82df8cd02816b06542256062eb291577ebe8b7
Reviewed-on: https://chromium-review.googlesource.com/1120953
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarYoav Weiss <yoav@yoav.ws>
Cr-Commit-Position: refs/heads/master@{#571986}
parent 202d88eb
......@@ -16,7 +16,7 @@
// of client hints it receives in the request headers.
promise_test(t => {
return fetch("https://{{domains[]}}:{{ports[https][0]}}/client-hints/echo_client_hints_received.py", {"mode": "no-cors"}).then(r => {
return fetch("https://{{domains[]}}:{{ports[https][0]}}/client-hints/echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser includes client hints in the headers for a
// same-origin fetch.
......
<html>
<meta http-equiv="Accept-CH" content="DPR, Width, Viewport-Width, Device-Memory, rtt, downlink, ect">
<title>Accept-CH http-equiv insecure transport test</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// Even though this HTML file contains "Accept-CH" http-equiv headers, the
// browser should NOT attach the specified client hints in the HTTP request
// headers since the page is being fetched over an insecure transport.
// Test this functionality by fetching an XHR from this page hosted on
// an insecure HTTP server.
// echo_client_hints_received.py sets the response headers depending on the set
// of client hints it receives in the request headers.
promise_test(t => {
return fetch("/client-hints/echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser does not include client hints in the headers
// when fetching the XHR from an insecure HTTP server.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
assert_false(r.headers.has("dpr-received"), "dpr-received");
assert_false(r.headers.has("viewport-width-received"), "viewport-width-received");
assert_false(r.headers.has("rtt-received"), "rtt-received");
assert_false(r.headers.has("downlink-received"), "downlink-received");
assert_false(r.headers.has("ect-received"), "ect-received");
});
}, "Accept-CH http-equiv test over insecure transport");
</script>
</body>
</html>
<html>
<meta http-equiv="Accept-CH" content="DPR, Width, Viewport-Width, Device-Memory, rtt, downlink, ect">
<title>Accept-CH http-equiv cross-navigation test</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=test>
<p>Apart from this webpage, the test opens another html web page. One test
is run in this web page, and another in the second web page.
</div>
<script>
// This test contains accept-ch http-equiv header. Due to the missing
// Accept-CH-Lifetime header, the user-agent should not persist origin
// preferences for the client hints specified in Accept-CH header.
// Next, to verify that the origin preferences were not persisted by the user
// agent, this test fetches resources/do_not_expect_client_hints_headers.html
// in a new window. Fetching of
// resources/do_not_expect_client_hints_headers.html
// verifies that the user agent does not send the client hints in the request
// headers.
// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
// is resolved.
promise_test(t => {
return fetch("echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser includes client hints in the request
// headers when fetching echo_client_hints_received.py within this page.
assert_true(r.headers.has("device-memory-received"), "device-memory-received");
});
}, "Test that the browser attaches client hints on subresources in the same navigation");
// Verify that the browser does not attach client hints on resources in a
// different navigation. This verifies that the client hint preferences were
// not persisted for the origin.
window.open("resources/do_not_expect_client_hints_headers.html");
async_test(t => {
window.addEventListener('message', function(event) {
t.done();
})
}, "Loading of resources/do_not_expect_client_hints_headers.html did not finish.");
</script>
</body>
</html>
<html>
<meta http-equiv="Accept-CH" content="DPR, Width, Viewport-Width, Device-Memory, rtt, downlink, ect">
<title>Accept-CH http-equiv same-origin and cross-origin test</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// Since this HTML file contains "Accept-CH" http-equiv headers the browser
// should attach the specified client hints in the HTTP request headers
// depending on whether the resource is being fetched from
// the same origin or a different origin. Test this functionality by fetching
// same-origin and cross-origin resources from this page.
//
// echo_client_hints_received.py sets the response headers depending on the set
// of client hints it receives in the request headers.
promise_test(t => {
return fetch("https://{{domains[]}}:{{ports[https][0]}}/client-hints/echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser includes client hints in the headers for a
// same-origin fetch.
assert_true(r.headers.has("device-memory-received"), "device-memory-received");
assert_true(r.headers.has("dpr-received"), "dpr-received");
assert_true(r.headers.has("viewport-width-received"), "viewport-width-received");
assert_true(r.headers.has("rtt-received"), "rtt-received");
var rtt = parseInt(r.headers.get("rtt-received"));
assert_greater_than_equal(rtt, 0);
assert_less_than_equal(rtt, 3000);
assert_equals(rtt % 50, 0, 'rtt must be a multiple of 50 msec');
assert_true(r.headers.has("downlink-received"), "downlink-received");
var downlinkKbps = r.headers.get("downlink-received") * 1000;
assert_greater_than_equal(downlinkKbps, 0);
assert_less_than_equal(downlinkKbps, 10000);
assert_in_array(r.headers.get("ect-received"), ["slow-2g", "2g",
"3g", "4g"], 'ect-received is unexpected');
});
}, "Same origin Accept-CH http-equiv test");
promise_test(t => {
return fetch("https://{{domains[www]}}:{{ports[https][0]}}/client-hints/echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser does not include client hints in the headers
// for a cross-origin fetch.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
assert_false(r.headers.has("dpr-received"), "dpr-received");
assert_false(r.headers.has("viewport-width-received"), "viewport-width-received");
assert_false(r.headers.has("rtt-received"), "rtt-received");
assert_false(r.headers.has("downlink-received"), "downlink-received");
assert_false(r.headers.has("ect-received"), "ect-received");
});
}, "Cross-Origin Accept-CH http-equiv test");
</script>
</body>
</html>
<html>
<meta http-equiv="Accept-CH" content="DPR Width">
<title>Accept-CH malformed http-equiv test</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(t => {
return fetch("/client-hints/echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser does not include client hints in the headers
// since Accept-CH value in http-equiv is malformed (includes whitespace
// between attributes instead of comma).
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
assert_false(r.headers.has("dpr-received"), "dpr-received");
assert_false(r.headers.has("viewport-width-received"), "viewport-width-received");
assert_false(r.headers.has("rtt-received"), "rtt-received");
assert_false(r.headers.has("downlink-received"), "downlink-received");
assert_false(r.headers.has("ect-received"), "ect-received");
});
}, "Accept-CH malformed http-equiv test");
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment