Skip to content

Commit c1be1a0

Browse files
miketaylrchromium-wpt-export-bot
authored andcommittedOct 26, 2021
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 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3243544 Commit-Queue: Aaron Tagliaboschi <aarontag@chromium.org> Auto-Submit: Mike Taylor <miketaylr@chromium.org> Reviewed-by: Aaron Tagliaboschi <aarontag@chromium.org> Cr-Commit-Position: refs/heads/main@{#935138}
1 parent 8c690c8 commit c1be1a0

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
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

+30-21
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,48 @@
33
<script src=/resources/testharness.js></script>
44
<script src=/resources/testharnessreport.js></script>
55
<script>
6-
var minor = "";
7-
promise_test(t => {
6+
var sec_ch_ua_header = "";
7+
8+
function grabSECCHUAHeader(t) {
89
return new Promise((resolve, reject) => {
910
var w;
1011
window.onmessage = e => {
1112
try {
12-
assert_not_equals(e.data.header, "", "The `Sec-CH-UA` header is delivered.");
13-
minor = e.data.header;
13+
resolve(e.data.header)
1414
} catch (ex) {
1515
reject(ex);
1616
}
17-
w.close();
18-
resolve();
1917
};
2018
w = window.open("./resources/sec-ch-ua.py");
19+
t.add_cleanup(w.close);
20+
});
21+
}
22+
promise_test(t => {
23+
return grabSECCHUAHeader(t).then(header => {
24+
sec_ch_ua_header = header;
25+
assert_not_equals(sec_ch_ua_header, "", "`Sec-CH-UA` is sent.");
2126
});
22-
}, "Open HTTPS window prior to opt-in: `Sec-CH-UA` header with minor version.")
27+
}, "Open HTTPS window: `Sec-CH-UA` header returned by default.");
2328

2429
promise_test(t => {
25-
return new Promise((resolve, reject) => {
26-
var w;
27-
window.onmessage = e => {
28-
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.");
31-
} catch (ex) {
32-
reject(ex);
33-
}
34-
w.close();
35-
resolve();
36-
};
37-
w = window.open("./resources/sec-ch-ua.py");
30+
return grabSECCHUAHeader(t).then(header => {
31+
assert_not_equals(header, "", "The `Sec-CH-UA` header is delivered.");
32+
assert_equals(header, sec_ch_ua_header,
33+
"The `Sec-CH-UA` header did not change between requests.");
34+
});
35+
}, "Open HTTPS window: `Sec-CH-UA` header is consistent across versions.");
36+
37+
promise_test(t => {
38+
return grabSECCHUAHeader(t).then(header => {
39+
assert_true(header.split(", ").every((brand) => {
40+
let brandEnd = brand.indexOf(";v=");
41+
assert_true(brandEnd !== -1,
42+
"A well-formed Sec-CH-UA header must have version (v=) params");
43+
/* 32 + 2, becuase of the extra quotes padding the brand,
44+
e.g. '"lol";v=22"' */
45+
return brandEnd < 34;
46+
}));
3847
});
39-
}, "Open HTTPS window post-opt-in: `Sec-CH-UA` header with minor version.")
48+
}, "Open HTTPS window: No brand in `Sec-CH-UA` header is > than 32 chars.");
4049
</script>
4150
</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)
Please sign in to comment.