Bug 1736376 [wpt PR 31298] - Clean up Client Hint WPT failures, a=testonly

Automatic update from web-platform-tests
Clean up Client Hint WPT failures

The wpt.fyi test runner does not restart the browser on a failure like
the trybot runners do, so any state left by the tests makes for
flakiness.

Also, accept-ch-change.https.html *actually* wasn't working properly, in
that nothing was running except the initial check

Leaving the cache-related failures for a separate patch

Bug: 1257191
Change-Id: I6a51ad020a6dde748afa9fa1efeeaf4c1ccf8b0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3213006
Reviewed-by: Mike Taylor <miketaylr@chromium.org>
Commit-Queue: Aaron Tagliaboschi <aarontag@chromium.org>
Cr-Commit-Position: refs/heads/main@{#932969}

--

wpt-commits: 207e223d74fdc1f1103101d47105102fab667b4b
wpt-pr: 31298
This commit is contained in:
Aaron Tagliaboschi 2021-10-28 10:19:12 +00:00 committed by moz-wptsync-bot
parent 76e188ae25
commit 6844006699
7 changed files with 90 additions and 52 deletions

View File

@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<title>Accept-CH test</title>
<body>
@ -25,50 +26,39 @@ in this web page, and two in the other web pages.
// After this, the same is done but with a differet Accept-CH header, to test
// that the preferences change after receiving a different header.
// 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("resources/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");
assert_false(r.headers.has("viewport-width-received"), "viewport-width-received");
});
}, "Precondition: Test that the browser does not have client hints preferences cached");
promise_test(async () => {
r = await fetch("resources/echo-client-hints-received.py");
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");
assert_false(r.headers.has("viewport-width-received"), "viewport-width-received");
// Fetching this webpage should cause user-agent to persist client hint
// preferences for the origin.
await open_and_add_load_event("resources/accept-ch.html");
function acceptChLoaded() {
// Open a new window. Verify that the user agent does attach the client hints.
open_and_add_load_event("resources/expect-client-hints-headers.html", changeCh);
}
await open_and_expect_headers("resources/expect-client-hints-headers.html");
function changeCh() {
// Use new window to overwrite client hint preferences, then verify new
// settings have been saved
open_and_add_load_event("resources/accept-ch-different.html", verifyChangeCh);
}
await open_and_add_load_event("resources/accept-ch-different.html");
function verifyChangeCh() {
// Use new window to overwrite client hint preferences, then verify new
// settings have been saved
open_and_add_load_event("resources/expect-client-hints-headers-different.html", clearCh);
}
await open_and_expect_headers("resources/expect-different-client-hints-headers.html");
function clearCh() {
// Use new window to overwrite client hint preferences, then verify new
// settings have been saved
open_and_add_load_event("resources/accept-ch-empty.html", verifyClearCh);
}
await open_and_add_load_event("resources/accept-ch-empty.html");
function verifyClearCh() {
// Use new window to overwrite client hint preferences, then verify new
// settings have been saved
open_and_add_load_event("resources/do-not-expect-client-hints.html", null);
}
await open_and_expect_headers("resources/expect-no-client-hints-headers.html");
// Fetching this webpage should cause user-agent to persist client hint
// preferences for the origin.
open_and_add_load_event("resources/accept-ch.html", acceptChLoaded);
}, "Accept-CH changes based on header");
</script>
</body>

View File

@ -1,24 +1,22 @@
<html>
<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/open-and-add-load-event.js"></script>
<script>
promise_test(t => {
return fetch("/client-hints/resources/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 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");
promise_test(async t => {
t.add_cleanup(() => {
return open_and_add_load_event("resources/accept-ch-empty.html");
});
}, "Accept-CH header test");
await open_and_add_load_event("resources/accept-ch-malformed.html");
// Verify that the browser does not include client hints in the headers
// since Accept-CH is malformed (includes whitespace between attributes
// instead of comma).
await open_and_expect_headers("resources/expect-no-client-hints-headers.html");
}, "Accept-CH malformed header test");
</script>

View File

@ -1 +0,0 @@
Accept-CH: device-memory dpr

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<body>
<!-- An empty webpage whose response headers include only the
Accept-CH header. Fetching this webpage should cause
user-agent to persist origin preferences for the client hints
specified in the Accept-CH header.-->
</body>
</html>

View File

@ -0,0 +1,2 @@
Accept-CH: device memory
Access-Control-Allow-Origin: *

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<body>
<script>
// This test checks if browser attaches the viewport-width client hint in the
// HTTP request headers.
// resources/echo-client-hints-received.py sets the response headers depending on the set
// of client hints it receives in the request headers.
fetch("../resources/echo-client-hints-received.py").then(r => {
if(r.status == 200 &&
!r.headers.has("viewport-width-received") &&
!r.headers.has("viewport-width-received")) {
window.top.opener.postMessage('PASS', '*');
} else {
window.top.opener.postMessage('FAIL', '*');
}
});
</script>
</body>
</html>

View File

@ -1,9 +1,23 @@
function open_and_add_load_event(href, func) {
// While not practically possible, opening "blank" first and setting the
// href after allows for the theoretical possibility of registering the event
// after the window is loaded.
let popup_window = window.open("about:blank");
assert_not_equals(popup_window, null, "Popup windows not allowed?");
popup_window.addEventListener('load', func, false);
popup_window.location.href=href;
function open_and_add_load_event(href) {
return new Promise((resolve) => {
// While not practically possible, opening "blank" first and setting the
// href after allows for the theoretical possibility of registering the event
// after the window is loaded.
let popup_window = window.open("/resources/blank.html");
assert_not_equals(popup_window, null, "Popup windows not allowed?");
popup_window.addEventListener('load', resolve, {once: true});
popup_window.location.href = href;
});
}
async function open_and_expect_headers(href) {
let e = await new Promise(resolve => {
let popup_window = window.open("/resources/blank.html");
assert_not_equals(popup_window, null, "Popup windows not allowed?");
window.addEventListener('message', resolve, false);
popup_window.location.href = href;
});
assert_equals(e.data, "PASS");
return e;
}