Skip to content

Commit

Permalink
Implement Sec-CH-Prefers-Reduced-Motion
Browse files Browse the repository at this point in the history
The `Sec-CH-Prefers-Reduced-Motion` client hint is modeled after the
`prefers-reduced-motion` user preference media feature as defined in
Media Queries 5.

Intent to ship: https://groups.google.com/a/chromium.org/g/blink-dev/c/_m5xConFTfY

Demo: https://sec-ch-prefers-reduced-motion.glitch.me
Spec: https://wicg.github.io/user-preference-media-features-headers/#sec-ch-prefers-reduced-motion
Bug: 1361871
Change-Id: I05da639019da14caec27c87852c6f6bfb9916c19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3883679
Commit-Queue: Fr <[email protected]>
Reviewed-by: Mike West <[email protected]>
Auto-Submit: Fr <[email protected]>
Reviewed-by: Reilly Grant <[email protected]>
Reviewed-by: Yoav Weiss <[email protected]>
Reviewed-by: Dominic Farolino <[email protected]>
Reviewed-by: Ari Chivukula <[email protected]>
Reviewed-by: Charlie Reis <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1052463}
  • Loading branch information
beaufortfrancois authored and chromium-wpt-export-bot committed Sep 28, 2022
1 parent 2ea30ed commit 38d5d64
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client-hints/accept-ch/__dir__.headers
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Accept-CH: device-memory, dpr, width, viewport-width, rtt, downlink, ect, sec-ch-ua, sec-ch-ua-arch, sec-ch-ua-platform, sec-ch-ua-model, sec-ch-ua-mobile, sec-ch-ua-full-version, sec-ch-ua-platform-version, sec-ch-prefers-color-scheme, sec-ch-ua-bitness, sec-ch-viewport-height, sec-ch-device-memory, sec-ch-dpr, sec-ch-width, sec-ch-viewport-width, sec-ch-ua-full-version-list, sec-ch-ua-wow64
Accept-CH: device-memory, dpr, width, viewport-width, rtt, downlink, ect, sec-ch-ua, sec-ch-ua-arch, sec-ch-ua-platform, sec-ch-ua-model, sec-ch-ua-mobile, sec-ch-ua-full-version, sec-ch-ua-platform-version, sec-ch-prefers-color-scheme, sec-ch-prefers-reduced-motion, sec-ch-ua-bitness, sec-ch-viewport-height, sec-ch-device-memory, sec-ch-dpr, sec-ch-width, sec-ch-viewport-width, sec-ch-ua-full-version-list, sec-ch-ua-wow64
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Accept-CH: device-memory, dpr, width, viewport-width, rtt, downlink, ect, sec-ch-ua, sec-ch-ua-arch, sec-ch-ua-platform, sec-ch-ua-model, sec-ch-ua-mobile, sec-ch-ua-full-version, sec-ch-ua-platform-version, sec-ch-prefers-color-scheme, sec-ch-ua-bitness, sec-ch-viewport-height, sec-ch-device-memory, sec-ch-dpr, sec-ch-width, sec-ch-viewport-width, sec-ch-ua-full-version-list, sec-ch-ua-wow64
Accept-CH: device-memory, dpr, width, viewport-width, rtt, downlink, ect, sec-ch-ua, sec-ch-ua-arch, sec-ch-ua-platform, sec-ch-ua-model, sec-ch-ua-mobile, sec-ch-ua-full-version, sec-ch-ua-platform-version, sec-ch-prefers-color-scheme, sec-ch-prefers-reduced-motion, sec-ch-ua-bitness, sec-ch-viewport-height, sec-ch-device-memory, sec-ch-dpr, sec-ch-width, sec-ch-viewport-width, sec-ch-ua-full-version-list, sec-ch-ua-wow64
2 changes: 2 additions & 0 deletions client-hints/accept-ch/feature-policy.sub.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
assert_true(r.headers.has("mobile-received"));
assert_in_array(r.headers.get("mobile-received"), ["?0", "?1"], 'mobile is unexpected');
assert_false(r.headers.has("prefers-color-scheme-received"), "prefers-color-scheme-received");
assert_false(r.headers.has("prefers-reduced-motion-received"), "prefers-reduced-motion-received");
assert_false(r.headers.has("viewport-height-received"), "viewport-height-received");
});
}, "Accept-CH header test");
Expand All @@ -63,6 +64,7 @@
assert_false(r.headers.has("downlink-received"), "downlink-received");
assert_false(r.headers.has("ect-received"), "ect-received");
assert_false(r.headers.has("prefers-color-scheme-received"), "prefers-color-scheme-received");
assert_false(r.headers.has("prefers-reduced-motion-received"), "prefers-reduced-motion-received");
assert_false(r.headers.has("viewport-height-received"), "viewport-height-received");
});
}, "Cross-Origin Accept-CH header test");
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Feature-Policy: ch-device-memory *; ch-dpr 'none'; ch-viewport-width 'self'; ch-mobile; ch-prefers-color-scheme 'none'; ch-viewport-height 'none'
Feature-Policy: ch-device-memory *; ch-dpr 'none'; ch-viewport-width 'self'; ch-mobile; ch-prefers-color-scheme 'none'; ch-prefers-reduced-motion 'none'; ch-viewport-height 'none'
2 changes: 2 additions & 0 deletions client-hints/http-equiv-accept-ch-merge.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<head>
<meta http-equiv="Accept-CH" content="sec-ch-viewport-width, viewport-width, rtt">
<meta http-equiv="Accept-CH" content="downlink, ect, sec-ch-prefers-color-scheme">
<meta http-equiv="Accept-CH" content="sec-ch-prefers-reduced-motion">
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down Expand Up @@ -38,6 +39,7 @@
assert_in_array(r.headers.get("ect-received"), ["slow-2g", "2g",
"3g", "4g"], 'ect-received is unexpected');
assert_true(r.headers.has("prefers-color-scheme-received"), "prefers-color-scheme-received");
assert_true(r.headers.has("prefers-reduced-motion-received"), "prefers-reduced-motion-received");
});
}, "Accept-CH header test");

Expand Down
2 changes: 1 addition & 1 deletion client-hints/meta-equiv-delegate-ch-injection.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
document.getElementsByTagName('meta')[0].setAttribute("content", "dpr;sec-ch-dpr;device-memory;sec-ch-device-memory;viewport-width;sec-ch-viewport-width;rtt;downlink;ect");
document.head.outerHTML += '<meta http-equiv="Delegate-CH" content="sec-ch-ua-arch;sec-ch-ua-platform;sec-ch-ua-model">';
document.head.innerHTML += '<meta http-equiv="Delegate-CH" content="sec-ch-ua-full-version;sec-ch-ua-bitness;sec-ch-ua-full-version-list">';
document.write('<meta http-equiv="Delegate-CH" content="sec-ch-ua-platform-version;sec-ch-prefers-color-scheme;sec-ch-viewport-height">');
document.write('<meta http-equiv="Delegate-CH" content="sec-ch-ua-platform-version;sec-ch-prefers-color-scheme;sec-ch-prefers-reduced-motion;sec-ch-viewport-height">');

// resources/echo-client-hints-received.py sets the response headers depending on the set
// of client hints it receives in the request headers.
Expand Down
2 changes: 2 additions & 0 deletions client-hints/meta-equiv-delegate-ch-merge.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta http-equiv="Delegate-CH" content="sec-ch-viewport-width; viewport-width; rtt">
<meta http-equiv="Delegate-CH" content="downlink; ect; sec-ch-prefers-color-scheme">
<meta http-equiv="Delegate-CH" content="sec-ch-prefers-reduced-motion">
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down Expand Up @@ -39,6 +40,7 @@
assert_in_array(r.headers.get("ect-received"), ["slow-2g", "2g",
"3g", "4g"], 'ect-received is unexpected');
assert_true(r.headers.has("prefers-color-scheme-received"), "prefers-color-scheme-received");
assert_true(r.headers.has("prefers-reduced-motion-received"), "prefers-reduced-motion-received");
});
}, "Delegate-CH header test");

Expand Down
1 change: 1 addition & 0 deletions client-hints/resources/clienthintslist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def client_hints_list():
b"sec-ch-ua-full-version",
b"sec-ch-ua-platform-version",
b"sec-ch-prefers-color-scheme",
b"sec-ch-prefers-reduced-motion",
b"sec-ch-ua-bitness",
b"sec-ch-viewport-height",
b"sec-ch-device-memory",
Expand Down
2 changes: 2 additions & 0 deletions client-hints/resources/echo-client-hints-received.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ def main(request, response):
response.headers.set(b"mobile-received", request.headers.get(b"sec-ch-ua-mobile"))
if b"sec-ch-prefers-color-scheme" in request.headers:
response.headers.set(b"prefers-color-scheme-received", request.headers.get(b"sec-ch-prefers-color-scheme"))
if b"sec-ch-prefers-reduced-motion" in request.headers:
response.headers.set(b"prefers-reduced-motion-received", request.headers.get(b"sec-ch-prefers-reduced-motion"))
1 change: 1 addition & 0 deletions client-hints/resources/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const client_hints_list = [
"sec-ch-ua-full-version",
"sec-ch-ua-platform-version",
"sec-ch-prefers-color-scheme",
"sec-ch-prefers-reduced-motion",
"sec-ch-ua-bitness",
"sec-ch-viewport-height",
"sec-ch-device-memory",
Expand Down
2 changes: 1 addition & 1 deletion client-hints/sandbox/__dir__.headers
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Accept-CH: device-memory, dpr, width, viewport-width, rtt, downlink, ect, sec-ch-ua, sec-ch-ua-arch, sec-ch-ua-platform, sec-ch-ua-model, sec-ch-ua-mobile, sec-ch-ua-full-version, sec-ch-ua-platform-version, sec-ch-prefers-color-scheme, sec-ch-ua-bitness, sec-ch-viewport-height, sec-ch-device-memory, sec-ch-dpr, sec-ch-width, sec-ch-viewport-width, sec-ch-ua-full-version-list, sec-ch-ua-wow64
Accept-CH: device-memory, dpr, width, viewport-width, rtt, downlink, ect, sec-ch-ua, sec-ch-ua-arch, sec-ch-ua-platform, sec-ch-ua-model, sec-ch-ua-mobile, sec-ch-ua-full-version, sec-ch-ua-platform-version, sec-ch-prefers-color-scheme, sec-ch-prefers-reduced-motion, sec-ch-ua-bitness, sec-ch-viewport-height, sec-ch-device-memory, sec-ch-dpr, sec-ch-width, sec-ch-viewport-width, sec-ch-ua-full-version-list, sec-ch-ua-wow64
1 change: 1 addition & 0 deletions client-hints/sec-ch-quotes.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"sec-ch-ua-model",
"sec-ch-ua-full-version",
"sec-ch-prefers-color-scheme",
"sec-ch-prefers-reduced-motion",
"sec-ch-ua-full-version-list",
"sec-ch-ua-wow64",
];
Expand Down
2 changes: 1 addition & 1 deletion client-hints/sec-ch-quotes.https.html.headers
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Accept-CH: sec-ch-ua,sec-ch-ua-arch,sec-ch-ua-platform,sec-ch-ua-platform-version,sec-ch-ua-model,sec-ch-prefers-color-scheme
Accept-CH: sec-ch-ua,sec-ch-ua-arch,sec-ch-ua-platform,sec-ch-ua-platform-version,sec-ch-ua-model,sec-ch-prefers-color-scheme,sec-ch-prefers-reduced-motion

0 comments on commit 38d5d64

Please sign in to comment.