| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Include test fixture. | 5 // Include test fixture. |
| 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']); | 6 GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']); |
| 7 | 7 |
| 8 GEN_INCLUDE(['../../testing/snippets.js']); | 8 GEN_INCLUDE(['../../testing/snippets.js']); |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Test fixture for automation_util.js. | 11 * Test fixture for automation_util.js. |
| 12 * @constructor | 12 * @constructor |
| 13 * @extends {ChromeVoxE2ETestBase} | 13 * @extends {ChromeVoxE2ETestBase} |
| 14 */ | 14 */ |
| 15 function AutomationUtilE2ETest() { | 15 function AutomationUtilE2ETest() { |
| 16 ChromeVoxNextE2ETest.call(this); | 16 ChromeVoxNextE2ETest.call(this); |
| 17 } | 17 } |
| 18 | 18 |
| 19 AutomationUtilE2ETest.prototype = { | 19 AutomationUtilE2ETest.prototype = { |
| 20 __proto__: ChromeVoxNextE2ETest.prototype, | 20 __proto__: ChromeVoxNextE2ETest.prototype, |
| 21 | 21 |
| 22 /** @override */ | 22 /** @override */ |
| 23 setUp: function() { | 23 setUp: function() { |
| 24 window.Dir = constants.Dir; | 24 window.Dir = constants.Dir; |
| 25 window.RoleType = chrome.automation.RoleType; | 25 window.RoleType = chrome.automation.RoleType; |
| 26 | 26 |
| 27 /** Filters nodes not rooted by desktop. */ | 27 /** Filters nodes not rooted by desktop. */ |
| 28 function filterNonDesktopRoot(node) { | 28 function filterNonDesktopRoot(node) { |
| 29 return node.root.role != RoleType.desktop; | 29 return node.root.role != RoleType.DESKTOP; |
| 30 } | 30 } |
| 31 | 31 |
| 32 window.getNonDesktopAncestors = function(node) { | 32 window.getNonDesktopAncestors = function(node) { |
| 33 return AutomationUtil.getAncestors(node) | 33 return AutomationUtil.getAncestors(node) |
| 34 .filter(filterNonDesktopRoot); | 34 .filter(filterNonDesktopRoot); |
| 35 } | 35 } |
| 36 | 36 |
| 37 window.getNonDesktopUniqueAncestors = function(node1, node2) { | 37 window.getNonDesktopUniqueAncestors = function(node1, node2) { |
| 38 return AutomationUtil.getUniqueAncestors(node1, node2) | 38 return AutomationUtil.getUniqueAncestors(node1, node2) |
| 39 .filter(filterNonDesktopRoot); | 39 .filter(filterNonDesktopRoot); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 TEST_F('AutomationUtilE2ETest', 'GetUniqueAncestors', function() { | 76 TEST_F('AutomationUtilE2ETest', 'GetUniqueAncestors', function() { |
| 77 this.runWithLoadedTree(this.basicDoc, function(root) { | 77 this.runWithLoadedTree(this.basicDoc, function(root) { |
| 78 var leftmost = root, rightmost = root; | 78 var leftmost = root, rightmost = root; |
| 79 while (leftmost.firstChild) | 79 while (leftmost.firstChild) |
| 80 leftmost = leftmost.firstChild; | 80 leftmost = leftmost.firstChild; |
| 81 while (rightmost.lastChild) | 81 while (rightmost.lastChild) |
| 82 rightmost = rightmost.lastChild; | 82 rightmost = rightmost.lastChild; |
| 83 | 83 |
| 84 var leftAncestors = getNonDesktopAncestors(leftmost); | 84 var leftAncestors = getNonDesktopAncestors(leftmost); |
| 85 var rightAncestors = getNonDesktopAncestors(rightmost); | 85 var rightAncestors = getNonDesktopAncestors(rightmost); |
| 86 assertEquals(RoleType.link, leftmost.role); | 86 assertEquals(RoleType.LINK, leftmost.role); |
| 87 assertEquals(RoleType.button, rightmost.role); | 87 assertEquals(RoleType.BUTTON, rightmost.role); |
| 88 assertEquals( | 88 assertEquals( |
| 89 1, AutomationUtil.getDivergence(leftAncestors, rightAncestors)); | 89 1, AutomationUtil.getDivergence(leftAncestors, rightAncestors)); |
| 90 | 90 |
| 91 assertEquals( | 91 assertEquals( |
| 92 -1, AutomationUtil.getDivergence(leftAncestors, leftAncestors)); | 92 -1, AutomationUtil.getDivergence(leftAncestors, leftAncestors)); |
| 93 | 93 |
| 94 var uniqueAncestorsLeft = | 94 var uniqueAncestorsLeft = |
| 95 getNonDesktopUniqueAncestors(rightmost, leftmost); | 95 getNonDesktopUniqueAncestors(rightmost, leftmost); |
| 96 var uniqueAncestorsRight = | 96 var uniqueAncestorsRight = |
| 97 getNonDesktopUniqueAncestors(leftmost, rightmost); | 97 getNonDesktopUniqueAncestors(leftmost, rightmost); |
| 98 | 98 |
| 99 assertEquals(2, uniqueAncestorsLeft.length); | 99 assertEquals(2, uniqueAncestorsLeft.length); |
| 100 assertEquals(RoleType.paragraph, | 100 assertEquals(RoleType.PARAGRAPH, |
| 101 uniqueAncestorsLeft[0].role); | 101 uniqueAncestorsLeft[0].role); |
| 102 assertEquals(RoleType.link, | 102 assertEquals(RoleType.LINK, |
| 103 uniqueAncestorsLeft[1].role); | 103 uniqueAncestorsLeft[1].role); |
| 104 | 104 |
| 105 assertEquals(3, uniqueAncestorsRight.length); | 105 assertEquals(3, uniqueAncestorsRight.length); |
| 106 assertEquals(RoleType.heading, | 106 assertEquals(RoleType.HEADING, |
| 107 uniqueAncestorsRight[0].role); | 107 uniqueAncestorsRight[0].role); |
| 108 assertEquals(RoleType.group, | 108 assertEquals(RoleType.GROUP, |
| 109 uniqueAncestorsRight[1].role); | 109 uniqueAncestorsRight[1].role); |
| 110 assertEquals(RoleType.button, | 110 assertEquals(RoleType.BUTTON, |
| 111 uniqueAncestorsRight[2].role); | 111 uniqueAncestorsRight[2].role); |
| 112 | 112 |
| 113 assertEquals( | 113 assertEquals( |
| 114 1, getNonDesktopUniqueAncestors(leftmost, leftmost).length); | 114 1, getNonDesktopUniqueAncestors(leftmost, leftmost).length); |
| 115 | 115 |
| 116 }.bind(this)); | 116 }.bind(this)); |
| 117 }); | 117 }); |
| 118 | 118 |
| 119 TEST_F('AutomationUtilE2ETest', 'GetDirection', function() { | 119 TEST_F('AutomationUtilE2ETest', 'GetDirection', function() { |
| 120 this.runWithLoadedTree(this.basicDoc, function(root) { | 120 this.runWithLoadedTree(this.basicDoc, function(root) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 assertEquals(h1, AutomationUtil.hitTest(r, getCP(h1.parent))); | 170 assertEquals(h1, AutomationUtil.hitTest(r, getCP(h1.parent))); |
| 171 assertEquals(h1.parent.parent, | 171 assertEquals(h1.parent.parent, |
| 172 AutomationUtil.hitTest(r, getCP(h1.parent.parent))); | 172 AutomationUtil.hitTest(r, getCP(h1.parent.parent))); |
| 173 | 173 |
| 174 assertEquals(a, AutomationUtil.hitTest(r, getCP(a))); | 174 assertEquals(a, AutomationUtil.hitTest(r, getCP(a))); |
| 175 assertEquals(a, AutomationUtil.hitTest(r, getCP(a.parent))); | 175 assertEquals(a, AutomationUtil.hitTest(r, getCP(a.parent))); |
| 176 assertEquals(a.parent.parent, | 176 assertEquals(a.parent.parent, |
| 177 AutomationUtil.hitTest(r, getCP(a.parent.parent))); | 177 AutomationUtil.hitTest(r, getCP(a.parent.parent))); |
| 178 }); | 178 }); |
| 179 }); | 179 }); |
| OLD | NEW |