From ead3af0163d7763bd59604bde962513d8f482844 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Thu, 19 Dec 2024 23:34:18 +0900 Subject: [PATCH] LibWeb: Ignore name-required landmark roles which lack accessible names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change implements the role-checking requirement from the ARIA spec at https://w3c.github.io/aria/#document-handling_author-errors_roles that the “form” and “region” roles are required to have accessible names — and that if they don’t have accessible names as required, UAs must treat them as if they’d not been specified at all. --- Libraries/LibWeb/ARIA/ARIAMixin.cpp | 8 +++ .../wai-aria/role/fallback-roles.txt | 17 ++++++ .../wpt-import/wai-aria/role/form-roles.txt | 7 +++ .../wpt-import/wai-aria/role/region-roles.txt | 7 +++ .../wai-aria/role/fallback-roles.html | 57 +++++++++++++++++++ .../wpt-import/wai-aria/role/form-roles.html | 28 +++++++++ .../wai-aria/role/region-roles.html | 27 +++++++++ 7 files changed, 151 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/fallback-roles.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/form-roles.txt create mode 100644 Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/region-roles.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/wai-aria/role/fallback-roles.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/wai-aria/role/form-roles.html create mode 100644 Tests/LibWeb/Text/input/wpt-import/wai-aria/role/region-roles.html diff --git a/Libraries/LibWeb/ARIA/ARIAMixin.cpp b/Libraries/LibWeb/ARIA/ARIAMixin.cpp index 2e47d36acf8..e4860be465f 100644 --- a/Libraries/LibWeb/ARIA/ARIAMixin.cpp +++ b/Libraries/LibWeb/ARIA/ARIAMixin.cpp @@ -130,6 +130,14 @@ Optional ARIAMixin::role_from_role_attribute_value() const } continue; } + // https://w3c.github.io/aria/#document-handling_author-errors_roles + // Certain landmark roles require names from authors. In situations where an author has not specified names for + // these landmarks, it is considered an authoring error. The user agent MUST treat such elements as if no role + // had been provided. If a valid fallback role had been specified, or if the element had an implicit ARIA role, + // then user agents would continue to expose that role, instead. + if ((role == ARIA::Role::form || role == ARIA::Role::region) + && to_element()->accessible_name(to_element()->document(), DOM::ShouldComputeRole::No).value().is_empty()) + continue; // 4. Use the first such substring in textual order that matches the name of a non-abstract WAI-ARIA role. if (!is_abstract_role(*role)) return *role; diff --git a/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/fallback-roles.txt b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/fallback-roles.txt new file mode 100644 index 00000000000..d1b2ac197dc --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/fallback-roles.txt @@ -0,0 +1,17 @@ +Harness status: OK + +Found 12 tests + +12 Pass +Pass fallback role w/ region with no label +Pass fallback role w/ region with label +Pass aria 1.1 switch role w/ fallback to aria 1.0 checkbox role +Pass div[role=button] ignoring invalid foo role token +Pass unknown[role=button] ignoring invalid foo role token +Pass button ignoring single invalid role token +Pass button ignoring multiple invalid role tokens +Pass div[role=button] ignoring invalid foo role token including punctuation-contaminated known link role +Pass div[role=button] ignoring invalid unicode diacritics etc on link and group role tokens +Pass div[role=button] ignoring tab char +Pass div[role=button] ignoring line break +Pass div[role=button] ignoring braille whitespace char \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/form-roles.txt b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/form-roles.txt new file mode 100644 index 00000000000..c8cdee8fc77 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/form-roles.txt @@ -0,0 +1,7 @@ +Harness status: OK + +Found 2 tests + +2 Pass +Pass form without label +Pass form with label \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/region-roles.txt b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/region-roles.txt new file mode 100644 index 00000000000..c595e2db224 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/wai-aria/role/region-roles.txt @@ -0,0 +1,7 @@ +Harness status: OK + +Found 2 tests + +2 Pass +Pass region without label +Pass region with label \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/wai-aria/role/fallback-roles.html b/Tests/LibWeb/Text/input/wpt-import/wai-aria/role/fallback-roles.html new file mode 100644 index 00000000000..af29edcd2e9 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/wai-aria/role/fallback-roles.html @@ -0,0 +1,57 @@ + + + + Fallback Role Verification Tests + + + + + + + + + +

Tests 8.1 Role Attribute role token list selection and 9.1 Roles - handling author errors.

+ + + + + + +
x
+ + +
x
+ + + x + + +