Commit 607bfe3b authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Add more WPT tests for client hints

The WPT tests check the Accept-CH-Lifetime (ACL) header functionality.

Add tests for:
(i) When ACL header is sent by a same-origin iframe.
(ii) When ACL header is sent by a cross-origin iframe.
(iii) When ACL header is sent by a subresource.
(iv) When ACL header is sent on the main frame.

Also, change the ACL persistence time-duration from 20
seconds to 5 seconds to make it easier to run multiple tests
quickly and without waiting too long.

Change-Id: I31047598bbb1e7c64cadf3e6845bf850c29aca8b
Bug: 856700
Reviewed-on: https://chromium-review.googlesource.com/1119848
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarYoav Weiss <yoav@yoav.ws>
Cr-Commit-Position: refs/heads/master@{#572273}
parent 2fdaa044
......@@ -4276,6 +4276,11 @@ crbug.com/843945 external/wpt/cookies/samesite/window-open-reload.html [ Failure
crbug.com/843945 external/wpt/cookies/samesite/window-open.html [ Failure ]
crbug.com/843945 external/wpt/cookies/secure/create-cookie-http.html [ Failure ]
# Client hint tests that fail in content_shell but pass when run manually using
# full browser.
crbug.com/856700 external/wpt/client-hints/accept_ch_lifetime_same_origin_iframe.tentative.https.html [ Skip ]
crbug.com/856700 external/wpt/client-hints/accept_ch_lifetime.tentative.https.html [ Skip ]
# Sheriff failures 2017-11-15
crbug.com/785179 [ Win7 Debug ] http/tests/devtools/console/console-viewport-stick-to-bottom.js [ Skip ]
......
......@@ -4,10 +4,10 @@
<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>
<!--
Apart from this webpage, the test opens two more html web page. One test is run
in this web page, and two in the other web pages.
-->
<script>
......@@ -23,11 +23,11 @@
// verifies that the user agent does not send the client hints in the request
// headers.
// Verify the initial state to make sure that the browser does not have client
// hints preferences cached from a previous run of the test.
// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
// is resolved.
// First, verify the initial state to make sure that the browser does not have
// client hints preferences cached from a previous run of the test.
promise_test(t => {
return fetch("echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
......@@ -35,22 +35,27 @@ promise_test(t => {
// headers when fetching echo_client_hints_received.py.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
});
}, "Test that the browser does not have client hints preferences cached");
}, "Precondition: Test that the browser does not have client hints preferences cached");
promise_test(t => {
return fetch("resources/accept_ch.html").then(r => {
assert_equals(r.status, 200)
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
// Open a new window.
window.open("resources/do_not_expect_client_hints_headers.html");
});
}, "Test receiving Accept-CH header");
// Fetching this webpage should NOT cause user-agent to persist client hint
// preferences for the origin.
var win = window.open("resources/accept_ch.html");
assert_not_equals(win, null, "Popup windows not allowed?");
// Open a new window. Verify that the user agent does not attach the client
// hints.
var verify_win = window.open("resources/do_not_expect_client_hints_headers.html");
assert_not_equals(verify_win, null, "Popup windows not allowed?");
async_test(t => {
window.addEventListener('message', function(event) {
t.done();
})
window.addEventListener('message', function(e) {
if(!e.source.location.pathname.includes("do_not_expect_client_hints_headers.html")) {
return;
}
if(typeof e.data != "string")
return;
assert_equals(e.data, "PASS");
t.done();
})
}, "Loading of resources/do_not_expect_client_hints_headers.html did not finish.");
</script>
......
......@@ -4,10 +4,10 @@
<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>
<!--
Apart from this webpage, the test opens two more html web page. One test is run
in this web page, and two in the other web pages.
-->
<script>
......@@ -23,11 +23,11 @@
// verifies that the user agent actually sends the client hints in the request
// headers.
// Verify the initial state to make sure that the browser does not have client
// hints preferences cached from a previous run of the test.
// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
// is resolved.
// First, verify the initial state to make sure that the browser does not have
// client hints preferences cached from a previous run of the test.
promise_test(t => {
return fetch("echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
......@@ -35,26 +35,29 @@ promise_test(t => {
// headers when fetching echo_client_hints_received.py.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
});
}, "Test that the browser does not have client hints preferences cached");
promise_test(t => {
return fetch("resources/accept_ch_lifetime.html").then(r => {
assert_equals(r.status, 200)
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
}, "Precondition: Test that the browser does not have client hints preferences cached");
// Open a new window.
window.open("resources/expect_client_hints_headers.html");
});
}, "Test receiving Accept-CH-Lifetime header");
// Fetching this webpage should cause user-agent to persist client hint
// preferences for the origin.
var win = window.open("resources/accept_ch_lifetime.html");
assert_not_equals(win, null, "Popup windows not allowed?");
// Open a new window. Verify that the user agent attaches the client hints.
var verify_win = window.open("resources/expect_client_hints_headers.html");
assert_not_equals(verify_win, null, "Popup windows not allowed?");
async_test(t => {
window.addEventListener('message', function(event) {
t.done();
window.addEventListener('message', function(e) {
if(!e.source.location.pathname.includes("expect_client_hints_headers.html")) {
return;
}
if(typeof e.data != "string")
return;
assert_equals(e.data, "PASS");
t.done();
})
}, "Loading of resources/expect_client_hints_headers.html did not finish.");
</script>
</body>
</html>
<html>
<title>Accept-CH-Lifetime test with cross-origin iframe</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!--
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.
-->
<script>
// This test fetches resources/accept_ch_lifetime.html in a cross origin iframe.
// The response headers to that webpage contain Accept-CH and Accept-CH-Lifetime
// headers.
// Fetching that webpage should NOT cause the user-agent to persist origin
// preferences for the client hints specified.
// Next, to verify if 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 did not actually sent the client hints in the
// request headers.
// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
// is resolved.
// First, verify the initial state to make sure that the browser does not have
// client hints preferences cached from a previous run of the test.
promise_test(t => {
return fetch("echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser did not include client hints in the request
// headers when fetching echo_client_hints_received.py.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
});
}, "Precondition: Test that the browser does not have client hints preferences cached");
</script>
<!-- Fetching this webpage should NOT cause user-agent to persist client hint
preferences for the origin.-->
<iframe src="https://{{hosts[][www]}}:{{ports[https][0]}}/client-hints/resources/accept_ch_lifetime.html"></iframe>
<script>
// Open a new window. Verify that the user agent does not attach the client
// hints.
var win = window.open("resources/do_not_expect_client_hints_headers.html");
assert_not_equals(win, null, "Popup windows not allowed?");
async_test(t => {
window.addEventListener('message', function(e) {
if(!e.source.location.pathname.includes("do_not_expect_client_hints_headers.html")) {
return;
}
if(typeof e.data != "string")
return;
assert_equals(e.data, "PASS");
t.done();
})
}, "Loading of resources/do_not_expect_client_hints_headers.html did not finish.");
</script>
</body>
</html>
<html>
<title>Accept-CH-Lifetime test with same-origin iframe</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!--
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.
-->
<script>
// This test fetches resources/accept_ch_lifetime.html in a same origin iframe.
// The response headers to that webpage contain Accept-CH and Accept-CH-Lifetime
// headers.
// Fetching that webpage should cause the user-agent to persist origin
// preferences for the client hints specified in Accept-CH header for a
// duration specified in the Accept-CH-Lifetime header.
// Next, to verify if the origin preferences were persisted by the user
// agent, this test fetches resources/expect_client_hints_headers.html
// in a new window. Fetching of resources/expect_client_hints_headers.html
// verifies that the user agent actually sends the client hints in the request
// headers.
// Test is marked as tentative until https://github.com/whatwg/fetch/issues/726
// is resolved.
// First, verify the initial state to make sure that the browser does not have
// client hints preferences cached from a previous run of the test.
promise_test(t => {
return fetch("echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser did not include client hints in the request
// headers when fetching echo_client_hints_received.py.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
});
}, "Precondition: Test that the browser does not have client hints preferences cached");
</script>
<!-- Fetching this webpage should cause user-agent to persist client hint
preferences for the origin.-->
<iframe src="resources/accept_ch_lifetime.html"></iframe>
<script>
// Open a new window. Verify that the user agent attaches the client hints.
var win = window.open("resources/expect_client_hints_headers.html");
assert_not_equals(win, null, "Popup windows not allowed?");
async_test(t => {
window.addEventListener('message', function(e) {
if(!e.source.location.pathname.includes("expect_client_hints_headers.html")) {
return;
}
if(typeof e.data != "string")
return;
assert_equals(e.data, "PASS");
t.done();
})
}, "Loading of resources/expect_client_hints_headers.html did not finish.");
</script>
</body>
</html>
<html>
<title>Accept-CH-Lifetime test with subresource</title>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!--
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.
-->
<script>
// This test fetches resources/accept_ch_lifetime.html as a subresource. The
// response headers to that webpage contain Accept-CH and Accept-CH-Lifetime
// headers.
// Fetching that webpage as a subresource should NOT cause the user-agent to
// persist origin preferences for the client hints specified in Accept-CH
// header.
// Next, to verify if 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.
// First, verify the initial state to make sure that the browser does not have
// client hints preferences cached from a previous run of the test.
promise_test(t => {
return fetch("echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser did not include client hints in the request
// headers when fetching echo_client_hints_received.py.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
});
}, "Precondition: Test that the browser does not have client hints preferences cached");
promise_test(t => {
// Fetching this web page as a subresource should NOT cause user-agent to
// persist client hint preferences for the origin.
return fetch("resources/accept_ch_lifetime.html").then(r => {
assert_equals(r.status, 200)
// Verify that the browser did not include client hints in the request
// headers.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
});
}, "Test receiving Accept-CH-Lifetime header");
// Open a new window. Verify that the user agent does not attach the client
// hints.
var win = window.open("resources/do_not_expect_client_hints_headers.html");
assert_not_equals(win, null, "Popup windows not allowed?");
async_test(t => {
window.addEventListener('message', function(e) {
if(!e.source.location.pathname.includes("do_not_expect_client_hints_headers.html")) {
return;
}
if(typeof e.data != "string")
return;
assert_equals(e.data, "PASS");
t.done();
})
}, "Loading of resources/do_not_expect_client_hints_headers.html did not finish.");
</script>
</body>
</html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// This test checks if browser attaches the device-memory client hint in the
......@@ -11,18 +8,15 @@
// 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("../echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser did not include client hints in the request
// headers when fetching echo_client_hints_received.py.
assert_false(r.headers.has("device-memory-received"), "device-memory-received");
fetch("../echo_client_hints_received.py").then(r => {
if(r.status == 200 && r.headers.has("device-memory-received") != "device-memory-received") {
window.top.opener.postMessage('PASS', '*');
});
}, "Test if device-memory header was not sent by the browser");
}
else {
window.top.opener.postMessage('FAIL '+ ex.message, '*');
}
});
</script>
</body>
</html>
<html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
// This test checks if browser attaches the device-memory client hint in the
......@@ -11,18 +8,15 @@
// 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("../echo_client_hints_received.py").then(r => {
assert_equals(r.status, 200)
// Verify that the browser included client hints in the request headers when
// fetching echo_client_hints_received.py.
assert_true(r.headers.has("device-memory-received"), "device-memory-received");
fetch("../echo_client_hints_received.py").then(r => {
if(r.status == 200 && r.headers.has("device-memory-received") == "device-memory-received") {
window.top.opener.postMessage('PASS', '*');
});
}, "Test if device-memory header was sent by the browser");
}
else {
window.top.opener.postMessage('FAIL '+ ex.message, '*');
}
});
</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