forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend testdriver to add accessibility API testing
- Loading branch information
1 parent
6198cae
commit 5fbd9d7
Showing
14 changed files
with
186 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>core-aam: acacia test using testdriver</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/resources/testdriver-actions.js"></script> | ||
|
||
<body> | ||
<div id=testtest role="button"></div> | ||
<script> | ||
promise_test(async t => { | ||
const node = await test_driver.get_accessibility_api_node('testtest'); | ||
assert_equals(node.role, 'push button'); | ||
}, 'An acacia test'); | ||
</script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import acacia_atspi | ||
import json | ||
from .protocol import (PlatformAccessibilityProtocolPart) | ||
|
||
# When running against chrome family browser: | ||
# 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)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters