From 7d55e7b7a3e55b881bef27b8eba56e21dfa91718 Mon Sep 17 00:00:00 2001 From: James Craig Date: Tue, 7 Mar 2023 05:03:37 +0000 Subject: [PATCH] Bug 1819504 [wpt PR 38758] - Update testdriver to support computedrole/computedlabel, a=testonly Automatic update from web-platform-tests Update testdriver to support computedrole/computedlabel (#38758) Closes https://github.com/web-platform-tests/interop-2023-accessibility-testing/issues/5 Includes basic explicit and implcit role/label tests each for accname (in /accname) and aria role computation (in /aria/role) -- wpt-commits: 790bb1a2ce2d99442f2e72054dd090a4b5b9c29c wpt-pr: 38758 --- testing/web-platform/tests/accname/basic.html | 22 ++++++++++++ .../tests/docs/writing-tests/testdriver.md | 7 ++++ .../tests/resources/testdriver.js | 34 +++++++++++++++++++ .../tests/tools/webdriver/webdriver/client.py | 8 +++++ .../wptrunner/wptrunner/executors/actions.py | 30 ++++++++++++++++ .../wptrunner/executors/executorwebdriver.py | 13 +++++++ .../wptrunner/wptrunner/executors/protocol.py | 21 ++++++++++++ .../wptrunner/wptrunner/testdriver-extra.js | 12 +++++++ .../tests/wai-aria/role/basic.html | 23 +++++++++++++ 9 files changed, 170 insertions(+) create mode 100644 testing/web-platform/tests/accname/basic.html create mode 100644 testing/web-platform/tests/wai-aria/role/basic.html diff --git a/testing/web-platform/tests/accname/basic.html b/testing/web-platform/tests/accname/basic.html new file mode 100644 index 0000000000000..0df93c87996d1 --- /dev/null +++ b/testing/web-platform/tests/accname/basic.html @@ -0,0 +1,22 @@ + + + + + + + +
+

test heading

+ diff --git a/testing/web-platform/tests/docs/writing-tests/testdriver.md b/testing/web-platform/tests/docs/writing-tests/testdriver.md index 11193b147f038..24159e82cc8ec 100644 --- a/testing/web-platform/tests/docs/writing-tests/testdriver.md +++ b/testing/web-platform/tests/docs/writing-tests/testdriver.md @@ -87,6 +87,13 @@ the global scope. ``` +### Accessibility ### +```eval_rst +.. js:autofunction:: test_driver.get_computed_label +.. js:autofunction:: test_driver.get_computed_role + +``` + ### Seure Payment Confirmation ### ```eval_rst .. js:autofunction:: test_driver.set_spc_transaction_mode diff --git a/testing/web-platform/tests/resources/testdriver.js b/testing/web-platform/tests/resources/testdriver.js index 76ae2834fdfb0..f8bb14c6e4851 100644 --- a/testing/web-platform/tests/resources/testdriver.js +++ b/testing/web-platform/tests/resources/testdriver.js @@ -220,6 +220,40 @@ return cookie; }, + /** + * Get Computed Label for an element. + * + * This matches the behaviour of the + * `Get Computed Label + * `_ + * WebDriver command. + * + * @param {Element} element + * @returns {Promise} fulfilled after the computed label is returned, or + * rejected in the cases the WebDriver command errors + */ + get_computed_label: async function(element) { + let label = await window.test_driver_internal.get_computed_label(element); + return label; + }, + + /** + * Get Computed Role for an element. + * + * This matches the behaviour of the + * `Get Computed Label + * `_ + * WebDriver command. + * + * @param {Element} element + * @returns {Promise} fulfilled after the computed role is returned, or + * 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); + return role; + }, + /** * Send keys to an element. * diff --git a/testing/web-platform/tests/tools/webdriver/webdriver/client.py b/testing/web-platform/tests/tools/webdriver/webdriver/client.py index 030e3fc56bede..ba01e1fe8668d 100644 --- a/testing/web-platform/tests/tools/webdriver/webdriver/client.py +++ b/testing/web-platform/tests/tools/webdriver/webdriver/client.py @@ -893,6 +893,14 @@ def shadow_root(self): def attribute(self, name): return self.send_element_command("GET", "attribute/%s" % name) + @command + def get_computed_label(self): + return self.send_element_command("GET", "computedlabel") + + @command + def get_computed_role(self): + return self.send_element_command("GET", "computedrole") + # This MUST come last because otherwise @property decorators above # will be overridden by this. @command diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/actions.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/actions.py index a4b689ba92177..6a4a0b889e4ce 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/actions.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/actions.py @@ -38,6 +38,34 @@ def __call__(self, payload): return self.protocol.cookies.get_all_cookies() +class GetComputedLabelAction: + name = "get_computed_label" + + def __init__(self, logger, protocol): + self.logger = logger + self.protocol = protocol + + def __call__(self, payload): + selector = payload["selector"] + element = self.protocol.select.element_by_selector(selector) + self.logger.debug("Getting computed label for element: %s" % element) + return self.protocol.accessibility.get_computed_label(element) + + +class GetComputedRoleAction: + name = "get_computed_role" + + def __init__(self, logger, protocol): + self.logger = logger + self.protocol = protocol + + def __call__(self, payload): + selector = payload["selector"] + element = self.protocol.select.element_by_selector(selector) + self.logger.debug("Getting computed role for element: %s" % element) + return self.protocol.accessibility.get_computed_role(element) + + class GetNamedCookieAction: name = "get_named_cookie" @@ -253,6 +281,8 @@ def __call__(self, payload): DeleteAllCookiesAction, GetAllCookiesAction, GetNamedCookieAction, + GetComputedLabelAction, + GetComputedRoleAction, SendKeysAction, MinimizeWindowAction, SetWindowRectAction, diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py index 54a571799995b..829eca0deb51f 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executorwebdriver.py @@ -20,6 +20,7 @@ TestharnessProtocolPart, Protocol, SelectorProtocolPart, + AccessibilityProtocolPart, ClickProtocolPart, CookiesProtocolPart, SendKeysProtocolPart, @@ -186,6 +187,17 @@ def elements_by_selector(self, selector): return self.webdriver.find.css(selector) +class WebDriverAccessibilityProtocolPart(AccessibilityProtocolPart): + def setup(self): + self.webdriver = self.parent.webdriver + + def get_computed_label(self, element): + return element.get_computed_label() + + def get_computed_role(self, element): + return element.get_computed_role() + + class WebDriverClickProtocolPart(ClickProtocolPart): def setup(self): self.webdriver = self.parent.webdriver @@ -342,6 +354,7 @@ class WebDriverProtocol(Protocol): implements = [WebDriverBaseProtocolPart, WebDriverTestharnessProtocolPart, WebDriverSelectorProtocolPart, + WebDriverAccessibilityProtocolPart, WebDriverClickProtocolPart, WebDriverCookiesProtocolPart, WebDriverSendKeysProtocolPart, diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/protocol.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/protocol.py index 75e113c71d3f3..af64cc855e212 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/protocol.py +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/protocol.py @@ -299,6 +299,27 @@ def element(self, element): pass + +class AccessibilityProtocolPart(ProtocolPart): + """Protocol part for accessibility introspection""" + __metaclass__ = ABCMeta + + name = "accessibility" + + @abstractmethod + def get_computed_label(self, element): + """Return the computed accessibility label for a specific element. + + :param element: A protocol-specific handle to an element.""" + pass + + def get_computed_role(self, element): + """Return the computed accessibility role for a specific element. + + :param element: A protocol-specific handle to an element.""" + pass + + class CookiesProtocolPart(ProtocolPart): """Protocol part for managing cookies""" __metaclass__ = ABCMeta diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/testdriver-extra.js b/testing/web-platform/tests/tools/wptrunner/wptrunner/testdriver-extra.js index 94a9a97125625..716da040bbc50 100644 --- a/testing/web-platform/tests/tools/wptrunner/wptrunner/testdriver-extra.js +++ b/testing/web-platform/tests/tools/wptrunner/wptrunner/testdriver-extra.js @@ -180,6 +180,18 @@ return create_action("get_all_cookies", {context}); }; + window.test_driver_internal.get_computed_label = function(element) { + const selector = get_selector(element); + const context = get_context(element); + return create_action("get_computed_label", {selector, context}); + }; + + window.test_driver_internal.get_computed_role = function(element) { + const selector = get_selector(element); + const context = get_context(element); + return create_action("get_computed_role", {selector, context}); + }; + window.test_driver_internal.get_named_cookie = function(name, context=null) { return create_action("get_named_cookie", {name, context}); }; diff --git a/testing/web-platform/tests/wai-aria/role/basic.html b/testing/web-platform/tests/wai-aria/role/basic.html new file mode 100644 index 0000000000000..d371aa72dcba6 --- /dev/null +++ b/testing/web-platform/tests/wai-aria/role/basic.html @@ -0,0 +1,23 @@ + + + + + + + +
+

test heading

+