| 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 var group; | 5 var group; |
| 6 var h1; | 6 var h1; |
| 7 var p1; | 7 var p1; |
| 8 var link; | 8 var link; |
| 9 var main; | 9 var main; |
| 10 var p2; | 10 var p2; |
| 11 var p3; | 11 var p3; |
| 12 var anonGroup; |
| 12 var okButton; | 13 var okButton; |
| 13 var cancelButton; | 14 var cancelButton; |
| 14 | 15 |
| 15 function initializeNodes(rootNode) { | 16 function initializeNodes(rootNode) { |
| 16 group = rootNode.firstChild; | 17 group = rootNode.firstChild; |
| 17 assertEq(RoleType.group, group.role); | 18 assertEq(RoleType.group, group.role); |
| 18 | 19 |
| 19 h1 = group.firstChild; | 20 h1 = group.firstChild; |
| 20 assertEq(RoleType.heading, h1.role); | 21 assertEq(RoleType.heading, h1.role); |
| 21 assertEq(1, h1.hierarchicalLevel); | 22 assertEq(1, h1.hierarchicalLevel); |
| 22 | 23 |
| 23 p1 = group.lastChild; | 24 p1 = group.lastChild; |
| 24 assertEq(RoleType.paragraph, p1.role); | 25 assertEq(RoleType.paragraph, p1.role); |
| 25 | 26 |
| 26 link = p1.children[1]; | 27 link = p1.children[1]; |
| 27 assertEq(RoleType.link, link.role); | 28 assertEq(RoleType.link, link.role); |
| 28 | 29 |
| 29 main = rootNode.children[1]; | 30 main = rootNode.children[1]; |
| 30 assertEq(RoleType.main, main.role); | 31 assertEq(RoleType.main, main.role); |
| 31 | 32 |
| 32 p2 = main.firstChild; | 33 p2 = main.firstChild; |
| 33 assertEq(RoleType.paragraph, p2.role); | 34 assertEq(RoleType.paragraph, p2.role); |
| 34 | 35 |
| 35 p3 = main.lastChild; | 36 p3 = main.lastChild; |
| 36 assertEq(RoleType.paragraph, p3.role); | 37 assertEq(RoleType.paragraph, p3.role); |
| 37 | 38 |
| 38 okButton = rootNode.children[2]; | 39 anonGroup = rootNode.lastChild; |
| 40 assertEq(RoleType.group, anonGroup.role); |
| 41 |
| 42 okButton = anonGroup.firstChild; |
| 39 assertEq(RoleType.button, okButton.role); | 43 assertEq(RoleType.button, okButton.role); |
| 40 assertEq('Ok', okButton.name); | 44 assertEq('Ok', okButton.name); |
| 41 assertTrue(StateType.disabled in okButton.state); | 45 assertTrue(StateType.disabled in okButton.state); |
| 42 assertTrue(okButton.state.disabled); | 46 assertTrue(okButton.state.disabled); |
| 43 | 47 |
| 44 cancelButton = rootNode.children[3]; | 48 cancelButton = anonGroup.lastChild; |
| 45 assertEq(RoleType.button, cancelButton.role); | 49 assertEq(RoleType.button, cancelButton.role); |
| 46 assertEq('Cancel', cancelButton.name); | 50 assertEq('Cancel', cancelButton.name); |
| 47 assertFalse(StateType.disabled in cancelButton.state); | 51 assertFalse(StateType.disabled in cancelButton.state); |
| 48 } | 52 } |
| 49 | 53 |
| 50 var allTests = [ | 54 var allTests = [ |
| 51 function testFindByRole() { | 55 function testFindByRole() { |
| 52 initializeNodes(rootNode); | 56 initializeNodes(rootNode); |
| 53 | 57 |
| 54 // Should find the only instance of this role. | 58 // Should find the only instance of this role. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 | 70 |
| 67 // No instances: find should return null; findAll should return empty array. | 71 // No instances: find should return null; findAll should return empty array. |
| 68 assertEq(null, rootNode.find({ role: RoleType.checkbox })); | 72 assertEq(null, rootNode.find({ role: RoleType.checkbox })); |
| 69 assertEq([], rootNode.findAll({ role: RoleType.checkbox })); | 73 assertEq([], rootNode.findAll({ role: RoleType.checkbox })); |
| 70 | 74 |
| 71 // Calling from node should search only its subtree. | 75 // Calling from node should search only its subtree. |
| 72 assertEq(p1, group.find({ role: RoleType.paragraph })); | 76 assertEq(p1, group.find({ role: RoleType.paragraph })); |
| 73 assertEq(p2, main.find({ role: RoleType.paragraph })); | 77 assertEq(p2, main.find({ role: RoleType.paragraph })); |
| 74 assertEq([p2, p3], main.findAll({ role: RoleType.paragraph })); | 78 assertEq([p2, p3], main.findAll({ role: RoleType.paragraph })); |
| 75 | 79 |
| 80 // Unlike querySelector, can search from an anonymous group without |
| 81 // unexpected results. |
| 82 assertEq(okButton, anonGroup.find({ role: RoleType.button })); |
| 83 assertEq([okButton, cancelButton], |
| 84 anonGroup.findAll({ role: RoleType.button })); |
| 85 assertEq(null, anonGroup.find({ role: RoleType.heading })); |
| 86 |
| 76 chrome.test.succeed(); | 87 chrome.test.succeed(); |
| 77 }, | 88 }, |
| 78 | 89 |
| 79 function testFindByStates() { | 90 function testFindByStates() { |
| 80 initializeNodes(rootNode); | 91 initializeNodes(rootNode); |
| 81 | 92 |
| 82 // Find all focusable elements (disabled button is not focusable). | 93 // Find all focusable elements (disabled button is not focusable). |
| 83 assertEq(link, rootNode.find({ state: { focusable: true }})); | 94 assertEq(link, rootNode.find({ state: { focusable: true }})); |
| 84 assertEq([link, cancelButton], | 95 assertEq([link, cancelButton], |
| 85 rootNode.findAll({ state: { focusable: true }})); | 96 rootNode.findAll({ state: { focusable: true }})); |
| 86 | 97 |
| 87 // Find disabled buttons. | 98 // Find disabled buttons. |
| 88 assertEq(okButton, rootNode.find({ role: RoleType.button, | 99 assertEq(okButton, rootNode.find({ role: RoleType.button, |
| 89 state: { disabled: true }})); | 100 state: { disabled: true }})); |
| 90 assertEq([okButton], rootNode.findAll({ role: RoleType.button, | 101 assertEq([okButton], rootNode.findAll({ role: RoleType.button, |
| 91 state: { disabled: true }})); | 102 state: { disabled: true }})); |
| 92 | 103 |
| 104 // Find disabled buttons within a portion of the tree. |
| 105 assertEq(okButton, anonGroup.find({ role: RoleType.button, |
| 106 state: { disabled: true }})); |
| 107 assertEq([okButton], anonGroup.findAll({ role: RoleType.button, |
| 108 state: { disabled: true }})); |
| 109 |
| 93 // Find enabled buttons. | 110 // Find enabled buttons. |
| 94 assertEq(cancelButton, rootNode.find({ role: RoleType.button, | 111 assertEq(cancelButton, rootNode.find({ role: RoleType.button, |
| 95 state: { disabled: false }})); | 112 state: { disabled: false }})); |
| 96 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button, | 113 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button, |
| 97 state: { disabled: false }})); | 114 state: { disabled: false }})); |
| 98 chrome.test.succeed(); | 115 chrome.test.succeed(); |
| 99 }, | 116 }, |
| 100 | 117 |
| 101 function testFindByAttribute() { | 118 function testFindByAttribute() { |
| 102 initializeNodes(rootNode); | 119 initializeNodes(rootNode); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 assertFalse( | 171 assertFalse( |
| 155 p2StaticText.matches({ role: RoleType.staticText, | 172 p2StaticText.matches({ role: RoleType.staticText, |
| 156 attributes: { name: 'relationship' } }), | 173 attributes: { name: 'relationship' } }), |
| 157 'p2 should not match name: \'relationship'); | 174 'p2 should not match name: \'relationship'); |
| 158 | 175 |
| 159 chrome.test.succeed(); | 176 chrome.test.succeed(); |
| 160 } | 177 } |
| 161 ]; | 178 ]; |
| 162 | 179 |
| 163 setUpAndRunTests(allTests, 'complex.html'); | 180 setUpAndRunTests(allTests, 'complex.html'); |
| OLD | NEW |