1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
// Checks that the interactions with the source code pages are working as expected.
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
show-text: true
// Check that we can click on the line number.
click: ".src-line-numbers > a:nth-child(4)" // This is the anchor for line 4.
// Ensure that the page URL was updated.
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
// 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"})
// We now check that the good anchors are highlighted
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html#4-6"
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"})
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:
assert-css: (
".src-line-numbers > a:not(.line-highlighted)",
{"color": |color|, "background-color": |background_color|},
ALL,
)
assert-css: (
".src-line-numbers > a.line-highlighted",
{"color": |highlight_color|, "background-color": |highlight_background_color|},
ALL,
)
},
)
call-function: ("check-colors", {
"theme": "ayu",
"color": "#5c6773",
"background_color": "transparent",
"highlight_color": "#708090",
"highlight_background_color": "rgba(255, 236, 164, 0.06)",
})
call-function: ("check-colors", {
"theme": "dark",
"color": "#3b91e2",
"background_color": "transparent",
"highlight_color": "#3b91e2",
"highlight_background_color": "#0a042f",
})
call-function: ("check-colors", {
"theme": "light",
"color": "#c67e2d",
"background_color": "transparent",
"highlight_color": "#c67e2d",
"highlight_background_color": "#fdffd3",
})
// This is to ensure that the content is correctly align with the line numbers.
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
// Check the `href` property so that users can treat anchors as links.
assert-property: (".src-line-numbers > a:nth-child(1)", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#1"
}, ENDS_WITH)
assert-property: (".src-line-numbers > a:nth-child(2)", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#2"
}, ENDS_WITH)
assert-property: (".src-line-numbers > a:nth-child(3)", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#3"
}, ENDS_WITH)
assert-property: (".src-line-numbers > a:nth-child(4)", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#4"
}, ENDS_WITH)
assert-property: (".src-line-numbers > a:nth-child(5)", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#5"
}, ENDS_WITH)
assert-property: (".src-line-numbers > a:nth-child(6)", {
"href": |DOC_PATH| + "/src/test_docs/lib.rs.html#6"
}, ENDS_WITH)
// Assert that the line numbers text is aligned to the right.
assert-css: (".src-line-numbers", {"text-align": "right"})
// 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!).
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// We use this assert-position to know where we will click.
assert-position: ("//*[@id='1']", {"x": 88, "y": 86})
// We click on the left of the "1" anchor but still in the "src-line-number" `<pre>`.
click: (87, 77)
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
// Checking the source code sidebar.
// First we "open" it.
click: "#src-sidebar-toggle"
assert: ".src-sidebar-expanded"
// We check that the first entry of the sidebar is collapsed
assert-property: ("#src-sidebar details:first-of-type", {"open": "false"})
assert-text: ("#src-sidebar details:first-of-type > summary", "extend_css")
// We now click on it.
click: "#src-sidebar details:first-of-type > summary"
assert-property: ("#src-sidebar details:first-of-type", {"open": "true"})
// And now we collapse it again.
click: "#src-sidebar details:first-of-type > summary"
assert-property: ("#src-sidebar details:first-of-type", {"open": "false"})
// And open it again, since it'll be the reference we use to check positions.
click: "#src-sidebar details:first-of-type > summary"
assert-property: ("#src-sidebar details:first-of-type", {"open": "true"})
// Check the sidebar directory entries have a marker and spacing (desktop).
store-property: (
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
{"offsetHeight": link_height},
)
define-function: (
"check-sidebar-dir-entry",
(x, y),
block {
assert: "details:first-of-type.dir-entry[open] > summary::marker"
assert-css: ("#src-sidebar > details:first-of-type.dir-entry", {"padding-left": "4px"})
// This check ensures that the summary is only one line.
assert-property: (
"#src-sidebar > details:first-of-type.dir-entry[open] > summary",
{"offsetHeight": |link_height|}
)
assert-position: (
"#src-sidebar > details:first-of-type.dir-entry[open] > summary",
{"x": |x|, "y": |y|}
)
assert-property: (
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
{"offsetHeight": |link_height|}
)
assert-position: (
"#src-sidebar > details:first-of-type.dir-entry[open] > .files > a",
// left margin
{"x": |x| + 27, "y": |y| + |link_height|}
)
}
)
store-property: ("#src-sidebar > .title", {
"offsetHeight": source_sidebar_title_height,
"offsetTop": source_sidebar_title_y,
})
call-function: ("check-sidebar-dir-entry", {
"x": 0,
// border + margin = 6
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6,
})
// 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": 15, "offsetHeight": 34})
assert-property: ("#main-content", {"offsetTop": 64})
// 15 = 64 - 34 - 15
// Now do the same check on moderately-sized, tablet mobile.
set-window-size: (700, 700)
assert-css: ("nav.sub", {"flex-direction": "row"})
assert-property: ("nav.sub form", {"offsetTop": 8, "offsetHeight": 34})
assert-property: ("#main-content", {"offsetTop": 50})
// 8 = 50 - 34 - 8
// Check the sidebar directory entries have a marker and spacing (tablet).
store-property: ("#src-sidebar > .title", {
"offsetHeight": source_sidebar_title_height,
"offsetTop": source_sidebar_title_y,
})
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.
set-window-size: (450, 700)
assert-css: ("nav.sub", {"flex-direction": "column"})
// Check the sidebar directory entries have a marker and spacing (phone).
store-property: ("#src-sidebar > .title", {
"offsetHeight": source_sidebar_title_height,
"offsetTop": source_sidebar_title_y,
})
call-function: ("check-sidebar-dir-entry", {
"x": 0,
"y": |source_sidebar_title_y| + |source_sidebar_title_height| + 6,
})
// The logo is not present on this page.
assert-false: ".sub-logo-container > img"
// Check the staged-api page instead, which does.
// Now we check that the logo has a bottom margin so it's not stuck to the search input.
go-to: "file://" + |DOC_PATH| + "/src/staged_api/lib.rs.html"
assert-css: (".sub-logo-container > img", {"margin-bottom": "8px"})
store-property: (".sub-logo-container", {"clientHeight": logo_height})
assert-position: (".search-form", {"y": |logo_height| + 8})
|