Skip to content

Commit

Permalink
Merge branch 'master' into htmlReport-2019-nam
Browse files Browse the repository at this point in the history
  • Loading branch information
nam-singh authored Sep 5, 2024
2 parents 8ef1235 + e186953 commit 023a651
Show file tree
Hide file tree
Showing 223 changed files with 99,809 additions and 240 deletions.
3 changes: 2 additions & 1 deletion accessibility-checker-engine/src/v4/api/IRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export type Issue = RuleResult & {
ruleTime: number,
message: string,
bounds?: Bounds,
snippet: string
snippet: string,
level?: string
}

export type RuleContextHierarchy = { [namespace: string] : IMapResult[] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getDeprecatedAriaRoles, getDeprecatedAriaAttributes, getRolesUndefinedB

export const aria_accessiblename_exists: Rule = {
id: "aria_accessiblename_exists",
context: "aria:columnheader, aria:form, aria:heading, aria:rowheader, aria:table, aria:graphics-document,aria:graphics-symbol, aria:img, doc-backlink, doc-biblioentry, doc-biblioref, doc-glossref, doc-noteref, doc-pagebreak",
context: "aria:columnheader, aria:form, aria:heading, aria:rowheader, aria:table, aria:graphics-document,aria:graphics-symbol, doc-backlink, doc-biblioentry, doc-biblioref, doc-glossref, doc-noteref, doc-pagebreak",
help: {
"en-US": {
"pass": "aria_accessiblename_exists.html",
Expand Down Expand Up @@ -51,8 +51,6 @@ export const aria_accessiblename_exists: Rule = {
let nodeName = ruleContext.nodeName.toLocaleLowerCase();
// svg element is handled in svg_graphics)labbelled rule
if (nodeName === 'svg') return;
// img element handled in img_alt_valid
if (nodeName === "img" && ruleContext.hasAttribute("alt")) return RulePass("pass");

// when table element with a caption as first child
if (nodeName === 'table'
Expand Down
10 changes: 7 additions & 3 deletions accessibility-checker-engine/src/v4/rules/aria_img_labelled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { RPTUtil } from "../../v2/checker/accessibility/util/legacy";
import { VisUtil } from "../../v2/dom/VisUtil";

export let aria_img_labelled: Rule = {
id: "aria_img_labelled",
context: "aria:img",
context: "aria:img, aria:image",
refactor: {
"HAAC_Aria_ImgAlt": {
"Pass_0": "Pass_0",
Expand Down Expand Up @@ -62,6 +61,11 @@ export let aria_img_labelled: Rule = {
// If no role, this is implicit, and covered by WCAG20_Img_HasAlt
return null;
}

let nodeName = ruleContext.nodeName.toLocaleLowerCase();
// svg and img elements are handled in svg_graphics_labbelled and img_alt_valid rules
if (nodeName === 'svg' || nodeName === 'img') return;

/* removed the role check role= presentation since if an element has role=img, then there needs to be a check for alt attribute regardless of the presecne of role=presentation
if (RPTUtil.hasRole(ruleContext, "presentation") || RPTUtil.hasRole(ruleContext, "none")){
return RulePass(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getCache, setCache } from "../util/CacheUtil";
import { FragmentUtil } from "../../v2/checker/accessibility/util/fragment";
import { RPTUtil } from "../../v2/checker/accessibility/util/legacy";

export let element_orientation_unlocked: Rule = {
export const element_orientation_unlocked: Rule = {
id: "element_orientation_unlocked",
context: "dom:*",
help: {
Expand Down Expand Up @@ -54,7 +54,7 @@ export let element_orientation_unlocked: Rule = {
if (RPTUtil.getAncestor(ruleContext, ["script", "meta", "title"]))
return null;

const nodeName = ruleContext.nodeName.toLowerCase();
const nodeName = ruleContext.nodeName.toLowerCase();

// cache the orientation result for all the elements in the page
let doc = FragmentUtil.getOwnerFragment(ruleContext) as any;
Expand All @@ -68,17 +68,25 @@ export let element_orientation_unlocked: Rule = {
let media_transforms = [];
Object.keys(orientationTransforms).forEach(key => {
Object.keys(orientationTransforms[key]).forEach(tag => {
if (Object.keys(orientationTransforms[key][tag]).length > 0 && selectorMatchesElem(ruleContext, tag))
media_transforms.push(orientationTransforms[key][tag].transform);
if (Object.keys(orientationTransforms[key][tag]).length > 0 && selectorMatchesElem(ruleContext, tag)) {
if (orientationTransforms[key][tag].transform)
media_transforms.push(orientationTransforms[key][tag].transform);
else
media_transforms.push(orientationTransforms[key][tag]);
}
});
});

// no match, the element is not in media orientation transform
if (media_transforms.length === 0) return null;

let ret = [];
for (let i=0; i < media_transforms.length; i++) {
const media_transform = media_transforms[i];
let media_transform = media_transforms[i];
if (typeof media_transform === 'object')
for(var key in media_transform)
media_transform = key +"(" + media_transform[key] +")";

let containsRotation = false;
['rotate', 'rotate3d', 'rotateZ', 'matrix', 'matrix3d'].forEach(rotation => {
if (media_transform.includes(rotation)) containsRotation = true;
Expand All @@ -104,11 +112,13 @@ export let element_orientation_unlocked: Rule = {
*/
if (definedStyle['transform']) {
const page_degree = getRotationDegree(definedStyle['transform']);
degree -= page_degree;
// rotate is additive
degree += page_degree;
}

// When degree is 1 turn (360 degree), it is not considered an orientation lock
// allow 1 degree floating range for the right angle
if ((degree > 89 && degree < 91) || (degree > -91 && degree < -89))
if (Math.abs(degree - 360) % 360 > 1)
ret.push(RuleFail("fail_locked", [nodeName]));
else ret.push(RulePass("pass"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { Rule, RuleResult, RuleContext, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { VisUtil } from "../../v2/dom/VisUtil";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { RPTUtil } from "../../v2/checker/accessibility/util/legacy";
import { VisUtil } from "../../v2/dom/VisUtil";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { Rule, RuleResult, RuleContext, RulePotential, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { VisUtil } from "../../v2/dom/VisUtil";

Expand Down
28 changes: 16 additions & 12 deletions accessibility-checker-engine/src/v4/rules/img_alt_null.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RulePotential, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { RPTUtil } from "../../v2/checker/accessibility/util/legacy";
import { VisUtil } from "../../v2/dom/VisUtil";
Expand All @@ -21,21 +21,23 @@ export let img_alt_null: Rule = {
context: "dom:img[alt]",
refactor: {
"WCAG20_Img_TitleEmptyWhenAltNull": {
"Pass_0": "Pass_0",
"Fail_1": "Fail_1"}
"Pass_0": "pass",
"Fail_1": "fail_decorative"}
},
help: {
"en-US": {
"Pass_0": "img_alt_null.html",
"Fail_1": "img_alt_null.html",
"pass": "img_alt_null.html",
"fail_decorative": "img_alt_null.html",
"potential_aria_override": "img_alt_null.html",
"group": "img_alt_null.html"
}
},
messages: {
"en-US": {
"Pass_0": "Rule Passed",
"Fail_1": "The image 'alt' attribute is empty, but the 'title' attribute is not empty",
"group": "When the image 'alt' attribute is empty, the 'title' attribute must also be empty"
"pass": "Neither 'aria' nor 'title' attributes are used for the decorative image",
"fail_decorative": "The image 'alt' attribute is empty, but the 'title' attribute is not empty",
"potential_aria_override": "The image 'alt' attribute is empty, but the 'aria' label is not empty and overrides the 'alt' attribute",
"group": "When the intent is to mark an image as decorative with an empty 'alt' attribute, the 'aria' or 'title' attributes should not be used"
}
},
rulesets: [{
Expand All @@ -44,7 +46,7 @@ export let img_alt_null: Rule = {
"level": eRulePolicy.VIOLATION,
"toolkitLevel": eToolkitLevel.LEVEL_ONE
}],
act: [],
act: [{"46ca7f": {"potential_aria_override": "fail"}}],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
//skip the rule
Expand All @@ -53,10 +55,12 @@ export let img_alt_null: Rule = {
return null;
}
// We have a title, but alt is empty
if (RPTUtil.attributeNonEmpty(ruleContext, "title")) {
return RuleFail("Fail_1");
if (RPTUtil.getAriaLabel(ruleContext).length > 0) {
return RulePotential("potential_aria_override");
} else if (RPTUtil.attributeNonEmpty(ruleContext, "title")) {
return RuleFail("fail_decorative");
} else {
return RulePass("Pass_0");
return RulePass("pass");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { NodeWalker, RPTUtil } from "../../v2/checker/accessibility/util/legacy";

Expand Down
2 changes: 1 addition & 1 deletion accessibility-checker-engine/src/v4/rules/img_alt_valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*****************************************************************************/

import { Rule, RuleResult, RuleFail, RuleContext, RulePotential, RuleManual, RulePass, RuleContextHierarchy } from "../api/IRule";
import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { RPTUtil } from "../../v2/checker/accessibility/util/legacy";
import { VisUtil } from "../../v2/dom/VisUtil";
Expand Down
8 changes: 5 additions & 3 deletions accessibility-checker-engine/src/v4/util/CSSUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ export function getMediaOrientationTransform(doc: Document) {

// Iterate through all of the stylesheets and rules
for (let ssIndex = 0; ssIndex < doc.styleSheets.length; ++ssIndex) {
const sheet = doc.styleSheets[ssIndex] as CSSStyleSheet;
const sheet = doc.styleSheets[ssIndex] as CSSStyleSheet;
try {
if (sheet && sheet.cssRules) {
for (let rIndex = 0; rIndex < sheet.cssRules.length; ++rIndex) {
const sheetRule = sheet.cssRules[rIndex];
const sheetRule = sheet.cssRules[rIndex];
if (4 /* CSSRule.MEDIA_RULE */ === sheetRule.MEDIA_RULE) {
const rule = sheetRule as CSSMediaRule;
if (rule && rule.media) {
const mediaList = rule.media;
const mediaList = rule.media;
for (let i = 0; i < mediaList.length; i++) {
let elem_transforms = orientationTransforms[mediaList.item(i).toLocaleLowerCase()];
if (!elem_transforms) elem_transforms = {};
Expand All @@ -225,6 +225,8 @@ export function getMediaOrientationTransform(doc: Document) {
} else {
transforms[key] = styles[key];
}
} else if (key.toLocaleLowerCase() === "rotate") {
transforms[key] = styles[key];
}
}
elem_transforms[selector] = transforms;
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">

<!--
/******************************************************************************
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> Test Suite</title>
</head>

<body>

<img id="image1" src="../support/nav_home.gif" usemap="#HomeNav_Map" alt="Home Navigation Bar" />


<script type="text/javascript">
UnitTest = {
ruleIds: ["aria_accessiblename_exists"],
results: [

]
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html lang="en">
<html id='html' lang="en">
<head>
<title>Page with some content</title>
<style>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<html id='html1' lang="en">
<head>
<title>Page with some content</title>
<style>
@media (orientation: portrait) {
html {
rotate: 180deg;
width: min(100vw, 100vh);
height: min(100vw, 100vh);
}
}
</style>
</head>
<body><div style="font-size:28;">
Page Content</div>
<script>
UnitTest = {
ruleIds: ["element_orientation_unlocked"],
results: [
{
"ruleId": "element_orientation_unlocked",
"value": [
"INFORMATION",
"FAIL"
],
"path": {
"dom": "/html[1]",
"aria": "/document[1]"
},
"reasonId": "fail_locked",
"message": "The element <html> is restricted to either landscape or portrait orientation using CSS transform property",
"messageArgs": [
"html"
],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<html lang="en">
<head>
<title>Page with some content</title>
<style>
@media (orientation: portrait) {
html {
rotate: 0turn;
}
}
</style>
</head>
<body>
<main>
Page Content
</main>
<script>
UnitTest = {
ruleIds: ["element_orientation_unlocked"],
results: [
{
"ruleId": "element_orientation_unlocked",
"value": [
"INFORMATION",
"PASS"
],
"path": {
"dom": "/html[1]",
"aria": "/document[1]"
},
"reasonId": "pass",
"message": "The element is not restricted to either landscape or portrait orientation using CSS transform property",
"messageArgs": [],
"apiArgs": [],
"category": "Accessibility"
}
]
}
</script>
</body>
</html>
Loading

0 comments on commit 023a651

Please sign in to comment.