Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poll for active tab (and non-busy state) #9

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/wpt/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def bin_path(self):

@property
def pip_path(self):
print(f"pip_path, self.bin_path is {self.bin_path}", file=sys.stderr)
path = which("pip3", path=self.bin_path)
if path is None:
path = which("pip", path=self.bin_path)
Expand Down
1 change: 1 addition & 0 deletions tools/wpt/wpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def create_complete_parser():
# `wpt build-docs` command but we need to look up the environment to
# find out where it's located.
venv_path = os.environ["VIRTUAL_ENV"]
print(f"venv_path: {venv_path}", file=sys.stderr)
venv = virtualenv.Virtualenv(venv_path, True)

for command in commands:
Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/executors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def process_complete(self, url, payload):
def process_action(self, url, payload):
action = payload["action"]
cmd_id = payload["id"]
self.logger.debug(f"Got action: {action}")
self.logger.info(f"Got action: {action}")
try:
action_handler = self.actions[action]
except KeyError as e:
Expand Down
60 changes: 33 additions & 27 deletions tools/wptrunner/wptrunner/executors/executoratspi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@
from gi.repository import Atspi
import json
import threading
import time

import sys

def poll_for_active_tab(root):
active_tab = find_active_tab(root)
iterations = 0
while not active_tab:
time.sleep(0.01)
active_tab = find_active_tab(root)
iterations += 1
spectranaut marked this conversation as resolved.
Show resolved Hide resolved

print(f"found active tab in {iterations} iterations", file=sys.stderr)
return active_tab


def find_active_tab(root):
stack = [root]
root_role = Atspi.Accessible.get_role_name(root)
while stack:
node = stack.pop()

role= Atspi.Accessible.get_role_name(node)
if Atspi.Accessible.get_role_name(node) == "frame":
attributes = Atspi.Accessible.get_attributes(node)
## Helper: list of string relations, get targets for relation?
relationset = Atspi.Accessible.get_relation_set(node)
for relation in relationset:
Expand Down Expand Up @@ -63,32 +80,15 @@ def find_browser(name):


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:
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.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)
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?"
Expand All @@ -100,15 +100,21 @@ def get_accessibility_api_node(self, dom_id):
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:
raise Exception(
f"Could not find the test page within the browser. Did you turn on accessiblity?"
)

active_tab = poll_for_active_tab(self.root)

state_set = Atspi.Accessible.get_state_set(active_tab)
iterations = 0
while Atspi.StateSet.contains(state_set, Atspi.StateType.BUSY):
state_set = Atspi.Accessible.get_state_set(active_tab)
iterations += 1
print(f"active tab no longer busy after {iterations} iterations", file=sys.stderr)
role = Atspi.Accessible.get_role_name(active_tab)
attributes = Atspi.Accessible.get_attributes(active_tab)
print(f"active tab role: {role}; attributes: {attributes}", file=sys.stderr)
document = Atspi.Accessible.get_document_iface(active_tab)
document_attributes = Atspi.Document.get_document_attributes(document)
url = document_attributes["DocURL"]
print(f"document: {document}; attributes: {document_attributes}, url: {url}", file=sys.stderr)
node = find_node(active_tab, dom_id)
if not node:
raise Exception(f"Couldn't find node with id {dom_id}.")
Expand Down
1 change: 1 addition & 0 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
return selector;
};

// NOTE(alice): this is where the action is :D
const create_action = function(name, props) {
let cmd_id;
const action_msg = {type: "action",
Expand Down
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def wait_event(self):
}
try:
command, data = self.command_queue.get(True, 1)
self.logger.debug("Got command: %r" % command)
# self.logger.debug("Got command: %r" % command)
except OSError:
self.logger.error("Got IOError from poll")
return RunnerManagerState.restarting(self.state.subsuite,
Expand Down