| 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; |
| 26 |
| 27 /** Filters nodes not rooted by desktop. */ |
| 28 function filterNonDesktopRoot(node) { |
| 29 return node.root.role != RoleType.desktop; |
| 30 } |
| 31 |
| 32 window.getNonDesktopAncestors = function(node) { |
| 33 return AutomationUtil.getAncestors(node) |
| 34 .filter(filterNonDesktopRoot); |
| 35 } |
| 36 |
| 37 window.getNonDesktopUniqueAncestors = function(node1, node2) { |
| 38 return AutomationUtil.getUniqueAncestors(node1, node2) |
| 39 .filter(filterNonDesktopRoot); |
| 40 } |
| 25 }, | 41 }, |
| 26 | 42 |
| 27 basicDoc: function() {/*! | 43 basicDoc: function() {/*! |
| 28 <p><a href='#'></a>hello</p> | 44 <p><a href='#'></a>hello</p> |
| 29 <h1><ul><li>a</ul><button></h1> | 45 <h1><ul><li>a</ul><button></h1> |
| 30 */}, | 46 */}, |
| 31 | 47 |
| 32 secondDoc: function() {/*! | 48 secondDoc: function() {/*! |
| 33 <html> | 49 <html> |
| 34 <head><title>Second doc</title></head> | 50 <head><title>Second doc</title></head> |
| 35 <body><div>Second</div></body> | 51 <body><div>Second</div></body> |
| 36 </html> | 52 </html> |
| 37 */}, | 53 */}, |
| 38 | 54 |
| 39 iframeDoc: function() {/*! | 55 iframeDoc: function() {/*! |
| 40 <html> | 56 <html> |
| 41 <head><title>Second doc</title></head> | 57 <head><title>Second doc</title></head> |
| 42 <body> | 58 <body> |
| 43 <iframe src="data:text/html,<p>Inside</p>"></iframe> | 59 <iframe src="data:text/html,<p>Inside</p>"></iframe> |
| 44 </body> | 60 </body> |
| 45 </html> | 61 </html> |
| 46 */} | 62 */} |
| 47 }; | 63 }; |
| 48 | 64 |
| 49 TEST_F('AutomationUtilE2ETest', 'GetAncestors', function() { | 65 TEST_F('AutomationUtilE2ETest', 'GetAncestors', function() { |
| 50 this.runWithLoadedTree(this.basicDoc, function(root) { | 66 this.runWithLoadedTree(this.basicDoc, function(root) { |
| 51 var expectedLength = 1; | 67 var expectedLength = 1; |
| 52 while (root) { | 68 while (root) { |
| 53 var ancestors = AutomationUtil.getAncestors(root); | 69 var ancestors = getNonDesktopAncestors(root); |
| 54 assertEquals(expectedLength++, ancestors.length); | 70 assertEquals(expectedLength++, ancestors.length); |
| 55 root = root.firstChild; | 71 root = root.firstChild; |
| 56 } | 72 } |
| 57 }); | 73 }); |
| 58 }); | 74 }); |
| 59 | 75 |
| 60 TEST_F('AutomationUtilE2ETest', 'GetUniqueAncestors', function() { | 76 TEST_F('AutomationUtilE2ETest', 'GetUniqueAncestors', function() { |
| 61 this.runWithLoadedTree(this.basicDoc, function(root) { | 77 this.runWithLoadedTree(this.basicDoc, function(root) { |
| 62 var leftmost = root, rightmost = root; | 78 var leftmost = root, rightmost = root; |
| 63 while (leftmost.firstChild) | 79 while (leftmost.firstChild) |
| 64 leftmost = leftmost.firstChild; | 80 leftmost = leftmost.firstChild; |
| 65 while (rightmost.lastChild) | 81 while (rightmost.lastChild) |
| 66 rightmost = rightmost.lastChild; | 82 rightmost = rightmost.lastChild; |
| 67 | 83 |
| 68 var leftAncestors = AutomationUtil.getAncestors(leftmost); | 84 var leftAncestors = getNonDesktopAncestors(leftmost); |
| 69 var rightAncestors = AutomationUtil.getAncestors(rightmost); | 85 var rightAncestors = getNonDesktopAncestors(rightmost); |
| 70 assertEquals(chrome.automation.RoleType.link, leftmost.role); | 86 assertEquals(RoleType.link, leftmost.role); |
| 71 assertEquals(chrome.automation.RoleType.button, rightmost.role); | 87 assertEquals(RoleType.button, rightmost.role); |
| 72 assertEquals( | 88 assertEquals( |
| 73 1, AutomationUtil.getDivergence(leftAncestors, rightAncestors)); | 89 1, AutomationUtil.getDivergence(leftAncestors, rightAncestors)); |
| 90 |
| 74 assertEquals( | 91 assertEquals( |
| 75 -1, AutomationUtil.getDivergence(leftAncestors, leftAncestors)); | 92 -1, AutomationUtil.getDivergence(leftAncestors, leftAncestors)); |
| 76 | 93 |
| 77 var uniqueAncestorsLeft = | 94 var uniqueAncestorsLeft = |
| 78 AutomationUtil.getUniqueAncestors(rightmost, leftmost); | 95 getNonDesktopUniqueAncestors(rightmost, leftmost); |
| 79 var uniqueAncestorsRight = | 96 var uniqueAncestorsRight = |
| 80 AutomationUtil.getUniqueAncestors(leftmost, rightmost); | 97 getNonDesktopUniqueAncestors(leftmost, rightmost); |
| 81 | 98 |
| 82 assertEquals(2, uniqueAncestorsLeft.length); | 99 assertEquals(2, uniqueAncestorsLeft.length); |
| 83 assertEquals(chrome.automation.RoleType.paragraph, | 100 assertEquals(RoleType.paragraph, |
| 84 uniqueAncestorsLeft[0].role); | 101 uniqueAncestorsLeft[0].role); |
| 85 assertEquals(chrome.automation.RoleType.link, | 102 assertEquals(RoleType.link, |
| 86 uniqueAncestorsLeft[1].role); | 103 uniqueAncestorsLeft[1].role); |
| 87 | 104 |
| 88 assertEquals(3, uniqueAncestorsRight.length); | 105 assertEquals(3, uniqueAncestorsRight.length); |
| 89 assertEquals(chrome.automation.RoleType.heading, | 106 assertEquals(RoleType.heading, |
| 90 uniqueAncestorsRight[0].role); | 107 uniqueAncestorsRight[0].role); |
| 91 assertEquals(chrome.automation.RoleType.group, | 108 assertEquals(RoleType.group, |
| 92 uniqueAncestorsRight[1].role); | 109 uniqueAncestorsRight[1].role); |
| 93 assertEquals(chrome.automation.RoleType.button, | 110 assertEquals(RoleType.button, |
| 94 uniqueAncestorsRight[2].role); | 111 uniqueAncestorsRight[2].role); |
| 95 | 112 |
| 96 assertEquals( | 113 assertEquals( |
| 97 1, AutomationUtil.getUniqueAncestors(leftmost, leftmost).length); | 114 1, getNonDesktopUniqueAncestors(leftmost, leftmost).length); |
| 98 | 115 |
| 99 }); | 116 }.bind(this)); |
| 100 }); | 117 }); |
| 101 | 118 |
| 102 TEST_F('AutomationUtilE2ETest', 'GetDirection', function() { | 119 TEST_F('AutomationUtilE2ETest', 'GetDirection', function() { |
| 103 this.runWithLoadedTree(this.basicDoc, function(root) { | 120 this.runWithLoadedTree(this.basicDoc, function(root) { |
| 104 var left = root, right = root; | 121 var left = root, right = root; |
| 105 | 122 |
| 106 // Same node. | 123 // Same node. |
| 107 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); | 124 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); |
| 108 | 125 |
| 109 // Ancestor. | 126 // Ancestor. |
| 110 left = left.firstChild; | 127 left = left.firstChild; |
| 111 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); | 128 assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 assertEquals('Back', back.name); | 202 assertEquals('Back', back.name); |
| 186 assertEquals(toolbar, | 203 assertEquals(toolbar, |
| 187 AutomationUtil.findNextNode(back, 'backward', pred)); | 204 AutomationUtil.findNextNode(back, 'backward', pred)); |
| 188 | 205 |
| 189 var forward = AutomationUtil.findNextNode(back, 'forward', pred); | 206 var forward = AutomationUtil.findNextNode(back, 'forward', pred); |
| 190 assertEquals('Forward', forward.name); | 207 assertEquals('Forward', forward.name); |
| 191 assertEquals(back, | 208 assertEquals(back, |
| 192 AutomationUtil.findNextNode(forward, 'backward', pred)); | 209 AutomationUtil.findNextNode(forward, 'backward', pred)); |
| 193 }); | 210 }); |
| 194 }); | 211 }); |
| OLD | NEW |