From c5966bbdcb5002befb15c49ce373ba5bbb60b54f Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Fri, 6 Dec 2024 16:29:11 +0900 Subject: [PATCH] LibWeb: Add window.internals.getComputedRole(element) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds a window.internals.getComputedLabel(element) function, for use in testing ARIA-related behavior. It also patches the imported WPT testdriver.js script’s test_driver.get_computed_role(element) function to call our window.internals.getComputedRole(element) function. --- Libraries/LibWeb/Internals/Internals.cpp | 8 ++++++++ Libraries/LibWeb/Internals/Internals.h | 1 + Libraries/LibWeb/Internals/Internals.idl | 1 + .../LibWeb/Text/input/wpt-import/resources/testdriver.js | 6 +++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cpp index ed53bc4b75..0d4bd0269b 100644 --- a/Libraries/LibWeb/Internals/Internals.cpp +++ b/Libraries/LibWeb/Internals/Internals.cpp @@ -203,6 +203,14 @@ void Internals::expire_cookies_with_time_offset(WebIDL::LongLong seconds) internals_page().client().page_did_expire_cookies_with_time_offset(AK::Duration::from_seconds(seconds)); } +// NOLINTNEXTLINE(readability-convert-member-functions-to-static +String Internals::get_computed_role(DOM::Element& element) +{ + if (auto role = element.role_or_default(); role.has_value()) + return MUST(String::from_utf8(ARIA::role_name(role.value()))); + return String {}; +} + String Internals::get_computed_label(DOM::Element& element) { auto& active_document = internals_window().associated_document(); diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.h index 3a7549150d..0b2770b394 100644 --- a/Libraries/LibWeb/Internals/Internals.h +++ b/Libraries/LibWeb/Internals/Internals.h @@ -48,6 +48,7 @@ public: void enable_cookies_on_file_domains(); void expire_cookies_with_time_offset(WebIDL::LongLong seconds); + String get_computed_role(DOM::Element& element); String get_computed_label(DOM::Element& element); static u16 get_echo_server_port(); diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idl index 87116d6604..c39a71c7b6 100644 --- a/Libraries/LibWeb/Internals/Internals.idl +++ b/Libraries/LibWeb/Internals/Internals.idl @@ -38,6 +38,7 @@ interface Internals { undefined enableCookiesOnFileDomains(); undefined expireCookiesWithTimeOffset(long long seconds); + DOMString getComputedRole(Element element); DOMString getComputedLabel(Element element); unsigned short getEchoServerPort(); }; diff --git a/Tests/LibWeb/Text/input/wpt-import/resources/testdriver.js b/Tests/LibWeb/Text/input/wpt-import/resources/testdriver.js index 2d1a89690c..3c78d97829 100644 --- a/Tests/LibWeb/Text/input/wpt-import/resources/testdriver.js +++ b/Tests/LibWeb/Text/input/wpt-import/resources/testdriver.js @@ -250,7 +250,11 @@ * rejected in the cases the WebDriver command errors */ get_computed_role: async function(element) { - let role = await window.test_driver_internal.get_computed_role(element); + // XXX: Ladybird-specific change: Upstream WPT calls + // window.test_driver_internal.get_computed_role(element) here, + // but we’ve changed that to our Ladybird-specific + // window.internals.getComputedRole(el). + let role = await window.internals.getComputedRole(element); return role; },