2022-06-14 09:21:28 +00:00
|
|
|
// Checks that the interactions with the source code pages are working as expected.
|
2023-04-11 17:11:34 +00:00
|
|
|
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
|
2022-10-26 15:51:20 +00:00
|
|
|
show-text: true
|
2021-05-10 12:12:00 +00:00
|
|
|
// Check that we can click on the line number.
|
2022-10-27 18:16:30 +00:00
|
|
|
click: ".src-line-numbers > a:nth-child(4)" // This is the anchor for line 4.
|
2022-05-30 15:07:21 +00:00
|
|
|
// Ensure that the page URL was updated.
|
2022-05-30 15:14:46 +00:00
|
|
|
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
|
2022-05-30 15:07:21 +00:00
|
|
|
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
|
2022-10-28 16:51:57 +00:00
|
|
|
// Ensure that the default style, with the right border, isn't used.
|
|
|
|
assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
|
|
|
|
reload:
|
|
|
|
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
|
|
|
|
assert-css: ("//*[@id='4']", {"border-right-width": "0px"})
|
2022-10-27 18:16:30 +00:00
|
|
|
// We now check that the good anchors are highlighted
|
2023-04-11 17:11:34 +00:00
|
|
|
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6"
|
2022-10-27 18:16:30 +00:00
|
|
|
assert-attribute-false: (".src-line-numbers > a:nth-child(3)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute: (".src-line-numbers > a:nth-child(4)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute: (".src-line-numbers > a:nth-child(5)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute: (".src-line-numbers > a:nth-child(6)", {"class": "line-highlighted"})
|
|
|
|
assert-attribute-false: (".src-line-numbers > a:nth-child(7)", {"class": "line-highlighted"})
|
2022-10-26 15:51:20 +00:00
|
|
|
|
|
|
|
define-function: (
|
|
|
|
"check-colors",
|
|
|
|
(theme, color, background_color, highlight_color, highlight_background_color),
|
2023-01-06 14:18:51 +00:00
|
|
|
block {
|
2023-04-11 17:11:34 +00:00
|
|
|
set-local-storage: {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}
|
2023-01-06 14:18:51 +00:00
|
|
|
reload:
|
|
|
|
assert-css: (
|
2022-10-27 18:16:30 +00:00
|
|
|
".src-line-numbers > a:not(.line-highlighted)",
|
2022-10-26 15:51:20 +00:00
|
|
|
{"color": |color|, "background-color": |background_color|},
|
|
|
|
ALL,
|
2023-01-06 14:18:51 +00:00
|
|
|
)
|
|
|
|
assert-css: (
|
2022-10-27 18:16:30 +00:00
|
|
|
".src-line-numbers > a.line-highlighted",
|
2022-10-26 15:51:20 +00:00
|
|
|
{"color": |highlight_color|, "background-color": |highlight_background_color|},
|
|
|
|
ALL,
|
2023-01-06 14:18:51 +00:00
|
|
|
)
|
|
|
|
},
|
2022-10-26 15:51:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "ayu",
|
2023-05-18 15:02:51 +00:00
|
|
|
"color": "#5c6773",
|
|
|
|
"background_color": "transparent",
|
|
|
|
"highlight_color": "#708090",
|
2022-10-26 15:51:20 +00:00
|
|
|
"highlight_background_color": "rgba(255, 236, 164, 0.06)",
|
|
|
|
})
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "dark",
|
2023-05-18 15:02:51 +00:00
|
|
|
"color": "#3b91e2",
|
|
|
|
"background_color": "transparent",
|
|
|
|
"highlight_color": "#3b91e2",
|
|
|
|
"highlight_background_color": "#0a042f",
|
2022-10-26 15:51:20 +00:00
|
|
|
})
|
|
|
|
call-function: ("check-colors", {
|
|
|
|
"theme": "light",
|
2023-05-18 15:02:51 +00:00
|
|
|
"color": "#c67e2d",
|
|
|
|
"background_color": "transparent",
|
|
|
|
"highlight_color": "#c67e2d",
|
|
|
|
"highlight_background_color": "#fdffd3",
|
2022-10-26 15:51:20 +00:00
|
|
|
})
|
|
|
|
|
2021-06-22 09:17:53 +00:00
|
|
|
// This is to ensure that the content is correctly align with the line numbers.
|
2021-08-16 21:19:00 +00:00
|
|
|
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
|
2022-10-27 18:16:30 +00:00
|
|
|
// Check the `href` property so that users can treat anchors as links.
|
|
|
|
assert-property: (".src-line-numbers > a:nth-child(1)", {
|
2023-06-14 14:23:00 +00:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#1"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 18:16:30 +00:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(2)", {
|
2023-06-14 14:23:00 +00:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#2"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 18:16:30 +00:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(3)", {
|
2023-06-14 14:23:00 +00:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#3"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 18:16:30 +00:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(4)", {
|
2023-06-14 14:23:00 +00:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#4"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 18:16:30 +00:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(5)", {
|
2023-06-14 14:23:00 +00:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#5"
|
|
|
|
}, ENDS_WITH)
|
2022-10-27 18:16:30 +00:00
|
|
|
assert-property: (".src-line-numbers > a:nth-child(6)", {
|
2023-06-14 14:23:00 +00:00
|
|
|
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#6"
|
|
|
|
}, ENDS_WITH)
|
2022-03-07 11:08:14 +00:00
|
|
|
|
|
|
|
// Assert that the line numbers text is aligned to the right.
|
2022-09-26 17:50:51 +00:00
|
|
|
assert-css: (".src-line-numbers", {"text-align": "right"})
|
2022-05-30 15:14:46 +00:00
|
|
|
|
|
|
|
// Now let's check that clicking on something else than the line number doesn't
|
|
|
|
// do anything (and certainly not add a `#NaN` to the URL!).
|
2023-04-11 17:11:34 +00:00
|
|
|
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
|
2022-05-30 15:14:46 +00:00
|
|
|
// We use this assert-position to know where we will click.
|
2022-12-24 05:55:04 +00:00
|
|
|
assert-position: ("//*[@id='1']", {"x": 88, "y": 112})
|
2022-10-27 18:16:30 +00:00
|
|
|
// We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`.
|
2022-12-24 05:55:04 +00:00
|
|
|
click: (87, 103)
|
2022-05-30 15:14:46 +00:00
|
|
|
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
|
2022-06-14 09:21:28 +00:00
|
|
|
|
|
|
|
// Checking the source code sidebar.
|
|
|
|
|
|
|
|
// First we "open" it.
|
2022-12-15 23:29:52 +00:00
|
|
|
click: "#src-sidebar-toggle"
|
2022-06-20 19:41:11 +00:00
|
|
|
assert: ".source-sidebar-expanded"
|
2022-06-14 09:21:28 +00:00
|
|
|
|
2022-07-01 17:33:06 +00:00
|
|
|
// We check that the first entry of the sidebar is collapsed
|
|
|
|
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
|
2023-04-12 13:17:33 +00:00
|
|
|
assert-text: ("#source-sidebar details:first-of-type > summary", "extend_css")
|
2022-06-14 09:21:28 +00:00
|
|
|
// We now click on it.
|
2022-07-01 17:33:06 +00:00
|
|
|
click: "#source-sidebar details:first-of-type > summary"
|
|
|
|
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})
|
2022-06-14 09:21:28 +00:00
|
|
|
|
|
|
|
// And now we collapse it again.
|
2022-07-01 17:33:06 +00:00
|
|
|
click: "#source-sidebar details:first-of-type > summary"
|
|
|
|
assert-property: ("#source-sidebar details:first-of-type", {"open": "false"})
|
2022-07-02 16:42:49 +00:00
|
|
|
|
2022-12-31 18:23:30 +00:00
|
|
|
// And open it again, since it'll be the reference we use to check positions.
|
|
|
|
click: "#source-sidebar details:first-of-type > summary"
|
|
|
|
assert-property: ("#source-sidebar details:first-of-type", {"open": "true"})
|
|
|
|
|
|
|
|
// Check the sidebar directory entries have a marker and spacing (desktop).
|
|
|
|
store-property: (
|
|
|
|
"#source-sidebar > details:first-of-type.dir-entry[open] > .files > a",
|
2023-05-10 08:56:59 +00:00
|
|
|
{"offsetHeight": link_height},
|
2022-12-31 18:23:30 +00:00
|
|
|
)
|
|
|
|
define-function: (
|
|
|
|
"check-sidebar-dir-entry",
|
|
|
|
(x, y),
|
2023-01-06 14:18:51 +00:00
|
|
|
block {
|
|
|
|
assert: "details:first-of-type.dir-entry[open] > summary::marker"
|
|
|
|
assert-css: ("#source-sidebar > details:first-of-type.dir-entry", {"padding-left": "4px"})
|
2022-12-31 18:23:30 +00:00
|
|
|
// This check ensures that the summary is only one line.
|
2023-01-06 14:18:51 +00:00
|
|
|
assert-property: (
|
2022-12-31 18:23:30 +00:00
|
|
|
"#source-sidebar > details:first-of-type.dir-entry[open] > summary",
|
|
|
|
{"offsetHeight": |link_height|}
|
2023-01-06 14:18:51 +00:00
|
|
|
)
|
|
|
|
assert-position: (
|
2022-12-31 18:23:30 +00:00
|
|
|
"#source-sidebar > details:first-of-type.dir-entry[open] > summary",
|
|
|
|
{"x": |x|, "y": |y|}
|
2023-01-06 14:18:51 +00:00
|
|
|
)
|
|
|
|
assert-property: (
|
2022-12-31 18:23:30 +00:00
|
|
|
"#source-sidebar > details:first-of-type.dir-entry[open] > .files > a",
|
|
|
|
{"offsetHeight": |link_height|}
|
2023-01-06 14:18:51 +00:00
|
|
|
)
|
|
|
|
assert-position: (
|
2022-12-31 18:23:30 +00:00
|
|
|
"#source-sidebar > details:first-of-type.dir-entry[open] > .files > a",
|
|
|
|
// left margin
|
|
|
|
{"x": |x| + 27, "y": |y| + |link_height|}
|
2023-01-06 14:18:51 +00:00
|
|
|
)
|
|
|
|
}
|
2022-12-31 18:23:30 +00:00
|
|
|
)
|
2023-05-10 08:56:59 +00:00
|
|
|
store-property: ("#source-sidebar > .title", {
|
|
|
|
"offsetHeight": source_sidebar_title_height,
|
|
|
|
"offsetTop": source_sidebar_title_y,
|
|
|
|
})
|
2022-12-31 18:23:30 +00:00
|
|
|
call-function: ("check-sidebar-dir-entry", {
|
|
|
|
"x": 0,
|
|
|
|
// border + margin = 6
|
|
|
|
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6,
|
|
|
|
})
|
2022-10-20 20:22:36 +00:00
|
|
|
|
|
|
|
// Check the search form
|
|
|
|
assert-css: ("nav.sub", {"flex-direction": "row"})
|
|
|
|
// The goal of this test is to ensure the search input is perfectly centered
|
|
|
|
// between the top of the page and the top of the gray code block.
|
|
|
|
// To check this, we maintain the invariant:
|
|
|
|
//
|
|
|
|
// offsetTop[nav.sub form] = offsetTop[#main-content] - offsetHeight[nav.sub form] - offsetTop[nav.sub form]
|
|
|
|
assert-property: ("nav.sub form", {"offsetTop": 28, "offsetHeight": 34})
|
|
|
|
assert-property: ("#main-content", {"offsetTop": 90})
|
|
|
|
// 28 = 90 - 34 - 28
|
|
|
|
|
2022-12-31 18:23:30 +00:00
|
|
|
// Now do the same check on moderately-sized, tablet mobile.
|
2023-04-11 17:11:34 +00:00
|
|
|
set-window-size: (700, 700)
|
2022-10-20 20:22:36 +00:00
|
|
|
assert-css: ("nav.sub", {"flex-direction": "row"})
|
|
|
|
assert-property: ("nav.sub form", {"offsetTop": 21, "offsetHeight": 34})
|
|
|
|
assert-property: ("#main-content", {"offsetTop": 76})
|
|
|
|
// 21 = 76 - 34 - 21
|
|
|
|
|
2022-12-31 18:23:30 +00:00
|
|
|
// Check the sidebar directory entries have a marker and spacing (tablet).
|
2023-05-10 08:56:59 +00:00
|
|
|
store-property: ("#source-sidebar > .title", {
|
|
|
|
"offsetHeight": source_sidebar_title_height,
|
|
|
|
"offsetTop": source_sidebar_title_y,
|
|
|
|
})
|
2022-12-31 18:23:30 +00:00
|
|
|
call-function: ("check-sidebar-dir-entry", {
|
|
|
|
"x": 0,
|
|
|
|
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6,
|
|
|
|
})
|
|
|
|
|
|
|
|
// Tiny, phone mobile gets a different display where the logo is stacked on top.
|
2023-04-11 17:11:34 +00:00
|
|
|
set-window-size: (450, 700)
|
2022-10-20 20:22:36 +00:00
|
|
|
assert-css: ("nav.sub", {"flex-direction": "column"})
|
2022-12-31 18:23:30 +00:00
|
|
|
|
|
|
|
// Check the sidebar directory entries have a marker and spacing (phone).
|
2023-05-10 08:56:59 +00:00
|
|
|
store-property: ("#source-sidebar > .title", {
|
|
|
|
"offsetHeight": source_sidebar_title_height,
|
|
|
|
"offsetTop": source_sidebar_title_y,
|
|
|
|
})
|
2022-12-31 18:23:30 +00:00
|
|
|
call-function: ("check-sidebar-dir-entry", {
|
|
|
|
"x": 0,
|
|
|
|
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6,
|
|
|
|
})
|
2023-04-05 15:13:12 +00:00
|
|
|
|
|
|
|
// Now we check that the logo has a bottom margin so it's not stuck to the search input.
|
|
|
|
assert-css: (".sub-logo-container > img", {"margin-bottom": "8px"})
|
2023-05-10 08:56:59 +00:00
|
|
|
store-property: (".sub-logo-container", {"clientHeight": logo_height})
|
2023-04-05 15:13:12 +00:00
|
|
|
assert-position: (".search-form", {"y": |logo_height| + 8})
|