@@ -232,6 +232,36 @@ impl<'a> Evaluator<'_> {
232
232
Ok ( violations)
233
233
}
234
234
235
+ /// Determines if the current page has a code example (using ACE) that has
236
+ /// a scrollbar by evaluating if the ace_scrollbar-[hv] element is displayed
237
+ async fn eval_code_example_scrollbar (
238
+ & self ,
239
+ ) -> anyhow:: Result < Vec < PolicyViolation > > {
240
+ let v_scrollbar_elements_path = fantoccini:: Locator :: XPath (
241
+ r#"//*[@id="content"]//div[contains(@class, "ace_scrollbar-v")]"# ,
242
+ ) ;
243
+ let h_scrollbar_elements_path = fantoccini:: Locator :: XPath (
244
+ r#"//*[@id="content"]//div[contains(@class, "ace_scrollbar-h")]"# ,
245
+ ) ;
246
+ let v_scrollbar_elements =
247
+ self . webclient . find_all ( v_scrollbar_elements_path) . await ?;
248
+ let h_scrollbar_elements =
249
+ self . webclient . find_all ( h_scrollbar_elements_path) . await ?;
250
+
251
+ let mut violations = vec ! [ ] ;
252
+ for element in v_scrollbar_elements {
253
+ if element. is_displayed ( ) . await ? {
254
+ violations. push ( PolicyViolation :: CodeExampleVScrollbar ) ;
255
+ }
256
+ }
257
+ for element in h_scrollbar_elements {
258
+ if element. is_displayed ( ) . await ? {
259
+ violations. push ( PolicyViolation :: CodeExampleHScrollbar ) ;
260
+ }
261
+ }
262
+ Ok ( violations)
263
+ }
264
+
235
265
/// evaluate a single slide
236
266
pub async fn eval_slide (
237
267
& self ,
@@ -245,6 +275,8 @@ impl<'a> Evaluator<'_> {
245
275
let mut policy_violations = vec ! [ ] ;
246
276
// evaluate main content element size
247
277
policy_violations. append ( & mut self . eval_main_element ( slide) . await ?) ;
278
+ // evaluate code examples size
279
+ policy_violations. append ( & mut self . eval_code_example_scrollbar ( ) . await ?) ;
248
280
249
281
let result = EvaluationResult { slide : slide. clone ( ) , policy_violations } ;
250
282
debug ! ( "information about element: {:?}" , result) ;
@@ -277,6 +309,10 @@ enum PolicyViolation {
277
309
MaxWidth ,
278
310
/// violation of the maximum width
279
311
MaxHeight ,
312
+ /// code examples should not contain a vertical scrollbar
313
+ CodeExampleVScrollbar ,
314
+ /// code examples should not contain a horizontal scrollbar
315
+ CodeExampleHScrollbar ,
280
316
}
281
317
282
318
/// the SlidePolicy struct contains all parameters for evaluating a slide
0 commit comments