Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: ios/showcase/payments/sc_payments_picker_egtest.mm

Issue 2778343002: [Payment Request] Picker view + showcase integration + egtests (Closed)
Patch Set: Initial Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import <EarlGrey/EarlGrey.h>
6
7 #import "ios/chrome/browser/payments/payment_request_picker_view_controller.h"
8 #import "ios/showcase/test/showcase_eg_utils.h"
9 #import "ios/showcase/test/showcase_test_case.h"
10
11 #if !defined(__has_feature) || !__has_feature(objc_arc)
12 #error "This file requires ARC support."
13 #endif
14
15 namespace {
16 using ::showcase_utils::Open;
17 using ::showcase_utils::Close;
18
19 // Returns the GREYMatcher for the section with the given title.
20 id<GREYMatcher> matcherForSectionWithTitle(NSString* title) {
lpromero 2017/03/29 11:38:15 I think the convention is to UpperCamelCase these.
lpromero 2017/03/29 11:38:15 I'd even omit the "matcher" in all these. It makes
Moe 2017/03/29 17:04:09 Done.
Moe 2017/03/29 17:04:09 Done.
21 return grey_allOf(grey_text(title), grey_kindOfClass([UILabel class]),
22 grey_sufficientlyVisible(), nil);
23 }
24
25 // Returns the GREYMatcher for the picker row with the given label. |selected|
26 // states whether or not the row must be selected.
27 id<GREYMatcher> matcherForRowWithLabel(NSString* label, BOOL selected) {
28 NSString* accessibilityID =
29 selected ? kPaymentRequestPickerSelectedRowAccessibilityID
lpromero 2017/03/29 11:38:15 Instead of having a different ID for both selected
Moe 2017/03/29 17:04:09 TIL! Done.
30 : kPaymentRequestPickerRowAccessibilityID;
31 return grey_allOf(grey_ancestor(grey_accessibilityID(accessibilityID)),
32 grey_text(label), grey_kindOfClass([UILabel class]),
33 grey_sufficientlyVisible(), nil);
34 }
35
36 // Returns the GREYMatcher for the search bar's cancel button.
37 id<GREYMatcher> cancelButtonMatcher() {
38 return grey_allOf(grey_accessibilityLabel(@"Cancel"),
39 grey_accessibilityTrait(UIAccessibilityTraitButton),
40 grey_sufficientlyVisible(), nil);
41 }
42
43 } // namespace
44
45 // Tests for the payment request picker view controller.
46 @interface SCPaymentsPickerTestCase : ShowcaseTestCase
47 @end
48
49 @implementation SCPaymentsPickerTestCase
50
51 - (void)setUp {
52 [super setUp];
53 Open(@"PaymentRequestPickerViewController");
54 }
55
56 - (void)tearDown {
57 Close();
58 [super tearDown];
59 }
60
61 // Tests if all the expected rows and sections are present and the expected row
62 // is selected.
63 - (void)testVerifyRowsAndSection {
64 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")]
65 assertWithMatcher:grey_notNil()];
66
67 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)]
68 assertWithMatcher:grey_notNil()];
69
70 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)]
71 assertWithMatcher:grey_notNil()];
72
73 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")]
74 assertWithMatcher:grey_notNil()];
75
76 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)]
77 assertWithMatcher:grey_notNil()];
78
79 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)]
80 assertWithMatcher:grey_notNil()];
81
82 // 'China' is selected.
83 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)]
84 assertWithMatcher:grey_notNil()];
85
86 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")]
87 assertWithMatcher:grey_notNil()];
88
89 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)]
90 assertWithMatcher:grey_notNil()];
91
92 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")]
93 assertWithMatcher:grey_notNil()];
94
95 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)]
96 assertWithMatcher:grey_notNil()];
97 }
98
99 // Tests if filtering works.
100 - (void)testVerifyFiltering {
101 // Type 'c' in the search bar.
102 [[EarlGrey
103 selectElementWithMatcher:
104 grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)]
105 performAction:grey_typeText(@"c")];
106
107 // Section 'B' should not be visible.
108 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")]
109 assertWithMatcher:grey_nil()];
110
111 // 'Belgium' should not be visible.
112 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)]
113 assertWithMatcher:grey_nil()];
114
115 // 'Brazil' should not be visible.
116 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)]
117 assertWithMatcher:grey_nil()];
118
119 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")]
120 assertWithMatcher:grey_notNil()];
121
122 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)]
123 assertWithMatcher:grey_notNil()];
124
125 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)]
126 assertWithMatcher:grey_notNil()];
127
128 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)]
129 assertWithMatcher:grey_notNil()];
130
131 // Section 'E' should not be visible.
132 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")]
133 assertWithMatcher:grey_nil()];
134
135 // 'España' should not be visible.
136 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)]
137 assertWithMatcher:grey_nil()];
138
139 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")]
140 assertWithMatcher:grey_notNil()];
141
142 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)]
143 assertWithMatcher:grey_notNil()];
144
145 // Type 'hi' in the search bar. So far we have typed "chi".
146 [[EarlGrey
147 selectElementWithMatcher:
148 grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)]
149 performAction:grey_typeText(@"hi")];
150
151 // Section 'B' should not be visible.
152 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")]
153 assertWithMatcher:grey_nil()];
154
155 // 'Belgium' should not be visible.
156 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)]
157 assertWithMatcher:grey_nil()];
158
159 // 'Brazil' should not be visible.
160 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)]
161 assertWithMatcher:grey_nil()];
162
163 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")]
164 assertWithMatcher:grey_notNil()];
165
166 // 'Canada' should not be visible.
167 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)]
168 assertWithMatcher:grey_nil()];
169
170 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)]
171 assertWithMatcher:grey_notNil()];
172
173 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)]
174 assertWithMatcher:grey_notNil()];
175
176 // Section 'E' should not be visible.
177 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")]
178 assertWithMatcher:grey_nil()];
179
180 // 'España' should not be visible.
181 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)]
182 assertWithMatcher:grey_nil()];
183
184 // Section 'M' should not be visible.
185 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")]
186 assertWithMatcher:grey_nil()];
187
188 // 'México' should not be visible.
189 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)]
190 assertWithMatcher:grey_nil()];
191
192 // Type 'l' in the search bar. So far we have typed "chil".
193 [[EarlGrey
194 selectElementWithMatcher:
195 grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)]
196 performAction:grey_typeText(@"l")];
197
198 // Section 'B' should not be visible.
199 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")]
200 assertWithMatcher:grey_nil()];
201
202 // 'Belgium' should not be visible.
203 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)]
204 assertWithMatcher:grey_nil()];
205
206 // 'Brazil' should not be visible.
207 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)]
208 assertWithMatcher:grey_nil()];
209
210 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")]
211 assertWithMatcher:grey_notNil()];
212
213 // 'Canada' should not be visible.
214 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)]
215 assertWithMatcher:grey_nil()];
216
217 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)]
218 assertWithMatcher:grey_notNil()];
219
220 // 'China' should not be visible.
221 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)]
222 assertWithMatcher:grey_nil()];
223
224 // Section 'E' should not be visible.
225 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")]
226 assertWithMatcher:grey_nil()];
227
228 // 'España' should not be visible.
229 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)]
230 assertWithMatcher:grey_nil()];
231
232 // Section 'M' should not be visible.
233 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")]
234 assertWithMatcher:grey_nil()];
235
236 // 'México' should not be visible.
237 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)]
238 assertWithMatcher:grey_nil()];
239
240 // Cancel filtering the text in the search bar.
241 [[EarlGrey selectElementWithMatcher:cancelButtonMatcher()]
242 performAction:grey_tap()];
243
244 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")]
245 assertWithMatcher:grey_notNil()];
246
247 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)]
248 assertWithMatcher:grey_notNil()];
249
250 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)]
251 assertWithMatcher:grey_notNil()];
252
253 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")]
254 assertWithMatcher:grey_notNil()];
255
256 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)]
257 assertWithMatcher:grey_notNil()];
258
259 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)]
260 assertWithMatcher:grey_notNil()];
261
262 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)]
263 assertWithMatcher:grey_notNil()];
264
265 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")]
266 assertWithMatcher:grey_notNil()];
267
268 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)]
269 assertWithMatcher:grey_notNil()];
270
271 [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")]
272 assertWithMatcher:grey_notNil()];
273
274 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)]
275 assertWithMatcher:grey_notNil()];
276 }
277
278 // Tests that tapping a row should make it the selected row.
279 - (void)testVerifySelection {
280 // 'China' is selected.
281 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)]
282 assertWithMatcher:grey_notNil()];
283
284 // 'Canada' is not selected. Tap it.
285 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)]
286 performAction:grey_tap()];
287
288 // 'China' is not selected anymore.
289 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", NO)]
290 assertWithMatcher:grey_notNil()];
291
292 // Now 'Canada' is selected. Tap it again.
293 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", YES)]
294 performAction:grey_tap()];
295
296 // 'China' is still not selected.
297 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", NO)]
298 assertWithMatcher:grey_notNil()];
299
300 // 'Canada' is still selected.
301 [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", YES)]
302 assertWithMatcher:grey_notNil()];
303 }
304
305 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698