Skip to content

Commit

Permalink
more test cases #1676
Browse files Browse the repository at this point in the history
  • Loading branch information
shunguoy committed Oct 10, 2023
1 parent a34b87c commit 854a623
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,37 @@ export let element_tabbable_unobscured: Rule = {
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 = [];
let violations = [];
let before = true;
elems.forEach(elem => {
if (VisUtil.isNodeVisible(elem) && !ruleContext.contains(elem) && !elem.contains(ruleContext)) {
const bnds = mapper.getBounds(elem);
var zStyle = win.getComputedStyle(elem);
let z_index;
if (zStyle === null)
z_index = 0;
else {
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))
violations.push(elem);
}
/**
* the nodes returned from querySelectorAll is in document order
* if z-index is not defined, then the node rendered next will overlay the node previously
*/
if (ruleContext.contains(elem)) {
//the next node in elems will be after the target node (ruleContext).
before = false;
} else {
if (VisUtil.isNodeVisible(elem) && !elem.contains(ruleContext)) {
const bnds = mapper.getBounds(elem);
var zStyle = win.getComputedStyle(elem);
let z_index;
if (zStyle === null)
z_index = 0;
else {
z_index = zStyle.zIndex;
if (!z_index || isNaN(z_index))
z_index = "0";
}
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
&& (before ? parseInt(zindex) < parseInt(z_index): parseInt(zindex) <= parseInt(z_index)))
violations.push(elem);
}
}
});

if (violations.length > 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!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;
}

#second {
width: 175px;
height: 175px;
background-color: #FF5C35;
top: 10px;
left: 10px;
}

#first {
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",
"POTENTIAL"
],
"path": {
"dom": "/html[1]/body[1]/div[1]",
"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"
},
{
"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>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
text-align: left;
}

#first {
#second {
width: 175px;
height: 175px;
z-index: 3;
Expand All @@ -42,7 +42,7 @@
left: 10px;
}

#second {
#first {
z-index: 2;
background-color: #192733;
top: 30px;
Expand All @@ -65,14 +65,14 @@
"ruleId": "element_tabbable_unobscured",
"value": [
"INFORMATION",
"PASS"
"POTENTIAL"
],
"path": {
"dom": "/html[1]/body[1]/div[1]",
"aria": "/document[1]"
},
"reasonId": "pass",
"message": "The element is not entirely covered by other content",
"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"
Expand All @@ -81,14 +81,14 @@
"ruleId": "element_tabbable_unobscured",
"value": [
"INFORMATION",
"POTENTIAL"
"PASS"
],
"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",
"reasonId": "pass",
"message": "The element is not entirely covered by other content",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!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;
background-color: #FF5C35;
top: 10px;
left: 10px;
}

#second {
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>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
text-align: left;
}

#first {
#second {
width: 175px;
height: 175px;
z-index: 2;
Expand All @@ -42,7 +42,7 @@
left: 10px;
}

#second {
#first {
z-index: 3;
background-color: #192733;
top: 30px;
Expand Down

0 comments on commit 854a623

Please sign in to comment.