Skip to content

Commit

Permalink
update the rule and test cases #2090
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Nov 25, 2024
1 parent d0ea23f commit 6fbb518
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { AriaUtil } from "../util/AriaUtil";
import { CommonUtil } from "../util/CommonUtil";
import { VisUtil } from "../util/VisUtil";
import { ARIADefinitions } from "../../v2/aria/ARIADefinitions";
import { AccNameUtil } from "../util/AccNameUtil";

export const aria_accessiblename_exists: Rule = {
Expand All @@ -33,14 +31,23 @@ export const aria_accessiblename_exists: Rule = {
"en-US": {
"pass": "An accessible name is provided for the element",
"fail_no_accessible_name": "Element <{0}> with \"{1}\" role has no accessible name",
"fail_no_accessible_name_image": "Element <{0}> with \"{1}\" role has no accessible name",
"group": "Elements with certain roles should have accessible names"
}
},
rulesets: [{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["4.1.2"],
"level": eRulePolicy.RECOMMENDATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_no_accessible_name"]
},
{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["ARIA"],
"level": eRulePolicy.RECOMMENDATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_no_accessible_name_image"]
}],
act: [],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
Expand All @@ -50,8 +57,8 @@ export const aria_accessiblename_exists: Rule = {
if (VisUtil.isNodeHiddenFromAT(ruleContext)) return null;

let nodeName = ruleContext.nodeName.toLocaleLowerCase();
// svg element is handled in svg_graphics)labbelled rule
if (nodeName === 'svg') return;
// svg element is handled in svg_graphics_labbelled rule and image rules
if (nodeName === 'svg' || nodeName === 'img') return;

// when table element with a caption as first child
if (nodeName === 'table'
Expand All @@ -69,9 +76,11 @@ export const aria_accessiblename_exists: Rule = {
let role = AriaUtil.getResolvedRole(ruleContext);

const name_pair = AccNameUtil.computeAccessibleName(ruleContext);
if (!name_pair || !name_pair.name || name_pair.name.trim().length === 0)
if (!name_pair || !name_pair.name || name_pair.name.trim().length === 0) {
if (role === 'img' || role === 'image')
return RuleFail("fail_no_accessible_name_image", [ruleContext.nodeName.toLowerCase(), role]);
return RuleFail("fail_no_accessible_name", [ruleContext.nodeName.toLowerCase(), role]);

}
return RulePass("pass");
}
}
13 changes: 11 additions & 2 deletions accessibility-checker-engine/src/v4/rules/img_alt_null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ export const img_alt_null: Rule = {
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["1.1.1"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
}],
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["fail_decorative"]
},
{
"id": ["IBM_Accessibility", "IBM_Accessibility_next", "WCAG_2_1", "WCAG_2_0", "WCAG_2_2"],
"num": ["ARIA"],
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE,
reasonCodes: ["potential_aria_override"]
}
],
act: [{"46ca7f": {"potential_aria_override": "fail"}}],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html lang="en">

<head>
<title>ACT Test case</title>
</head>

<body>

<div role="img" style="width:72px; height:48px; background-image: url(/test-assets/shared/w3c-logo.png)"></div>

<script>
UnitTest = {
ruleIds: ["aria_accessiblename_exists"],
results: [
{
"ruleId": "aria_accessiblename_exists",
"value": [
"INFORMATION",
"FAIL"
],
"path": {
"dom": "/html[1]/body[1]/div[1]",
"aria": "/document[1]/img[1]"
},
"reasonId": "fail_no_accessible_name_image",
"message": "Element <div> with \"img\" role has no accessible name",
"messageArgs": [
"div",
"img"
],
"apiArgs": [],
"category": "Accessibility"
}
]
};
</script>
</body>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,7 @@
UnitTest = {
ruleIds: ["aria_accessiblename_exists"],
results: [
{
"ruleId": "aria_accessiblename_exists",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/img[1]",
"aria": "/document[1]/img[1]"
},
"reasonId": "pass",
"message": "An accessible name is provided for the element",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}

]
}
</script>
Expand Down

0 comments on commit 6fbb518

Please sign in to comment.