Skip to content

Commit d529b66

Browse files
committed
AX: add Mac client accessibility test infrastructure for bounding boxes
https://bugs.webkit.org/show_bug.cgi?id=307651 rdar://170208415 Reviewed by Tyler Wilcock. Fill in more AccessibilityUIElementClientMac code, including some numeric attributes and the fields to get an element's bounding box, and add some test coverage for those. A small fix was needed to ensure isolated tree mode was fully enabled for the bounding box calculations to work. Tests: accessibility/mac/client/div-bounds.html accessibility/mac/client/hierarchical-level.html accessibility/mac/client/range-values.html * LayoutTests/accessibility/mac/client/div-bounds-expected.txt: Added. * LayoutTests/accessibility/mac/client/div-bounds.html: Added. * LayoutTests/accessibility/mac/client/hierarchical-level-expected.txt: Added. * LayoutTests/accessibility/mac/client/hierarchical-level.html: Added. * LayoutTests/accessibility/mac/client/range-values-expected.txt: Added. * LayoutTests/accessibility/mac/client/range-values.html: Added. * Source/WebCore/testing/js/WebCoreTestSupport.cpp: (WebCoreTestSupport::setAccessibilityIsolatedTreeEnabled): * Source/WebCore/testing/js/WebCoreTestSupport.h: * Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm: (WTR::AccessibilityController::updateIsolatedTreeMode): * Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementClientMac.h: * Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementClientMac.mm: (WTR::axCopyAttributeValueAsNumber): (WTR::axCopyAttributeValueAsPoint): (WTR::axCopyAttributeValueAsSize): (WTR::AccessibilityUIElementClientMac::getNumberAttribute const): (WTR::AccessibilityUIElementClientMac::hierarchicalLevel const): (WTR::AccessibilityUIElementClientMac::minValue): (WTR::AccessibilityUIElementClientMac::maxValue): (WTR::AccessibilityUIElementClientMac::x): (WTR::AccessibilityUIElementClientMac::y): (WTR::AccessibilityUIElementClientMac::width): (WTR::AccessibilityUIElementClientMac::height): * Tools/WebKitTestRunner/TestController.cpp: * Tools/WebKitTestRunner/TestController.h: Canonical link: https://commits.webkit.org/307432@main
1 parent a924f9f commit d529b66

13 files changed

Lines changed: 371 additions & 0 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Test x, y, width, height via the client accessibility APIs.
2+
3+
webArea role: AXRole: AXWebArea
4+
webArea childrenCount: 2
5+
div1 role: AXRole: AXGroup
6+
div2 role: AXRole: AXGroup
7+
div1 width: 200
8+
div1 height: 80
9+
div2 width: 120
10+
div2 height: 60
11+
x difference (div2.x - div1.x): 50
12+
y difference (div2.y - div1.y): 130
13+
14+
PASS successfullyParsed is true
15+
16+
TEST COMPLETE
17+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<html>
2+
<head>
3+
<script src="../../../resources/accessibility-helper.js"></script>
4+
<script src="../../../resources/js-test.js"></script>
5+
<style>
6+
body { margin: 0; padding: 0; }
7+
.box {
8+
position: absolute;
9+
border: none;
10+
background: #ccc;
11+
}
12+
#div1 {
13+
left: 100px;
14+
top: 50px;
15+
width: 200px;
16+
height: 80px;
17+
}
18+
#div2 {
19+
left: 150px;
20+
top: 180px;
21+
width: 120px;
22+
height: 60px;
23+
}
24+
</style>
25+
</head>
26+
<body>
27+
28+
<div id="div1" class="box" role="group">First div</div>
29+
<div id="div2" class="box" role="group">Second div</div>
30+
31+
<script>
32+
var output = "Test x, y, width, height via the client accessibility APIs.\n\n";
33+
34+
if (window.accessibilityController) {
35+
window.jsTestIsAsync = true;
36+
accessibilityController.setForceInitialFrameCaching(true);
37+
accessibilityController.setClientAccessibilityMode(true);
38+
39+
setTimeout(async function() {
40+
await waitForElements([
41+
(element) => element.role.includes("AXGroup"),
42+
]);
43+
44+
var webArea = accessibilityController.rootElement.childAtIndex(0);
45+
output += `webArea role: ${webArea.role}\n`;
46+
output += `webArea childrenCount: ${webArea.childrenCount}\n`;
47+
48+
var div1 = webArea.childAtIndex(0);
49+
output += `div1 role: ${div1.role}\n`;
50+
51+
var div2 = webArea.childAtIndex(1);
52+
output += `div2 role: ${div2.role}\n`;
53+
54+
// Check exact sizes
55+
output += `div1 width: ${div1.width}\n`;
56+
output += `div1 height: ${div1.height}\n`;
57+
output += `div2 width: ${div2.width}\n`;
58+
output += `div2 height: ${div2.height}\n`;
59+
60+
// Check relative positions (div2.x - div1.x should be 50, div2.y - div1.y should be 130)
61+
// Absolute positions depend on window location so only test relative differences
62+
var xDiff = div2.x - div1.x;
63+
var yDiff = div2.y - div1.y;
64+
output += `x difference (div2.x - div1.x): ${xDiff}\n`;
65+
output += `y difference (div2.y - div1.y): ${yDiff}\n`;
66+
67+
debug(output);
68+
document.getElementById("div1").hidden = true;
69+
document.getElementById("div2").hidden = true;
70+
finishJSTest();
71+
}, 0);
72+
}
73+
</script>
74+
</body>
75+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Test hierarchicalLevel via the client accessibility APIs.
2+
3+
Tree role: AXRole: AXOutline
4+
Item 1 hierarchicalLevel: 0
5+
Item 2 hierarchicalLevel: 1
6+
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<html>
2+
<head>
3+
<script src="../../../resources/accessibility-helper.js"></script>
4+
<script src="../../../resources/js-test.js"></script>
5+
</head>
6+
<body>
7+
8+
<ul id="tree" role="tree" tabindex="0">
9+
<li id="item1" role="treeitem" aria-level="1">Level 1 item</li>
10+
<li id="item2" role="treeitem" aria-level="2">Level 2 item</li>
11+
</ul>
12+
13+
<script>
14+
var output = "Test hierarchicalLevel via the client accessibility APIs.\n\n";
15+
16+
if (window.accessibilityController) {
17+
window.jsTestIsAsync = true;
18+
accessibilityController.setClientAccessibilityMode(true);
19+
20+
setTimeout(async function() {
21+
await waitForElements([
22+
(element) => element.role.includes("AXOutline"),
23+
]);
24+
25+
var tree = accessibilityController.rootElement.childAtIndex(0).childAtIndex(0);
26+
output += `Tree role: ${tree.role}\n`;
27+
28+
var item1 = tree.childAtIndex(0);
29+
output += `Item 1 hierarchicalLevel: ${item1.hierarchicalLevel}\n`;
30+
31+
var item2 = tree.childAtIndex(1);
32+
output += `Item 2 hierarchicalLevel: ${item2.hierarchicalLevel}\n`;
33+
34+
debug(output);
35+
document.getElementById("tree").hidden = true;
36+
finishJSTest();
37+
}, 0);
38+
}
39+
</script>
40+
</body>
41+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Test minValue and maxValue via the client accessibility APIs.
2+
3+
Slider role: AXRole: AXSlider
4+
Slider minValue: 10
5+
Slider maxValue: 100
6+
7+
PASS successfullyParsed is true
8+
9+
TEST COMPLETE
10+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<html>
2+
<head>
3+
<script src="../../../resources/accessibility-helper.js"></script>
4+
<script src="../../../resources/js-test.js"></script>
5+
</head>
6+
<body>
7+
8+
<input type="range" id="slider" min="10" max="100" value="50">
9+
10+
<script>
11+
var output = "Test minValue and maxValue via the client accessibility APIs.\n\n";
12+
13+
if (window.accessibilityController) {
14+
window.jsTestIsAsync = true;
15+
accessibilityController.setClientAccessibilityMode(true);
16+
17+
setTimeout(async function() {
18+
await waitForElements([
19+
(element) => element.role.includes("AXSlider"),
20+
]);
21+
22+
var webArea = accessibilityController.rootElement.childAtIndex(0);
23+
var slider = webArea.childAtIndex(0);
24+
output += `Slider role: ${slider.role}\n`;
25+
output += `Slider minValue: ${slider.minValue}\n`;
26+
output += `Slider maxValue: ${slider.maxValue}\n`;
27+
28+
debug(output);
29+
document.getElementById("slider").hidden = true;
30+
finishJSTest();
31+
}, 0);
32+
}
33+
</script>
34+
</body>
35+
</html>

Source/WebCore/testing/js/WebCoreTestSupport.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@ void setLinkedOnOrAfterEverythingForTesting()
168168
#endif
169169
}
170170

171+
#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
172+
void setAccessibilityIsolatedTreeEnabled(bool isEnabled)
173+
{
174+
DeprecatedGlobalSettings::setIsAccessibilityIsolatedTreeEnabled(isEnabled);
175+
}
176+
#endif
177+
171178
void installMockGamepadProvider()
172179
{
173180
#if ENABLE(GAMEPAD)

Source/WebCore/testing/js/WebCoreTestSupport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ TEST_SUPPORT_EXPORT void setAllowsAnySSLCertificate(bool);
6363
TEST_SUPPORT_EXPORT bool allowsAnySSLCertificate();
6464
TEST_SUPPORT_EXPORT void setLinkedOnOrAfterEverythingForTesting();
6565

66+
#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
67+
TEST_SUPPORT_EXPORT void setAccessibilityIsolatedTreeEnabled(bool);
68+
#endif
69+
6670
TEST_SUPPORT_EXPORT void installMockGamepadProvider();
6771
TEST_SUPPORT_EXPORT void connectMockGamepad(unsigned index);
6872
TEST_SUPPORT_EXPORT void disconnectMockGamepad(unsigned index);

Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityControllerMac.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#import "InjectedBundle.h"
3636
#import "InjectedBundlePage.h"
3737
#import "JSBasics.h"
38+
#import "WebCoreTestSupport.h"
3839
#import <JavaScriptCore/JSStringRefCF.h>
3940
#import <WebKit/WKBundle.h>
4041
#import <WebKit/WKBundleFramePrivate.h>
@@ -154,6 +155,7 @@ static id findAccessibleObjectById(id obj, NSString *idAttribute)
154155
#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
155156
void AccessibilityController::updateIsolatedTreeMode()
156157
{
158+
WebCoreTestSupport::setAccessibilityIsolatedTreeEnabled(m_accessibilityIsolatedTreeMode);
157159
_AXSSetIsolatedTreeMode(m_accessibilityIsolatedTreeMode ? AXSIsolatedTreeModeSecondaryThread : AXSIsolatedTreeModeOff);
158160
}
159161
#endif

Tools/WebKitTestRunner/InjectedBundle/mac/AccessibilityUIElementClientMac.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,17 @@ class AccessibilityUIElementClientMac final : public AccessibilityUIElement {
5353
JSRetainPtr<JSStringRef> stringValue() override;
5454
unsigned childrenCount() override;
5555
RefPtr<AccessibilityUIElement> childAtIndex(unsigned) override;
56+
int hierarchicalLevel() const override;
57+
double minValue() override;
58+
double maxValue() override;
59+
double x() override;
60+
double y() override;
61+
double width() override;
62+
double height() override;
5663

5764
// Helpers.
5865
JSRetainPtr<JSStringRef> getStringAttribute(const char* attributeName) const;
66+
double getNumberAttribute(const char* attributeName) const;
5967
Vector<RefPtr<AccessibilityUIElement>> getChildren() const;
6068
Vector<RefPtr<AccessibilityUIElement>> getChildrenInRange(unsigned location, unsigned length) const;
6169

0 commit comments

Comments
 (0)