From 1976f5a23eed3d254460ac00e87a9029c4a8c4be Mon Sep 17 00:00:00 2001 From: Shunguo Date: Tue, 22 Oct 2024 17:39:40 -0500 Subject: [PATCH] fix merge error #1974 --- .../v4/rules/element_orientation_unlocked.ts | 2 +- .../src/v4/rules/img_alt_null.ts | 9 +- .../src/v4/util/CSSUtil.ts | 93 ++++++++++--------- .../aria_imge.html | 17 +++- 4 files changed, 69 insertions(+), 52 deletions(-) diff --git a/accessibility-checker-engine/src/v4/rules/element_orientation_unlocked.ts b/accessibility-checker-engine/src/v4/rules/element_orientation_unlocked.ts index 9cb72847a..5c1095b41 100644 --- a/accessibility-checker-engine/src/v4/rules/element_orientation_unlocked.ts +++ b/accessibility-checker-engine/src/v4/rules/element_orientation_unlocked.ts @@ -68,7 +68,7 @@ export const 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 && CSSUtil.selectorMatchesElem(ruleContext, tag)) + if (Object.keys(orientationTransforms[key][tag]).length > 0 && CSSUtil.selectorMatchesElem(ruleContext, tag)) { if (orientationTransforms[key][tag].transform) media_transforms.push(orientationTransforms[key][tag].transform); else diff --git a/accessibility-checker-engine/src/v4/rules/img_alt_null.ts b/accessibility-checker-engine/src/v4/rules/img_alt_null.ts index 31dc475b2..4b108d034 100644 --- a/accessibility-checker-engine/src/v4/rules/img_alt_null.ts +++ b/accessibility-checker-engine/src/v4/rules/img_alt_null.ts @@ -11,10 +11,11 @@ limitations under the License. *****************************************************************************/ -import { Rule, RuleResult, RuleFail, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule"; +import { Rule, RuleResult, RuleFail, RulePotential, RuleContext, RulePass, RuleContextHierarchy } from "../api/IRule"; import { eRulePolicy, eToolkitLevel } from "../api/IRule"; -import { CommonUtil } from "../util/CommonUtil"; import { VisUtil } from "../util/VisUtil"; +import { AriaUtil } from "../util/AriaUtil"; +import { CommonUtil } from "../util/CommonUtil"; export const img_alt_null: Rule = { id: "img_alt_null", @@ -55,9 +56,9 @@ export const img_alt_null: Rule = { return null; } // We have a title, but alt is empty - if (RPTUtil.getAriaLabel(ruleContext).length > 0) { + if (AriaUtil.getAriaLabel(ruleContext).length > 0) { return RulePotential("potential_aria_override"); - } else if (RPTUtil.attributeNonEmpty(ruleContext, "title")) { + } else if (CommonUtil.attributeNonEmpty(ruleContext, "title")) { return RuleFail("fail_decorative"); } else { return RulePass("pass"); diff --git a/accessibility-checker-engine/src/v4/util/CSSUtil.ts b/accessibility-checker-engine/src/v4/util/CSSUtil.ts index 22afe4cbf..887e0d492 100644 --- a/accessibility-checker-engine/src/v4/util/CSSUtil.ts +++ b/accessibility-checker-engine/src/v4/util/CSSUtil.ts @@ -239,62 +239,63 @@ export class CSSUtil { } } -/** - * Returns the media query defined for the document - * - * - * @param {Document} doc - */ -export function getMediaOrientationTransform(doc: Document) { - let orientationTransforms = {} - - // Iterate through all of the stylesheets and rules - for (let ssIndex = 0; ssIndex < doc.styleSheets.length; ++ssIndex) { - 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]; - if (4 /* CSSRule.MEDIA_RULE */ === sheetRule.MEDIA_RULE) { - const rule = sheetRule as CSSMediaRule; - if (rule && 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 = {}; - let styleRules = rule.cssRules; - for (let i = 0; i < styleRules.length; ++i) { - if (1 /* CSSRule.STYLE_RULE */ === styleRules[i].STYLE_RULE) { - const styleRule = styleRules[i] as CSSStyleRule; - const selector = styleRule.selectorText; - if (selector) { - let transforms = {}; - const styles = styleRule.style; - for (let s=0; s < styles.length; ++s) { - const key = styles[s]; - if (key.toLocaleLowerCase() === "transform") { - if (key === "all" && styles[key]) { - delete transforms[key]; - break; - } else { + /** + * Returns the media query defined for the document + * + * + * @param {Document} doc + */ + public static getMediaOrientationTransform(doc: Document) { + let orientationTransforms = {} + + // Iterate through all of the stylesheets and rules + for (let ssIndex = 0; ssIndex < doc.styleSheets.length; ++ssIndex) { + 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]; + if (4 /* CSSRule.MEDIA_RULE */ === sheetRule.MEDIA_RULE) { + const rule = sheetRule as CSSMediaRule; + if (rule && rule.media) { + const mediaList = rule.media; + for (let i = 0; i < mediaList.length; i++) { + if (!mediaList.item(i)) continue; + let elem_transforms = orientationTransforms[mediaList.item(i).toLocaleLowerCase()]; + if (!elem_transforms) elem_transforms = {}; + let styleRules = rule.cssRules; + for (let i = 0; i < styleRules.length; ++i) { + if (1 /* CSSRule.STYLE_RULE */ === styleRules[i].STYLE_RULE) { + const styleRule = styleRules[i] as CSSStyleRule; + const selector = styleRule.selectorText; + if (selector) { + let transforms = {}; + const styles = styleRule.style; + for (let s = 0; s < styles.length; ++s) { + const key = styles[s]; + if (key.toLocaleLowerCase() === "transform") { + if (key === "all" && styles[key]) { + delete transforms[key]; + break; + } else { + transforms[key] = styles[key]; + } + } else if (key.toLocaleLowerCase() === "rotate") { transforms[key] = styles[key]; } - } else if (key.toLocaleLowerCase() === "rotate") { - transforms[key] = styles[key]; + elem_transforms[selector] = + transforms; } - elem_transforms[selector] = - transforms; } } + if (mediaList.item(i)) + orientationTransforms[mediaList.item(i).toLocaleLowerCase()] = elem_transforms; } - orientationTransforms[ - mediaList.item(i).toLocaleLowerCase() - ] = elem_transforms; } } } } - } + } } catch (err) { if ( !err.toString().includes("Cannot access rules") && diff --git a/accessibility-checker-engine/test/v2/checker/accessibility/rules/aria_accessiblename_exists_ruleunit/aria_imge.html b/accessibility-checker-engine/test/v2/checker/accessibility/rules/aria_accessiblename_exists_ruleunit/aria_imge.html index b5a5f36c3..7a06f4120 100755 --- a/accessibility-checker-engine/test/v2/checker/accessibility/rules/aria_accessiblename_exists_ruleunit/aria_imge.html +++ b/accessibility-checker-engine/test/v2/checker/accessibility/rules/aria_accessiblename_exists_ruleunit/aria_imge.html @@ -33,7 +33,22 @@ 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" + } ] }