Commit 35687c94 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Test that client hints are not sent on insecure transports

Also, add tests for other client hints.

Finally. use the built-in sub pipe to enable running the
cross-origin test.

Bug: 817049
Change-Id: Ib4155f50e0ffd3a0447cf250cd4018b650f3b419
Reviewed-on: https://chromium-review.googlesource.com/963403
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543433}
parent 28be6900
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// When the response for the HTML file contains "Accept-CH" in the response
// headers, then the browser should not attach the specified client hints in
// the HTTP request headers if the response was delivered by an insecure HTTP
// server. Test this functionality by fetching an XHR from this page hosted on
// an insecure HTTP server. The response headers for this page include
// "Accept-CH: device-memory, dpr, viewport-width".
//
// echo_client_hints_received.py includes "device-memory-received",
// "dpr-received" and "viewport-width-received" in 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"));
assert_false(r.headers.has("dpr-received"));
assert_false(r.headers.has("viewport-width-received"));
});
}, "Accept-CH header test");
</script>
</body>
</html>
Accept-CH: device-memory, dpr, viewport-width
\ No newline at end of file
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// If the response for the HTML file contains "Accept-CH: device-memory" in
// the response headers, then the browser should attach device-memory client
// hint in the HTTP request headers. Test this functionality by fetching an
// XHR from this page. The response headers for this page include
// "Accept-CH: device-memory".
//
// echo_device_memory_header_received.py includes "device-memory-received" in
// the response headers only if the request included "device-memory" in the
// headers.
promise_test(t => {
return fetch("/client-hints/echo_device_memory_header_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser included "device-memory" in the headers when
// fetching the XHR.
assert_true(r.headers.has("device-memory-received"));
});
}, "Accept-CH header test");
</script>
</body>
</html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// If the response for the HTML file contains "Accept-CH" in the response
// headers, then the browser should attach the specified client hints in the
// HTTP request headers. Test this functionality by fetching an
// XHR from this page. The response headers for this page include
// "Accept-CH: device-memory, dpr, viewport-width".
//
// echo_client_hints_received.py includes "device-memory-received",
// "dpr-received" and "viewport-width-received" in 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", {"mode": "no-cors"}).then(r => {
assert_equals(r.status, 200)
// Verify that the browser includes client hints in the headers when
// fetching the XHR.
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");
});
}, "Accept-CH header test");
</script>
</body>
</html>
Accept-CH: device-memory, dpr, viewport-width
\ No newline at end of file
......@@ -6,3 +6,7 @@ def main(request, response):
if "device-memory" in request.headers:
response.headers.set("device-memory-received", "true")
if "dpr" in request.headers:
response.headers.set("dpr-received", "true")
if "viewport-width" in request.headers:
response.headers.set("viewport-width-received", "true")
\ No newline at end of file
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