Skip to content

Commit b8c372f

Browse files
authored
Rollup merge of rust-lang#110037 - notriddle:notriddle/theme-default, r=GuillaumeGomez
rustdoc: add test and bug fix for theme defaults Part of rust-lang#66181
2 parents 33c6e08 + 5cad51c commit b8c372f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/librustdoc/html/static/js/storage.js

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ const updateTheme = (function() {
158158
if (getSettingValue("use-system-theme") !== "false") {
159159
const lightTheme = getSettingValue("preferred-light-theme") || "light";
160160
const darkTheme = getSettingValue("preferred-dark-theme") || "dark";
161+
updateLocalStorage("use-system-theme", "true");
161162

162163
if (mql.matches) {
163164
use(darkTheme, true);

tests/rustdoc-gui/theme-defaults.goml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Ensure that the theme picker always starts with the actual defaults.
2+
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
3+
click: "#settings-menu"
4+
wait-for: "#theme-system-preference"
5+
assert: "#theme-system-preference:checked"
6+
assert: "#preferred-light-theme-light:checked"
7+
assert: "#preferred-dark-theme-dark:checked"
8+
assert-false: "#preferred-dark-theme-ayu:checked"
9+
10+
// Test legacy migration from old theme setup without system-preference matching.
11+
// See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732
12+
local-storage: {
13+
"rustdoc-preferred-light-theme": null,
14+
"rustdoc-preferred-dark-theme": null,
15+
"rustdoc-use-system-theme": null,
16+
"rustdoc-theme": "ayu"
17+
}
18+
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
19+
click: "#settings-menu"
20+
wait-for: "#theme-system-preference"
21+
assert: "#theme-system-preference:checked"
22+
assert: "#preferred-light-theme-light:checked"
23+
assert-false: "#preferred-dark-theme-dark:checked"
24+
assert: "#preferred-dark-theme-ayu:checked"

0 commit comments

Comments
 (0)