1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Include test fixture.
6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']);
9 * Test fixture for automation_util.js.
11 * @extends {ChromeVoxE2ETestBase}
13 function AutomationUtilE2ETest() {
14 ChromeVoxNextE2ETest.call(this);
17 AutomationUtilE2ETest.prototype = {
18 __proto__: ChromeVoxNextE2ETest.prototype,
22 window.Dir = AutomationUtil.Dir;
25 basicDoc: function() {/*!
26 <p><a href='#'></a>hello</p>
27 <h1><ul><li>a</ul><button></h1>
31 TEST_F('AutomationUtilE2ETest', 'GetAncestors', function() {
32 this.runWithLoadedTree(this.basicDoc, function(root) {
33 var expectedLength = 1;
35 var ancestors = AutomationUtil.getAncestors(root);
36 assertEquals(expectedLength++, ancestors.length);
37 root = root.firstChild;
42 TEST_F('AutomationUtilE2ETest', 'GetUniqueAncestors', function() {
43 this.runWithLoadedTree(this.basicDoc, function(root) {
44 var leftmost = root, rightmost = root;
45 while (leftmost.firstChild)
46 leftmost = leftmost.firstChild;
47 while (rightmost.lastChild)
48 rightmost = rightmost.lastChild;
50 var leftAncestors = AutomationUtil.getAncestors(leftmost);
51 var rightAncestors = AutomationUtil.getAncestors(rightmost);
52 assertEquals(chrome.automation.RoleType.link, leftmost.role);
53 assertEquals(chrome.automation.RoleType.button, rightmost.role);
55 1, AutomationUtil.getDivergence(leftAncestors, rightAncestors));
57 -1, AutomationUtil.getDivergence(leftAncestors, leftAncestors));
59 var uniqueAncestorsLeft =
60 AutomationUtil.getUniqueAncestors(rightmost, leftmost);
61 var uniqueAncestorsRight =
62 AutomationUtil.getUniqueAncestors(leftmost, rightmost);
64 assertEquals(2, uniqueAncestorsLeft.length);
65 assertEquals(chrome.automation.RoleType.paragraph,
66 uniqueAncestorsLeft[0].role);
67 assertEquals(chrome.automation.RoleType.link,
68 uniqueAncestorsLeft[1].role);
70 assertEquals(3, uniqueAncestorsRight.length);
71 assertEquals(chrome.automation.RoleType.heading,
72 uniqueAncestorsRight[0].role);
73 assertEquals(chrome.automation.RoleType.group,
74 uniqueAncestorsRight[1].role);
75 assertEquals(chrome.automation.RoleType.button,
76 uniqueAncestorsRight[2].role);
79 1, AutomationUtil.getUniqueAncestors(leftmost, leftmost).length);
84 TEST_F('AutomationUtilE2ETest', 'GetDirection', function() {
85 this.runWithLoadedTree(this.basicDoc, function(root) {
86 var left = root, right = root;
89 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
92 left = left.firstChild;
93 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
94 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(right, left));
97 right = right.lastChild;
98 assertEquals(Dir.BACKWARD, AutomationUtil.getDirection(right, left));
99 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));