| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 /** | 5 /** |
| 6 * Test fixture for automation_predicate.js. | 6 * Test fixture for automation_predicate.js. |
| 7 * @constructor | 7 * @constructor |
| 8 * @extends {testing.Test} | 8 * @extends {testing.Test} |
| 9 */ | 9 */ |
| 10 function AutomationPredicateUnitTest () { | 10 function AutomationPredicateUnitTest () { |
| 11 testing.Test.call(this); | 11 testing.Test.call(this); |
| 12 }; | 12 }; |
| 13 | 13 |
| 14 AutomationPredicateUnitTest.prototype = { | 14 AutomationPredicateUnitTest.prototype = { |
| 15 __proto__: testing.Test.prototype, | 15 __proto__: testing.Test.prototype, |
| 16 | 16 |
| 17 /** @override */ | 17 /** @override */ |
| 18 extraLibraries: [ | 18 extraLibraries: [ |
| 19 'automation_predicate.js', | 19 'automation_predicate.js', |
| 20 ], | 20 ], |
| 21 | 21 |
| 22 /** @override */ | 22 /** @override */ |
| 23 browsePreload: DUMMY_URL, | 23 browsePreload: DUMMY_URL, |
| 24 |
| 25 /** @override */ |
| 26 setUp: function() { |
| 27 chrome.automation = { |
| 28 RoleType: { |
| 29 CLIENT: 'client', DESKTOP: 'desktop', ROOT_WEB_AREA: 'rootWebArea', |
| 30 TAB: 'tab', TAB_LIST: 'tabList', WEB_VIEW: 'webView' |
| 31 }, |
| 32 StateType: {FOCUSABLE: 'focusable', OFFSCREEN: 'offscreen'} |
| 33 }; |
| 34 }, |
| 35 |
| 36 fakeLoc: function(x) { |
| 37 return {left: x, top: x, width: x, height: x}; |
| 38 }, |
| 39 |
| 40 getMoreInterestingSampleTree: function() { |
| 41 // - = interesting, (g) = group |
| 42 // root (g) |
| 43 // upper1 (g) |
| 44 // lower1 (g) |
| 45 // leaf1 - |
| 46 // leaf2 |
| 47 // leaf3 - |
| 48 // lower2 |
| 49 // leaf4 |
| 50 // leaf5 - |
| 51 // upper2 - |
| 52 // lower3 (g) |
| 53 // leaf6 - |
| 54 // leaf7 - |
| 55 let root = {location: this.fakeLoc(0), state: {}}; |
| 56 let upper1 = {location: this.fakeLoc(1), state: {}}; |
| 57 let upper2 = {location: this.fakeLoc(2), state: {focusable: true}}; |
| 58 let lower1 = {location: this.fakeLoc(3), state: {}}; |
| 59 let lower2 = {location: this.fakeLoc(4), state: {}}; |
| 60 let lower3 = {location: this.fakeLoc(5), state: {}}; |
| 61 let leaf1 = {location: this.fakeLoc(6), state: {focusable: true}}; |
| 62 let leaf2 = {location: this.fakeLoc(7), state: {}}; |
| 63 let leaf3 = {location: this.fakeLoc(8), state: {focusable: true}}; |
| 64 let leaf4 = {location: this.fakeLoc(9), state: {}}; |
| 65 let leaf5 = {location: this.fakeLoc(10), state: {focusable: true}}; |
| 66 let leaf6 = {location: this.fakeLoc(11), state: {focusable: true}}; |
| 67 let leaf7 = {location: this.fakeLoc(12), state: {focusable: true}}; |
| 68 |
| 69 root.children = [upper1, upper2]; |
| 70 upper1.children = [lower1, lower2]; |
| 71 upper2.children = [lower3]; |
| 72 lower1.children = [leaf1, leaf2, leaf3]; |
| 73 lower2.children = [leaf4, leaf5]; |
| 74 lower3.children = [leaf6, leaf7]; |
| 75 |
| 76 return { |
| 77 root: root, |
| 78 upper1: upper1, |
| 79 upper2: upper2, |
| 80 lower1: lower1, |
| 81 lower2: lower2, |
| 82 lower3: lower3, |
| 83 leaf1: leaf1, |
| 84 leaf2: leaf2, |
| 85 leaf3: leaf3, |
| 86 leaf4: leaf4, |
| 87 leaf5: leaf5, |
| 88 leaf6: leaf6, |
| 89 leaf7: leaf7, |
| 90 }; |
| 91 }, |
| 92 |
| 93 getLessInterestingSampleTree: function() { |
| 94 // - = interesting |
| 95 // root |
| 96 // upper1 |
| 97 // lower1 |
| 98 // leaf1 - |
| 99 // leaf2 |
| 100 // leaf3 - |
| 101 // lower2 |
| 102 // leaf4 |
| 103 // leaf5 - |
| 104 // upper2 - |
| 105 // lower3 |
| 106 // leaf6 |
| 107 // leaf7 |
| 108 let root = {location: this.fakeLoc(0), state: {}}; |
| 109 let upper1 = {location: this.fakeLoc(0), state: {}}; |
| 110 let upper2 = {location: this.fakeLoc(0), state: {focusable: true}}; |
| 111 let lower1 = {location: this.fakeLoc(0), state: {}}; |
| 112 let lower2 = {location: this.fakeLoc(0), state: {}}; |
| 113 let lower3 = {location: this.fakeLoc(0), state: {}}; |
| 114 let leaf1 = {location: this.fakeLoc(0), state: {focusable: true}}; |
| 115 let leaf2 = {location: this.fakeLoc(0), state: {}}; |
| 116 let leaf3 = {location: this.fakeLoc(0), state: {focusable: true}}; |
| 117 let leaf4 = {location: this.fakeLoc(0), state: {}}; |
| 118 let leaf5 = {location: this.fakeLoc(0), state: {focusable: true}}; |
| 119 let leaf6 = {location: this.fakeLoc(0), state: {}}; |
| 120 let leaf7 = {location: this.fakeLoc(0), state: {}}; |
| 121 |
| 122 root.children = [upper1, upper2]; |
| 123 upper1.children = [lower1, lower2]; |
| 124 upper2.children = [lower3]; |
| 125 lower1.children = [leaf1, leaf2, leaf3]; |
| 126 lower2.children = [leaf4, leaf5]; |
| 127 lower3.children = [leaf6, leaf7]; |
| 128 |
| 129 return { |
| 130 root: root, |
| 131 upper1: upper1, |
| 132 upper2: upper2, |
| 133 lower1: lower1, |
| 134 lower2: lower2, |
| 135 lower3: lower3, |
| 136 leaf1: leaf1, |
| 137 leaf2: leaf2, |
| 138 leaf3: leaf3, |
| 139 leaf4: leaf4, |
| 140 leaf5: leaf5, |
| 141 leaf6: leaf6, |
| 142 leaf7: leaf7, |
| 143 }; |
| 144 }, |
| 24 }; | 145 }; |
| 25 | 146 |
| 147 TEST_F('AutomationPredicateUnitTest', 'IsSubtreeLeaf', function() { |
| 148 let t = this.getMoreInterestingSampleTree(); |
| 149 |
| 150 assertTrue(AutomationPredicate.isSubtreeLeaf(t.root, t.root)); |
| 151 assertTrue(AutomationPredicate.isSubtreeLeaf(t.upper1, t.root)); |
| 152 assertTrue(AutomationPredicate.isSubtreeLeaf(t.upper2, t.root)); |
| 153 assertTrue(AutomationPredicate.isSubtreeLeaf(t.lower1, t.upper1)); |
| 154 assertFalse(AutomationPredicate.isSubtreeLeaf(t.lower2, t.upper1)); |
| 155 assertTrue(AutomationPredicate.isSubtreeLeaf(t.lower3, t.root)); |
| 156 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf1, t.lower1)); |
| 157 assertFalse(AutomationPredicate.isSubtreeLeaf(t.leaf2, t.lower1)); |
| 158 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf3, t.lower1)); |
| 159 assertFalse(AutomationPredicate.isSubtreeLeaf(t.leaf4, t.upper1)); |
| 160 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf5, t.upper1)); |
| 161 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf6, t.lower3)); |
| 162 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf7, t.lower3)); |
| 163 }); |
| 164 |
| 165 TEST_F('AutomationPredicateUnitTest', 'IsGroup', function() { |
| 166 let t = this.getMoreInterestingSampleTree(); |
| 167 |
| 168 assertTrue(AutomationPredicate.isGroup(t.root, t.root)); |
| 169 assertTrue(AutomationPredicate.isGroup(t.upper1, t.root)); |
| 170 assertFalse(AutomationPredicate.isGroup(t.upper2, t.root)); |
| 171 assertTrue(AutomationPredicate.isGroup(t.lower1, t.upper1)); |
| 172 assertFalse(AutomationPredicate.isGroup(t.lower2, t.upper1)); |
| 173 assertTrue(AutomationPredicate.isGroup(t.lower3, t.root)); |
| 174 assertFalse(AutomationPredicate.isGroup(t.leaf1, t.lower1)); |
| 175 assertFalse(AutomationPredicate.isGroup(t.leaf2, t.lower1)); |
| 176 assertFalse(AutomationPredicate.isGroup(t.leaf3, t.lower1)); |
| 177 assertFalse(AutomationPredicate.isGroup(t.leaf4, t.upper1)); |
| 178 assertFalse(AutomationPredicate.isGroup(t.leaf5, t.upper1)); |
| 179 assertFalse(AutomationPredicate.isGroup(t.leaf6, t.lower3)); |
| 180 assertFalse(AutomationPredicate.isGroup(t.leaf7, t.lower3)); |
| 181 |
| 182 t.upper1.location = this.fakeLoc(0); |
| 183 assertFalse(AutomationPredicate.isGroup(t.upper1, t.root)); |
| 184 }); |
| 185 |
| 186 TEST_F('AutomationPredicateUnitTest', 'IsInterestingSubtree', function() { |
| 187 let t = this.getLessInterestingSampleTree(); |
| 188 |
| 189 assertTrue(AutomationPredicate.isInterestingSubtree(t.root)); |
| 190 assertTrue(AutomationPredicate.isInterestingSubtree(t.upper1)); |
| 191 assertTrue(AutomationPredicate.isInterestingSubtree(t.upper2)); |
| 192 assertTrue(AutomationPredicate.isInterestingSubtree(t.lower1)); |
| 193 assertTrue(AutomationPredicate.isInterestingSubtree(t.lower2)); |
| 194 assertFalse(AutomationPredicate.isInterestingSubtree(t.lower3)); |
| 195 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf1)); |
| 196 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf2)); |
| 197 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf3)); |
| 198 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf4)); |
| 199 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf5)); |
| 200 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf6)); |
| 201 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf7)); |
| 202 }); |
| 203 |
| 26 TEST_F('AutomationPredicateUnitTest', 'IsInteresting', function() { | 204 TEST_F('AutomationPredicateUnitTest', 'IsInteresting', function() { |
| 27 chrome.automation = { | |
| 28 RoleType: { | |
| 29 DESKTOP: 'desktop', ROOT_WEB_AREA: 'rootWebArea', TAB: 'tab', | |
| 30 TAB_LIST: 'tabList', WEB_VIEW: 'webView' | |
| 31 }, | |
| 32 StateType: {FOCUSABLE: 'focusable', OFFSCREEN: 'offscreen'} | |
| 33 }; | |
| 34 | |
| 35 // Testing focusable. | 205 // Testing focusable. |
| 36 let loc1 = {left: 0, top: 0, width: 0, height: 0}; | 206 let loc1 = {left: 0, top: 0, width: 0, height: 0}; |
| 37 let node1 = {location: loc1, state: {}}; | 207 let node1 = {location: loc1, state: {}}; |
| 38 let node2 = {location: loc1, state: {focusable: false}}; | 208 let node2 = {location: loc1, state: {focusable: false}}; |
| 39 let node3 = {location: loc1, state: {focusable: true}}; | 209 let node3 = {location: loc1, state: {focusable: true}}; |
| 40 assertFalse(AutomationPredicate.isInteresting(node1)); | 210 assertFalse(AutomationPredicate.isInteresting(node1)); |
| 41 assertFalse(AutomationPredicate.isInteresting(node2)); | 211 assertFalse(AutomationPredicate.isInteresting(node2)); |
| 42 assertTrue(AutomationPredicate.isInteresting(node3)); | 212 assertTrue(AutomationPredicate.isInteresting(node3)); |
| 43 | 213 |
| 44 // Testing onscreen. | 214 // Testing onscreen. |
| 45 let loc2 = {left: -1, top: 0, width: 0, height: 0}; | 215 let loc2 = {left: -1, top: 0, width: 0, height: 0}; |
| 46 let loc3 = {left: 0, top: -1, width: 0, height: 0}; | 216 let loc3 = {left: 0, top: -1, width: 0, height: 0}; |
| 47 let node4 = {location: loc2, state: {focusable: true}}; | 217 let node4 = {location: loc2, state: {focusable: true}}; |
| 48 let node5 = {location: loc3, state: {focusable: true}}; | 218 let node5 = {location: loc3, state: {focusable: true}}; |
| 49 let node6 = {location: loc1, state: {focusable: true, offscreen: true}} | 219 let node6 = {location: loc1, state: {focusable: true, offscreen: true}} |
| 50 assertFalse(AutomationPredicate.isInteresting(node4)); | 220 assertFalse(AutomationPredicate.isInteresting(node4)); |
| 51 assertFalse(AutomationPredicate.isInteresting(node5)); | 221 assertFalse(AutomationPredicate.isInteresting(node5)); |
| 52 assertFalse(AutomationPredicate.isInteresting(node6)); | 222 assertFalse(AutomationPredicate.isInteresting(node6)); |
| 53 | 223 |
| 54 // Testing if tab. | 224 // Testing if tab. |
| 55 let node7 = {location: loc1, role: 'desktop', state: {}}; | 225 let node7 = {location: loc1, role: 'desktop', state: {}}; |
| 56 let node8 = {location: loc1, role: 'tabList', state: {}}; | 226 let node8 = {location: loc1, role: 'tabList', state: {}}; |
| 57 let node9 = | 227 let node9 = |
| 58 {location: loc1, parent: node8, root: node7, role: 'tab', state: {}}; | 228 {location: loc1, parent: node8, root: node7, role: 'tab', state: {}}; |
| 59 assertFalse(AutomationPredicate.isInteresting(node7)); | 229 assertFalse(AutomationPredicate.isInteresting(node7)); |
| 60 assertFalse(AutomationPredicate.isInteresting(node8)); | 230 assertFalse(AutomationPredicate.isInteresting(node8)); |
| 61 assertTrue(AutomationPredicate.isInteresting(node9)); | 231 assertTrue(AutomationPredicate.isInteresting(node9)); |
| 232 |
| 233 // Testing if webView or rootWebArea. |
| 234 let node10 = {location: loc1, role: 'webView', state: {focusable: true}}; |
| 235 let node11 = {location: loc1, role: 'rootWebArea', state: {focusable: true}}; |
| 236 assertFalse(AutomationPredicate.isInteresting(node10)); |
| 237 assertFalse(AutomationPredicate.isInteresting(node11)); |
| 62 }); | 238 }); |
| OLD | NEW |