From e55fd34f4464fbc8d81dcac5e568cefe0ca7f566 Mon Sep 17 00:00:00 2001 From: j-mendez Date: Tue, 10 Oct 2023 15:21:10 -0400 Subject: [PATCH] chore(iframe): add frame title case --- RULES.md | 3 +- accessibility-rs/src/engine/rules/ids.rs | 3 + .../src/engine/rules/wcag_rule_map.rs | 10 +++ accessibility-rs/src/i18n/locales.rs | 49 ++++++----- accessibility-rs/tests/unit/meta.rs | 88 +++++++++++++++++++ 5 files changed, 132 insertions(+), 21 deletions(-) diff --git a/RULES.md b/RULES.md index ac4b307..be98a05 100644 --- a/RULES.md +++ b/RULES.md @@ -11,9 +11,10 @@ List of techniques we want to have and whether we have it handled or not for WCA | [H25](https://www.w3.org/TR/WCAG20-TECHS/H25.html) | empty titles | error | ✅ | | [H32](https://www.w3.org/TR/WCAG20-TECHS/H32.html) | missing form submit button | error | ✅ | | [H57](https://www.w3.org/TR/WCAG20-TECHS/H57.html) | html contains valid lang | error | ✅ | +| [H64](https://www.w3.org/TR/WCAG20-TECHS/H64.html) | iframe missing title | error | ✅ | | [F40](https://www.w3.org/TR/WCAG20-TECHS/F40.html) | meta redirect used with a time limit | error | ✅ | | [F40](https://www.w3.org/TR/WCAG20-TECHS/F41.html) | meta refresh used to reload the page | error | ✅ | -| [F47](https://www.w3.org/TR/WCAG20-TECHS/F41.html) | blink element used for attention | error | ✅ | +| [F47](https://www.w3.org/TR/WCAG20-TECHS/F47.html) | blink element used for attention | error | ✅ | ### WCAGAA diff --git a/accessibility-rs/src/engine/rules/ids.rs b/accessibility-rs/src/engine/rules/ids.rs index 485e1fe..b6f3261 100644 --- a/accessibility-rs/src/engine/rules/ids.rs +++ b/accessibility-rs/src/engine/rules/ids.rs @@ -16,6 +16,8 @@ pub enum Techniques { F41, /// F47, + /// + H64, } impl Techniques { @@ -32,6 +34,7 @@ impl Techniques { Techniques::F40 => vec!["F40.2"], Techniques::F41 => vec!["F41.2"], Techniques::F47 => vec!["F47"], + Techniques::H64 => vec!["H64.1", "H64.2"], } } } diff --git a/accessibility-rs/src/engine/rules/wcag_rule_map.rs b/accessibility-rs/src/engine/rules/wcag_rule_map.rs index 8e95376..08a753c 100644 --- a/accessibility-rs/src/engine/rules/wcag_rule_map.rs +++ b/accessibility-rs/src/engine/rules/wcag_rule_map.rs @@ -66,6 +66,16 @@ lazy_static! { (nodes.is_empty(), "", Default::default()) }), ])), + ("iframe", Vec::from([ + Rule::new(Techniques::H64, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { + (nodes.iter().all(|e| !e.0.attr("title").unwrap_or_default().is_empty()), "", Default::default()) + }), + ])), + ("frame", Vec::from([ + Rule::new(Techniques::H64, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { + (nodes.iter().all(|e| !e.0.attr("title").unwrap_or_default().is_empty()), "", Default::default()) + }), + ])), ("form", Vec::from([ Rule::new(Techniques::H32, Criteria::Error, Principle::Operable, Guideline::Predictable, |_rule, nodes| { // check the first element for now diff --git a/accessibility-rs/src/i18n/locales.rs b/accessibility-rs/src/i18n/locales.rs index 3be636f..4aaa123 100644 --- a/accessibility-rs/src/i18n/locales.rs +++ b/accessibility-rs/src/i18n/locales.rs @@ -1,27 +1,29 @@ use crate::engine::rules::ids::Techniques; use std::collections::BTreeMap; +type M = &'static str; + /// messages to display for issues #[derive(std::cmp::Eq, PartialEq, PartialOrd, Ord)] pub struct Messages { /// english - en: &'static str, + en: M, /// spanish - es: &'static str, + es: M, /// german - de: &'static str, + de: M, /// japanese - ja: &'static str, + ja: M, /// portugese portugal - pt_pt: &'static str, + pt_pt: M, /// portugese brazil - pt_br: &'static str, + pt_br: M, /// chinese cantanese - zh_cn: &'static str, + zh_cn: M, /// chinese traditional - zh_tw: &'static str, + zh_tw: M, /// hindi - hi: &'static str, + hi: M, } pub enum Langs { @@ -65,12 +67,13 @@ impl Langs { /// the context of the issue impl Messages { /// create a new message - pub fn new(en: &'static str, es: &'static str, de: &'static str) -> Messages { + pub fn new(en: M, es: M, de: M, ja: M) -> Messages + { Messages { en, es, de, - ja: &"", + ja, pt_pt: &"", pt_br: &"", zh_cn: &"", @@ -103,15 +106,21 @@ lazy_static! { /// message for an issue pub static ref LOCALES: BTreeMap<&'static str, Messages> = { BTreeMap::from([ - (Techniques::H25.pairs()[0], Messages::new(&"A title should be provided for the document, using a non-empty title element in the head section.", "", "")), - (Techniques::H25.pairs()[1], Messages::new(&"The title element in the head section should be non-empty.", "", "")), - (Techniques::H32.pairs()[0], Messages::new(&r###"Form does not contain a submit button (input type="submit", input type="image", or button type="submit")."###, "", "")), - (Techniques::H57.pairs()[0], Messages::new(&"The html element should have a lang or xml:lang attribute which describes the language of the document.", "", "")), - (Techniques::H57.pairs()[1], Messages::new(&"The language specified in the lang attribute of the document element does not appear to be well-formed.", "", "")), - (Techniques::H57.pairs()[2], Messages::new(&"The language specified in the xml:lang attribute of the document element does not appear to be well-formed.", "", "")), - (Techniques::F40.pairs()[0], Messages::new(&"Meta refresh tag used to redirect to another page, with a time limit that is not zero. Users cannot control this time limit.", "", "")), - (Techniques::F41.pairs()[0], Messages::new(&"Meta refresh tag used to refresh the current page. Users cannot control the time limit for this refresh.", "", "")), - (Techniques::F47.pairs()[0], Messages::new(&"Blink elements cannot satisfy the requirement that blinking information can be stopped within five seconds.", "", "")), + (Techniques::H25.pairs()[0], Messages::new( + "A title should be provided for the document, using a non-empty title element in the head section.", + "Se debe proporcionar un título para el documento, utilizando un elemento de título no vacío en la sección head.", + "", + "head セクションの空でない title 要素を使って、文書にタイトルをつけるべきです。" + )), + (Techniques::H25.pairs()[1], Messages::new(&"The title element in the head section should be non-empty.", "", "", "")), + (Techniques::H32.pairs()[0], Messages::new(&r###"Form does not contain a submit button (input type="submit", input type="image", or button type="submit")."###, "", "", "")), + (Techniques::H64.pairs()[0], Messages::new(&"Iframe element requires a non-empty title attribute that identifies the frame.", "", "", "")), + (Techniques::H57.pairs()[0], Messages::new(&"The html element should have a lang or xml:lang attribute which describes the language of the document.", "", "", "")), + (Techniques::H57.pairs()[1], Messages::new(&"The language specified in the lang attribute of the document element does not appear to be well-formed.", "", "", "")), + (Techniques::H57.pairs()[2], Messages::new(&"The language specified in the xml:lang attribute of the document element does not appear to be well-formed.", "", "", "")), + (Techniques::F40.pairs()[0], Messages::new(&"Meta refresh tag used to redirect to another page, with a time limit that is not zero. Users cannot control this time limit.", "", "", "")), + (Techniques::F41.pairs()[0], Messages::new(&"Meta refresh tag used to refresh the current page. Users cannot control the time limit for this refresh.", "", "", "")), + (Techniques::F47.pairs()[0], Messages::new(&"Blink elements cannot satisfy the requirement that blinking information can be stopped within five seconds.", "", "", "")), ]) }; } diff --git a/accessibility-rs/tests/unit/meta.rs b/accessibility-rs/tests/unit/meta.rs index 9b971de..8e3c63a 100644 --- a/accessibility-rs/tests/unit/meta.rs +++ b/accessibility-rs/tests/unit/meta.rs @@ -101,3 +101,91 @@ fn _audit_blink_found() { assert_eq!(valid, false); } + +#[test] +/// iframe missing title +fn _iframe_missing_title() { + let audit = accessibility_rs::audit( + r###" + + A simple frameset document + + + + + + <body> + <a href="lib.html" title="Library link">Select to + go to the electronic library</a> + </body> + + + "###, + &"", + false, + ); + let mut valid = true; + + for x in &audit { + if x.code == "WCAGAAA.Principle2.Guideline2_4.H64" { + valid = false; + break; + } + } + + assert_eq!(valid, true); + + let audit = accessibility_rs::audit( + r###" + + A simple frameset document + + + + + + <body> + <a href="lib.html" title="Library link">Select to + go to the electronic library</a> + </body> + + + "###, + &"", + false, + ); + let mut valid = true; + + for x in &audit { + if x.code == "WCAGAAA.Principle2.Guideline2_4.H64" { + valid = false; + break; + } + } + + assert_eq!(valid, false); + + let audit = accessibility_rs::audit( + r###" + + A document using iframe + + + "###, + &"", + false, + ); + let mut valid = true; + + for x in &audit { + if x.code == "WCAGAAA.Principle2.Guideline2_4.H64" { + valid = false; + break; + } + } + + assert_eq!(valid, true); +}