Skip to content

Commit

Permalink
update the rules #1676
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Oct 9, 2023
1 parent be536bd commit a34b87c
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1369,22 +1369,6 @@ export class RPTUtil {
return walkNode;
}

/**
* return all the ancestor element names of the given element
* @param element
*/
public static getAncestorNames(element) {
if (!element) return null;
let ancestors = [];
let walkNode = DOMWalker.parentNode(element);
while (walkNode !== null) {
if (walkNode.nodeType === 1)
ancestors.push(walkNode.nodeName.toLowerCase());
walkNode = DOMWalker.parentNode(walkNode);
}
return ancestors;
}

// return true if element1 and element2 are siblings
public static isSibling(element1, element2) {
if (element1 && element2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Rule, RuleResult, RuleContext, RulePass, RuleContextHierarchy, RulePote
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { VisUtil } from "../../v2/dom/VisUtil";
import { DOMMapper } from "../../v2/dom/DOMMapper";
import { DOMUtil } from "../../v2/dom/DOMUtil";

export let element_tabbable_unobscured: Rule = {
id: "element_tabbable_unobscured",
Expand Down Expand Up @@ -48,7 +49,7 @@ export let element_tabbable_unobscured: Rule = {
return null;

const nodeName = ruleContext.nodeName.toLocaleLowerCase();

//ignore certain elements
if (RPTUtil.getAncestor(ruleContext, ["pre", "code", "script", "meta"]) !== null
|| nodeName === "body" || nodeName === "html" )
Expand All @@ -71,42 +72,33 @@ export let element_tabbable_unobscured: Rule = {
if (!win) {
return null;
}

var cStyle = win.getComputedStyle(ruleContext);
if (cStyle === null)
return null;

let zindex = cStyle.zIndex;
if (!zindex || zindex === 'auto')
zindex = "0";

const ancestors = RPTUtil.getAncestorNames(ruleContext);
let ignoreList = nodeName +' *, ' + nodeName +', script';
if (ancestors) {
ancestors.forEach(ancestor=> {
if (!["html", "body"].includes(ancestor))
ignoreList += ", " + ancestor;
});
}
var elems = doc.querySelectorAll('body *:not(' + ignoreList +')');

var elems = doc.querySelectorAll('body *:not(script)');
if (!elems || elems.length == 0)
return;

console.log("node="+nodeName +", id=" + ruleContext.getAttribute("id") +", bounds=" + JSON.stringify(bounds)+", zindex="+zindex);
const mapper : DOMMapper = new DOMMapper();
let violations = [];
elems.forEach(elem => {
// Skip hidden
if (VisUtil.isNodeVisible(elem)) {
if (VisUtil.isNodeVisible(elem) && !ruleContext.contains(elem) && !elem.contains(ruleContext)) {
const bnds = mapper.getBounds(elem);
var zStyle = win.getComputedStyle(elem);
var zStyle = win.getComputedStyle(elem);
let z_index;
if (zStyle === null)
z_index = 0;
else {
z_index = zStyle.zIndex;
if (!z_index || !Number.isInteger(z_index))
z_index = zStyle.zIndex;
if (!z_index || isNaN(z_index))
z_index = "0";
}
} console.log("element="+elem.nodeName +", id=" + elem.getAttribute("id") +", bnds=" + JSON.stringify(bnds)+", z_index="+z_index);
if (bnds.height !== 0 && bnds.width !== 0
&& bnds.top <= bounds.top && bnds.left <= bounds.left && bnds.top + bnds.height >= bounds.top + bounds.height
&& bnds.left + bnds.height >= bounds.left + bounds.width && parseInt(zindex) <= parseInt(z_index))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!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">

<head>
<title>RPT Test Suite</title>
<style>
div {
position: absolute;
width: 75px;
height: 75px;
border-radius: 10px;
color: white;
padding: 5px;
text-align: left;
}

#first {
width: 175px;
height: 175px;
z-index: 3;
background-color: #FF5C35;
top: 10px;
left: 10px;
}

#second {
z-index: 2;
background-color: #192733;
top: 30px;
left: 30px;
}

</style>
</head>

<body>

<div id="first" tabindex="0">1</div>
<div id="second" tabindex="0">2</div>

<script>
UnitTest = {
ruleIds: ["element_tabbable_unobscured"],
results: [
{
"ruleId": "element_tabbable_unobscured",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/div[1]",
"aria": "/document[1]"
},
"reasonId": "pass",
"message": "The element is not entirely covered by other content",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "element_tabbable_unobscured",
"value": [
"INFORMATION",
"POTENTIAL"
],
"path": {
"dom": "/html[1]/body[1]/div[2]",
"aria": "/document[1]"
},
"reasonId": "potential_obscured",
"message": "Confirm that when the element receives focus, it is not covered or, if covered by user action, can be uncovered without moving focus",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!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">

<head>
<title>RPT Test Suite</title>
<style>
div {
position: absolute;
width: 75px;
height: 75px;
border-radius: 10px;
color: white;
padding: 5px;
text-align: left;
}

#first {
width: 175px;
height: 175px;
z-index: 2;
background-color: #FF5C35;
top: 10px;
left: 10px;
}

#second {
z-index: 3;
background-color: #192733;
top: 30px;
left: 30px;
}

</style>
</head>

<body>

<div id="first" tabindex="0">1</div>
<div id="second" tabindex="0">2</div>

<script>
UnitTest = {
ruleIds: ["element_tabbable_unobscured"],
results: [
{
"ruleId": "element_tabbable_unobscured",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/div[1]",
"aria": "/document[1]"
},
"reasonId": "pass",
"message": "The element is not entirely covered by other content",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
},
{
"ruleId": "element_tabbable_unobscured",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]/body[1]/div[2]",
"aria": "/document[1]"
},
"reasonId": "pass",
"message": "The element is not entirely covered by other content",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>

</html>

0 comments on commit a34b87c

Please sign in to comment.