Skip to content

Commit

Permalink
chore(rules): add F40 meta refresh test
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 10, 2023
1 parent dfde6c9 commit aa34614
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ List of techniques we want to have and whether we have it handled or not for WCA

### WCAGA

| Technique | Description | Complete |
| -------------------------------------------------- | -------------------------- | -------- |
| [H25](https://www.w3.org/TR/WCAG20-TECHS/H25.html) | empty titles ||
| [H32](https://www.w3.org/TR/WCAG20-TECHS/H32.html) | missing form submit button ||
| [H57](https://www.w3.org/TR/WCAG20-TECHS/H57.html) | html contains valid lang ||
| Technique | Description | Type | Complete |
| -------------------------------------------------- | -------------------------------------------- | ----- | -------- |
| [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 ||
| [F40](https://www.w3.org/TR/WCAG20-TECHS/F40.html) | using meta redirect with a time limit | error ||
| [F40](https://www.w3.org/TR/WCAG20-TECHS/F41.html) | due to using meta refresh to reload the page | error ||

### WCAGAA

Expand Down
2 changes: 1 addition & 1 deletion accessibility-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "accessibility-rs"
version = "0.0.6"
version = "0.0.7"
authors = ["The A11yWatch Project Developers", "Jeff Mendez <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
12 changes: 9 additions & 3 deletions accessibility-rs/src/engine/rules/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ pub enum Techniques {
/// <https://www.w3.org/TR/WCAG20-TECHS/H32.html>
H32,
/// <https://www.w3.org/TR/WCAG20-TECHS/H57>
H57
H57,
/// <https://www.w3.org/TR/WCAG20-TECHS/F40>
F40,
/// <https://www.w3.org/TR/WCAG20-TECHS/F41>
F41,
}

impl Techniques {
/// get rule id to string
pub fn as_str(&self) -> &'static str {
// todo: make macro
self.into()
self.into()
}
/// get pairs for a rule
pub fn pairs(&self) -> Vec<&'static str> {
match self {
Techniques::H25 => vec!["H25.1.NoTitleEl", "H25.1.EmptyTitle"],
Techniques::H32 => vec!["H32.2"],
Techniques::H57 => vec!["H57.2", "H57.3.Lang", "H57.3.XmlLang"],
Techniques::F40 => vec!["F40.2"],
Techniques::F41 => vec!["F41.2"],
_ => vec![""],
}
}
}
3 changes: 3 additions & 0 deletions accessibility-rs/src/engine/rules/wcag_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ pub enum Guideline {
Readable,
/// Make Web pages appear and operate in predictable ways.
Predictable,
/// Provide users enough time to read and use content.
EnoughTime
}

impl Guideline {
pub fn as_str(&self) -> &'static str {
match self {
Guideline::EnoughTime => "Guideline2_2",
Guideline::Navigable => "Guideline2_4",
Guideline::Readable => "Guideline3_1",
Guideline::Predictable => "Guideline3_2",
Expand Down
37 changes: 36 additions & 1 deletion accessibility-rs/src/engine/rules/wcag_rule_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,48 @@ lazy_static! {
(lang.chars().all(|x| x.is_alphanumeric()) && !lang.contains("_") && lang.len() < 12, "3.Lang", Default::default())
}),
])),
// empty titles
("meta", Vec::from([
Rule::new(Techniques::F40, Criteria::Error, Principle::Operable, Guideline::EnoughTime, |_rule, nodes| {
let mut valid = true;

for node in nodes {
let element = node.0;
let meta_refresh = element.attr("http-equiv").unwrap_or_default();
if meta_refresh == "refresh" {
let content = element.attr("content").unwrap_or_default();
if content.contains("url") {
valid = content.starts_with("0;");
}
}
}

(valid, "2", Default::default())
}),
Rule::new(Techniques::F41, Criteria::Error, Principle::Understandable, Guideline::EnoughTime, |_rule, nodes| {
let mut valid = true;

for node in nodes {
let element = node.0;
let meta_refresh = element.attr("http-equiv").unwrap_or_default();
if meta_refresh == "refresh" {
let content = element.attr("content").unwrap_or_default();
if !content.is_empty() {
valid = content == "0";
}
}
}

(valid, "2", Default::default())
}),
])),
// empty titles
("title", Vec::from([
Rule::new(Techniques::H25, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| {
(!nodes.is_empty(), "1.NoTitleEl", Default::default())
}),
Rule::new(Techniques::H25, Criteria::Error, Principle::Understandable, Guideline::Predictable, |_rule, nodes| {
(nodes.is_empty() || nodes[0].0.html().is_empty(), "2", Default::default())
(nodes.is_empty() || nodes[0].0.html().is_empty(), "1.EmptyTitle", Default::default())
}),
])),
// missing form submit
Expand Down
2 changes: 2 additions & 0 deletions accessibility-rs/src/i18n/locales.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ lazy_static! {
(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.", "", "")),
])
};
}
2 changes: 1 addition & 1 deletion accessibility-rs/tests/mocks/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod mock;
pub mod mock;
2 changes: 1 addition & 1 deletion accessibility-rs/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod mocks;
pub mod unit;
pub mod mocks;
53 changes: 52 additions & 1 deletion accessibility-rs/tests/unit/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::mocks::mock;
#[test]
/// missing title element
fn _audit_missing_headers() {
let audit = accessibility_rs::audit(mock::MOCK_WEBSITE_HTML, &mock::MOCK_CSS_RULES, false);
let audit = accessibility_rs::audit(mock::MOCK_WEBSITE_HTML, &"", false);
let mut valid = true;

for x in &audit {
Expand All @@ -17,3 +17,54 @@ fn _audit_missing_headers() {

assert_eq!(valid, false)
}


#[test]
/// meta refresh redirect
fn _audit_meta_refresh() {
let audit = accessibility_rs::audit(r###"<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Do not use this!</title>
<meta http-equiv="refresh"
content="5; url=http://www.example.com/newpage" />
</head>
<body>
<p>
If your browser supports Refresh, you'll be
transported to our
<a href="http://www.example.com/newpage">new site</a>
in 5 seconds, otherwise, select the link manually.
</p>
</body>
</html>"###, &"", false);
let mut valid = true;

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

assert_eq!(valid, false);

let audit = accessibility_rs::audit(r###"<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>HTML Techniques for WCAG 2.0</title>
<meta http-equiv="refresh" content="60" />
</head>
<body>
</body>
</html>"###, &"", false);
let mut valid = true;

for x in &audit {
if x.code == "WCAGAAA.Principle3.Guideline2_2.F41" {
valid = false;
break;
}
}

assert_eq!(valid, false);
}

2 changes: 1 addition & 1 deletion accessibility-rs/tests/unit/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod meta;
pub mod meta;

0 comments on commit aa34614

Please sign in to comment.