1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Include test fixture.
GEN_INCLUDE([
'testing/assert_additions.js',
'testing/common_e2e_test_base.js',
'testing/snippets.js',
]);
/**
* Test fixture for automation_util.js.
*/
AccessibilityExtensionAutomationUtilE2ETest = class extends CommonE2ETestBase {
/** @override */
async setUpDeferred() {
await super.setUpDeferred();
globalThis.Dir = constants.Dir;
globalThis.RoleType = chrome.automation.RoleType;
/** Filters nodes not rooted by desktop. */
function filterNonDesktopRoot(node) {
return node.root.role !== RoleType.DESKTOP;
}
globalThis.getNonDesktopAncestors = function(node) {
return AutomationUtil.getAncestors(node).filter(filterNonDesktopRoot);
};
globalThis.getNonDesktopUniqueAncestors = function(node1, node2) {
return AutomationUtil.getUniqueAncestors(node1, node2)
.filter(filterNonDesktopRoot);
};
}
basicDoc() {
return `
<p><a href='#'></a>hello</p>
<h1><ul><li>a</ul><div role="group"><button></button></div></h1>
`;
}
secondDoc() {
return `
<html>
<head><title>Second doc</title></head>
<body><div>Second</div></body>
</html>
`;
}
iframeDoc() {
return `
<html>
<head><title>Second doc</title></head>
<body>
<iframe src="data:text/html,<p>Inside</p>"></iframe>
</body>
</html>
`;
}
};
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'GetAncestors',
async function() {
let current = await this.runWithLoadedTree(this.basicDoc());
let expectedLength = 1;
while (current) {
const ancestors = getNonDesktopAncestors(current);
assertEquals(expectedLength++, ancestors.length);
current = current.firstChild;
}
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'GetFirstAncestorWithRole',
async function() {
const root = await this.runWithLoadedTree(`
<div tabindex="0" aria-label="x">
<div tabindex="0" aria-label="y">
<p>
<button>Hello world</div>
</p>
</div>
</div>`);
const buttonNode = root.firstChild.firstChild.firstChild;
const containerNode = AutomationUtil.getFirstAncestorWithRole(
buttonNode, RoleType.GENERIC_CONTAINER);
assertEquals(containerNode.name, 'y');
const parentContainerNode = AutomationUtil.getFirstAncestorWithRole(
containerNode, RoleType.GENERIC_CONTAINER);
assertEquals(parentContainerNode.name, 'x');
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'GetUniqueAncestors',
async function() {
const root = await this.runWithLoadedTree(this.basicDoc());
let leftmost = root;
let rightmost = root;
while (leftmost.firstChild) {
leftmost = leftmost.firstChild;
}
while (rightmost.lastChild) {
rightmost = rightmost.lastChild;
}
const leftAncestors = getNonDesktopAncestors(leftmost);
const rightAncestors = getNonDesktopAncestors(rightmost);
assertEquals(RoleType.LINK, leftmost.role);
assertEquals(RoleType.BUTTON, rightmost.role);
assertEquals(
1, AutomationUtil.getDivergence(leftAncestors, rightAncestors));
assertEquals(
-1, AutomationUtil.getDivergence(leftAncestors, leftAncestors));
const uniqueAncestorsLeft =
getNonDesktopUniqueAncestors(rightmost, leftmost);
const uniqueAncestorsRight =
getNonDesktopUniqueAncestors(leftmost, rightmost);
assertEquals(2, uniqueAncestorsLeft.length);
assertEquals(RoleType.PARAGRAPH, uniqueAncestorsLeft[0].role);
assertEquals(RoleType.LINK, uniqueAncestorsLeft[1].role);
assertEquals(3, uniqueAncestorsRight.length);
assertEquals(RoleType.HEADING, uniqueAncestorsRight[0].role);
assertEquals(RoleType.GROUP, uniqueAncestorsRight[1].role);
assertEquals(RoleType.BUTTON, uniqueAncestorsRight[2].role);
assertEquals(1, getNonDesktopUniqueAncestors(leftmost, leftmost).length);
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'GetDirection',
async function() {
const root = await this.runWithLoadedTree(this.basicDoc());
let left = root;
let right = root;
// Same node.
assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
// Ancestry.
left = left.firstChild;
// Upward movement is backward (in dfs).
assertEquals(Dir.BACKWARD, AutomationUtil.getDirection(left, right));
// Downward movement is forward.
assertEquals(Dir.FORWARD, AutomationUtil.getDirection(right, left));
// Ordered.
right = right.lastChild;
assertEquals(Dir.BACKWARD, AutomationUtil.getDirection(right, left));
assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'VisitContainer',
async function() {
const r = await this.runWithLoadedTree(toolbarDoc());
const pred = function(n) {
return n.role !== 'rootWebArea';
};
const toolbar = AutomationUtil.findNextNode(r, 'forward', pred);
assertEquals('toolbar', toolbar.role);
const back = AutomationUtil.findNextNode(toolbar, 'forward', pred);
assertEquals('Back', back.name);
assertEquals(
toolbar, AutomationUtil.findNextNode(back, 'backward', pred));
const forward = AutomationUtil.findNextNode(back, 'forward', pred);
assertEquals('Forward', forward.name);
assertEquals(
back, AutomationUtil.findNextNode(forward, 'backward', pred));
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'HitTest', async function() {
const r = await this.runWithLoadedTree(headingDoc);
const [h1, h2, a] = r.findAll({role: 'inlineTextBox'});
assertEquals(h1, AutomationUtil.hitTest(r, RectUtil.center(h1.location)));
assertEquals(
h1, AutomationUtil.hitTest(r, RectUtil.center(h1.parent.location)));
assertEquals(
h1.parent.parent,
AutomationUtil.hitTest(
r, RectUtil.center(h1.parent.parent.location)));
assertEquals(a, AutomationUtil.hitTest(r, RectUtil.center(a.location)));
assertEquals(
a, AutomationUtil.hitTest(r, RectUtil.center(a.parent.location)));
assertEquals(
a.parent.parent,
AutomationUtil.hitTest(r, RectUtil.center(a.parent.parent.location)));
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'FindLastNodeSimple',
async function() {
const r = await this.runWithLoadedTree(
`<p aria-label=" "><div tabindex="0" aria-label="x"></div></p>`);
assertEquals(
'x',
AutomationUtil
.findLastNode(r, n => n.role === RoleType.GENERIC_CONTAINER)
.name);
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'FindLastNodeNonLeaf',
async function() {
const r = await this.runWithLoadedTree(`
<div role="button" aria-label="outer">
<div role="heading" aria-label="inner">
</div>
</div>
`);
assertEquals(
'outer',
AutomationUtil.findLastNode(r, n => n.role === RoleType.BUTTON).name);
});
AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'FindLastNodeLeaf',
async function() {
const r = await this.runWithLoadedTree(`
<p>start</p>
<div aria-label="outer"><div tabindex="0" aria-label="inner"></div></div>
<p>end</p>
`);
assertEquals(
'inner',
AutomationUtil
.findLastNode(r, n => n.role === RoleType.GENERIC_CONTAINER)
.name);
});
|