Skip to content

Commit 0a9debb

Browse files
[a11y] [Interop] Ignore ARIA roles that lack required parent context
According to the CORE-AAM and HTML-AAM specifications, if an explicit ARIA role token (like listitem or option) is used on an element but it is not contained within its required parent context (e.g., a listitem must be owned by a list; an option must be owned by a listbox), the user agent must ignore the role token and fallback to the next role in the string or the native host element's role. This CL fixes this in Blink accessibility by implementing a context-aware role determination loop: 1. Implement AXObject::HasRequiredParentContext() to verify if listitem or option elements have a valid owner, checking both DOM parent chain traversal (reentrancy-free) and the relation cache (for aria-owns). 2. Implement AXObject::FirstValidRoleInRoleStringWithContext() to iterate through all role attribute tokens and return the first valid role that satisfies its parent context. Ensure empty tokens resulting from whitespace-only roles are safely skipped to avoid fatal C++ DCHECK failures. 3. Update AXObject::DetermineAriaRole() to use the new context-valid role, meaning orphaned listitems and options now cleanly fallback. 4. Add a public AXRelationCache* RelationCache() getter to AXObjectCacheImpl for AXObject's checks. 5. Add a public AXObject::UpdateRole() to re-evaluate and cache the role in place when its required parent context changes dynamically (e.g., via aria-owns reparenting inside MapOwnedChildren()). 6. Support presentational containers. Update DOM parent walking loops in IsOrphanedListItem() and IsOrphanedOption() to safely skip over ignored, presentational wrapper elements (role="presentation" or role="none"). 7. Add C++ unit tests in ax_object_test.cc to cover orphaned role fallbacks, aria-owns allowed roles, and presentational skips. 8. Update focusgroup unittests in ax_node_object_test.cc to wrap explicit listitems in valid role="list" parents so they are compliant and not orphans. 9. Update layout tests in web_tests/accessibility/ by wrapping orphaned option elements in valid role="listbox" containers, and update expected baseline text files. 10. Update DumpAccessibility browser tests in content/test/data/ and focusgroup WPT layout tests in web_tests/ by wrapping orphaned elements in valid list/listbox containers, and regenerate expected test baseline dumps (including Blink, AuraLinux, and Mac platforms). 11. Update AXTreeDistiller browser tests mock HTML to wrap orphaned listitems in a valid list container. This fixes WPT failures in roles-generic.html, list-roles.tentative.html, and listbox-roles.tentative.html. Bug: 341369184, 341362249 Change-Id: I04f17e398e0e61148375a96456899241ba69c969 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7841776 Reviewed-by: David Grogan <dgrogan@chromium.org> Commit-Queue: Lucas Radaelli <lucasradaelli@google.com> Reviewed-by: Jacques Newman <janewman@microsoft.com> Cr-Commit-Position: refs/heads/main@{#1631553}
1 parent 0ab57ba commit 0a9debb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

html/interaction/focus/focusgroup/tentative/ax-role-inference-children.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737

3838
<!-- Explicit child role (should not be overridden) -->
3939
<div id=fgExplicitChild focusgroup="tablist">
40-
<span id="explicitChild" tabindex=0 role=listitem>List Item</span>
40+
<div role="list">
41+
<span id="explicitChild" tabindex=0 role=listitem>List Item</span>
42+
</div>
4143
</div>
4244

4345
<!-- Native child semantics (link) should be preserved -->
@@ -72,7 +74,9 @@
7274

7375
<!-- Button child with explicit role should be preserved -->
7476
<div id=fgButtonExplicit focusgroup="tablist">
75-
<button tabindex=0 id=buttonExplicitChild role="listitem">List Item</button>
77+
<div role="list">
78+
<button tabindex=0 id=buttonExplicitChild role="listitem">List Item</button>
79+
</div>
7680
</div>
7781

7882
<!-- Popup button child should be inferred (menu) -->
@@ -97,7 +101,9 @@
97101

98102
<!-- Popup button with explicit role should be preserved -->
99103
<div id=fgPopupButtonExplicit focusgroup="menubar">
100-
<button tabindex=0 id=popupButtonExplicitChild aria-haspopup="menu" role="listitem">List Item</button>
104+
<div role="list">
105+
<button tabindex=0 id=popupButtonExplicitChild aria-haspopup="menu" role="listitem">List Item</button>
106+
</div>
101107
</div>
102108

103109
<!-- aria-haspopup="listbox" also produces kPopUpButton; should infer menuitem -->

0 commit comments

Comments
 (0)