Skip to content

Commit

Permalink
Rollup merge of #110037 - notriddle:notriddle/theme-default, r=Guilla…
Browse files Browse the repository at this point in the history
…umeGomez

rustdoc: add test and bug fix for theme defaults

Part of #66181
  • Loading branch information
Noratrieb authored Apr 8, 2023
2 parents 77639c0 + 5cad51c commit 3700848
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustdoc/html/static/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const updateTheme = (function() {
if (getSettingValue("use-system-theme") !== "false") {
const lightTheme = getSettingValue("preferred-light-theme") || "light";
const darkTheme = getSettingValue("preferred-dark-theme") || "dark";
updateLocalStorage("use-system-theme", "true");

// use light theme if user prefers it, or has no preference
switchTheme(mql.matches ? darkTheme : lightTheme, true);
Expand Down
24 changes: 24 additions & 0 deletions tests/rustdoc-gui/theme-defaults.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Ensure that the theme picker always starts with the actual defaults.
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
click: "#settings-menu"
wait-for: "#theme-system-preference"
assert: "#theme-system-preference:checked"
assert: "#preferred-light-theme-light:checked"
assert: "#preferred-dark-theme-dark:checked"
assert-false: "#preferred-dark-theme-ayu:checked"

// Test legacy migration from old theme setup without system-preference matching.
// See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732
local-storage: {
"rustdoc-preferred-light-theme": null,
"rustdoc-preferred-dark-theme": null,
"rustdoc-use-system-theme": null,
"rustdoc-theme": "ayu"
}
goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
click: "#settings-menu"
wait-for: "#theme-system-preference"
assert: "#theme-system-preference:checked"
assert: "#preferred-light-theme-light:checked"
assert-false: "#preferred-dark-theme-dark:checked"
assert: "#preferred-dark-theme-ayu:checked"

0 comments on commit 3700848

Please sign in to comment.