Skip to content

Commit

Permalink
Update the rules and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Jan 24, 2025
1 parent 83eaa93 commit 3b268f2
Show file tree
Hide file tree
Showing 29 changed files with 712 additions and 31 deletions.
49 changes: 30 additions & 19 deletions accessibility-checker-engine/src/v4/rules/meta_redirect_optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
limitations under the License.
*****************************************************************************/

import { FragmentUtil } from "../../v2/checker/accessibility/util/fragment";
import { CommonUtil } from "../util/CommonUtil";
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { CacheUtil } from "../util/CacheUtil";

export const meta_redirect_optional: Rule = {
id: "meta_redirect_optional",
Expand Down Expand Up @@ -49,39 +48,51 @@ export const meta_redirect_optional: Rule = {
"toolkitLevel": eToolkitLevel.LEVEL_THREE
}],
// Removed ACT bisz58 AAA
act: [{
/**act: [{
"bc659a" : {
"pass": "pass",
"fail": "fail",
"fail_longrefresh": "pass"
}
}],
}],*/
act: [ "bisz58"], // fail even if a page is redirected after more than 20 hours (7200)
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
// JCH - NO OUT OF SCOPE hidden in context

if (ruleContext.getAttribute("http-equiv").toLowerCase() !== 'refresh') {
return null;
}

let doc = ruleContext.ownerDocument;
if (!doc) return;

// check if the rule already passed or failed: only the first one tridders if multiple
if (CacheUtil.getCache(doc, "meta_redirect_optional_done", false))
return null;

let content = ruleContext.getAttribute("content").toLowerCase();
// Invalid content field
if (!content.match(/^\d+$/) && !content.match(/^\d+;/)) {
if (!content || content.trim().length ===0)
return null;

let time:number = -1;
if (content.match(/^\d+$/))
time = parseInt(content);
else if (content.match(/^\d+;/)) {
let pos = content.indexOf(";");
time = parseInt(content.substring(0, pos));
}
// Only check the first one since it takes priority
if (CommonUtil.triggerOnce(FragmentUtil.getOwnerFragment(ruleContext), "meta_redirect_optional", false)) {
// Invalid content field
if (time === -1) {
return null;
}
let timeMatch = content.match(/^(\d+); +[^ ]/);
if (!timeMatch || parseInt(timeMatch[1]) === 0) {

CacheUtil.setCache(doc, "meta_redirect_optional_done", true);
if (time === 0)
return RulePass("pass");
} else {
let time = parseInt(timeMatch[1]);
if (time < 72001) {
return RuleFail("fail");
} else {
return RuleFail("fail_longrefresh");
}
}
else if (time < 72001)
return RuleFail("fail");

return RuleFail("fail_longrefresh");

}
}
42 changes: 32 additions & 10 deletions accessibility-checker-engine/src/v4/rules/meta_refresh_delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,29 @@

import { Rule, RuleResult, RuleContext, RulePotential, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { CacheUtil } from "../util/CacheUtil";

export const meta_refresh_delay: Rule = {
id: "meta_refresh_delay",
context: "dom:meta[http-equiv][content]",
refactor: {
"RPT_Meta_Refresh": {
"Pass_0": "Pass_0",
"Potential_1": "Potential_1"
"Pass_0": "pass",
"Potential_1": "potential_refresh"
}
},
help: {
"en-US": {
"group": "meta_refresh_delay.html",
"Pass_0": "meta_refresh_delay.html",
"Potential_1": "meta_refresh_delay.html"
"pass": "meta_refresh_delay.html",
"potential_refresh": "meta_refresh_delay.html"
}
},
messages: {
"en-US": {
"group": "Pages should not refresh automatically",
"Pass_0": "Rule Passed",
"Potential_1": "Verify page is not being caused to refresh automatically",
"pass": "Pages do not refresh automatically",
"potential_refresh": "Verify page is not being caused to refresh automatically",
}
},
rulesets: [{
Expand All @@ -43,18 +44,39 @@ export const meta_refresh_delay: Rule = {
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_THREE
}],
act: [ "bisz58", "bc659a" ],
//act: [ "bisz58", "bc659a" ],
act: [ "bc659a" ], // pass if a page is redirected after more than 20 hours (7200)
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
if (ruleContext.getAttribute("http-equiv").toLowerCase() !== 'refresh')
return null;

let doc = ruleContext.ownerDocument;
if (!doc) return;

// check if the rule already passed: the first one takes priority
if (CacheUtil.getCache(doc, "meta_refresh_delay_done", false))
return null;

let content = ruleContext.getAttribute("content").toLowerCase();
if (!content || content.trim().length ===0)
return null;

let time:number = -1;
if (content.match(/^\d+$/))
time = parseInt(content);
else if (content.match(/^\d+;/)) {
let pos = content.indexOf(";");
time = parseInt(content.substring(0, pos));
}
// Invalid content field
if (!content.match(/^\d+$/) && !content.match(/^\d+;/)) {
if (time === -1) {
return null;
}
let fail = !content.match(/^\d+; +[^ ]/);
return !fail ? RulePass("Pass_0") : RulePotential("Potential_1");

CacheUtil.setCache(doc, "meta_refresh_delay_done", true);
if (time === 0)
return RulePass("pass");
return RulePotential("potential_refresh");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<html lang="en">
<head>
<meta http-equiv="refresh" content="30" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [
{
"ruleId": "meta_redirect_optional",
"value": [
"INFORMATION",
"FAIL"
],
"path": {
"dom": "/html[1]/head[1]/meta[1]",
"aria": "/document[1]"
},
"reasonId": "fail",
"message": "Check page does not automatically refresh without warning or options",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

<html lang="en">
<head>
<meta http-equiv="refresh" content="72001; URL='https://w3.org'" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [
{
"ruleId": "meta_redirect_optional",
"value": [
"INFORMATION",
"FAIL"
],
"path": {
"dom": "/html[1]/head[1]/meta[1]",
"aria": "/document[1]"
},
"reasonId": "fail_longrefresh",
"message": "Check page does not automatically refresh without warning or options",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

<html lang="en">
<head>
<meta http-equiv="refresh" content="0: https://w3.org" />
<meta http-equiv="refresh" content="72001; https://w3.org" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [
{
"ruleId": "meta_redirect_optional",
"value": [
"INFORMATION",
"FAIL"
],
"path": {
"dom": "/html[1]/head[1]/meta[2]",
"aria": "/document[1]"
},
"reasonId": "fail_longrefresh",
"message": "Check page does not automatically refresh without warning or options",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<html lang="en">
<head>
<meta http-equiv="refresh" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [

]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<html lang="en">
<head>
<meta content="72001" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [

]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<html lang="en">
<head>
<meta http-equiv="refresh" content="0: http://example.com" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [

]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<html lang="en">
<head>
<meta http-equiv="refresh" content="-00.12 foo" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [

]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<html lang="en">
<head>
<meta http-equiv="refresh" content="; 72001" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [

]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<html lang="en">
<head>
<meta http-equiv="refresh" content="" />
</head>
<body data-new-gr-c-s-check-loaded="14.1192.0" data-gr-ext-installed="">
<img src="/WAI/content-assets/wcag-act-rules/test-assets/shared/w3c-logo.png" alt="" aria-labelledby="label"> <span hidden="" id="label">W3C logo</span>

<script>
UnitTest = {
ruleIds: ["meta_redirect_optional"],
results: [

]
}
</script>
</body>

</html>
Loading

0 comments on commit 3b268f2

Please sign in to comment.