From 8a14630839771cf613420070a8feb5bc78135359 Mon Sep 17 00:00:00 2001 From: Valerie Young Date: Wed, 29 May 2024 12:15:34 -0700 Subject: [PATCH 1/2] Clean up example --- ...-testdriver.html => all_apis_example.html} | 23 +++++++++++-------- resources/testdriver.js | 8 ++++--- .../wptrunner/executors/executoratspi.py | 16 ++++--------- 3 files changed, 23 insertions(+), 24 deletions(-) rename core-aam/acacia/{test-testdriver.html => all_apis_example.html} (50%) diff --git a/core-aam/acacia/test-testdriver.html b/core-aam/acacia/all_apis_example.html similarity index 50% rename from core-aam/acacia/test-testdriver.html rename to core-aam/acacia/all_apis_example.html index cffa0f8b48dbbf..38e2e3cca5b031 100644 --- a/core-aam/acacia/test-testdriver.html +++ b/core-aam/acacia/all_apis_example.html @@ -1,6 +1,6 @@ -core-aam: acacia test using testdriver +core-aam: role button @@ -8,18 +8,21 @@ -
+
click me
diff --git a/resources/testdriver.js b/resources/testdriver.js index 9bc0db5e208c96..ec892af499a9b5 100644 --- a/resources/testdriver.js +++ b/resources/testdriver.js @@ -1076,8 +1076,10 @@ * rejected in the cases of failures. */ get_accessibility_api_node: async function(dom_id) { - let jsonresult = await window.test_driver_internal.get_accessibility_api_node(dom_id); - return JSON.parse(jsonresult); + return window.test_driver_internal.get_accessibility_api_node(dom_id) + .then((jsonresult) => { + return JSON.parse(jsonresult); + }); } }; @@ -1269,7 +1271,7 @@ }, async get_accessibility_api_node(dom_id) { - throw new Error("not implemented, whoops!"); + throw new Error("get_accessibility_api_node() is not available."); } }; })(); diff --git a/tools/wptrunner/wptrunner/executors/executoratspi.py b/tools/wptrunner/wptrunner/executors/executoratspi.py index d0a2cdea210573..7bda5a7457963b 100644 --- a/tools/wptrunner/wptrunner/executors/executoratspi.py +++ b/tools/wptrunner/wptrunner/executors/executoratspi.py @@ -5,11 +5,6 @@ import threading from .protocol import (PlatformAccessibilityProtocolPart) - -import traceback -import time - - def find_active_tab(root): stack = [root] while stack: @@ -31,13 +26,11 @@ def find_active_tab(root): def serialize_node(node): node_dictionary = {} + node_dictionary['API'] = 'atspi'; node_dictionary['role'] = Atspi.Accessible.get_role_name(node) node_dictionary['name'] = Atspi.Accessible.get_name(node) node_dictionary['description'] = Atspi.Accessible.get_description(node) - # TODO: serialize other attributes - # states, interfaces, attributes, etc. - return node_dictionary def find_node(root, dom_id): @@ -99,18 +92,19 @@ def setup(self, product_name): def get_accessibility_api_node(self, dom_id): if not self.found_browser: - return json.dumps({"role": "couldn't find browser"}) + raise Exception(f"Couldn't find browser {self.product_name}. Did you turn on accessibility?") if not self.load_complete: self.atspi_listener_thread.join() active_tab = find_active_tab(self.root) if not active_tab: - return json.dumps({"role": "couldn't find active tab"}) + raise Exception(f"Could not find the test page within the browser. Did you turn on accessiblity?") node = find_node(active_tab, dom_id) if not node: - return json.dumps({"role": "couldn't find the node with that ID"}) + raise Exception(f"Couldn't find node with id {dom_id}.") + return json.dumps(serialize_node(node)) From c80d37864f72945f54526950aa66ae17640b1a05 Mon Sep 17 00:00:00 2001 From: Valerie Young Date: Wed, 29 May 2024 12:27:52 -0700 Subject: [PATCH 2/2] python black formatter --- .../wptrunner/executors/executoracacia.py | 14 +++--- .../wptrunner/executors/executoratspi.py | 49 +++++++++++-------- .../wptrunner/executors/executoraxapi.py | 2 +- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/tools/wptrunner/wptrunner/executors/executoracacia.py b/tools/wptrunner/wptrunner/executors/executoracacia.py index 988230b05adca8..acafbc3625ea69 100644 --- a/tools/wptrunner/wptrunner/executors/executoracacia.py +++ b/tools/wptrunner/wptrunner/executors/executoracacia.py @@ -1,14 +1,15 @@ -from .protocol import (PlatformAccessibilityProtocolPart) +from .protocol import PlatformAccessibilityProtocolPart from sys import platform + linux = False mac = False if platform == "linux": - linux = True - from .executoratspi import * + linux = True + from .executoratspi import * if platform == "darwin": - mac = True - from .executoraxapi import * + mac = True + from .executoraxapi import * class AcaciaPlatformAccessibilityProtocolPart(PlatformAccessibilityProtocolPart): @@ -22,6 +23,5 @@ def setup(self): self.impl = AXAPIExecutorImpl() self.impl.setup(self.product_name) - def get_accessibility_api_node(self, dom_id): - return self.impl.get_accessibility_api_node(dom_id) \ No newline at end of file + return self.impl.get_accessibility_api_node(dom_id) diff --git a/tools/wptrunner/wptrunner/executors/executoratspi.py b/tools/wptrunner/wptrunner/executors/executoratspi.py index 7bda5a7457963b..cd0cae5503b386 100644 --- a/tools/wptrunner/wptrunner/executors/executoratspi.py +++ b/tools/wptrunner/wptrunner/executors/executoratspi.py @@ -1,21 +1,23 @@ import gi + gi.require_version("Atspi", "2.0") from gi.repository import Atspi import json import threading -from .protocol import (PlatformAccessibilityProtocolPart) +from .protocol import PlatformAccessibilityProtocolPart + def find_active_tab(root): stack = [root] while stack: node = stack.pop() - if Atspi.Accessible.get_role_name(node) == 'frame': + if Atspi.Accessible.get_role_name(node) == "frame": ## Helper: list of string relations, get targets for relation? relationset = Atspi.Accessible.get_relation_set(node) for relation in relationset: - if relation.get_relation_type() == Atspi.RelationType.EMBEDS: - return relation.get_target(0) + if relation.get_relation_type() == Atspi.RelationType.EMBEDS: + return relation.get_target(0) contiue for i in range(Atspi.Accessible.get_child_count(node)): @@ -24,22 +26,24 @@ def find_active_tab(root): return None + def serialize_node(node): node_dictionary = {} - node_dictionary['API'] = 'atspi'; - node_dictionary['role'] = Atspi.Accessible.get_role_name(node) - node_dictionary['name'] = Atspi.Accessible.get_name(node) - node_dictionary['description'] = Atspi.Accessible.get_description(node) + node_dictionary["API"] = "atspi" + node_dictionary["role"] = Atspi.Accessible.get_role_name(node) + node_dictionary["name"] = Atspi.Accessible.get_name(node) + node_dictionary["description"] = Atspi.Accessible.get_description(node) return node_dictionary + def find_node(root, dom_id): stack = [root] while stack: node = stack.pop() attributes = Atspi.Accessible.get_attributes(node) - if 'id' in attributes and attributes['id'] == dom_id: + if "id" in attributes and attributes["id"] == dom_id: return node for i in range(Atspi.Accessible.get_child_count(node)): @@ -48,6 +52,7 @@ def find_node(root, dom_id): return None + def find_browser(name): desktop = Atspi.get_desktop(0) child_count = Atspi.Accessible.get_child_count(desktop) @@ -59,53 +64,55 @@ def find_browser(name): return (None, None) -class AtspiExecutorImpl(): +class AtspiExecutorImpl: def start_atspi_listener(self): self._event_listener = Atspi.EventListener.new(self.handle_event) self._event_listener.register("document:load-complete") Atspi.event_main() - def handle_event(self, e): app = Atspi.Accessible.get_application(e.source) app_name = Atspi.Accessible.get_name(app) - if (self.full_app_name == app_name and e.any_data): + if self.full_app_name == app_name and e.any_data: self.load_complete = True self._event_listener.deregister("document:load-complete") Atspi.event_quit() def setup(self, product_name): self.product_name = product_name - self.full_app_name = '' + self.full_app_name = "" self.root = None self.found_browser = False self.load_complete = False self.atspi_listener_thread = threading.Thread(target=self.start_atspi_listener) - (self.root, self.full_app_name) = find_browser(self.product_name); + (self.root, self.full_app_name) = find_browser(self.product_name) if self.root: self.found_browser = True self.atspi_listener_thread.start() else: - print(f"Cannot find root accessibility node for {self.product_name} - did you turn on accessibility?") + print( + f"Cannot find root accessibility node for {self.product_name} - did you turn on accessibility?" + ) def get_accessibility_api_node(self, dom_id): if not self.found_browser: - raise Exception(f"Couldn't find browser {self.product_name}. Did you turn on accessibility?") + raise Exception( + f"Couldn't find browser {self.product_name}. Did you turn on accessibility?" + ) if not self.load_complete: - self.atspi_listener_thread.join() + self.atspi_listener_thread.join() active_tab = find_active_tab(self.root) if not active_tab: - raise Exception(f"Could not find the test page within the browser. Did you turn on accessiblity?") + raise Exception( + f"Could not find the test page within the browser. Did you turn on accessiblity?" + ) node = find_node(active_tab, dom_id) if not node: raise Exception(f"Couldn't find node with id {dom_id}.") - return json.dumps(serialize_node(node)) - - diff --git a/tools/wptrunner/wptrunner/executors/executoraxapi.py b/tools/wptrunner/wptrunner/executors/executoraxapi.py index 5663f116698a4f..571aa525c36092 100644 --- a/tools/wptrunner/wptrunner/executors/executoraxapi.py +++ b/tools/wptrunner/wptrunner/executors/executoraxapi.py @@ -15,6 +15,7 @@ kAXValueAXErrorType, ) + class AXAPIExecutorImpl: def setup(self, product_name): self.product_name = product_name @@ -33,4 +34,3 @@ def get_application_by_name(self, name): def get_accessibility_api_node(self, dom_id): app = self.get_application_by_name(self.product_name) -