Skip to content

Commit 6812adb

Browse files
committed
Fix test cases and hide-sidebar mode
1 parent a02218b commit 6812adb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+262
-217
lines changed

src/librustdoc/html/static/css/rustdoc.css

+10-2
Original file line numberDiff line numberDiff line change
@@ -1867,15 +1867,19 @@ a.tooltip:hover::after {
18671867
display: flex;
18681868
margin-right: 4px;
18691869
position: fixed;
1870+
margin-top: 25px;
18701871
left: 6px;
18711872
height: 34px;
18721873
width: 34px;
18731874
background-color: var(--main-background-color);
18741875
z-index: 1;
18751876
}
18761877
.src #sidebar-button {
1878+
margin-top: 0;
1879+
top: 8px;
18771880
left: 8px;
18781881
z-index: calc(var(--desktop-sidebar-z-index) + 1);
1882+
border-color: var(--border-color);
18791883
}
18801884
.hide-sidebar .src #sidebar-button {
18811885
position: static;
@@ -1902,14 +1906,14 @@ button#toggle-all-docs {
19021906
}
19031907
#sidebar-button > a {
19041908
background-color: var(--button-background-color);
1905-
border-color: var(--border-color);
19061909
width: 33px;
19071910
}
19081911

19091912
#search-button > a:hover, #search-button > a:focus-visible,
19101913
.settings-menu > a:hover, .settings-menu > a:focus-visible,
19111914
.help-menu > a:hover, #help-menu > a:focus-visible,
19121915
#sidebar-button > a:hover, #sidebar-button > a:focus-visible,
1916+
#copy-path:hover, #copy-path:focus-visible,
19131917
button#toggle-all-docs:hover, button#toggle-all-docs:focus-visible {
19141918
border-color: var(--settings-button-border-focus);
19151919
text-decoration: none;
@@ -2023,7 +2027,8 @@ rustdoc-toolbar span.label {
20232027
margin-left: 10px;
20242028
padding: 0;
20252029
padding-left: 2px;
2026-
border: 0;
2030+
border: solid 1px transparent;
2031+
border-radius: var(--button-border-radius);
20272032
font-size: 0;
20282033
}
20292034
#copy-path::before {
@@ -2549,6 +2554,9 @@ in src-script.js and main.js
25492554
}
25502555

25512556
/* sidebar button becomes topbar button */
2557+
.hide-sidebar #sidebar-button {
2558+
margin-top: 0;
2559+
}
25522560
#sidebar-button > a:before {
25532561
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" \
25542562
viewBox="0 0 22 22" fill="none" stroke="black">\

src/librustdoc/html/static/js/main.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,9 @@ function preLoadCss(cssUrl) {
220220
const out = searchState.outputElement().parentElement;
221221
const hdr = document.createElement("div");
222222
hdr.className = "main-heading search-results-main-heading";
223-
const rootPath = getVar("root-path");
224-
const currentCrate = getVar("current-crate");
225223
hdr.innerHTML = `<nav class="sub">
226224
<form class="search-form">
227225
<span></span> <!-- This empty span is a hacky fix for Safari: see #93184 -->
228-
<div id="sidebar-button" tabindex="-1">
229-
<a href="${rootPath}${currentCrate}/all.html" title="show sidebar"></a>
230-
</div>
231226
<input
232227
class="search-input"
233228
name="search"
@@ -1599,7 +1594,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
15991594
// On larger, "desktop-sized" viewports (though that includes many
16001595
// tablets), it's fixed-position, appears in the left side margin,
16011596
// and it can be activated by resizing the sidebar into nothing.
1602-
const sidebarButton = document.getElementById("sidebar-button");
1597+
let sidebarButton = document.getElementById("sidebar-button");
1598+
if (!sidebarButton) {
1599+
sidebarButton = document.createElement("div");
1600+
sidebarButton.id = "sidebar-button";
1601+
const path = `${window.rootPath}${window.currentCrate}/all.html`;
1602+
sidebarButton.innerHTML = `<a href="${path}" title="show sidebar"></a>`;
1603+
const body = document.querySelector(".main-heading");
1604+
body.insertBefore(sidebarButton, body.firstChild);
1605+
}
16031606
if (sidebarButton) {
16041607
sidebarButton.addEventListener("click", e => {
16051608
removeClass(document.documentElement, "hide-sidebar");

tests/rustdoc-gui/code-example-buttons.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ include: "utils.goml"
55
// First we check we "hover".
66
move-cursor-to: ".example-wrap"
77
assert-css: (".example-wrap .copy-button", { "visibility": "visible" })
8-
move-cursor-to: ".search-input"
8+
move-cursor-to: "#search-button"
99
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })
1010

1111
// Now we check the click.
1212
assert-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 0)
1313
click: ".example-wrap"
14-
move-cursor-to: ".search-input"
14+
move-cursor-to: "#search-button"
1515
// It should have a new class and be visible.
1616
wait-for-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 1)
1717
wait-for-css: (".example-wrap:not(:hover) .button-holder.keep-visible", { "visibility": "visible" })
1818
// Clicking again will remove the class.
1919
click: ".example-wrap"
20-
move-cursor-to: ".search-input"
20+
move-cursor-to: "rustdoc-toolbar #search-button"
2121
assert-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 0)
2222
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })
2323

2424
// Clicking on the "copy code" button shouldn't make the buttons stick.
2525
click: ".example-wrap .copy-button"
26-
move-cursor-to: ".search-input"
26+
move-cursor-to: "#search-button"
2727
assert-count: (".example-wrap:not(:hover) .button-holder.keep-visible", 0)
2828
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })
2929

tests/rustdoc-gui/copy-code.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define-function: (
1212
assert-count: (".example-wrap .copy-button", 1)
1313
// We now ensure it's only displayed when the example is hovered.
1414
assert-css: (".example-wrap .copy-button", { "visibility": "visible" })
15-
move-cursor-to: ".search-input"
15+
move-cursor-to: "rustdoc-toolbar #search-button"
1616
assert-css: (".example-wrap .copy-button", { "visibility": "hidden" })
1717
// Checking that the copy button has the same size as the "copy path" button.
1818
compare-elements-size: (

tests/rustdoc-gui/cursor.goml

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ assert-css: ("#toggle-all-docs", {"cursor": "pointer"})
88
assert-css: ("#copy-path", {"cursor": "pointer"})
99

1010
// the search tabs
11+
click: "#search-button"
12+
wait-for: ".search-input"
1113
write-into: (".search-input", "Foo")
1214
// To be SURE that the search will be run.
1315
press-key: 'Enter'

tests/rustdoc-gui/docblock-code-block-line-number.goml

+4-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ assert-text: ("pre.example-line-numbers", "1\n2")
8181
// and make sure it goes away.
8282

8383
// First, open the settings menu.
84-
click: "#settings-menu"
84+
click: "rustdoc-toolbar .settings-menu"
8585
wait-for: "#settings"
8686
assert-css: ("#settings", {"display": "block"})
8787

@@ -188,7 +188,7 @@ call-function: ("check-padding", {
188188
define-function: ("check-line-numbers-existence", [], block {
189189
assert-local-storage: {"rustdoc-line-numbers": "true" }
190190
assert-false: ".example-line-numbers"
191-
click: "#settings-menu"
191+
click: "rustdoc-toolbar .settings-menu"
192192
wait-for: "#settings"
193193

194194
// Then, click the toggle button.
@@ -204,7 +204,7 @@ define-function: ("check-line-numbers-existence", [], block {
204204
// Line numbers should still be there.
205205
assert: ".src-line-numbers"
206206
// Closing settings menu.
207-
click: "#settings-menu"
207+
click: "rustdoc-toolbar .settings-menu"
208208
wait-for-css: ("#settings", {"display": "none"})
209209
})
210210

@@ -237,7 +237,7 @@ assert: ".example-wrap > pre.rust"
237237
assert-count: (".example-wrap", 2)
238238
assert-count: (".example-wrap > pre.example-line-numbers", 2)
239239

240-
click: "#settings-menu"
240+
click: "rustdoc-toolbar .settings-menu"
241241
wait-for: "#settings"
242242

243243
// Then, click the toggle button.

tests/rustdoc-gui/escape-key.goml

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// current content displayed.
33
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
44
// First, we check that the search results are hidden when the Escape key is pressed.
5+
click: "#search-button"
6+
wait-for: "#search .search-switcher" // The search element is empty before the first search
57
write-into: (".search-input", "test")
6-
// To be SURE that the search will be run.
7-
press-key: 'Enter'
8-
wait-for: "#search h1" // The search element is empty before the first search
8+
press-key: "Enter"
99
// Check that the currently displayed element is search.
1010
wait-for: "#alternative-display #search"
1111
assert-attribute: ("#main-content", {"class": "content hidden"})
@@ -17,8 +17,8 @@ assert-false: "#alternative-display #search"
1717
assert-attribute: ("#main-content", {"class": "content"})
1818
assert-document-property: ({"URL": "index.html"}, [ENDS_WITH])
1919

20-
// Check that focusing the search input brings back the search results
21-
focus: ".search-input"
20+
// Check that clicking the search button brings back the search results
21+
click: "#search-button"
2222
wait-for: "#alternative-display #search"
2323
assert-attribute: ("#main-content", {"class": "content hidden"})
2424
assert-document-property: ({"URL": "index.html?search=test"}, ENDS_WITH)

tests/rustdoc-gui/globals.goml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ assert-window-property: {"srcIndex": null}
1010

1111
// Form input
1212
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
13+
click: "#search-button"
1314
write-into: (".search-input", "Foo")
1415
press-key: 'Enter'
1516
wait-for: "#search-tabs"

tests/rustdoc-gui/help-page.goml

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ assert-css: ("#help", {"display": "block"})
66
assert-css: ("#help dd", {"font-size": "16px"})
77
assert-false: "#help-button > a"
88
assert-css: ("#help", {"display": "block"})
9-
compare-elements-property: (".sub", "#help", ["offsetWidth"])
10-
compare-elements-position: (".sub", "#help", ["x"])
9+
compare-elements-property: (".main-heading", "#help", ["offsetWidth"])
10+
compare-elements-position: (".main-heading", "#help", ["x"])
1111
set-window-size: (500, 1000) // Try mobile next.
1212
assert-css: ("#help", {"display": "block"})
13-
compare-elements-property: (".sub", "#help", ["offsetWidth"])
14-
compare-elements-position: (".sub", "#help", ["x"])
13+
compare-elements-property: (".main-heading", "#help", ["offsetWidth"])
14+
compare-elements-position: (".main-heading", "#help", ["x"])
1515

1616
// Checking the color of the elements of the help menu.
1717
show-text: true
@@ -54,19 +54,17 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=a"
5454
wait-for: "#search-tabs" // Waiting for the search.js to load.
5555
set-window-size: (1000, 1000) // Only supported on desktop.
5656
assert-false: "#help"
57-
click: "#help-button > a"
57+
click: "rustdoc-toolbar .help-menu > a"
5858
assert-css: ("#help", {"display": "block"})
5959
assert-css: ("#help dd", {"font-size": "16px"})
60-
click: "#help-button > a"
61-
assert-css: ("#help", {"display": "none"})
62-
compare-elements-property-false: (".sub", "#help", ["offsetWidth"])
63-
compare-elements-position-false: (".sub", "#help", ["x"])
60+
click: "rustdoc-toolbar .help-menu > a"
61+
assert-false: "#help"
6462

6563
// This test ensures that the "the rustdoc book" anchor link within the help popover works.
6664
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=a"
6765
wait-for: "#search-tabs" // Waiting for the search.js to load.
6866
set-window-size: (1000, 1000) // Popover only appears when the screen width is >700px.
6967
assert-false: "#help"
70-
click: "#help-button > a"
68+
click: "rustdoc-toolbar .help-menu > a"
7169
click: "//*[@id='help']//a[text()='the rustdoc book']"
7270
wait-for-document-property: ({"URL": "https://doc.rust-lang.org/"}, STARTS_WITH)
+4-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// Checks sidebar resizing stays synced with the setting
2-
go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
2+
go-to: "file://" + |DOC_PATH| + "/settings.html"
33
set-window-size: (400, 600)
44

55
// Verify that the "hide" option is unchecked
6-
click: "#settings-menu"
76
wait-for: "#settings"
87
assert-css: ("#settings", {"display": "block"})
98
assert-property: ("#hide-sidebar", {"checked": "false"})
10-
assert-css: (".mobile-topbar", {"display": "flex"})
9+
assert-css: ("rustdoc-topbar", {"display": "flex"})
1110

1211
// Toggle it
1312
click: "#hide-sidebar"
1413
assert-property: ("#hide-sidebar", {"checked": "true"})
15-
assert-css: (".mobile-topbar", {"display": "none"})
14+
assert-css: ("rustdoc-topbar", {"display": "none"})
1615

1716
// Toggle it again
1817
click: "#hide-sidebar"
1918
assert-property: ("#hide-sidebar", {"checked": "false"})
20-
assert-css: (".mobile-topbar", {"display": "flex"})
19+
assert-css: ("rustdoc-topbar", {"display": "flex"})

tests/rustdoc-gui/huge-logo.goml

-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,3 @@ assert-property: (".sidebar-crate .logo-container", {"offsetWidth": "96", "offse
88
// offsetWidth = width of sidebar, offsetHeight = height + top padding
99
assert-property: (".sidebar-crate .logo-container img", {"offsetWidth": "48", "offsetHeight": 64})
1010
assert-css: (".sidebar-crate .logo-container img", {"border-top-width": "16px", "margin-top": "-16px"})
11-
12-
set-window-size: (400, 600)
13-
// offset = size + margin
14-
assert-property: (".mobile-topbar .logo-container", {"offsetWidth": "55", "offsetHeight": 45})
15-
assert-property: (".mobile-topbar .logo-container img", {"offsetWidth": "35", "offsetHeight": 35})

tests/rustdoc-gui/item-info.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ store-position: (
2020
{"x": second_line_x, "y": second_line_y},
2121
)
2222
assert: |first_line_x| != |second_line_x| && |first_line_x| == 521 && |second_line_x| == 277
23-
assert: |first_line_y| != |second_line_y| && |first_line_y| == 718 && |second_line_y| == 741
23+
assert: |first_line_y| != |second_line_y| && |first_line_y| == 674 && |second_line_y| == 697
2424

2525
// Now we ensure that they're not rendered on the same line.
2626
set-window-size: (1100, 800)

tests/rustdoc-gui/mobile-crate-name.goml

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
55
// First we change the title to make it big.
66
set-window-size: (350, 800)
77
// We ensure that the "format" of the title is the same as the one we'll use.
8-
assert-text: (".mobile-topbar .location a", "test_docs")
8+
assert-text: ("rustdoc-topbar h2 a", "Crate test_docs")
99
// We store the height we know is correct.
10-
store-property: (".mobile-topbar .location", {"offsetHeight": height})
10+
store-property: ("rustdoc-topbar h2", {"offsetHeight": height})
1111
// We change the crate name to something longer.
12-
set-text: (".mobile-topbar .location a", "cargo_packager_resource_resolver")
12+
set-text: ("rustdoc-topbar h2 a", "cargo_packager_resource_resolver")
1313
// And we check that the size remained the same.
14-
assert-property: (".mobile-topbar .location", {"offsetHeight": |height|})
14+
assert-property: ("rustdoc-topbar h2", {"offsetHeight": |height|})
1515

1616
// Now we check if it works for the non-crate pages as well.
1717
go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html"
1818
// We store the height we know is correct.
19-
store-property: (".mobile-topbar .location", {"offsetHeight": height})
20-
set-text: (".mobile-topbar .location a", "Something_incredibly_long_because")
19+
store-property: ("rustdoc-topbar h2", {"offsetHeight": height})
20+
set-text: ("rustdoc-topbar h2 a", "Something_incredibly_long_because")
2121
// And we check that the size remained the same.
22-
assert-property: (".mobile-topbar .location", {"offsetHeight": |height|})
22+
assert-property: ("rustdoc-topbar h2", {"offsetHeight": |height|})

tests/rustdoc-gui/mobile.goml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set-window-size: (400, 600)
55
set-font-size: 18
66
wait-for: 100 // wait a bit for the resize and the font-size change to be fully taken into account.
77

8-
assert-property: (".mobile-topbar h2", {"offsetHeight": 33})
8+
assert-property: ("rustdoc-topbar h2", {"offsetHeight": 33})
99

1010
// On the settings page, the theme buttons should not line-wrap. Instead, they should
1111
// all be placed as a group on a line below the setting name "Theme."
1.81 MB
Loading

tests/rustdoc-gui/notable-trait.goml

+13-13
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@ call-function: ("check-notable-tooltip-position", {
8282
"i_x": 528,
8383
})
8484

85-
// Checking on mobile now.
86-
set-window-size: (650, 600)
87-
wait-for-size: ("body", {"width": 650})
88-
call-function: ("check-notable-tooltip-position-complete", {
89-
"x": 26,
90-
"i_x": 305,
91-
"popover_x": 0,
92-
})
93-
9485
// Now check the colors.
9586
define-function: (
9687
"check-colors",
@@ -176,6 +167,15 @@ call-function: (
176167
},
177168
)
178169

170+
// Checking on mobile now.
171+
set-window-size: (650, 600)
172+
wait-for-size: ("body", {"width": 650})
173+
call-function: ("check-notable-tooltip-position-complete", {
174+
"x": 26,
175+
"i_x": 305,
176+
"popover_x": 0,
177+
})
178+
179179
reload:
180180

181181
// Check that pressing escape works
@@ -189,7 +189,7 @@ assert: "#method\.create_an_iterator_from_read .tooltip:focus"
189189
// Check that clicking outside works.
190190
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
191191
assert-count: ("//*[@class='tooltip popover']", 1)
192-
click: ".search-input"
192+
click: ".main-heading h1"
193193
assert-count: ("//*[@class='tooltip popover']", 0)
194194
assert-false: "#method\.create_an_iterator_from_read .tooltip:focus"
195195

@@ -219,14 +219,14 @@ define-function: (
219219
store-window-property: {"scrollY": scroll}
220220
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
221221
wait-for: "//*[@class='tooltip popover']"
222-
click: "#settings-menu a"
222+
click: ".main-heading h1"
223223
}
224224
)
225225

226226
// Now we check that the focus isn't given back to the wrong item when opening
227227
// another popover.
228228
call-function: ("setup-popup", {})
229-
click: ".search-input"
229+
click: ".main-heading h1"
230230
// We ensure we didn't come back to the previous focused item.
231231
assert-window-property-false: {"scrollY": |scroll|}
232232

@@ -255,7 +255,7 @@ reload:
255255
assert-count: ("//*[@class='tooltip popover']", 0)
256256
click: "//*[@id='method.create_an_iterator_from_read']//*[@class='tooltip']"
257257
assert-count: ("//*[@class='tooltip popover']", 1)
258-
click: "#settings-menu a"
258+
click: "rustdoc-toolbar .settings-menu a"
259259
wait-for: "#settings"
260260
assert-count: ("//*[@class='tooltip popover']", 0)
261261
assert-false: "#method\.create_an_iterator_from_read .tooltip:focus"

0 commit comments

Comments
 (0)