Skip to content

Commit

Permalink
add test cases for li and update rule logic #1301
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed May 1, 2023
1 parent 73ded94 commit 502033f
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 13 deletions.
17 changes: 12 additions & 5 deletions accessibility-checker-engine/src/v2/aria/ARIADefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1906,11 +1906,6 @@ export class ARIADefinitions {
validRoles: null,
globalAriaAttributesValid: true
},
"li": {
implicitRole: ["listitem"],
validRoles: ["menuitem", "menuitemcheckbox", "menuitemradio", "none", "option", "presentation", "radio", "separator", "tab", "treeitem"],
globalAriaAttributesValid: true
},
"link": {
implicitRole: null,
validRoles: null,
Expand Down Expand Up @@ -2471,6 +2466,18 @@ export class ARIADefinitions {
globalAriaAttributesValid: true
}
},
"li": {
"child-of-list-role": {
implicitRole: ['listitem'],
validRoles: null,
globalAriaAttributesValid: true
},
"no-child-of-list-role": {
implicitRole: ['listitem'],
validRoles: ["any"],
globalAriaAttributesValid: true
}
},
"section": {
"with-name": {
implicitRole: ["region"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2552,14 +2552,21 @@ export class RPTUtil {
RPTUtil.attributeNonEmpty(ruleContext, "list") ? tagProperty = specialTagProperties["text-with-list"] : tagProperty = specialTagProperties["text-no-list"];
}
break;
case "li":
specialTagProperties = ARIADefinitions.documentConformanceRequirementSpecialTags["li"];
if (ruleContext.parentElement && RPTUtil.hasRoleInSemantics(ruleContext.parentElement, "list"))
tagProperty = specialTagProperties["child-of-list-role"];
else
tagProperty = specialTagProperties["no-child-of-list-role"];
break;
case "section":
name = ARIAMapper.computeName(ruleContext);
if (name && name.trim().length > 0) {
tagProperty = specialTagProperties["with-name"];
} else {
tagProperty = specialTagProperties["without-name"];
}
break;
break;
case "select":
specialTagProperties = ARIADefinitions.documentConformanceRequirementSpecialTags["select"];
if (ruleContext.hasAttribute("multiple") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,16 @@ <h1 id="contents1">Button 1 Label</h1>
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
"FAIL"
],
"path": {
"dom": "/html[1]/body[1]/ol[1]/li[1]",
"aria": "/document[1]/document[1]/list[2]/listitem[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"reasonId": "Fail_1",
"message": "The ARIA role 'tab, separator' is not valid for the element <li>",
"messageArgs": [
"listitem, tab, separator",
"tab, separator",
"li"
],
"apiArgs": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1293,14 +1293,14 @@ <h2 role="heading" aria-label="h2_El" id="h2_El2" aria-level="1"> Heading level
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"FAIL"
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/div[1]/li[1]",
"aria": "/document[1]/generic[1]/region[1]/slider[9]"
},
"reasonId": "Fail_1",
"message": "The ARIA role 'slider' is not valid for the element <li>",
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"slider",
"li"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
/******************************************************************************
Copyright:: 2020- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
-->

<html lang="en" id="id-32">

<head id="id-29">
<title id="id-36">Li Element</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>

<body id="id-9" aria-atomic="true">
<ul>
<li> normal use of an li element</li>
</ul>

<ul>
<li role="listitem"> redundant use of role 'listitem'</li>
</ul>

<ul role='none'>
<li role="button">allowed because ul is no longer a 'list'</li>
</ul>

<ul role='menu'>
<li role='button'>not allowed due to violation of menu hierarchy</button>
</ul>

<div role='tablist'>
<ul role='presentation'>
<li role=button>not allowed due to violation of tablist hierarchy</li>
</ul>
</div>

<article>
<li role='note'>allowed, li is not part of list and article role doesn't have a hierarchy restraint</li>
</article>

<script type="text/javascript">
UnitTest = {
ruleIds: ["aria_semantics_role" ],
results: [
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/ul[2]/li[1]",
"aria": "/document[1]/generic[1]/list[2]/listitem[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"listitem",
"li"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/ul[3]",
"aria": "/document[1]/generic[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"none",
"ul"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/ul[3]/li[1]",
"aria": "/document[1]/generic[1]/button[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"button",
"li"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/ul[4]",
"aria": "/document[1]/generic[1]/menu[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"menu",
"ul"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/ul[4]/li[1]",
"aria": "/document[1]/generic[1]/menu[1]/button[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"button",
"li"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/div[1]",
"aria": "/document[1]/generic[1]/tablist[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"tablist",
"div"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/div[1]/ul[1]",
"aria": "/document[1]/generic[1]/tablist[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"presentation",
"ul"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/div[1]/ul[1]/li[1]",
"aria": "/document[1]/generic[1]/tablist[1]/button[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"button",
"li"
],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "aria_semantics_role",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/article[1]/li[1]",
"aria": "/document[1]/generic[1]/article[1]/note[1]"
},
"reasonId": "Pass_0",
"message": "Rule Passed",
"messageArgs": [
"note",
"li"
],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>

</html>

0 comments on commit 502033f

Please sign in to comment.