1 // This test ensures that the settings menu display is working as expected and that
2 // the settings page is also rendered as expected.
3 goto: "file://" + |DOC_PATH| + "/test_docs/index.html"
4 show-text: true // needed when we check for colors below.
5 // First, we check that the settings page doesn't exist.
6 assert-false: "#settings"
7 // We now click on the settings button.
8 click: "#settings-menu"
10 assert-css: ("#settings", {"display": "block"})
12 // Store the line margin to compare with the settings.html later.
13 store-css: (setting_line_margin, ".setting-line", "margin")
15 // Let's close it by clicking on the same button.
16 click: "#settings-menu"
17 wait-for-css: ("#settings", {"display": "none"})
19 // Let's check that pressing "ESCAPE" is closing it.
20 click: "#settings-menu"
21 wait-for-css: ("#settings", {"display": "block"})
23 wait-for-css: ("#settings", {"display": "none"})
25 // Let's click on it when the search results are displayed.
26 focus: ".search-input"
28 // To be SURE that the search will be run.
30 wait-for: "#alternative-display #search"
31 click: "#settings-menu"
32 wait-for-css: ("#settings", {"display": "block"})
33 // Ensure that the search is still displayed.
34 wait-for: "#alternative-display #search"
35 assert: "#main-content.hidden"
37 // Now let's check the content of the settings menu.
38 local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"}
40 click: "#settings-menu"
43 // We check that the "Use system theme" is disabled.
44 assert-property: ("#theme-system-preference", {"checked": "false"})
45 // Meaning that only the "theme" menu is showing up.
46 assert: "#theme.setting-line:not(.hidden)"
47 assert: "#preferred-dark-theme.setting-line.hidden"
48 assert: "#preferred-light-theme.setting-line.hidden"
50 // We check that the correct theme is selected.
51 assert-property: ("#theme .setting-radio-choices #theme-dark", {"checked": "true"})
53 // Some style checks...
54 move-cursor-to: "#settings-menu > a"
55 // First we check the "default" display for radio buttons.
59 "border-color": "rgb(221, 221, 221)",
60 "box-shadow": "rgb(53, 53, 53) 0px 0px 0px 3px inset",
63 assert-css: ("#theme-light", {"border-color": "rgb(221, 221, 221)", "box-shadow": "none"})
64 // Let's start with the hover for radio buttons.
65 move-cursor-to: "#theme-dark"
69 "border-color": "rgb(33, 150, 243)",
70 "box-shadow": "rgb(53, 53, 53) 0px 0px 0px 3px inset",
73 move-cursor-to: "#theme-light"
74 assert-css: ("#theme-light", {"border-color": "rgb(33, 150, 243)", "box-shadow": "none"})
75 move-cursor-to: "#theme-ayu"
76 // Let's now check with the focus for radio buttons.
81 "border-color": "rgb(221, 221, 221)",
82 "box-shadow": "rgb(53, 53, 53) 0px 0px 0px 3px inset, rgb(33, 150, 243) 0px 0px 2px 2px",
89 "border-color": "rgb(221, 221, 221)",
90 "box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
93 // Now we check we both focus and hover for radio buttons.
94 move-cursor-to: "#theme-dark"
99 "border-color": "rgb(33, 150, 243)",
100 "box-shadow": "rgb(53, 53, 53) 0px 0px 0px 3px inset, rgb(33, 150, 243) 0px 0px 2px 2px",
103 move-cursor-to: "#theme-light"
104 focus: "#theme-light"
108 "border-color": "rgb(33, 150, 243)",
109 "box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
112 // Now we check the setting-radio-name is on a different line than the label.
113 compare-elements-position-near: (
114 "#theme .setting-radio-name",
115 "#theme .setting-radio-choices",
118 compare-elements-position-near-false: (
119 "#theme .setting-radio-name",
120 "#theme .setting-radio-choices",
123 // Now we check that the label positions are all on the same line.
124 compare-elements-position-near: (
125 "#theme .setting-radio-choices #theme-light",
126 "#theme .setting-radio-choices #theme-dark",
129 compare-elements-position-near: (
130 "#theme .setting-radio-choices #theme-dark",
131 "#theme .setting-radio-choices #theme-ayu",
134 compare-elements-position-near: (
135 "#theme .setting-radio-choices #theme-ayu",
136 "#theme .setting-radio-choices #theme-system-preference",
140 // First we check the "default" display for toggles.
142 "#auto-hide-large-items",
144 "background-color": "rgb(33, 150, 243)",
145 "border-color": "rgb(221, 221, 221)",
148 // Let's start with the hover for toggles.
149 move-cursor-to: "#auto-hide-large-items"
151 "#auto-hide-large-items",
153 "background-color": "rgb(33, 150, 243)",
154 "border-color": "rgb(33, 150, 243)",
157 move-cursor-to: "#settings-menu > a"
158 // Let's now check with the focus for toggles.
159 focus: "#auto-hide-large-items"
161 "#auto-hide-large-items",
163 "background-color": "rgb(33, 150, 243)",
164 "border-color": "rgb(221, 221, 221)",
165 "box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
168 // Now we check we both focus and hover for toggles.
169 move-cursor-to: "#auto-hide-large-items"
170 focus: "#auto-hide-large-items"
172 "#auto-hide-large-items",
174 "background-color": "rgb(33, 150, 243)",
175 "border-color": "rgb(33, 150, 243)",
176 "box-shadow": "rgb(33, 150, 243) 0px 0px 1px 1px",
180 // We now switch the display.
181 click: "#theme-system-preference"
182 // Wait for the hidden element to show up.
183 wait-for: "#preferred-dark-theme.setting-line:not(.hidden)"
184 assert: "#preferred-light-theme.setting-line:not(.hidden)"
186 // We check their text as well.
187 assert-text: ("#preferred-dark-theme .setting-radio-name", "Preferred dark theme")
188 assert-text: ("#preferred-light-theme .setting-radio-name", "Preferred light theme")
190 // We now check that clicking on the toggles' text is like clicking on the checkbox.
191 // To test it, we use the "Disable keyboard shortcuts".
192 local-storage: {"rustdoc-disable-shortcuts": "false"}
193 click: ".setting-line:last-child .setting-check span"
194 assert-local-storage: {"rustdoc-disable-shortcuts": "true"}
196 // Make sure that "Disable keyboard shortcuts" actually took effect.
199 assert-false: "#help-button .popover"
200 wait-for-css: ("#settings-menu .popover", {"display": "block"})
202 // Now turn keyboard shortcuts back on, and see if they work.
203 click: ".setting-line:last-child .setting-check span"
204 assert-local-storage: {"rustdoc-disable-shortcuts": "false"}
207 wait-for-css: ("#help-button .popover", {"display": "block"})
208 assert-css: ("#settings-menu .popover", {"display": "none"})
210 // Now switch back to the settings popover, and make sure the keyboard
211 // shortcut works when a check box is selected.
212 click: "#settings-menu > a"
213 wait-for-css: ("#settings-menu .popover", {"display": "block"})
214 focus: "#auto-hide-large-items"
216 wait-for-css: ("#settings-menu .popover", {"display": "none"})
217 wait-for-css: ("#help-button .popover", {"display": "block"})
219 // Now switch back to the settings popover, and make sure the keyboard
220 // shortcut works when a check box is selected.
221 click: "#settings-menu > a"
222 wait-for-css: ("#settings-menu .popover", {"display": "block"})
223 wait-for-css: ("#help-button .popover", {"display": "none"})
224 focus: "#theme-system-preference"
226 wait-for-css: ("#settings-menu .popover", {"display": "none"})
227 wait-for-css: ("#help-button .popover", {"display": "block"})
229 // Now we go to the settings page to check that the CSS is loaded as expected.
230 goto: "file://" + |DOC_PATH| + "/settings.html"
231 wait-for: "#settings"
232 assert-css: (".setting-line", {"position": "relative"})
234 assert-attribute-false: ("#settings", {"class": "popover"}, CONTAINS)
235 compare-elements-position: (".sub form", "#settings", ("x"))
237 // Check that setting-line has the same margin in this mode as in the popover.
238 assert-css: (".setting-line", {"margin": |setting_line_margin|})
240 // We now check the display with JS disabled.
241 assert-false: "noscript section"
244 assert-css: ("noscript section", {"display": "block"})
247 // Check for the display on small screen
251 click: "#settings-menu"
252 wait-for: "#settings"
253 assert-css: (".setting-line", {"position": "relative"})