diff --git a/tests/rustdoc-gui/anchors.goml b/tests/rustdoc-gui/anchors.goml index 3239e54a866b5..61b2e8880c602 100644 --- a/tests/rustdoc-gui/anchors.goml +++ b/tests/rustdoc-gui/anchors.goml @@ -1,4 +1,5 @@ // This test is to ensure that the anchors (`§`) have the expected color and position. +include: "utils.goml" define-function: ( "check-colors", @@ -8,10 +9,7 @@ define-function: ( // This is needed to ensure that the text color is computed. show-text: true - // Setting the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - // We reload the page so the local storage settings are being used. - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ("#toggle-all-docs", {"color": |main_color|}) assert-css: (".main-heading h1 a:nth-of-type(1)", {"color": |main_heading_color|}) diff --git a/tests/rustdoc-gui/code-color.goml b/tests/rustdoc-gui/code-color.goml index e17af5e7f1fa4..661709aa1ceaa 100644 --- a/tests/rustdoc-gui/code-color.goml +++ b/tests/rustdoc-gui/code-color.goml @@ -2,6 +2,7 @@ // check that the rule isn't applied on other "" elements. // // While we're at it, we also check it for the other themes. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" // If the text isn't displayed, the browser doesn't compute color style correctly... show-text: true @@ -10,10 +11,7 @@ define-function: ( "check-colors", [theme, doc_code_color, doc_inline_code_color], block { - // Set the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - // We reload the page so the local storage settings are being used. - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".docblock pre > code", {"color": |doc_code_color|}, ALL) assert-css: (".docblock > p > code", {"color": |doc_inline_code_color|}, ALL) }, diff --git a/tests/rustdoc-gui/codeblock-tooltip.goml b/tests/rustdoc-gui/codeblock-tooltip.goml index 19e3927f64293..654589c3ebaa5 100644 --- a/tests/rustdoc-gui/codeblock-tooltip.goml +++ b/tests/rustdoc-gui/codeblock-tooltip.goml @@ -1,4 +1,5 @@ // Checking the colors of the codeblocks tooltips. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" show-text: true @@ -6,9 +7,7 @@ define-function: ( "check-colors", [theme, background, color, border], block { - // Setting the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) // compile_fail block assert-css: ( diff --git a/tests/rustdoc-gui/docblock-code-block-line-number.goml b/tests/rustdoc-gui/docblock-code-block-line-number.goml index cb7bdaab4c8db..fc80932cabaa0 100644 --- a/tests/rustdoc-gui/docblock-code-block-line-number.goml +++ b/tests/rustdoc-gui/docblock-code-block-line-number.goml @@ -1,4 +1,5 @@ // Checks that the setting "line numbers" is working as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" // Otherwise, we can't check text color @@ -13,14 +14,10 @@ define-function: ( [theme, color], block { // We now set the setting to show the line numbers on code examples. - set-local-storage: { - "rustdoc-theme": |theme|, - "rustdoc-use-system-theme": "false", - "rustdoc-line-numbers": "true" - } - // We reload to make the line numbers appear and change theme. - reload: - // We wait for them to be added into the DOM by the JS... + set-local-storage: {"rustdoc-line-numbers": "true"} + // Page will be reloaded in "switch-theme". + call-function: ("switch-theme", {"theme": |theme|}) + // We wait for the line numbers to be added into the DOM by the JS... wait-for: "pre.example-line-numbers" // If the test didn't fail, it means that it was found! assert-css: ( diff --git a/tests/rustdoc-gui/docblock-details.goml b/tests/rustdoc-gui/docblock-details.goml index 4b8f5b54fac5d..b8fc58ef1e497 100644 --- a/tests/rustdoc-gui/docblock-details.goml +++ b/tests/rustdoc-gui/docblock-details.goml @@ -1,8 +1,8 @@ // This ensures that the `
`/`` elements are displayed as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/details/struct.Details.html" show-text: true -set-local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"} -reload: +call-function: ("switch-theme", {"theme": "dark"}) // We first check that the headers in the `.top-doc` doc block still have their // bottom border. diff --git a/tests/rustdoc-gui/docblock-table.goml b/tests/rustdoc-gui/docblock-table.goml index db6d065a4b338..a73f4aaa7677c 100644 --- a/tests/rustdoc-gui/docblock-table.goml +++ b/tests/rustdoc-gui/docblock-table.goml @@ -1,4 +1,5 @@ // This test checks the appearance of the tables in the doc comments. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/doc_block_table/struct.DocBlockTable.html#method.func" compare-elements-css: (".impl-items .docblock table th", ".top-doc .docblock table th", ["border"]) @@ -8,8 +9,7 @@ define-function: ( "check-colors", [theme, border_color, zebra_stripe_color], block { - set-local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": |theme|} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".top-doc .docblock table tbody tr:nth-child(1)", { "background-color": "rgba(0, 0, 0, 0)", }) diff --git a/tests/rustdoc-gui/headers-color.goml b/tests/rustdoc-gui/headers-color.goml index 2a181c0669fe9..81346fc12d06d 100644 --- a/tests/rustdoc-gui/headers-color.goml +++ b/tests/rustdoc-gui/headers-color.goml @@ -1,5 +1,7 @@ // This test check for headings text and background colors for the different themes. +include: "utils.goml" + define-function: ( "check-colors", [theme, color, code_header_color, focus_background_color, headings_color], @@ -7,8 +9,7 @@ define-function: ( go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" // This is needed so that the text color is computed. show-text: true - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ( ".impl", {"color": |color|, "background-color": "rgba(0, 0, 0, 0)"}, diff --git a/tests/rustdoc-gui/headings.goml b/tests/rustdoc-gui/headings.goml index cdc61e36be200..94d80a3e3df5f 100644 --- a/tests/rustdoc-gui/headings.goml +++ b/tests/rustdoc-gui/headings.goml @@ -11,6 +11,7 @@ // 18px 1.125em // 16px 1rem // 14px 0.875rem +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/struct.HeavilyDocumentedStruct.html" assert-css: (".main-heading h1", {"font-size": "24px"}) @@ -158,8 +159,8 @@ define-function: ( "check-colors", [theme, heading_color, small_heading_color, heading_border_color], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) + assert-css: ( ".top-doc .docblock h2", {"color": |heading_color|, "border-bottom": "1px solid " + |heading_border_color|}, @@ -222,8 +223,7 @@ define-function: ( "check-since-color", [theme], block { - set-local-storage: {"rustdoc-theme": |theme|} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".since", {"color": "#808080"}, ALL) }, ) diff --git a/tests/rustdoc-gui/help-page.goml b/tests/rustdoc-gui/help-page.goml index 9a7247a737ba9..09d33af139cdd 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" @@ -19,10 +20,7 @@ define-function: ( "check-colors", [theme, color, background, box_shadow], block { - // Setting the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - // We reload the page so the local storage settings are being used. - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ("#help kbd", { "color": |color|, "background-color": |background|, diff --git a/tests/rustdoc-gui/highlight-colors.goml b/tests/rustdoc-gui/highlight-colors.goml index 48bef319d42f8..65fb3e1285eb0 100644 --- a/tests/rustdoc-gui/highlight-colors.goml +++ b/tests/rustdoc-gui/highlight-colors.goml @@ -1,4 +1,5 @@ // This test checks the highlight colors in the source code pages. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" show-text: true @@ -22,8 +23,7 @@ define-function: ( doc_comment, ], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ("pre.rust .kw", {"color": |kw|}, ALL) assert-css: ("pre.rust .kw-2", {"color": |kw2|}, ALL) assert-css: ("pre.rust .prelude-ty", {"color": |prelude_ty|}, ALL) diff --git a/tests/rustdoc-gui/item-decl-colors.goml b/tests/rustdoc-gui/item-decl-colors.goml index e68d206a51181..18545f0356753 100644 --- a/tests/rustdoc-gui/item-decl-colors.goml +++ b/tests/rustdoc-gui/item-decl-colors.goml @@ -1,5 +1,7 @@ // This test ensures that the color of the items in the type decl are working as expected. +include: "utils.goml" + // We need to disable this check because `trait.impl/test_docs/trait.TraitWithoutGenerics.js` // doesn't exist. fail-on-request-error: false @@ -21,8 +23,8 @@ define-function: ( go-to: "file://" + |DOC_PATH| + "/test_docs/struct.WithGenerics.html" show-text: true - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) + assert-css: (".item-decl .code-attribute", {"color": |attr_color|}, ALL) assert-css: (".item-decl .trait", {"color": |trait_color|}, ALL) // We need to add `code` here because otherwise it would select the parent too. diff --git a/tests/rustdoc-gui/item-decl-comment-highlighting.goml b/tests/rustdoc-gui/item-decl-comment-highlighting.goml index 056b6a5b1e811..3ffbbe1c40f0b 100644 --- a/tests/rustdoc-gui/item-decl-comment-highlighting.goml +++ b/tests/rustdoc-gui/item-decl-comment-highlighting.goml @@ -1,4 +1,5 @@ // This test checks that comments in item declarations are highlighted. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/private/enum.Enum.html" show-text: true @@ -7,8 +8,7 @@ define-function: ( [theme, url, comment_color], block { go-to: |url| - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".item-decl .comment", {"color": |comment_color|}, ALL) } ) diff --git a/tests/rustdoc-gui/jump-to-def-background.goml b/tests/rustdoc-gui/jump-to-def-background.goml index ae9c0c560cf30..71320360740c4 100644 --- a/tests/rustdoc-gui/jump-to-def-background.goml +++ b/tests/rustdoc-gui/jump-to-def-background.goml @@ -1,14 +1,12 @@ // We check the background color on the jump to definition links in the src code page. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/src/link_to_definition/lib.rs.html" define-function: ( "check-background-color", [theme, background_color], block { - // Set the theme. - set-local-storage: { "rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false" } - // We reload the page so the local storage settings are being used. - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ( "body.src .example-wrap pre.rust a", {"background-color": |background_color|}, diff --git a/tests/rustdoc-gui/links-color.goml b/tests/rustdoc-gui/links-color.goml index a1fb619a5d34c..ad1b5e801ca32 100644 --- a/tests/rustdoc-gui/links-color.goml +++ b/tests/rustdoc-gui/links-color.goml @@ -1,4 +1,5 @@ // This test checks links colors. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" // This is needed so that the text color is computed. @@ -9,11 +10,7 @@ define-function: ( [theme, mod, macro, struct, enum, trait, fn, type, union, keyword, sidebar, sidebar_current, sidebar_current_background], block { - set-local-storage: { - "rustdoc-theme": |theme|, - "rustdoc-use-system-theme": "false", - } - reload: + call-function: ("switch-theme", {"theme": |theme|}) // Checking results colors. assert-css: (".item-table .mod", {"color": |mod|}, ALL) assert-css: (".item-table .macro", {"color": |macro|}, ALL) diff --git a/tests/rustdoc-gui/notable-trait.goml b/tests/rustdoc-gui/notable-trait.goml index 0b1c6622596a1..34fafe9a14120 100644 --- a/tests/rustdoc-gui/notable-trait.goml +++ b/tests/rustdoc-gui/notable-trait.goml @@ -1,4 +1,5 @@ // This test checks the position of the `i` for the notable traits. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/struct.NotableStructWithLongName.html" show-text: true // We start with a wide screen. @@ -128,10 +129,7 @@ define-function: ( // This is needed to ensure that the text color is computed. show-text: true - // Setting the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - // We reload the page so the local storage settings are being used. - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ( "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']", diff --git a/tests/rustdoc-gui/pocket-menu.goml b/tests/rustdoc-gui/pocket-menu.goml index b16150cd0d368..ec31f492abe7c 100644 --- a/tests/rustdoc-gui/pocket-menu.goml +++ b/tests/rustdoc-gui/pocket-menu.goml @@ -1,4 +1,5 @@ // This test ensures that the "pocket menus" are working as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" // First we check that the help menu doesn't exist yet. assert-false: "#help-button .popover" @@ -33,11 +34,7 @@ define-function: ( "check-popover-colors", [theme, border_color], block { - set-local-storage: { - "rustdoc-theme": |theme|, - "rustdoc-use-system-theme": "false", - } - reload: + call-function: ("switch-theme", {"theme": |theme|}) click: "#help-button" assert-css: ( diff --git a/tests/rustdoc-gui/run-on-hover.goml b/tests/rustdoc-gui/run-on-hover.goml index 19b15afbac3ca..087dd3374f803 100644 --- a/tests/rustdoc-gui/run-on-hover.goml +++ b/tests/rustdoc-gui/run-on-hover.goml @@ -2,6 +2,7 @@ // Playground. That button is hidden until the user hovers over the code block. // This test checks that it is hidden, and that it shows on hover. It also // checks for its color. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" show-text: true @@ -9,8 +10,7 @@ define-function: ( "check-run-button", [theme, color, background, hover_color, hover_background], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".test-arrow", {"visibility": "hidden"}) move-cursor-to: ".example-wrap" assert-css: (".test-arrow", { diff --git a/tests/rustdoc-gui/rust-logo.goml b/tests/rustdoc-gui/rust-logo.goml index a3b420e5eb92c..7a999fa854c4d 100644 --- a/tests/rustdoc-gui/rust-logo.goml +++ b/tests/rustdoc-gui/rust-logo.goml @@ -1,4 +1,5 @@ // This test ensures that the correct style is applied to the rust logo in the sidebar. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/staged_api/index.html" define-function: ( @@ -8,14 +9,12 @@ define-function: ( // Going to the doc page. go-to: "file://" + |DOC_PATH| + "/staged_api/index.html" // Changing theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".rust-logo", {"filter": |filter|}) // Now we check that the non-rust logos don't have a CSS filter set. go-to: "file://" + |DOC_PATH| + "/huge_logo/index.html" // Changing theme on the new page (again...). - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) // Check there is no rust logo assert-false: ".rust-logo" // Check there is no filter. diff --git a/tests/rustdoc-gui/scrape-examples-color.goml b/tests/rustdoc-gui/scrape-examples-color.goml index b1675a5f1fd7e..588ba08a60c7a 100644 --- a/tests/rustdoc-gui/scrape-examples-color.goml +++ b/tests/rustdoc-gui/scrape-examples-color.goml @@ -1,4 +1,5 @@ // Check that scrape example code blocks have the expected colors. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html" show-text: true @@ -7,8 +8,7 @@ define-function: ( [theme, highlight, highlight_focus, help_border, help_color, help_hover_border, help_hover_color], block { - set-local-storage: { "rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false", } - reload: + call-function: ("switch-theme", {"theme": |theme|}) wait-for: ".more-examples-toggle" assert-css: (".scraped-example .example-wrap .rust span.highlight:not(.focus)", { "background-color": |highlight|, @@ -66,8 +66,7 @@ define-function: ( "check-background", [theme, background_color_start, background_color_end], block { - set-local-storage: { "rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false", } - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".scraped-example:not(.expanded) .code-wrapper::before", { "background-image": "linear-gradient(" + |background_color_start| + ", " + |background_color_end| + ")", diff --git a/tests/rustdoc-gui/scrape-examples-toggle.goml b/tests/rustdoc-gui/scrape-examples-toggle.goml index ea645d2892444..a9d37048188cd 100644 --- a/tests/rustdoc-gui/scrape-examples-toggle.goml +++ b/tests/rustdoc-gui/scrape-examples-toggle.goml @@ -1,4 +1,5 @@ // This tests checks that the "scraped examples" toggle is working as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html" // Checking the color of the toggle line. @@ -7,8 +8,7 @@ define-function: ( "check-color", [theme, toggle_line_color, toggle_line_hover_color], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) // Clicking "More examples..." will open additional examples assert-attribute-false: (".more-examples-toggle", {"open": ""}) diff --git a/tests/rustdoc-gui/search-error.goml b/tests/rustdoc-gui/search-error.goml index d3de77b5635ca..4dc60669c7a58 100644 --- a/tests/rustdoc-gui/search-error.goml +++ b/tests/rustdoc-gui/search-error.goml @@ -1,4 +1,5 @@ // Checks that the crate search filtering is handled correctly and changes the results. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=sa'%3Bda'%3Bds" show-text: true @@ -6,11 +7,7 @@ define-function: ( "check-colors", [theme, error_background], block { - // Setting the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - // We reload the page so the local storage settings are being used. - reload: - + call-function: ("switch-theme", {"theme": |theme|}) wait-for: "#search .error code" assert-css: ("#search .error code", {"background-color": |error_background|}) } diff --git a/tests/rustdoc-gui/search-filter.goml b/tests/rustdoc-gui/search-filter.goml index 8c50322fcd4e4..d6421599a207b 100644 --- a/tests/rustdoc-gui/search-filter.goml +++ b/tests/rustdoc-gui/search-filter.goml @@ -1,4 +1,5 @@ // Checks that the crate search filtering is handled correctly and changes the results. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" show-text: true write-into: (".search-input", "test") @@ -59,8 +60,7 @@ assert-text: (".search-results-title", "Results in all crates", STARTS_WITH) // Checking the display of the crate filter. // We start with the light theme. -set-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} -reload: +call-function: ("switch-theme", {"theme": "light"}) set-timeout: 2000 wait-for: "#crate-search" diff --git a/tests/rustdoc-gui/search-form-elements.goml b/tests/rustdoc-gui/search-form-elements.goml index 2fc66259291cd..63d2ceb3e7c1c 100644 --- a/tests/rustdoc-gui/search-form-elements.goml +++ b/tests/rustdoc-gui/search-form-elements.goml @@ -1,4 +1,5 @@ // This test ensures that the elements in ".search-form" have the expected display. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" show-text: true @@ -9,11 +10,7 @@ define-function: ( menu_button_border, menu_button_a_color, menu_button_a_border_hover, menu_a_color, ], block { - set-local-storage: { - "rustdoc-theme": |theme|, - "rustdoc-use-system-theme": "false", - } - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ( ".search-input", { diff --git a/tests/rustdoc-gui/search-no-result.goml b/tests/rustdoc-gui/search-no-result.goml index dda50ec3fb64b..2e89278b46cb4 100644 --- a/tests/rustdoc-gui/search-no-result.goml +++ b/tests/rustdoc-gui/search-no-result.goml @@ -1,4 +1,5 @@ // The goal of this test is to check the color of the "no result" links. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/lib2/index.html?search=sdkfskjfsdks" show-text: true @@ -6,9 +7,7 @@ define-function: ( "check-no-result", [theme, link, link_hover], block { - // Changing theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) wait-for: "#results" assert: ".search-failed.active" assert-css: ("#results a", {"color": |link|}, ALL) diff --git a/tests/rustdoc-gui/search-reexport.goml b/tests/rustdoc-gui/search-reexport.goml index 2e7c967d5c333..fa9eedeceac2e 100644 --- a/tests/rustdoc-gui/search-reexport.goml +++ b/tests/rustdoc-gui/search-reexport.goml @@ -1,8 +1,8 @@ // Checks that the reexports are present in the search index, can have // doc aliases and are highligted when their ID is the hash of the page. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" -set-local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"} -reload: +call-function: ("switch-theme", {"theme": "dark"}) // First we check that the reexport has the correct ID and no background color. assert-text: ("//*[@id='reexport.TheStdReexport']", "pub use ::std as TheStdReexport;") assert-css: ("//*[@id='reexport.TheStdReexport']", {"background-color": "rgba(0, 0, 0, 0)"}) diff --git a/tests/rustdoc-gui/search-result-color.goml b/tests/rustdoc-gui/search-result-color.goml index 1a19ea2d84327..d4da23fa156d9 100644 --- a/tests/rustdoc-gui/search-result-color.goml +++ b/tests/rustdoc-gui/search-result-color.goml @@ -1,5 +1,6 @@ // The goal of this test is to ensure the color of the text is the one expected. +include: "utils.goml" define-function: ( "check-result-color", [result_kind, color, hover_color], @@ -43,11 +44,7 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=coo" show-text: true // Ayu theme -set-local-storage: { - "rustdoc-theme": "ayu", - "rustdoc-use-system-theme": "false", -} -reload: +call-function: ("switch-theme", {"theme": "ayu"}) // Waiting for the search results to appear... wait-for: "#search-tabs" @@ -155,11 +152,7 @@ assert-css: ( ) // Dark theme -set-local-storage: { - "rustdoc-theme": "dark", - "rustdoc-use-system-theme": "false", -} -reload: +call-function: ("switch-theme", {"theme": "dark"}) // Waiting for the search results to appear... wait-for: "#search-tabs" @@ -255,8 +248,7 @@ assert-css: ( ) // Light theme -set-local-storage: {"rustdoc-theme": "light", "rustdoc-use-system-theme": "false"} -reload: +call-function: ("switch-theme", {"theme": "light"}) // Waiting for the search results to appear... wait-for: "#search-tabs" @@ -360,8 +352,7 @@ define-function: ( "check-alias", [theme, alias, grey], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) write-into: (".search-input", "thisisanalias") // To be SURE that the search will be run. press-key: 'Enter' diff --git a/tests/rustdoc-gui/search-result-display.goml b/tests/rustdoc-gui/search-result-display.goml index b1a5548808e01..3ca46f3c56931 100644 --- a/tests/rustdoc-gui/search-result-display.goml +++ b/tests/rustdoc-gui/search-result-display.goml @@ -1,5 +1,6 @@ // ignore-tidy-linelength // Checks that the search results have the expected width. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" set-window-size: (900, 1000) write-into: (".search-input", "test") @@ -71,8 +72,7 @@ define-function: ( "check-filter", [theme, border, filter, hover_border, hover_filter], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) wait-for: "#crate-search" assert-css: ("#crate-search", {"border": "1px solid " + |border|}) assert-css: ("#crate-search-div::after", {"filter": |filter|}) diff --git a/tests/rustdoc-gui/search-tab.goml b/tests/rustdoc-gui/search-tab.goml index c33866593c355..4329726398c10 100644 --- a/tests/rustdoc-gui/search-tab.goml +++ b/tests/rustdoc-gui/search-tab.goml @@ -1,4 +1,5 @@ // Checking the colors of the search tab headers. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html?search=foo" show-text: true @@ -8,9 +9,7 @@ define-function: ( border_bottom_selected, border_bottom_hover, border_top, border_top_selected, border_top_hover], block { - // Setting the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) // These two commands are used to be sure the search will be run. focus: ".search-input" diff --git a/tests/rustdoc-gui/settings.goml b/tests/rustdoc-gui/settings.goml index 0bb21c28cb529..56d0f8624e8f6 100644 --- a/tests/rustdoc-gui/settings.goml +++ b/tests/rustdoc-gui/settings.goml @@ -1,5 +1,6 @@ // This test ensures that the settings menu display is working as expected and that // the settings page is also rendered as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" show-text: true // needed when we check for colors below. // First, we check that the settings page doesn't exist. @@ -35,8 +36,7 @@ wait-for: "#alternative-display #search" assert: "#main-content.hidden" // Now let's check the content of the settings menu. -set-local-storage: {"rustdoc-theme": "dark", "rustdoc-use-system-theme": "false"} -reload: +call-function: ("switch-theme", {"theme": "dark"}) click: "#settings-menu" wait-for: "#settings" diff --git a/tests/rustdoc-gui/sidebar-links-color.goml b/tests/rustdoc-gui/sidebar-links-color.goml index 0edffc51a816d..57c45555a76bd 100644 --- a/tests/rustdoc-gui/sidebar-links-color.goml +++ b/tests/rustdoc-gui/sidebar-links-color.goml @@ -1,4 +1,5 @@ // This test checks links colors in sidebar before and after hover. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" // This is needed so that the text color is computed. @@ -13,8 +14,7 @@ define-function: ( type_hover_background, keyword, keyword_hover, keyword_hover_background, ], block { - set-local-storage: { "rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false" } - reload: + call-function: ("switch-theme", {"theme": |theme|}) // Struct assert-css: ( ".sidebar .block.struct li:not(.current) a", diff --git a/tests/rustdoc-gui/sidebar-mobile.goml b/tests/rustdoc-gui/sidebar-mobile.goml index 8843de8d7e943..b4ff483c18097 100644 --- a/tests/rustdoc-gui/sidebar-mobile.goml +++ b/tests/rustdoc-gui/sidebar-mobile.goml @@ -1,6 +1,7 @@ // This test ensure that the sidebar isn't "hidden" on mobile but instead moved out of the viewport. // This is especially important for devices for "text-first" content (like for users with // sight issues). +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" // Switching to "mobile view" by reducing the width to 600px. set-window-size: (600, 600) @@ -59,7 +60,7 @@ define-function: ( "check-colors", [theme, color, background], block { - set-local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": |theme|} + call-function: ("switch-theme", {"theme": |theme|}) reload: // Open the sidebar menu. diff --git a/tests/rustdoc-gui/sidebar-source-code-display.goml b/tests/rustdoc-gui/sidebar-source-code-display.goml index 41c8e45f4a6d3..3bfbe820b8dfe 100644 --- a/tests/rustdoc-gui/sidebar-source-code-display.goml +++ b/tests/rustdoc-gui/sidebar-source-code-display.goml @@ -1,4 +1,5 @@ // This test ensures that the elements in the sidebar are displayed correctly. +include: "utils.goml" javascript: false go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" // Since the javascript is disabled, there shouldn't be a toggle. @@ -34,8 +35,7 @@ define-function: ( theme, color, color_hover, background, background_hover, background_toggle, ], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) wait-for-css: (".src .sidebar > *", {"visibility": "visible"}) assert-css: ( "#src-sidebar details[open] > .files a.selected", diff --git a/tests/rustdoc-gui/sidebar-source-code.goml b/tests/rustdoc-gui/sidebar-source-code.goml index 3f7ef643d18e7..ef0b5ab38b138 100644 --- a/tests/rustdoc-gui/sidebar-source-code.goml +++ b/tests/rustdoc-gui/sidebar-source-code.goml @@ -1,5 +1,6 @@ // The goal of this test is to ensure that the sidebar is working as expected in the source // code pages. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" show-text: true @@ -8,11 +9,7 @@ define-function: ( "check-colors", [theme, color, background_color], block { - set-local-storage: { - "rustdoc-theme": |theme|, - "rustdoc-use-system-theme": "false", - } - reload: + call-function: ("switch-theme", {"theme": |theme|}) // Checking results colors. assert-css: (".src .sidebar", { "color": |color|, diff --git a/tests/rustdoc-gui/sidebar.goml b/tests/rustdoc-gui/sidebar.goml index 115b1eb323c4d..452545958f961 100644 --- a/tests/rustdoc-gui/sidebar.goml +++ b/tests/rustdoc-gui/sidebar.goml @@ -1,4 +1,5 @@ // Checks multiple things on the sidebar display (width of its elements, colors, etc). +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" assert-property: (".sidebar", {"clientWidth": "200"}) show-text: true @@ -8,11 +9,7 @@ define-function: ( "check-colors", [theme, color, background_color], block { - set-local-storage: { - "rustdoc-theme": |theme|, - "rustdoc-use-system-theme": "false", - } - reload: + call-function: ("switch-theme", {"theme": |theme|}) // Checking results colors. assert-css: (".sidebar", { "color": |color|, @@ -46,9 +43,7 @@ call-function: ( } ) -set-local-storage: {"rustdoc-theme": "light"} -// We reload the page so the local storage settings are being used. -reload: +call-function: ("switch-theme", {"theme": "light"}) assert-text: (".sidebar > .sidebar-crate > h2 > a", "test_docs") // Crate root has no "location" element diff --git a/tests/rustdoc-gui/source-code-page.goml b/tests/rustdoc-gui/source-code-page.goml index e29d123d2270b..619d2b37d8daf 100644 --- a/tests/rustdoc-gui/source-code-page.goml +++ b/tests/rustdoc-gui/source-code-page.goml @@ -1,4 +1,5 @@ // Checks that the interactions with the source code pages are working as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" show-text: true // Check that we can click on the line number. @@ -23,8 +24,7 @@ define-function: ( "check-colors", [theme, color, background_color, highlight_color, highlight_background_color], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ( ".src-line-numbers > a:not(.line-highlighted)", {"color": |color|, "background-color": |background_color|}, diff --git a/tests/rustdoc-gui/stab-badge.goml b/tests/rustdoc-gui/stab-badge.goml index 46df0946c4592..3568d7a3e48db 100644 --- a/tests/rustdoc-gui/stab-badge.goml +++ b/tests/rustdoc-gui/stab-badge.goml @@ -1,12 +1,13 @@ // All stability badges should have rounded corners and colored backgrounds. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" show-text: true define-function: ( "check-badge", [theme, background, color], block { - set-local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": |theme|} go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" + call-function: ("switch-theme", {"theme": |theme|}) assert: ".docblock .stab" assert: ".item-table .stab" assert-css: (".stab", { diff --git a/tests/rustdoc-gui/target.goml b/tests/rustdoc-gui/target.goml index 0f8f770936356..82bd34ed2746e 100644 --- a/tests/rustdoc-gui/target.goml +++ b/tests/rustdoc-gui/target.goml @@ -1,4 +1,5 @@ // Check that the targeted element has the expected styles. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/lib2/struct.Foo.html#method.a_method" show-text: true @@ -9,8 +10,7 @@ define-function: ( "check-style", [theme, background, border], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ("#method\.a_method:target", { "background-color": |background|, "border-right": "3px solid " + |border|, diff --git a/tests/rustdoc-gui/theme-change.goml b/tests/rustdoc-gui/theme-change.goml index fdaf9d6289a3c..5898711050992 100644 --- a/tests/rustdoc-gui/theme-change.goml +++ b/tests/rustdoc-gui/theme-change.goml @@ -1,7 +1,7 @@ // Ensures that the theme change is working as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" -set-local-storage: {"rustdoc-use-system-theme": "false", "rustdoc-theme": "dark"} -reload: +call-function: ("switch-theme", {"theme": "dark"}) store-value: (background_light, "white") store-value: (background_dark, "#353535") @@ -68,8 +68,7 @@ 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: +call-function: ("switch-theme", {"theme": "dark"}) store-value: (background_light, "white") store-value: (background_dark, "#353535") diff --git a/tests/rustdoc-gui/theme-in-history.goml b/tests/rustdoc-gui/theme-in-history.goml index 42c5b5e6e69e3..71cc64ac60050 100644 --- a/tests/rustdoc-gui/theme-in-history.goml +++ b/tests/rustdoc-gui/theme-in-history.goml @@ -1,12 +1,10 @@ // Ensures that the theme is working when going back in history. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" + // Set the theme to dark. -set-local-storage: { - "rustdoc-theme": "dark", - "rustdoc-use-system-theme": "false", -} -// We reload the page so the local storage settings are being used. -reload: +call-function: ("switch-theme", {"theme": "dark"}) + assert-css: ("body", { "background-color": "#353535" }) assert-local-storage: { "rustdoc-theme": "dark" } diff --git a/tests/rustdoc-gui/toggle-docs.goml b/tests/rustdoc-gui/toggle-docs.goml index cfd18bd2e14f3..1235ee4b754ce 100644 --- a/tests/rustdoc-gui/toggle-docs.goml +++ b/tests/rustdoc-gui/toggle-docs.goml @@ -1,4 +1,5 @@ // Checks that the documentation toggles have the correct position, style and work as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" assert-attribute: ("#main-content > details.top-doc", {"open": ""}) assert-text: ("#toggle-all-docs", "[−]") @@ -51,10 +52,7 @@ define-function: ( "check-color", [theme, filter], block { - // Setting the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - // We reload the page so the local storage settings are being used. - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: ("details.toggle > summary::before", { "opacity": "0.5", diff --git a/tests/rustdoc-gui/unsafe-fn.goml b/tests/rustdoc-gui/unsafe-fn.goml index 83503121a0469..b8b2e1e27f52d 100644 --- a/tests/rustdoc-gui/unsafe-fn.goml +++ b/tests/rustdoc-gui/unsafe-fn.goml @@ -1,4 +1,5 @@ // Check position and color of the `` for unsafe elements. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/index.html" // If the text isn't displayed, the browser doesn't compute color style correctly... show-text: true @@ -15,10 +16,7 @@ define-function: ( // `color` is the expected color of the `` element. [theme, color], block { - // Set the theme. - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - // We reload the page so the local storage settings are being used. - reload: + call-function: ("switch-theme", {"theme": |theme|}) assert-css: (".item-name sup", {"color": |color|}) }, ) diff --git a/tests/rustdoc-gui/utils.goml b/tests/rustdoc-gui/utils.goml new file mode 100644 index 0000000000000..d9f8726ec5318 --- /dev/null +++ b/tests/rustdoc-gui/utils.goml @@ -0,0 +1,11 @@ +// This file contains code to be re-used by other tests. +define-function: ( + "switch-theme", + [theme], + block { + // Set the theme. + set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} + // We reload the page so the local storage settings are being used. + reload: + }, +) diff --git a/tests/rustdoc-gui/warning-block.goml b/tests/rustdoc-gui/warning-block.goml index a5a47f868db22..34207ed580524 100644 --- a/tests/rustdoc-gui/warning-block.goml +++ b/tests/rustdoc-gui/warning-block.goml @@ -1,4 +1,5 @@ // Test to check that the "warning blocks" are displayed as expected. +include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" show-text: true @@ -7,8 +8,7 @@ define-function: ( "check-warning", [theme, color, border_color], block { - set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"} - reload: + call-function: ("switch-theme", {"theme": |theme|}) // The IDs are added directly into the DOM to make writing this test easier. assert-css: ("#doc-warning-1", {