Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixrule(meta_refresh_delay | meta_redirect_optional) Fix the rules to algin with ACT -- main-4.x #2162

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions accessibility-checker-engine/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
//{ pattern: 'test/v2/checker/accessibility/rules/label_name_visible_ruleunit/label_offscreen.html', watched: true },
//{ pattern: 'test/v2/checker/accessibility/rules/aria_role_valid_ruleunit/td_attribute_invalid_copy.html', watched: true },
//{ pattern: 'test/v2/checker/accessibility/rules/text_block_heading_ruleunit/Headings-noneUsedEmphasizedText.html', watched: true },
{ pattern: 'test/v2/checker/accessibility/rules/aria_landmark_name_unique_ruleunit/*.html', watched: true },
//{ pattern: 'test/v2/checker/accessibility/rules/meta_redirect_optional_ruleunit/*.html', watched: true },
// { pattern: 'test/v2/checker/accessibility/rules/aria_parent_required_ruleunit/webComponentPass2.html', watched: true },


// { pattern: 'test/**/*_ruleunit/*.html', watched: true },
// { pattern: 'test/**/*_ruleunit/*.htm', watched: true },
{ pattern: 'test/**/*_ruleunit/*.html', watched: true },
{ pattern: 'test/**/*_ruleunit/*.htm', watched: true },
// all files ending in "_test"
// { pattern: 'test/*_test.js', watched: true },
{ pattern: 'test/**/*_test.js', watched: true }
Expand Down
48 changes: 29 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,50 @@ 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>
Loading