Skip to content

Commit b3410ae

Browse files
committed
Fix test cases and hide-sidebar mode
1 parent 0c08c39 commit b3410ae

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

+276
-210
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,8 @@ a.tooltip:hover::after {
20212021
display: flex;
20222022
margin-right: 4px;
20232023
position: fixed;
2024+
margin-top: 25px;
2025+
left: 6px;
20242026
height: 34px;
20252027
width: 34px;
20262028
}
@@ -2030,8 +2032,11 @@ a.tooltip:hover::after {
20302032
z-index: 1;
20312033
}
20322034
.src #sidebar-button {
2035+
margin-top: 0;
2036+
top: 8px;
20332037
left: 8px;
20342038
z-index: calc(var(--desktop-sidebar-z-index) + 1);
2039+
border-color: var(--border-color);
20352040
}
20362041
.hide-sidebar .src #sidebar-button {
20372042
position: static;
@@ -2059,7 +2064,7 @@ button#toggle-all-docs {
20592064
min-width: 0;
20602065
}
20612066
#sidebar-button > a {
2062-
background-color: var(--sidebar-background-color);
2067+
background-color: var(--button-background-color);
20632068
width: 33px;
20642069
}
20652070
#sidebar-button > a:hover, #sidebar-button > a:focus-visible {
@@ -2070,6 +2075,7 @@ button#toggle-all-docs {
20702075
.settings-menu > a:hover, .settings-menu > a:focus-visible,
20712076
.help-menu > a:hover, #help-menu > a:focus-visible,
20722077
#sidebar-button > a:hover, #sidebar-button > a:focus-visible,
2078+
#copy-path:hover, #copy-path:focus-visible,
20732079
button#toggle-all-docs:hover, button#toggle-all-docs:focus-visible {
20742080
border-color: var(--settings-button-border-focus);
20752081
text-decoration: none;
@@ -2183,7 +2189,8 @@ rustdoc-toolbar span.label {
21832189
margin-left: 10px;
21842190
padding: 0;
21852191
padding-left: 2px;
2186-
border: 0;
2192+
border: solid 1px transparent;
2193+
border-radius: var(--button-border-radius);
21872194
font-size: 0;
21882195
}
21892196
#copy-path::before {
@@ -2708,6 +2715,9 @@ in src-script.js and main.js
27082715
}
27092716

27102717
/* sidebar button becomes topbar button */
2718+
.hide-sidebar #sidebar-button {
2719+
margin-top: 0;
2720+
}
27112721
#sidebar-button > a::before {
27122722
content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" \
27132723
viewBox="0 0 22 22" fill="none" stroke="black">\

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,9 @@ function preLoadCss(cssUrl) {
253253
const out = nonnull(nonnull(window.searchState.outputElement()).parentElement);
254254
const hdr = document.createElement("div");
255255
hdr.className = "main-heading search-results-main-heading";
256-
const rootPath = getVar("root-path");
257-
const currentCrate = getVar("current-crate");
258256
hdr.innerHTML = `<nav class="sub">
259257
<form class="search-form">
260258
<span></span> <!-- This empty span is a hacky fix for Safari: see #93184 -->
261-
<div id="sidebar-button" tabindex="-1">
262-
<a href="${rootPath}${currentCrate}/all.html" title="show sidebar"></a>
263-
</div>
264259
<input
265260
class="search-input"
266261
name="search"
@@ -1753,7 +1748,15 @@ function preLoadCss(cssUrl) {
17531748
// On larger, "desktop-sized" viewports (though that includes many
17541749
// tablets), it's fixed-position, appears in the left side margin,
17551750
// and it can be activated by resizing the sidebar into nothing.
1756-
const sidebarButton = document.getElementById("sidebar-button");
1751+
let sidebarButton = document.getElementById("sidebar-button");
1752+
if (!sidebarButton) {
1753+
sidebarButton = document.createElement("div");
1754+
sidebarButton.id = "sidebar-button";
1755+
const path = `${window.rootPath}${window.currentCrate}/all.html`;
1756+
sidebarButton.innerHTML = `<a href="${path}" title="show sidebar"></a>`;
1757+
const body = document.querySelector(".main-heading");
1758+
body.insertBefore(sidebarButton, body.firstChild);
1759+
}
17571760
if (sidebarButton) {
17581761
sidebarButton.addEventListener("click", e => {
17591762
removeClass(document.documentElement, "hide-sidebar");

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

Lines changed: 4 additions & 4 deletions
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
// Since we clicked on the copy button, the clipboard content should have been updated.

tests/rustdoc-gui/copy-code.goml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ call-function: ("check-colors", {
6969
// and make sure it goes away.
7070

7171
// First, open the settings menu.
72-
click: "#settings-menu"
72+
click: "rustdoc-toolbar .settings-menu"
7373
wait-for: "#settings"
7474
assert-css: ("#settings", {"display": "block"})
7575

@@ -121,7 +121,7 @@ call-function: ("check-padding", {
121121
define-function: ("check-line-numbers-existence", [], block {
122122
assert-local-storage: {"rustdoc-line-numbers": "true" }
123123
assert-false: ".example-line-numbers"
124-
click: "#settings-menu"
124+
click: "rustdoc-toolbar .settings-menu"
125125
wait-for: "#settings"
126126

127127
// Then, click the toggle button.
@@ -137,7 +137,7 @@ define-function: ("check-line-numbers-existence", [], block {
137137
// Line numbers should still be there.
138138
assert-css: ("[data-nosnippet]", { "display": "inline-block"})
139139
// Closing settings menu.
140-
click: "#settings-menu"
140+
click: "rustdoc-toolbar .settings-menu"
141141
wait-for-css: ("#settings", {"display": "none"})
142142
})
143143

@@ -168,7 +168,7 @@ assert: ".example-wrap > pre.rust"
168168
assert-count: (".example-wrap", 2)
169169
assert-count: (".example-wrap.digits-1", 2)
170170

171-
click: "#settings-menu"
171+
click: "rustdoc-toolbar .settings-menu"
172172
wait-for: "#settings"
173173

174174
// Then, click the toggle button.

tests/rustdoc-gui/escape-key.goml

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 8 additions & 10 deletions
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)
Lines changed: 4 additions & 5 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 13 additions & 13 deletions
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

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

0 commit comments

Comments
 (0)