| 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; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 p3 = main.lastChild; | 36 p3 = main.lastChild; |
| 37 assertEq(RoleType.paragraph, p3.role); | 37 assertEq(RoleType.paragraph, p3.role); |
| 38 | 38 |
| 39 anonGroup = rootNode.lastChild; | 39 anonGroup = rootNode.lastChild; |
| 40 assertEq(RoleType.group, anonGroup.role); | 40 assertEq(RoleType.group, anonGroup.role); |
| 41 | 41 |
| 42 okButton = anonGroup.firstChild; | 42 okButton = anonGroup.firstChild; |
| 43 assertEq(RoleType.button, okButton.role); | 43 assertEq(RoleType.button, okButton.role); |
| 44 assertEq('Ok', okButton.name); | 44 assertEq('Ok', okButton.name); |
| 45 assertFalse(StateType.enabled in okButton.state); | 45 assertTrue(StateType.disabled in okButton.state); |
| 46 assertTrue(okButton.state.disabled); |
| 46 | 47 |
| 47 cancelButton = anonGroup.lastChild; | 48 cancelButton = anonGroup.lastChild; |
| 48 assertEq(RoleType.button, cancelButton.role); | 49 assertEq(RoleType.button, cancelButton.role); |
| 49 assertEq('Cancel', cancelButton.name); | 50 assertEq('Cancel', cancelButton.name); |
| 50 assertTrue(StateType.enabled in cancelButton.state); | 51 assertFalse(StateType.disabled in cancelButton.state); |
| 51 } | 52 } |
| 52 | 53 |
| 53 var allTests = [ | 54 var allTests = [ |
| 54 function testFindByRole() { | 55 function testFindByRole() { |
| 55 initializeNodes(rootNode); | 56 initializeNodes(rootNode); |
| 56 | 57 |
| 57 // Should find the only instance of this role. | 58 // Should find the only instance of this role. |
| 58 assertEq(h1, rootNode.find({ role: RoleType.heading})); | 59 assertEq(h1, rootNode.find({ role: RoleType.heading})); |
| 59 assertEq([h1], rootNode.findAll({ role: RoleType.heading})); | 60 assertEq([h1], rootNode.findAll({ role: RoleType.heading})); |
| 60 | 61 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 89 function testFindByStates() { | 90 function testFindByStates() { |
| 90 initializeNodes(rootNode); | 91 initializeNodes(rootNode); |
| 91 | 92 |
| 92 // Find all focusable elements (disabled button is not focusable). | 93 // Find all focusable elements (disabled button is not focusable). |
| 93 assertEq(link, rootNode.find({ state: { focusable: true }})); | 94 assertEq(link, rootNode.find({ state: { focusable: true }})); |
| 94 assertEq([link, cancelButton], | 95 assertEq([link, cancelButton], |
| 95 rootNode.findAll({ state: { focusable: true }})); | 96 rootNode.findAll({ state: { focusable: true }})); |
| 96 | 97 |
| 97 // Find disabled buttons. | 98 // Find disabled buttons. |
| 98 assertEq(okButton, rootNode.find({ role: RoleType.button, | 99 assertEq(okButton, rootNode.find({ role: RoleType.button, |
| 99 state: { enabled: false }})); | 100 state: { disabled: true }})); |
| 100 assertEq([okButton], rootNode.findAll({ role: RoleType.button, | 101 assertEq([okButton], rootNode.findAll({ role: RoleType.button, |
| 101 state: { enabled: false }})); | 102 state: { disabled: true }})); |
| 102 | 103 |
| 103 // Find disabled buttons within a portion of the tree. | 104 // Find disabled buttons within a portion of the tree. |
| 104 assertEq(okButton, anonGroup.find({ role: RoleType.button, | 105 assertEq(okButton, anonGroup.find({ role: RoleType.button, |
| 105 state: { enabled: false }})); | 106 state: { disabled: true }})); |
| 106 assertEq([okButton], anonGroup.findAll({ role: RoleType.button, | 107 assertEq([okButton], anonGroup.findAll({ role: RoleType.button, |
| 107 state: { enabled: false }})); | 108 state: { disabled: true }})); |
| 108 | 109 |
| 109 // Find enabled buttons. | 110 // Find enabled buttons. |
| 110 assertEq(cancelButton, rootNode.find({ role: RoleType.button, | 111 assertEq(cancelButton, rootNode.find({ role: RoleType.button, |
| 111 state: { enabled: true }})); | 112 state: { disabled: false }})); |
| 112 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button, | 113 assertEq([cancelButton], rootNode.findAll({ role: RoleType.button, |
| 113 state: { enabled: true }})); | 114 state: { disabled: false }})); |
| 114 chrome.test.succeed(); | 115 chrome.test.succeed(); |
| 115 }, | 116 }, |
| 116 | 117 |
| 117 function testFindByAttribute() { | 118 function testFindByAttribute() { |
| 118 initializeNodes(rootNode); | 119 initializeNodes(rootNode); |
| 119 | 120 |
| 120 // Find by name attribute. | 121 // Find by name attribute. |
| 121 assertEq(okButton, rootNode.find({ attributes: { name: 'Ok' }})); | 122 assertEq(okButton, rootNode.find({ attributes: { name: 'Ok' }})); |
| 122 assertEq(cancelButton, rootNode.find({ attributes: { name: 'Cancel' }})); | 123 assertEq(cancelButton, rootNode.find({ attributes: { name: 'Cancel' }})); |
| 123 | 124 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 assertFalse( | 171 assertFalse( |
| 171 p2StaticText.matches({ role: RoleType.staticText, | 172 p2StaticText.matches({ role: RoleType.staticText, |
| 172 attributes: { name: 'relationship' } }), | 173 attributes: { name: 'relationship' } }), |
| 173 'p2 should not match name: \'relationship'); | 174 'p2 should not match name: \'relationship'); |
| 174 | 175 |
| 175 chrome.test.succeed(); | 176 chrome.test.succeed(); |
| 176 } | 177 } |
| 177 ]; | 178 ]; |
| 178 | 179 |
| 179 setUpAndRunTests(allTests, 'complex.html'); | 180 setUpAndRunTests(allTests, 'complex.html'); |
| OLD | NEW |