Skip to content

Commit

Permalink
chore(iframe): add frame title case
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 10, 2023
1 parent 28abfee commit e55fd34
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 21 deletions.
3 changes: 2 additions & 1 deletion RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions accessibility-rs/src/engine/rules/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub enum Techniques {
F41,
/// <https://www.w3.org/TR/WCAG20-TECHS/F47>
F47,
/// <https://www.w3.org/TR/WCAG20-TECHS/H64>
H64,
}

impl Techniques {
Expand All @@ -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"],
}
}
}
10 changes: 10 additions & 0 deletions accessibility-rs/src/engine/rules/wcag_rule_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 29 additions & 20 deletions accessibility-rs/src/i18n/locales.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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: &"",
Expand Down Expand Up @@ -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.", "", "", "")),
])
};
}
88 changes: 88 additions & 0 deletions accessibility-rs/tests/unit/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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###"<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A simple frameset document</title>
</head>
<frameset cols="10%, 90%">
<frame src="nav.html" title="Main menu" />
<frame src="doc.html" title="Documents" />
<noframes>
<body>
<a href="lib.html" title="Library link">Select to
go to the electronic library</a>
</body>
</noframes>
</frameset>
</html>"###,
&"",
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###"<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A simple frameset document</title>
</head>
<frameset cols="10%, 90%">
<frame src="nav.html" />
<frame src="doc.html" />
<noframes>
<body>
<a href="lib.html" title="Library link">Select to
go to the electronic library</a>
</body>
</noframes>
</frameset>
</html>"###,
&"",
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###" <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A document using iframe</title>
</head>
<iframe src="banner-ad.html" id="testiframe"
name="testiframe" title="Advertisement">
<a href="banner-ad.html">Advertisement</a>
</iframe>
</html>"###,
&"",
false,
);
let mut valid = true;

for x in &audit {
if x.code == "WCAGAAA.Principle2.Guideline2_4.H64" {
valid = false;
break;
}
}

assert_eq!(valid, true);
}

0 comments on commit e55fd34

Please sign in to comment.