diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 6e7a6daa307cd..acf60114bd47a 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1478,6 +1478,13 @@ so that we can apply CSS-filters to change the arrow color in themes */ padding: 4px; transform: rotate(-45deg); top: -5px; + /* So the arrow doesn't go above the content in the popover. */ + z-index: -1; +} +#settings.popover::before { + /* Because of the tabs, it renders weird if we pick a different color than the tab's + background. */ + background-color: var(--search-tab-button-not-selected-background); } .setting-line { @@ -1548,9 +1555,22 @@ so that we can apply CSS-filters to change the arrow color in themes */ border-color: var(--settings-input-color) !important; } +.settings-menu #settings { + /* This is to prevent the popover width to change when we switch tabs. I picked the biggest + width based on the setting with the longest text. The `- 2px` is to includes the borders + width when the window's width is very thin. */ + width: min(456px, calc(100vw - 2px)); +} #settings.popover { --popover-arrow-offset: 196px; top: calc(100% - 16px); + right: 1px; +} + +#settings .settings { + height: 100%; + display: flex; + flex-direction: column; } /* use larger max-width for help popover, but not for help.html */ @@ -2032,13 +2052,15 @@ a.tooltip:hover::after { #search-tabs { margin-top: 0.25rem; + margin-bottom: 4px; +} + +#search-tabs, #settings .tabs { display: flex; flex-direction: row; gap: 1px; - margin-bottom: 4px; } - -#search-tabs button { +#search-tabs button, #settings .tabs button.tab { text-align: center; font-size: 1.125rem; border: 0; @@ -2047,15 +2069,23 @@ a.tooltip:hover::after { line-height: 1.5; color: inherit; } -#search-tabs button:not(.selected) { +#search-tabs button:not(.selected), #settings .tabs button.tab:not(.selected) { background-color: var(--search-tab-button-not-selected-background); border-top-color: var(--search-tab-button-not-selected-border-top-color); } -#search-tabs button:hover, #search-tabs button.selected { +#search-tabs button:hover, #search-tabs button.selected, +#settings .tabs button.tab:hover, #settings .tabs button.tab.selected { background-color: var(--search-tab-button-selected-background); border-top-color: var(--search-tab-button-selected-border-top-color); } +#settings .settings .setting { + display: none; +} +#settings .settings .setting.selected { + display: block; +} + #search-tabs .count { font-size: 1rem; font-variant-numeric: tabular-nums; @@ -2067,8 +2097,7 @@ a.tooltip:hover::after { color: transparent; } -.search-form.loading::after -{ +.search-form.loading::after { width: 18px; height: 18px; border-radius: 18px; @@ -2777,8 +2806,11 @@ in src-script.js and main.js } /* The `overflow-y` property is used on an internal content instead of the top one otherwise the little arrow at the top can't be displayed. */ - #settings.popover .settings, #help.popover .content { + #settings.popover .settings .setting, #help.popover .content { overflow-y: scroll; + } + + #help.popover .content { height: 100%; } @@ -3491,10 +3523,10 @@ Original by Dempfi (https://github.com/dempfi/ayu) --search-results-alias-color: #c5c5c5; --search-results-grey-color: #999; --search-tab-title-count-color: #888; - --search-tab-button-not-selected-border-top-color: none; - --search-tab-button-not-selected-background: transparent !important; - --search-tab-button-selected-border-top-color: none; - --search-tab-button-selected-background: #141920 !important; + --search-tab-button-not-selected-border-top-color: #1d1f20; + --search-tab-button-not-selected-background: #1d1f20; + --search-tab-button-selected-border-top-color: #ffb44c; + --search-tab-button-selected-background: #141920; --settings-menu-filter: invert(70%); --settings-menu-hover-filter: invert(100%); --stab-background-color: #314559; @@ -3621,18 +3653,6 @@ Original by Dempfi (https://github.com/dempfi/ayu) color: #788797; } -:root[data-theme="ayu"] #search-tabs > button.selected { - border-bottom: 1px solid #ffb44c !important; - border-top: none; -} -:root[data-theme="ayu"] #search-tabs > button:not(.selected) { - border: none; - background-color: transparent !important; -} -:root[data-theme="ayu"] #search-tabs > button:hover { - border-bottom: 1px solid rgba(242, 151, 24, 0.3); -} - :root[data-theme="ayu"] .settings-menu > a img, :root[data-theme="ayu"] #sidebar-button > a::before { filter: invert(100); diff --git a/src/librustdoc/html/static/js/rustdoc.d.ts b/src/librustdoc/html/static/js/rustdoc.d.ts index 9bd6a1a587e5d..fef93a01a26cb 100644 --- a/src/librustdoc/html/static/js/rustdoc.d.ts +++ b/src/librustdoc/html/static/js/rustdoc.d.ts @@ -562,7 +562,7 @@ declare namespace rustdoc { type Dir = [string, rustdoc.Dir[], string[]] /** - * Indivitual setting object, used in `settings.js` + * Individual setting object, used in `settings.js`. */ interface Setting { js_name: string, @@ -571,6 +571,14 @@ declare namespace rustdoc { default: string | boolean, } + /** + * Individual settings tab, used in `settings.js`. + */ + interface SettingsTab { + name: string, + settings: Array, + } + /** * Single element in the data-locs field of a scraped example. * First field is the start and end char index, diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 0bbeb6931e443..ef5b31a4ce407 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -115,52 +115,65 @@ } /** - * This function builds the sections inside the "settings page". It takes a `settings` list + * This function builds the sections inside the "settings page". It takes a `tabs` list * as argument which describes each setting and how to render it. It returns a string * representing the raw HTML. * - * @param {Array} settings + * @param {Array} tabs * * @return {string} */ - function buildSettingsPageSections(settings) { + function buildSettingsPageSections(tabs) { let output = ""; - for (const setting of settings) { - const js_data_name = setting["js_name"]; - const setting_name = setting["name"]; + output += "
"; + for (const [index, tab] of tabs.entries()) { + output += `\ + `; + } + output += "
"; + for (const [index, tab] of tabs.entries()) { + output += `\ +
`; + for (const setting of tab.settings) { + const js_data_name = setting["js_name"]; + const setting_name = setting["name"]; - if (setting["options"] !== undefined) { - // This is a select setting. - output += `\ + if (setting["options"] !== undefined) { + // This is a select setting. + output += `\
${setting_name}
`; - onEach(setting["options"], option => { - const checked = option === setting["default"] ? " checked" : ""; - const full = `${js_data_name}-${option.replace(/ /g,"-")}`; + onEach(setting["options"], option => { + const checked = option === setting["default"] ? " checked" : ""; + const full = `${js_data_name}-${option.replace(/ /g,"-")}`; - output += `\ + output += `\ `; - }); - output += `\ + }); + output += `\
`; - } else { - // This is a checkbox toggle. - const checked = setting["default"] === true ? " checked" : ""; - output += `\ + } else { + // This is a checkbox toggle. + const checked = setting["default"] === true ? " checked" : ""; + output += `\
\ \
`; + } } + output += "
"; } return output; } @@ -176,96 +189,133 @@ .split(",").filter(t => t); theme_names.push("light", "dark", "ayu"); - const settings = [ - { - "name": "Theme", - "js_name": "theme", - "default": "system preference", - "options": theme_names.concat("system preference"), - }, - { - "name": "Preferred light theme", - "js_name": "preferred-light-theme", - "default": "light", - "options": theme_names, - }, - { - "name": "Preferred dark theme", - "js_name": "preferred-dark-theme", - "default": "dark", - "options": theme_names, - }, - { - "name": "Auto-hide item contents for large items", - "js_name": "auto-hide-large-items", - "default": true, - }, - { - "name": "Auto-hide item methods' documentation", - "js_name": "auto-hide-method-docs", - "default": false, - }, - { - "name": "Auto-hide trait implementation documentation", - "js_name": "auto-hide-trait-implementations", - "default": false, - }, + const tabs = [ { - "name": "Directly go to item in search if there is only one result", - "js_name": "go-to-only-result", - "default": false, + name: "Appearance", + settings: [ + { + "name": "Theme", + "js_name": "theme", + "default": "system preference", + "options": theme_names.concat("system preference"), + }, + { + "name": "Preferred light theme", + "js_name": "preferred-light-theme", + "default": "light", + "options": theme_names, + }, + { + "name": "Preferred dark theme", + "js_name": "preferred-dark-theme", + "default": "dark", + "options": theme_names, + }, + { + "name": "Use sans serif fonts", + "js_name": "sans-serif-fonts", + "default": false, + }, + ], }, { - "name": "Show line numbers on code examples", - "js_name": "line-numbers", - "default": false, + name: "Interface", + settings: [ + { + "name": "Hide persistent navigation bar", + "js_name": "hide-sidebar", + "default": false, + }, + { + "name": "Hide table of contents", + "js_name": "hide-toc", + "default": false, + }, + { + "name": "Hide module navigation", + "js_name": "hide-modnav", + "default": false, + }, + { + "name": "Disable keyboard shortcuts", + "js_name": "disable-shortcuts", + "default": false, + }, + { + "name": "Directly go to item in search if there is only one result", + "js_name": "go-to-only-result", + "default": false, + }, + ], }, { - "name": "Hide persistent navigation bar", - "js_name": "hide-sidebar", - "default": false, - }, - { - "name": "Hide table of contents", - "js_name": "hide-toc", - "default": false, - }, - { - "name": "Hide module navigation", - "js_name": "hide-modnav", - "default": false, - }, - { - "name": "Disable keyboard shortcuts", - "js_name": "disable-shortcuts", - "default": false, - }, - { - "name": "Use sans serif fonts", - "js_name": "sans-serif-fonts", - "default": false, - }, - { - "name": "Word wrap source code", - "js_name": "word-wrap-source-code", - "default": false, - }, - { - "name": "Hide deprecated items", - "js_name": "hide-deprecated-items", - "default": false, + name: "Content", + settings: [ + { + "name": "Show line numbers on code examples", + "js_name": "line-numbers", + "default": false, + }, + { + "name": "Word wrap source code", + "js_name": "word-wrap-source-code", + "default": false, + }, + { + "name": "Auto-hide item contents for large items", + "js_name": "auto-hide-large-items", + "default": true, + }, + { + "name": "Auto-hide item methods' documentation", + "js_name": "auto-hide-method-docs", + "default": false, + }, + { + "name": "Auto-hide trait implementation documentation", + "js_name": "auto-hide-trait-implementations", + "default": false, + }, + { + "name": "Hide deprecated items", + "js_name": "hide-deprecated-items", + "default": false, + }, + ], }, ]; // Then we build the DOM. const elementKind = isSettingsPage ? "section" : "div"; - const innerHTML = `
${buildSettingsPageSections(settings)}
`; + const innerHTML = `
${buildSettingsPageSections(tabs)}
`; const el = document.createElement(elementKind); el.id = "settings"; if (!isSettingsPage) { el.className = "popover"; } el.innerHTML = innerHTML; + const selectedClass = "selected"; + onEachLazy(el.getElementsByClassName("tab"), tab => { + tab.onclick = () => { + if (tab.classList.contains(selectedClass)) { + return; + } + const selectedTab = el.querySelector(`.tab.${selectedClass}`); + if (selectedTab) { + selectedTab.classList.remove(selectedClass); + } + const name = tab.getAttribute("data-name"); + const selected = el.querySelector(`#settings .setting.${selectedClass}`); + if (selected) { + selected.classList.remove(selectedClass); + } + const newSelected = el.querySelector(`#settings .setting[data-name="${name}"]`); + if (newSelected) { + newSelected.classList.add(selectedClass); + } + tab.classList.add(selectedClass); + }; + }); if (isSettingsPage) { const mainElem = document.getElementById(MAIN_ID); @@ -274,7 +324,7 @@ } } else { el.setAttribute("tabindex", "-1"); - onEachLazy(document.querySelectorAll(".settings-menu"), menu => { + onEachLazy(document.getElementsByClassName("settings-menu"), menu => { if (menu.offsetWidth !== 0) { menu.appendChild(el); return true; @@ -288,7 +338,7 @@ function displaySettings() { settingsMenu.style.display = ""; - onEachLazy(document.querySelectorAll(".settings-menu"), menu => { + onEachLazy(document.getElementsByClassName("settings-menu"), menu => { if (menu.offsetWidth !== 0) { if (!menu.contains(settingsMenu) && settingsMenu.parentElement) { settingsMenu.parentElement.removeChild(settingsMenu); diff --git a/tests/rustdoc-gui/copy-code.goml b/tests/rustdoc-gui/copy-code.goml index 13cf2290d7791..b6a964e3ea843 100644 --- a/tests/rustdoc-gui/copy-code.goml +++ b/tests/rustdoc-gui/copy-code.goml @@ -51,7 +51,7 @@ assert: |copy_height| > 0 && |copy_width| > 0 assert-clipboard: "" // We make the line numbers appear. -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#line-numbers" wait-for-local-storage: {"rustdoc-line-numbers": "true" } diff --git a/tests/rustdoc-gui/font-serif-change.goml b/tests/rustdoc-gui/font-serif-change.goml index 32e95cdc6ee17..1727fcfcc1d68 100644 --- a/tests/rustdoc-gui/font-serif-change.goml +++ b/tests/rustdoc-gui/font-serif-change.goml @@ -9,7 +9,7 @@ assert-css: ("body", {"font-family": |serif_font|}) assert-css: ("p code", {"font-family": |serif_code_font|}) // We now switch to the sans serif font -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {"tab_name": "Appearance"}) click: "#sans-serif-fonts" store-value: (font, '"Fira Sans", sans-serif') @@ -23,7 +23,7 @@ assert-css: ("body", {"font-family": |font|}) assert-css: ("p code", {"font-family": |code_font|}) // We switch back to the serif font -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {"tab_name": "Appearance"}) click: "#sans-serif-fonts" assert-css: ("body", {"font-family": |serif_font|}) diff --git a/tests/rustdoc-gui/help-page.goml b/tests/rustdoc-gui/help-page.goml index 34b4081402766..a35f84bd5e866 100644 --- a/tests/rustdoc-gui/help-page.goml +++ b/tests/rustdoc-gui/help-page.goml @@ -1,4 +1,5 @@ // This test ensures that opening the help page in its own tab works. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/help.html" set-window-size: (1000, 1000) // Try desktop size first. wait-for: "#help" @@ -55,8 +56,24 @@ wait-for: "#search-tabs" // Waiting for the search.js to load. set-window-size: (1000, 1000) // Only supported on desktop. assert-false: "#help" click: "rustdoc-toolbar .help-menu > a" -assert-css: ("#help", {"display": "block"}) +wait-for-css: ("#help", {"display": "block"}) assert-css: ("#help dd", {"font-size": "16px"}) + +define-function: ("check-arrow-color", [theme], block { + call-function: ("switch-theme", {"theme": |theme|}) + click: "rustdoc-toolbar .help-menu > a" + wait-for-css: ("#help", {"display": "block"}) + store-css: ("#help", {"background-color": background}) + assert-css: ("#help::before", { + "background-color": |background|, + }) +}) + +// We check that the "top arrow" has the same color as the popover background. +call-function: ("check-arrow-color", {"theme": "ayu"}) +call-function: ("check-arrow-color", {"theme": "dark"}) +call-function: ("check-arrow-color", {"theme": "light"}) + click: "rustdoc-toolbar .help-menu > a" assert-false: "#help" diff --git a/tests/rustdoc-gui/hide-mobile-topbar.goml b/tests/rustdoc-gui/hide-mobile-topbar.goml index 1e46d23582793..8e029f68246d9 100644 --- a/tests/rustdoc-gui/hide-mobile-topbar.goml +++ b/tests/rustdoc-gui/hide-mobile-topbar.goml @@ -1,4 +1,7 @@ // Checks sidebar resizing stays synced with the setting + +include: "utils.goml" + go-to: "file://" + |DOC_PATH| + "/settings.html" set-window-size: (400, 600) @@ -9,6 +12,7 @@ assert-property: ("#hide-sidebar", {"checked": "false"}) assert-css: ("rustdoc-topbar", {"display": "flex"}) // Toggle it +call-function: ("change-settings-tab", {'tab_name': 'Interface'}) click: "#hide-sidebar" assert-property: ("#hide-sidebar", {"checked": "true"}) assert-css: ("rustdoc-topbar", {"display": "none"}) diff --git a/tests/rustdoc-gui/mobile-topbar-menu-popovers.goml b/tests/rustdoc-gui/mobile-topbar-menu-popovers.goml index 29a2096bba895..91bb20ff1aa22 100644 --- a/tests/rustdoc-gui/mobile-topbar-menu-popovers.goml +++ b/tests/rustdoc-gui/mobile-topbar-menu-popovers.goml @@ -1,6 +1,6 @@ // Ensure that topbar popover menus content can be scrolled on mobile. go-to: "file://" + |DOC_PATH| + "/lib2/index.html" -store-value: (window_height, 500) +store-value: (window_height, 300) set-window-size: (400, |window_height|) include: "utils.goml" @@ -8,16 +8,16 @@ include: "utils.goml" // We open the settings menu call-function: ("open-settings-menu", {}) // We ensure it's not scrolled down yet. -assert-property: ("#settings .settings", {"scrollTop": 0}) +assert-property: ("#settings .settings .setting", {"scrollTop": 0}) // We ensure its height is smaller than the window's, but its content's height is bigger. -store-property: ("#settings .settings", {"offsetHeight": menu_height, "scrollHeight": scroll_height}) +store-property: ("#settings .settings .setting", {"offsetHeight": menu_height, "scrollHeight": scroll_height}) assert: |menu_height| < |window_height| && |scroll_height| > |window_height| // We scroll to the last element of the menu. scroll-to: "#settings .setting-line:last-of-type input" // The item should be visible now, and so the Y scroll value should have changed. // Note: The `scrollTop` value will change if settings are added or removed. -assert-property: ("#settings .settings", {"scrollTop": 335}) +assert-property: ("#settings .settings .setting", {"scrollTop": 84}) // Now we open the help menu. click: ".help-menu a" @@ -31,4 +31,4 @@ assert: |menu_height| < |window_height| && |scroll_height| > |window_height| // We scroll to the last element of the menu. scroll-to: "#help .infos > :last-child" // The item should be visible now, and so the Y scroll value should have changed. -assert-property: ("#help .content", {"scrollTop": 339}) +assert-property: ("#help .content", {"scrollTop": 439}) diff --git a/tests/rustdoc-gui/search-tab.goml b/tests/rustdoc-gui/search-tab.goml index 54457924e4125..956776987877a 100644 --- a/tests/rustdoc-gui/search-tab.goml +++ b/tests/rustdoc-gui/search-tab.goml @@ -39,15 +39,15 @@ define-function: ( call-function: ("check-colors", { "theme": "ayu", - "background": "transparent", + "background": "#1d1f20", "background_selected": "#141920", - "background_hover": "transparent", + "background_hover": "#141920", "border_bottom": "0px none #c5c5c5", - "border_bottom_selected": "1px solid #ffb44c", - "border_bottom_hover": "1px solid rgba(242, 151, 24, 0.3)", - "border_top": "0px none #c5c5c5", - "border_top_selected": "0px none #c5c5c5", - "border_top_hover": "0px none #c5c5c5", + "border_bottom_selected": "0px none #c5c5c5", + "border_bottom_hover": "0px none #c5c5c5", + "border_top": "2px solid #1d1f20", + "border_top_selected": "2px solid #ffb44c", + "border_top_hover": "2px solid #ffb44c", }) call-function: ("check-colors", { "theme": "dark", diff --git a/tests/rustdoc-gui/setting-auto-hide-content-large-items.goml b/tests/rustdoc-gui/setting-auto-hide-content-large-items.goml index dbf80ae34912b..bdc7a2ac31008 100644 --- a/tests/rustdoc-gui/setting-auto-hide-content-large-items.goml +++ b/tests/rustdoc-gui/setting-auto-hide-content-large-items.goml @@ -27,6 +27,7 @@ call-function: ("check-setting", { }) // Now we change its value. +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#auto-hide-large-items" assert-local-storage: {"rustdoc-auto-hide-large-items": "false"} @@ -40,6 +41,7 @@ call-function: ("check-setting", { }) // And now we re-enable the setting. +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#auto-hide-large-items" assert-local-storage: {"rustdoc-auto-hide-large-items": "true"} diff --git a/tests/rustdoc-gui/setting-auto-hide-item-methods-docs.goml b/tests/rustdoc-gui/setting-auto-hide-item-methods-docs.goml index 89c1a8b0e98e9..a5a468326608d 100644 --- a/tests/rustdoc-gui/setting-auto-hide-item-methods-docs.goml +++ b/tests/rustdoc-gui/setting-auto-hide-item-methods-docs.goml @@ -24,6 +24,7 @@ call-function: ("check-setting", { }) // Now we change its value. +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#auto-hide-method-docs" assert-local-storage: {"rustdoc-auto-hide-method-docs": "true"} @@ -37,6 +38,7 @@ call-function: ("check-setting", { }) // And now we re-disable the setting. +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#auto-hide-method-docs" assert-local-storage: {"rustdoc-auto-hide-method-docs": "false"} diff --git a/tests/rustdoc-gui/setting-auto-hide-trait-implementations.goml b/tests/rustdoc-gui/setting-auto-hide-trait-implementations.goml index 81c26bfb7f3a0..2c140c0245c79 100644 --- a/tests/rustdoc-gui/setting-auto-hide-trait-implementations.goml +++ b/tests/rustdoc-gui/setting-auto-hide-trait-implementations.goml @@ -22,6 +22,7 @@ call-function: ("check-setting", { "toggle_attribute_value": "", }) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) // Now we change its value. click: "#auto-hide-trait-implementations" assert-local-storage: {"rustdoc-auto-hide-trait-implementations": "true"} @@ -35,6 +36,7 @@ call-function: ("check-setting", { "toggle_attribute_value": null, }) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) // And now we re-disable the setting. click: "#auto-hide-trait-implementations" assert-local-storage: {"rustdoc-auto-hide-trait-implementations": "false"} diff --git a/tests/rustdoc-gui/setting-go-to-only-result.goml b/tests/rustdoc-gui/setting-go-to-only-result.goml index f94f45fe102ef..be15ce2c3f1c0 100644 --- a/tests/rustdoc-gui/setting-go-to-only-result.goml +++ b/tests/rustdoc-gui/setting-go-to-only-result.goml @@ -27,7 +27,7 @@ wait-for: "#search" assert-document-property: ({"URL": "/lib2/index.html"}, CONTAINS) // Now we change its value. -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Interface'}) click: "#go-to-only-result" assert-local-storage: {"rustdoc-go-to-only-result": "true"} @@ -58,6 +58,7 @@ call-function: ("check-setting", { }) // And now we re-disable the setting. +call-function: ("change-settings-tab", {'tab_name': 'Interface'}) click: "#go-to-only-result" assert-local-storage: {"rustdoc-go-to-only-result": "false"} @@ -105,7 +106,7 @@ write-into: (".search-input", "Whitespace") call-function: ("search-multiple-results", {"location": |location|}) // We now toggle the setting and reload the page. -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Interface'}) click: "#go-to-only-result" assert-local-storage: {"rustdoc-go-to-only-result": "true"} diff --git a/tests/rustdoc-gui/setting-hide-deprecated.goml b/tests/rustdoc-gui/setting-hide-deprecated.goml index 0fefe00f9457b..eee48c8ce88d4 100644 --- a/tests/rustdoc-gui/setting-hide-deprecated.goml +++ b/tests/rustdoc-gui/setting-hide-deprecated.goml @@ -12,7 +12,7 @@ assert-count: ("dt" + |deprecated_class|, 2) assert-css: ("dt" + |deprecated_class|, {"display": "block"}, ALL) // We enable the "hide deprecated items" setting. -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#hide-deprecated-items" // None of them should be displayed anymore. wait-for-css: ("dt" + |deprecated_class|, {"display": "none"}, ALL) @@ -31,7 +31,7 @@ assert-count: ("details" + |deprecated_class|, 2) assert-css: ("details" + |deprecated_class|, {"display": "block"}, ALL) // We enable the "hide deprecated items" setting. -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#hide-deprecated-items" // They shouldn't be displayed anymore. @@ -56,7 +56,7 @@ assert: "details:not(" + |deprecated_class| + ") #method\.future_deprecated_fn" assert-css: ("details" + |deprecated_class|, {"display": "block"}, ALL) // We enable the "hide deprecated items" setting. -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#hide-deprecated-items" // They shouldn't be displayed anymore. @@ -84,7 +84,7 @@ assert-text: ( ) assert-css: ("#results ul.search-results.active .deprecated-count", {"display": "none"}) // We enable the "hide deprecated items" setting. -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) click: "#hide-deprecated-items" // None of them should be displayed anymore. wait-for-css: ( diff --git a/tests/rustdoc-gui/settings.goml b/tests/rustdoc-gui/settings.goml index 85994be468d3c..52f2dc57c8e27 100644 --- a/tests/rustdoc-gui/settings.goml +++ b/tests/rustdoc-gui/settings.goml @@ -150,6 +150,7 @@ compare-elements-position-near: ( {"y": 1} ) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) // First we check the "default" display for toggles. assert-css: ( "#auto-hide-large-items", @@ -241,6 +242,7 @@ assert-css: ( ) // We now switch the display. +call-function: ("change-settings-tab", {'tab_name': 'Appearance'}) click: "#theme-system-preference" // Wait for the hidden element to show up. wait-for: "#preferred-dark-theme.setting-line:not(.hidden)" @@ -250,8 +252,77 @@ assert: "#preferred-light-theme.setting-line:not(.hidden)" assert-text: ("#preferred-dark-theme .setting-radio-name", "Preferred dark theme") assert-text: ("#preferred-light-theme .setting-radio-name", "Preferred light theme") +// We check the display of the settings popover tabs. +define-function: ( + "check-tabs", + [theme, background, background_selected, background_hover, border_bottom, + border_bottom_selected, border_bottom_hover, border_top, border_top_selected, + border_top_hover], + block { + call-function: ("switch-theme-and-keep-open", {"theme": |theme|}) + + assert-css: ("#settings .tabs > button.tab:not(.selected)", { + "background-color": |background|, + "border-bottom": |border_bottom|, + "border-top": |border_top|, + }) + assert-css: ("#settings .tabs > button.tab.selected", { + "background-color": |background_selected|, + "border-bottom": |border_bottom_selected|, + "border-top": |border_top_selected|, + }) + // We ensure that the popover "top arrow" has the same color as the tabs background. + assert-css: ("#settings::before", { + "background-color": |background|, + }) + move-cursor-to: "#settings .tabs > button.tab:not(.selected)" + assert-css: ("#settings .tabs > button.tab:not(.selected):hover", { + "background-color": |background_hover|, + "border-bottom": |border_bottom_hover|, + "border-top": |border_top_hover|, + }) +}) + +call-function: ("check-tabs", { + "theme": "ayu", + "background": "#1d1f20", + "background_selected": "#141920", + "background_hover": "#141920", + "border_bottom": "0px none #c5c5c5", + "border_bottom_selected": "0px none #c5c5c5", + "border_bottom_hover": "0px none #c5c5c5", + "border_top": "2px solid #1d1f20", + "border_top_selected": "2px solid #ffb44c", + "border_top_hover": "2px solid #ffb44c", +}) +call-function: ("check-tabs", { + "theme": "dark", + "background": "#252525", + "background_selected": "#353535", + "background_hover": "#353535", + "border_bottom": "0px none #ddd", + "border_bottom_selected": "0px none #ddd", + "border_bottom_hover": "0px none #ddd", + "border_top": "2px solid #252525", + "border_top_selected": "2px solid #0089ff", + "border_top_hover": "2px solid #0089ff", +}) +call-function: ("check-tabs", { + "theme": "light", + "background": "#e6e6e6", + "background_selected": "#fff", + "background_hover": "#fff", + "border_bottom": "0px none #000", + "border_bottom_selected": "0px none #000", + "border_bottom_hover": "0px none #000", + "border_top": "2px solid #e6e6e6", + "border_top_selected": "2px solid #0089ff", + "border_top_hover": "2px solid #0089ff", +}) + // We now check that clicking on the toggles' text is like clicking on the checkbox. // To test it, we use the "Disable keyboard shortcuts". +call-function: ("change-settings-tab", {'tab_name': 'Interface'}) set-local-storage: {"rustdoc-disable-shortcuts": "false"} click: "#disable-shortcuts" assert-local-storage: {"rustdoc-disable-shortcuts": "true"} @@ -312,7 +383,7 @@ assert-css: (".setting-line", {"margin": |setting_line_margin|}) // We will check that the checkboxes size doesn't change either. assert-size: ( - "#settings label > input[type='checkbox']", + "#settings .selected label > input[type='checkbox']", {"width": 19, "height": 19}, ALL, ) @@ -333,7 +404,7 @@ assert-css: (".setting-radio", {"cursor": "pointer"}) // We ensure that the checkboxes size didn't change. assert-size: ( - "#settings label > input[type='checkbox']", + "#settings .selected label > input[type='checkbox']", {"width": 19, "height": 19}, ALL, ) diff --git a/tests/rustdoc-gui/sidebar-resize-setting.goml b/tests/rustdoc-gui/sidebar-resize-setting.goml index 132f5f387b29f..ea04c10ba06e4 100644 --- a/tests/rustdoc-gui/sidebar-resize-setting.goml +++ b/tests/rustdoc-gui/sidebar-resize-setting.goml @@ -5,8 +5,7 @@ assert-property: (".sidebar", {"clientWidth": "199"}) show-text: true // Verify that the "hide" option is unchecked -call-function: ("open-settings-menu", {}) -assert-css: ("#settings", {"display": "block"}) +call-function: ("change-settings-tab", {'tab_name': 'Interface'}) assert-property: ("#hide-sidebar", {"checked": "false"}) press-key: "Escape" wait-for-css: ("#settings", {"display": "none"}) @@ -28,7 +27,7 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" set-window-size: (600, 600) focus: "rustdoc-topbar .settings-menu a" press-key: "Enter" -wait-for-css: ("#settings", {"display": "block"}) +call-function: ("change-settings-tab", {'tab_name': 'Interface'}) wait-for-css: ("#sidebar-button", {"position": "static"}) assert-property: ("#hide-sidebar", {"checked": "false"}) click: "#hide-sidebar" diff --git a/tests/rustdoc-gui/source-code-wrapping.goml b/tests/rustdoc-gui/source-code-wrapping.goml index 6dc56672da805..8534bb35b73d1 100644 --- a/tests/rustdoc-gui/source-code-wrapping.goml +++ b/tests/rustdoc-gui/source-code-wrapping.goml @@ -14,7 +14,7 @@ define-function: ( ) store-size: (".rust code", {"width": width, "height": height}) -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) call-function: ("click-code-wrapping", {"expected": "true"}) wait-for-size-false: (".rust code", {"width": |width|, "height": |height|}) store-size: (".rust code", {"width": new_width, "height": new_height}) @@ -28,7 +28,7 @@ assert-size: (".rust code", {"width": |width|, "height": |height|}) // Now let's check in docs code examples. go-to: "file://" + |DOC_PATH| + "/test_docs/trait_bounds/index.html" -call-function: ("open-settings-menu", {}) +call-function: ("change-settings-tab", {'tab_name': 'Content'}) store-property: (".example-wrap .rust code", {"scrollWidth": rust_width, "scrollHeight": rust_height}) store-property: (".example-wrap .language-text code", {"scrollWidth": txt_width, "scrollHeight": txt_height}) diff --git a/tests/rustdoc-gui/utils.goml b/tests/rustdoc-gui/utils.goml index 24ce5f7b0e03b..b4576c6ebcaaf 100644 --- a/tests/rustdoc-gui/utils.goml +++ b/tests/rustdoc-gui/utils.goml @@ -44,6 +44,18 @@ define-function: ( } ) +define-function: ( + "change-settings-tab", + [tab_name], + block { + // In case it's not open yet, we open it. + call-function: ("open-settings-menu", {}) + click: "#settings .tabs button[data-name='" + |tab_name| + "']" + // We ensure it worked. + wait-for: "#settings .tabs button[data-name='" + |tab_name| + "'].selected" + } +) + define-function: ( "close-settings-menu", [], @@ -64,19 +76,28 @@ define-function: ( ) define-function: ( - "switch-theme", + "switch-theme-and-keep-open", [theme], block { - // Set the theme. - call-function: ("open-settings-menu", {}) + // Open the settings menu. + call-function: ("change-settings-tab", {'tab_name': 'Appearance'}) // Change the setting. click: "#theme-"+ |theme| - call-function: ("close-settings-menu", {}) // Ensure that the local storage was correctly updated. assert-local-storage: {"rustdoc-theme": |theme|} }, ) +define-function: ( + "switch-theme", + [theme], + block { + call-function: ("switch-theme-and-keep-open", {'theme': |theme|}) + // Close the settings menu. + call-function: ("close-settings-menu", {}) + }, +) + define-function: ( "open-search", [], @@ -134,7 +155,7 @@ define-function: ( "switch-line-numbers-setting", [expected_status], block { - call-function: ("open-settings-menu", {}) + call-function: ("change-settings-tab", {'tab_name': 'Content'}) // We change the line numbers setting. click: "#line-numbers" call-function: ("close-settings-menu", {})