Skip to content

Commit

Permalink
Get it all working
Browse files Browse the repository at this point in the history
  • Loading branch information
spectranaut committed May 6, 2024
1 parent 1e40fd0 commit 06b8480
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 23 deletions.
13 changes: 9 additions & 4 deletions core-aam/acacia/test-testdriver.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
<script src="/resources/testdriver-actions.js"></script>

<body>
<div id=test role="button"></div>
<div id=testtest role="button"></div>
<script>
promise_test(async t => {
const node = await test_driver.get_accessibility_api_node('test');
const node = await test_driver.get_accessibility_api_node('testtest');
console.log(node);
assert_equals(node, 'push button');
//assert_equals(node.role, 'push button');

// TODO: what to do with this error?
if (node.error) {
console.log(node.error);
}

assert_equals(node.role, 'push button');
}, 'An acacia test');
</script>
</body>
5 changes: 3 additions & 2 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,9 @@
* @returns {Promise} Fullfilled with object representing accessibilty node
* rejected in the cases of failures
*/
get_accessibility_api_node: function(dom_id) {
return window.test_driver_internal.get_accessibility_api_node(dom_id);
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);
}
};

Expand Down
91 changes: 91 additions & 0 deletions tools/wptrunner/wptrunner/executors/executoracacia.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import acacia_atspi
import json
from .protocol import (PlatformAccessibilityProtocolPart)

# Notes:
# self.parent is WebDriverProtocol
# self.parent.webdriver is webdriver

def findActiveTab(root):
stack = [root]
while stack:
node = stack.pop()

if node.getRoleName() == 'frame':
relations = node.getRelations()
if 'ATSPI_RELATION_EMBEDS' in relations:
index = relations.index('ATSPI_RELATION_EMBEDS')
target = node.getTargetForRelationAtIndex(index)
print(target.getRoleName())
print(target.getName())
return target
continue

for i in range(node.getChildCount()):
child = node.getChildAtIndex(i)
stack.append(child)

return None

def serialize_node(node):
node_dictionary = {}
node_dictionary['role'] = node.getRoleName()
node_dictionary['name'] = node.getName()
node_dictionary['description'] = node.getDescription()
node_dictionary['states'] = sorted(node.getStates())
node_dictionary['interfaces'] = sorted(node.getInterfaces())
node_dictionary['attributes'] = sorted(node.getAttributes())

# TODO: serialize other attributes

return node_dictionary

def find_node(root, dom_id):
stack = [root]
while stack:
node = stack.pop()

attributes = node.getAttributes()
for attribute_pair in attributes:
[attribute, value] = attribute_pair.split(':', 1)
if attribute == 'id':
if value == dom_id:
return node

for i in range(node.getChildCount()):
child = node.getChildAtIndex(i)
stack.append(child)

return None

class AcaciaPlatformAccessibilityProtocolPart(PlatformAccessibilityProtocolPart):
def setup(self):
self.product_name = self.parent.product_name
self.root = None
self.errormsg = None

self.root = acacia_atspi.findRootAtspiNodeForName(self.product_name);
if self.root.isNull():
error = f"Cannot find root accessibility node for {self.product_name} - did you turn on accessibility?"
print(error)
self.errormsg = error


def get_accessibility_api_node(self, dom_id):
if self.root.isNull():
return json.dumps({"role": self.errormsg})

active_tab = findActiveTab(self.root)

# This will fail sometimes when accessibilty is off.
if not active_tab or active_tab.isNull():
return json.dumps({"role": "couldn't find active tab"})

# This fails sometimes for unknown reasons.
node = find_node(active_tab, dom_id)
if not node or node.isNull():
return json.dumps({"role": "couldn't find the node with that ID"})

return json.dumps(serialize_node(node))


6 changes: 5 additions & 1 deletion tools/wptrunner/wptrunner/executors/executormarionette.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
WdspecExecutor,
get_pages,
strip_server)

from .protocol import (AccessibilityProtocolPart,
ActionSequenceProtocolPart,
AssertsProtocolPart,
Expand All @@ -48,6 +49,7 @@
DevicePostureProtocolPart,
merge_dicts)

from .executoracacia import (AcaciaPlatformAccessibilityProtocolPart)

def do_delayed_imports():
global errors, marionette, Addons, WebAuthn
Expand Down Expand Up @@ -782,12 +784,14 @@ class MarionetteProtocol(Protocol):
MarionetteDebugProtocolPart,
MarionetteAccessibilityProtocolPart,
MarionetteVirtualSensorProtocolPart,
MarionetteDevicePostureProtocolPart]
MarionetteDevicePostureProtocolPart,
AcaciaPlatformAccessibilityProtocolPart]

def __init__(self, executor, browser, capabilities=None, timeout_multiplier=1, e10s=True, ccov=False):
do_delayed_imports()

super().__init__(executor, browser)
self.product_name = browser.product_name
self.marionette = None
self.marionette_port = browser.marionette_port
self.capabilities = capabilities
Expand Down
21 changes: 5 additions & 16 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Protocol,
SelectorProtocolPart,
AccessibilityProtocolPart,
PlatformAccessibilityProtocolPart,
ClickProtocolPart,
CookiesProtocolPart,
SendKeysProtocolPart,
Expand All @@ -39,6 +38,8 @@
DevicePostureProtocolPart,
merge_dicts)

from .executoracacia import (AcaciaPlatformAccessibilityProtocolPart)

from webdriver.client import Session
from webdriver import error

Expand Down Expand Up @@ -218,17 +219,6 @@ def get_computed_role(self, element):
return element.get_computed_role()


# TODO: this is not actually a webdriver protocol, so, where to put it.. exactly?
class WebDriverPlatformAccessibilityProtocolPart(PlatformAccessibilityProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver # self.parent is WebDriverProtocol
self.platform = self.webdriver.capabilities['platformName'] # 'linux'
self.browser_name = self.webdriver.capabilities['browserName'] # 'chrome' for both chrome and chromium, unfortunately;

def get_accessibility_api_node(self, id):
return "Test"


class WebDriverClickProtocolPart(ClickProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver
Expand Down Expand Up @@ -460,7 +450,6 @@ class WebDriverProtocol(Protocol):
WebDriverTestharnessProtocolPart,
WebDriverSelectorProtocolPart,
WebDriverAccessibilityProtocolPart,
WebDriverPlatformAccessibilityProtocolPart,
WebDriverClickProtocolPart,
WebDriverCookiesProtocolPart,
WebDriverSendKeysProtocolPart,
Expand All @@ -475,12 +464,12 @@ class WebDriverProtocol(Protocol):
WebDriverFedCMProtocolPart,
WebDriverDebugProtocolPart,
WebDriverVirtualSensorPart,
WebDriverDevicePostureProtocolPart]
WebDriverDevicePostureProtocolPart,
AcaciaPlatformAccessibilityProtocolPart]

def __init__(self, executor, browser, capabilities, **kwargs):
# Now we have browser.product_name! Does that help?

super().__init__(executor, browser)
self.product_name = browser.product_name
self.capabilities = capabilities
if hasattr(browser, "capabilities"):
if self.capabilities is None:
Expand Down

0 comments on commit 06b8480

Please sign in to comment.