rusdoc: add gui test for custom CSS themes

Based on
https://github.com/rust-lang/rust/pull/115829#issuecomment-1720056602
This commit is contained in:
Michael Howell 2023-09-14 13:24:23 -07:00
parent ccf817b9bb
commit cbccf800b8
6 changed files with 149 additions and 1 deletions

View File

@ -73,7 +73,7 @@ assert: "//*[@class='dir-entry' and @open]/*[text()='sub_mod']"
// Only "another_folder" should be "open" in "lib2". // Only "another_folder" should be "open" in "lib2".
assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']" assert: "//*[@class='dir-entry' and not(@open)]/*[text()='another_mod']"
// All other trees should be collapsed. // All other trees should be collapsed.
assert-count: ("//*[@id='src-sidebar']/details[not(text()='lib2') and not(@open)]", 9) assert-count: ("//*[@id='src-sidebar']/details[not(text()='lib2') and not(@open)]", 10)
// We now switch to mobile mode. // We now switch to mobile mode.
set-window-size: (600, 600) set-window-size: (600, 600)

View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "theme_css"
version = "0.1.0"

View File

@ -0,0 +1,7 @@
[package]
name = "theme_css"
version = "0.1.0"
edition = "2018"
[lib]
path = "lib.rs"

View File

@ -0,0 +1,99 @@
:root {
--main-background-color: red;
--main-color: black;
--settings-input-color: #2196f3;
--settings-input-border-color: #717171;
--settings-button-color: #000;
--settings-button-border-focus: #717171;
--sidebar-background-color: #f5f5f5;
--sidebar-background-color-hover: #e0e0e0;
--code-block-background-color: #f5f5f5;
--scrollbar-track-background-color: #dcdcdc;
--scrollbar-thumb-background-color: rgba(36, 37, 39, 0.6);
--scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9;
--headings-border-bottom-color: #ddd;
--border-color: #e0e0e0;
--button-background-color: #fff;
--right-side-color: grey;
--code-attribute-color: #999;
--toggles-color: #999;
--toggle-filter: none;
--search-input-focused-border-color: #66afe9;
--copy-path-button-color: #999;
--copy-path-img-filter: invert(50%);
--copy-path-img-hover-filter: invert(35%);
--codeblock-error-hover-color: rgb(255, 0, 0);
--codeblock-error-color: rgba(255, 0, 0, .5);
--codeblock-ignore-hover-color: rgb(255, 142, 0);
--codeblock-ignore-color: rgba(255, 142, 0, .6);
--warning-border-color: #ff8e00;
--type-link-color: #ad378a;
--trait-link-color: #6e4fc9;
--assoc-item-link-color: #3873ad;
--function-link-color: #ad7c37;
--macro-link-color: #068000;
--keyword-link-color: #3873ad;
--mod-link-color: #3873ad;
--link-color: #3873ad;
--sidebar-link-color: #356da4;
--sidebar-current-link-background-color: #fff;
--search-result-link-focus-background-color: #ccc;
--search-result-border-color: #aaa3;
--search-color: #000;
--search-error-code-background-color: #d0cccc;
--search-results-alias-color: #000;
--search-results-grey-color: #999;
--search-tab-title-count-color: #888;
--search-tab-button-not-selected-border-top-color: #e6e6e6;
--search-tab-button-not-selected-background: #e6e6e6;
--search-tab-button-selected-border-top-color: #0089ff;
--search-tab-button-selected-background: #fff;
--stab-background-color: #fff5d6;
--stab-code-color: #000;
--code-highlight-kw-color: #8959a8;
--code-highlight-kw-2-color: #4271ae;
--code-highlight-lifetime-color: #b76514;
--code-highlight-prelude-color: #4271ae;
--code-highlight-prelude-val-color: #c82829;
--code-highlight-number-color: #718c00;
--code-highlight-string-color: #718c00;
--code-highlight-literal-color: #c82829;
--code-highlight-attribute-color: #c82829;
--code-highlight-self-color: #c82829;
--code-highlight-macro-color: #3e999f;
--code-highlight-question-mark-color: #ff9011;
--code-highlight-comment-color: #8e908c;
--code-highlight-doc-comment-color: #4d4d4c;
--src-line-numbers-span-color: #c67e2d;
--src-line-number-highlighted-background-color: #fdffd3;
--test-arrow-color: #f5f5f5;
--test-arrow-background-color: rgba(78, 139, 202, 0.2);
--test-arrow-hover-color: #f5f5f5;
--test-arrow-hover-background-color: rgb(78, 139, 202);
--target-background-color: #fdffd3;
--target-border-color: #ad7c37;
--kbd-color: #000;
--kbd-background: #fafbfc;
--kbd-box-shadow-color: #c6cbd1;
--rust-logo-filter: initial;
/* match border-color; uses https://codepen.io/sosuke/pen/Pjoqqp */
--crate-search-div-filter: invert(100%) sepia(0%) saturate(4223%) hue-rotate(289deg)
brightness(114%) contrast(76%);
--crate-search-div-hover-filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg)
brightness(96%) contrast(93%);
--crate-search-hover-border: #717171;
--src-sidebar-background-selected: #fff;
--src-sidebar-background-hover: #e0e0e0;
--table-alt-row-background-color: #f5f5f5;
--codeblock-link-background: #eee;
--scrape-example-toggle-line-background: #ccc;
--scrape-example-toggle-line-hover-background: #999;
--scrape-example-code-line-highlight: #fcffd6;
--scrape-example-code-line-highlight-focus: #f6fdb0;
--scrape-example-help-border-color: #555;
--scrape-example-help-color: #333;
--scrape-example-help-hover-border-color: #000;
--scrape-example-help-hover-color: #000;
--scrape-example-code-wrapper-background-start: rgba(255, 255, 255, 1);
--scrape-example-code-wrapper-background-end: rgba(255, 255, 255, 0);
}

View File

@ -0,0 +1,2 @@
// compile-flags: --theme custom-theme.css
//! <div class="custom-text">custom text</div>

View File

@ -65,3 +65,36 @@ assert-local-storage: { "rustdoc-theme": "light" }
reload: reload:
wait-for: "#settings" wait-for: "#settings"
assert: "#preferred-light-theme.setting-line.hidden" assert: "#preferred-light-theme.setting-line.hidden"
// Ensures that the custom theme feature is working as expected.
go-to: "file://" + |DOC_PATH| + "/theme_css/index.html"
set-local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "dark"}
reload:
store-value: (background_light, "white")
store-value: (background_dark, "#353535")
store-value: (background_ayu, "#0f1419")
store-value: (background_custom_theme, "red")
click: "#settings-menu"
wait-for: "#theme-ayu"
click: "#theme-ayu"
// should be the ayu theme so let's check the color.
wait-for-css: ("body", { "background-color": |background_ayu| })
assert-local-storage: { "rustdoc-theme": "ayu" }
assert-text: (".custom-text", "custom text")
click: "#theme-light"
// should be the light theme so let's check the color.
wait-for-css: ("body", { "background-color": |background_light| })
assert-local-storage: { "rustdoc-theme": "light" }
assert-text: (".custom-text", "custom text")
click: "#theme-dark"
// Should be the dark theme so let's check the color.
wait-for-css: ("body", { "background-color": |background_dark| })
assert-local-storage: { "rustdoc-theme": "dark" }
assert-text: (".custom-text", "custom text")
click: "#theme-custom-theme"
// Should be the custom theme so let's check the color.
wait-for-css: ("body", { "background-color": |background_custom_theme| })
assert-local-storage: { "rustdoc-theme": "custom-theme" }
assert-text: (".custom-text", "custom text")