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 'test_support.js' |
20 ], | 21 ], |
21 | 22 |
22 /** @override */ | 23 /** @override */ |
23 browsePreload: DUMMY_URL, | 24 browsePreload: DUMMY_URL, |
| 25 |
| 26 /** @override */ |
| 27 setUp: function() { |
| 28 chrome.automation = { |
| 29 RoleType: { |
| 30 CLIENT: 'client', DESKTOP: 'desktop', ROOT_WEB_AREA: 'rootWebArea', |
| 31 TAB: 'tab', TAB_LIST: 'tabList', WEB_VIEW: 'webView' |
| 32 }, |
| 33 StateType: {FOCUSABLE: 'focusable', OFFSCREEN: 'offscreen'} |
| 34 }; |
| 35 }, |
| 36 |
| 37 fakeLoc: function(x) { |
| 38 return {left: x, top: x, width: x, height: x}; |
| 39 }, |
| 40 |
| 41 getSampleTree: function() { |
| 42 // - = interesting, (g) = group |
| 43 // root (g) |
| 44 // upper1 (g) |
| 45 // lower1 (g) |
| 46 // leaf1 - |
| 47 // leaf2 |
| 48 // leaf3 - |
| 49 // lower2 |
| 50 // leaf4 |
| 51 // leaf5 - |
| 52 // upper2 - |
| 53 // lower3 |
| 54 // leaf6 |
| 55 // leaf7 |
| 56 let root = {location: this.fakeLoc(0), state: {}}; |
| 57 let upper1 = {location: this.fakeLoc(1), state: {}}; |
| 58 let upper2 = {location: this.fakeLoc(2), state: {focusable: true}}; |
| 59 let lower1 = {location: this.fakeLoc(3), state: {}}; |
| 60 let lower2 = {location: this.fakeLoc(4), state: {}}; |
| 61 let lower3 = {location: this.fakeLoc(5), state: {}}; |
| 62 let leaf1 = {location: this.fakeLoc(6), state: {focusable: true}}; |
| 63 let leaf2 = {location: this.fakeLoc(7), state: {}}; |
| 64 let leaf3 = {location: this.fakeLoc(8), state: {focusable: true}}; |
| 65 let leaf4 = {location: this.fakeLoc(9), state: {}}; |
| 66 let leaf5 = {location: this.fakeLoc(10), state: {focusable: true}}; |
| 67 let leaf6 = {location: this.fakeLoc(11), state: {}}; |
| 68 let leaf7 = {location: this.fakeLoc(12), state: {}}; |
| 69 |
| 70 let ts = new TestSupport(); |
| 71 ts.setChildren(root, [upper1, upper2]); |
| 72 ts.setChildren(upper1, [lower1, lower2]); |
| 73 ts.setChildren(upper2, [lower3]); |
| 74 ts.setChildren(lower1, [leaf1, leaf2, leaf3]); |
| 75 ts.setChildren(lower2, [leaf4, leaf5]); |
| 76 ts.setChildren(lower3, [leaf6, leaf7]); |
| 77 |
| 78 return { |
| 79 root: root, |
| 80 upper1: upper1, |
| 81 upper2: upper2, |
| 82 lower1: lower1, |
| 83 lower2: lower2, |
| 84 lower3: lower3, |
| 85 leaf1: leaf1, |
| 86 leaf2: leaf2, |
| 87 leaf3: leaf3, |
| 88 leaf4: leaf4, |
| 89 leaf5: leaf5, |
| 90 leaf6: leaf6, |
| 91 leaf7: leaf7, |
| 92 }; |
| 93 }, |
24 }; | 94 }; |
25 | 95 |
| 96 TEST_F('AutomationPredicateUnitTest', 'IsSubtreeLeaf', function() { |
| 97 let t = this.getSampleTree(); |
| 98 |
| 99 // Make t.leaf6 and t.leaf7 interesting. t.lower3 becomes a group. |
| 100 t.leaf6.state = {focusable: true}; |
| 101 t.leaf7.state = {focusable: true}; |
| 102 |
| 103 assertTrue(AutomationPredicate.isSubtreeLeaf(t.root, t.root)); |
| 104 assertTrue(AutomationPredicate.isSubtreeLeaf(t.upper1, t.root)); |
| 105 assertTrue(AutomationPredicate.isSubtreeLeaf(t.upper2, t.root)); |
| 106 assertTrue(AutomationPredicate.isSubtreeLeaf(t.lower1, t.upper1)); |
| 107 assertFalse(AutomationPredicate.isSubtreeLeaf(t.lower2, t.upper1)); |
| 108 assertTrue(AutomationPredicate.isSubtreeLeaf(t.lower3, t.root)); |
| 109 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf1, t.lower1)); |
| 110 assertFalse(AutomationPredicate.isSubtreeLeaf(t.leaf2, t.lower1)); |
| 111 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf3, t.lower1)); |
| 112 assertFalse(AutomationPredicate.isSubtreeLeaf(t.leaf4, t.upper1)); |
| 113 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf5, t.upper1)); |
| 114 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf6, t.lower3)); |
| 115 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf7, t.lower3)); |
| 116 }); |
| 117 |
| 118 TEST_F('AutomationPredicateUnitTest', 'IsGroup', function() { |
| 119 let t = this.getSampleTree(); |
| 120 |
| 121 // Make t.leaf6 and t.leaf7 interesting. t.lower3 becomes a group. |
| 122 t.leaf6.state = {focusable: true}; |
| 123 t.leaf7.state = {focusable: true}; |
| 124 |
| 125 assertTrue(AutomationPredicate.isGroup(t.root, t.root)); |
| 126 assertTrue(AutomationPredicate.isGroup(t.upper1, t.root)); |
| 127 assertFalse(AutomationPredicate.isGroup(t.upper2, t.root)); |
| 128 assertTrue(AutomationPredicate.isGroup(t.lower1, t.upper1)); |
| 129 assertFalse(AutomationPredicate.isGroup(t.lower2, t.upper1)); |
| 130 assertTrue(AutomationPredicate.isGroup(t.lower3, t.root)); |
| 131 assertFalse(AutomationPredicate.isGroup(t.leaf1, t.lower1)); |
| 132 assertFalse(AutomationPredicate.isGroup(t.leaf2, t.lower1)); |
| 133 assertFalse(AutomationPredicate.isGroup(t.leaf3, t.lower1)); |
| 134 assertFalse(AutomationPredicate.isGroup(t.leaf4, t.upper1)); |
| 135 assertFalse(AutomationPredicate.isGroup(t.leaf5, t.upper1)); |
| 136 assertFalse(AutomationPredicate.isGroup(t.leaf6, t.lower3)); |
| 137 assertFalse(AutomationPredicate.isGroup(t.leaf7, t.lower3)); |
| 138 |
| 139 // Set location of t.upper1 to equal location of t.root |
| 140 t.upper1.location = this.fakeLoc(0); |
| 141 assertFalse(AutomationPredicate.isGroup(t.upper1, t.root)); |
| 142 }); |
| 143 |
| 144 TEST_F('AutomationPredicateUnitTest', 'IsInterestingSubtree', function() { |
| 145 let t = this.getSampleTree(); |
| 146 |
| 147 assertTrue(AutomationPredicate.isInterestingSubtree(t.root)); |
| 148 assertTrue(AutomationPredicate.isInterestingSubtree(t.upper1)); |
| 149 assertTrue(AutomationPredicate.isInterestingSubtree(t.upper2)); |
| 150 assertTrue(AutomationPredicate.isInterestingSubtree(t.lower1)); |
| 151 assertTrue(AutomationPredicate.isInterestingSubtree(t.lower2)); |
| 152 assertFalse(AutomationPredicate.isInterestingSubtree(t.lower3)); |
| 153 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf1)); |
| 154 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf2)); |
| 155 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf3)); |
| 156 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf4)); |
| 157 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf5)); |
| 158 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf6)); |
| 159 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf7)); |
| 160 }); |
| 161 |
26 TEST_F('AutomationPredicateUnitTest', 'IsInteresting', function() { | 162 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. | 163 // Testing focusable. |
36 let loc1 = {left: 0, top: 0, width: 0, height: 0}; | 164 let loc1 = {left: 0, top: 0, width: 0, height: 0}; |
37 let node1 = {location: loc1, state: {}}; | 165 let node1 = {location: loc1, state: {}}; |
38 let node2 = {location: loc1, state: {focusable: false}}; | 166 let node2 = {location: loc1, state: {focusable: false}}; |
39 let node3 = {location: loc1, state: {focusable: true}}; | 167 let node3 = {location: loc1, state: {focusable: true}}; |
40 assertFalse(AutomationPredicate.isInteresting(node1)); | 168 assertFalse(AutomationPredicate.isInteresting(node1)); |
41 assertFalse(AutomationPredicate.isInteresting(node2)); | 169 assertFalse(AutomationPredicate.isInteresting(node2)); |
42 assertTrue(AutomationPredicate.isInteresting(node3)); | 170 assertTrue(AutomationPredicate.isInteresting(node3)); |
43 | 171 |
44 // Testing onscreen. | 172 // Testing onscreen. |
45 let loc2 = {left: -1, top: 0, width: 0, height: 0}; | 173 let loc2 = {left: -1, top: 0, width: 0, height: 0}; |
46 let loc3 = {left: 0, top: -1, width: 0, height: 0}; | 174 let loc3 = {left: 0, top: -1, width: 0, height: 0}; |
47 let node4 = {location: loc2, state: {focusable: true}}; | 175 let node4 = {location: loc2, state: {focusable: true}}; |
48 let node5 = {location: loc3, state: {focusable: true}}; | 176 let node5 = {location: loc3, state: {focusable: true}}; |
49 let node6 = {location: loc1, state: {focusable: true, offscreen: true}} | 177 let node6 = {location: loc1, state: {focusable: true, offscreen: true}} |
50 assertFalse(AutomationPredicate.isInteresting(node4)); | 178 assertFalse(AutomationPredicate.isInteresting(node4)); |
51 assertFalse(AutomationPredicate.isInteresting(node5)); | 179 assertFalse(AutomationPredicate.isInteresting(node5)); |
52 assertFalse(AutomationPredicate.isInteresting(node6)); | 180 assertFalse(AutomationPredicate.isInteresting(node6)); |
53 | 181 |
54 // Testing if tab. | 182 // Testing if tab. |
55 let node7 = {location: loc1, role: 'desktop', state: {}}; | 183 let node7 = {location: loc1, role: 'desktop', state: {}}; |
56 let node8 = {location: loc1, role: 'tabList', state: {}}; | 184 let node8 = {location: loc1, role: 'tabList', state: {}}; |
57 let node9 = | 185 let node9 = |
58 {location: loc1, parent: node8, root: node7, role: 'tab', state: {}}; | 186 {location: loc1, parent: node8, root: node7, role: 'tab', state: {}}; |
59 assertFalse(AutomationPredicate.isInteresting(node7)); | 187 assertFalse(AutomationPredicate.isInteresting(node7)); |
60 assertFalse(AutomationPredicate.isInteresting(node8)); | 188 assertFalse(AutomationPredicate.isInteresting(node8)); |
61 assertTrue(AutomationPredicate.isInteresting(node9)); | 189 assertTrue(AutomationPredicate.isInteresting(node9)); |
| 190 |
| 191 // Testing if webView or rootWebArea. |
| 192 let node10 = {location: loc1, role: 'webView', state: {focusable: true}}; |
| 193 let node11 = {location: loc1, role: 'rootWebArea', state: {focusable: true}}; |
| 194 assertFalse(AutomationPredicate.isInteresting(node10)); |
| 195 assertFalse(AutomationPredicate.isInteresting(node11)); |
62 }); | 196 }); |
OLD | NEW |