Skip to content

Commit 1aeba33

Browse files
miketaylrchromium-wpt-export-bot
authored andcommitted
Update Sec-CH-UA tests: fix existing tests, and test brand size.
As of WICG/ua-client-hints#179, https://wicg.github.io/ua-client-hints/#user-agent-brand now requires that a brand in a brand list not be longer than 32 bytes. This CL adds a new test for the userAgentData.brands interface, and modifies the existing sec-ch-ua HTTP tests. Also, the existing sec-ch-ua HTTP tests were updated to more closely reflect the current state of UA-CH ("UA" is not a valid token, and "Accept-CH-Lifetime" is not shipping). Bug: 1263180 Change-Id: Ifa7cbf18d67271e2dd1dc1d485f432d4ca9327fa
1 parent 4d23eaf commit 1aeba33

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

client-hints/resources/sec-ch-ua.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
def main(request, response):
2-
ua = request.headers.get(b'sec-ch-ua', b'')
2+
ua = request.headers.get(b'Sec-CH-UA', b'')
33
response.headers.set(b"Content-Type", b"text/html")
4-
response.headers.set(b"Accept-CH", b"UA")
5-
response.headers.set(b"Accept-CH-Lifetime", b"10")
64
response.content = b'''
75
<script>
86
window.opener.postMessage({ header: '%s' }, "*");

client-hints/sec-ch-ua.https.html

+34-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<script src=/resources/testharness.js></script>
44
<script src=/resources/testharnessreport.js></script>
55
<script>
6-
var minor = "";
6+
var sec_ch_ua_header = "";
77
promise_test(t => {
88
return new Promise((resolve, reject) => {
99
var w;
1010
window.onmessage = e => {
1111
try {
12-
assert_not_equals(e.data.header, "", "The `Sec-CH-UA` header is delivered.");
13-
minor = e.data.header;
12+
assert_not_equals(e.data.header, "", "`Sec-CH-UA` is sent.");
13+
sec_ch_ua_header = e.data.header;
1414
} catch (ex) {
1515
reject(ex);
1616
}
@@ -19,15 +19,18 @@
1919
};
2020
w = window.open("./resources/sec-ch-ua.py");
2121
});
22-
}, "Open HTTPS window prior to opt-in: `Sec-CH-UA` header with minor version.")
22+
}, "Open HTTPS window: `Sec-CH-UA` header returned by default.");
2323

2424
promise_test(t => {
2525
return new Promise((resolve, reject) => {
2626
var w;
2727
window.onmessage = e => {
2828
try {
29-
assert_not_equals(e.data.header, "", "The `Sec-CH-UA` header is delivered.");
30-
assert_equals(e.data.header, minor, "The `Sec-CH-UA` header did not change after the opt-in.");
29+
assert_not_equals(e.data.header, "",
30+
"The `Sec-CH-UA` header is delivered.");
31+
assert_equals(e.data.header,
32+
sec_ch_ua_header,
33+
"The `Sec-CH-UA` header did not change between requests.");
3134
} catch (ex) {
3235
reject(ex);
3336
}
@@ -36,6 +39,30 @@
3639
};
3740
w = window.open("./resources/sec-ch-ua.py");
3841
});
39-
}, "Open HTTPS window post-opt-in: `Sec-CH-UA` header with minor version.")
42+
}, "Open HTTPS window: `Sec-CH-UA` header is consistent across versions.");
43+
44+
promise_test(t => {
45+
return new Promise((resolve, reject) => {
46+
var w;
47+
window.onmessage = e => {
48+
try {
49+
let header = e.data.header;
50+
assert_true(header.split(", ").every((brand) => {
51+
let brandEnd = brand.indexOf(";v=");
52+
assert_true(brandEnd !== -1,
53+
"A well-formed Sec-CH-UA header must have version (v=) params");
54+
/* 32 + 2, becuase of the extra quotes padding the brand,
55+
e.g. '"lol";v=22"' */
56+
return brandEnd < 34;
57+
}));
58+
} catch (ex) {
59+
reject(ex);
60+
}
61+
w.close();
62+
resolve();
63+
};
64+
w = window.open("./resources/sec-ch-ua.py");
65+
});
66+
}, "Open HTTPS window: No brand in `Sec-CH-UA` header is > than 32 chars.");
4067
</script>
4168
</head>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// META: title=tests for navigator.userAgentData
2+
3+
test(t => {
4+
const brands = navigator.userAgentData.brands;
5+
assert_true(brands.every(brand => brand.brand.length < 32),
6+
"No brand should be longer than 32 characters.");
7+
});

0 commit comments

Comments
 (0)