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 getMoreInterestingSampleTree: 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 (g) | |
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: {focusable: true}}; | |
68 let leaf7 = {location: this.fakeLoc(12), state: {focusable: true}}; | |
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 }, | |
94 | |
95 getLessInterestingSampleTree: function() { | |
dmazzoni
2017/05/10 05:57:03
This tree and the one above are basically the same
elichtenberg
2017/05/10 17:13:57
Done.
| |
96 // - = interesting | |
97 // root | |
98 // upper1 | |
99 // lower1 | |
100 // leaf1 - | |
101 // leaf2 | |
102 // leaf3 - | |
103 // lower2 | |
104 // leaf4 | |
105 // leaf5 - | |
106 // upper2 - | |
107 // lower3 | |
108 // leaf6 | |
109 // leaf7 | |
110 let root = {location: this.fakeLoc(0), state: {}}; | |
111 let upper1 = {location: this.fakeLoc(0), state: {}}; | |
112 let upper2 = {location: this.fakeLoc(0), state: {focusable: true}}; | |
113 let lower1 = {location: this.fakeLoc(0), state: {}}; | |
114 let lower2 = {location: this.fakeLoc(0), state: {}}; | |
115 let lower3 = {location: this.fakeLoc(0), state: {}}; | |
116 let leaf1 = {location: this.fakeLoc(0), state: {focusable: true}}; | |
117 let leaf2 = {location: this.fakeLoc(0), state: {}}; | |
118 let leaf3 = {location: this.fakeLoc(0), state: {focusable: true}}; | |
119 let leaf4 = {location: this.fakeLoc(0), state: {}}; | |
120 let leaf5 = {location: this.fakeLoc(0), state: {focusable: true}}; | |
121 let leaf6 = {location: this.fakeLoc(0), state: {}}; | |
122 let leaf7 = {location: this.fakeLoc(0), state: {}}; | |
123 | |
124 let ts = new TestSupport(); | |
125 ts.setChildren(root, [upper1, upper2]); | |
126 ts.setChildren(upper1, [lower1, lower2]); | |
127 ts.setChildren(upper2, [lower3]); | |
128 ts.setChildren(lower1, [leaf1, leaf2, leaf3]); | |
129 ts.setChildren(lower2, [leaf4, leaf5]); | |
130 ts.setChildren(lower3, [leaf6, leaf7]); | |
131 | |
132 return { | |
133 root: root, | |
134 upper1: upper1, | |
135 upper2: upper2, | |
136 lower1: lower1, | |
137 lower2: lower2, | |
138 lower3: lower3, | |
139 leaf1: leaf1, | |
140 leaf2: leaf2, | |
141 leaf3: leaf3, | |
142 leaf4: leaf4, | |
143 leaf5: leaf5, | |
144 leaf6: leaf6, | |
145 leaf7: leaf7, | |
146 }; | |
147 }, | |
24 }; | 148 }; |
25 | 149 |
150 TEST_F('AutomationPredicateUnitTest', 'IsSubtreeLeaf', function() { | |
151 let t = this.getMoreInterestingSampleTree(); | |
152 | |
153 assertTrue(AutomationPredicate.isSubtreeLeaf(t.root, t.root)); | |
154 assertTrue(AutomationPredicate.isSubtreeLeaf(t.upper1, t.root)); | |
155 assertTrue(AutomationPredicate.isSubtreeLeaf(t.upper2, t.root)); | |
156 assertTrue(AutomationPredicate.isSubtreeLeaf(t.lower1, t.upper1)); | |
157 assertFalse(AutomationPredicate.isSubtreeLeaf(t.lower2, t.upper1)); | |
158 assertTrue(AutomationPredicate.isSubtreeLeaf(t.lower3, t.root)); | |
159 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf1, t.lower1)); | |
160 assertFalse(AutomationPredicate.isSubtreeLeaf(t.leaf2, t.lower1)); | |
161 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf3, t.lower1)); | |
162 assertFalse(AutomationPredicate.isSubtreeLeaf(t.leaf4, t.upper1)); | |
163 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf5, t.upper1)); | |
164 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf6, t.lower3)); | |
165 assertTrue(AutomationPredicate.isSubtreeLeaf(t.leaf7, t.lower3)); | |
166 }); | |
167 | |
168 TEST_F('AutomationPredicateUnitTest', 'IsGroup', function() { | |
169 let t = this.getMoreInterestingSampleTree(); | |
170 | |
171 assertTrue(AutomationPredicate.isGroup(t.root, t.root)); | |
172 assertTrue(AutomationPredicate.isGroup(t.upper1, t.root)); | |
173 assertFalse(AutomationPredicate.isGroup(t.upper2, t.root)); | |
174 assertTrue(AutomationPredicate.isGroup(t.lower1, t.upper1)); | |
175 assertFalse(AutomationPredicate.isGroup(t.lower2, t.upper1)); | |
176 assertTrue(AutomationPredicate.isGroup(t.lower3, t.root)); | |
177 assertFalse(AutomationPredicate.isGroup(t.leaf1, t.lower1)); | |
178 assertFalse(AutomationPredicate.isGroup(t.leaf2, t.lower1)); | |
179 assertFalse(AutomationPredicate.isGroup(t.leaf3, t.lower1)); | |
180 assertFalse(AutomationPredicate.isGroup(t.leaf4, t.upper1)); | |
181 assertFalse(AutomationPredicate.isGroup(t.leaf5, t.upper1)); | |
182 assertFalse(AutomationPredicate.isGroup(t.leaf6, t.lower3)); | |
183 assertFalse(AutomationPredicate.isGroup(t.leaf7, t.lower3)); | |
184 | |
185 t.upper1.location = this.fakeLoc(0); | |
186 assertFalse(AutomationPredicate.isGroup(t.upper1, t.root)); | |
187 }); | |
188 | |
189 TEST_F('AutomationPredicateUnitTest', 'IsInterestingSubtree', function() { | |
190 let t = this.getLessInterestingSampleTree(); | |
191 | |
192 assertTrue(AutomationPredicate.isInterestingSubtree(t.root)); | |
193 assertTrue(AutomationPredicate.isInterestingSubtree(t.upper1)); | |
194 assertTrue(AutomationPredicate.isInterestingSubtree(t.upper2)); | |
195 assertTrue(AutomationPredicate.isInterestingSubtree(t.lower1)); | |
196 assertTrue(AutomationPredicate.isInterestingSubtree(t.lower2)); | |
197 assertFalse(AutomationPredicate.isInterestingSubtree(t.lower3)); | |
198 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf1)); | |
199 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf2)); | |
200 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf3)); | |
201 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf4)); | |
202 assertTrue(AutomationPredicate.isInterestingSubtree(t.leaf5)); | |
203 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf6)); | |
204 assertFalse(AutomationPredicate.isInterestingSubtree(t.leaf7)); | |
205 }); | |
206 | |
26 TEST_F('AutomationPredicateUnitTest', 'IsInteresting', function() { | 207 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. | 208 // Testing focusable. |
36 let loc1 = {left: 0, top: 0, width: 0, height: 0}; | 209 let loc1 = {left: 0, top: 0, width: 0, height: 0}; |
37 let node1 = {location: loc1, state: {}}; | 210 let node1 = {location: loc1, state: {}}; |
38 let node2 = {location: loc1, state: {focusable: false}}; | 211 let node2 = {location: loc1, state: {focusable: false}}; |
39 let node3 = {location: loc1, state: {focusable: true}}; | 212 let node3 = {location: loc1, state: {focusable: true}}; |
40 assertFalse(AutomationPredicate.isInteresting(node1)); | 213 assertFalse(AutomationPredicate.isInteresting(node1)); |
41 assertFalse(AutomationPredicate.isInteresting(node2)); | 214 assertFalse(AutomationPredicate.isInteresting(node2)); |
42 assertTrue(AutomationPredicate.isInteresting(node3)); | 215 assertTrue(AutomationPredicate.isInteresting(node3)); |
43 | 216 |
44 // Testing onscreen. | 217 // Testing onscreen. |
45 let loc2 = {left: -1, top: 0, width: 0, height: 0}; | 218 let loc2 = {left: -1, top: 0, width: 0, height: 0}; |
46 let loc3 = {left: 0, top: -1, width: 0, height: 0}; | 219 let loc3 = {left: 0, top: -1, width: 0, height: 0}; |
47 let node4 = {location: loc2, state: {focusable: true}}; | 220 let node4 = {location: loc2, state: {focusable: true}}; |
48 let node5 = {location: loc3, state: {focusable: true}}; | 221 let node5 = {location: loc3, state: {focusable: true}}; |
49 let node6 = {location: loc1, state: {focusable: true, offscreen: true}} | 222 let node6 = {location: loc1, state: {focusable: true, offscreen: true}} |
50 assertFalse(AutomationPredicate.isInteresting(node4)); | 223 assertFalse(AutomationPredicate.isInteresting(node4)); |
51 assertFalse(AutomationPredicate.isInteresting(node5)); | 224 assertFalse(AutomationPredicate.isInteresting(node5)); |
52 assertFalse(AutomationPredicate.isInteresting(node6)); | 225 assertFalse(AutomationPredicate.isInteresting(node6)); |
53 | 226 |
54 // Testing if tab. | 227 // Testing if tab. |
55 let node7 = {location: loc1, role: 'desktop', state: {}}; | 228 let node7 = {location: loc1, role: 'desktop', state: {}}; |
56 let node8 = {location: loc1, role: 'tabList', state: {}}; | 229 let node8 = {location: loc1, role: 'tabList', state: {}}; |
57 let node9 = | 230 let node9 = |
58 {location: loc1, parent: node8, root: node7, role: 'tab', state: {}}; | 231 {location: loc1, parent: node8, root: node7, role: 'tab', state: {}}; |
59 assertFalse(AutomationPredicate.isInteresting(node7)); | 232 assertFalse(AutomationPredicate.isInteresting(node7)); |
60 assertFalse(AutomationPredicate.isInteresting(node8)); | 233 assertFalse(AutomationPredicate.isInteresting(node8)); |
61 assertTrue(AutomationPredicate.isInteresting(node9)); | 234 assertTrue(AutomationPredicate.isInteresting(node9)); |
235 | |
236 // Testing if webView or rootWebArea. | |
237 let node10 = {location: loc1, role: 'webView', state: {focusable: true}}; | |
238 let node11 = {location: loc1, role: 'rootWebArea', state: {focusable: true}}; | |
239 assertFalse(AutomationPredicate.isInteresting(node10)); | |
240 assertFalse(AutomationPredicate.isInteresting(node11)); | |
62 }); | 241 }); |
OLD | NEW |