OLD | NEW |
(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> SectionWithTitle(NSString* title) { |
| 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> RowWithLabel(NSString* label, BOOL selected) { |
| 28 id<GREYMatcher> matcher = grey_allOf( |
| 29 grey_ancestor( |
| 30 grey_accessibilityID(kPaymentRequestPickerRowAccessibilityID)), |
| 31 grey_text(label), grey_kindOfClass([UILabel class]), |
| 32 grey_sufficientlyVisible(), nil); |
| 33 |
| 34 if (selected) { |
| 35 return grey_allOf( |
| 36 matcher, |
| 37 grey_ancestor(grey_accessibilityTrait(UIAccessibilityTraitSelected)), |
| 38 nil); |
| 39 } |
| 40 return matcher; |
| 41 } |
| 42 |
| 43 // Returns the GREYMatcher for the search bar's cancel button. |
| 44 id<GREYMatcher> CancelButton() { |
| 45 return grey_allOf(grey_accessibilityLabel(@"Cancel"), |
| 46 grey_accessibilityTrait(UIAccessibilityTraitButton), |
| 47 grey_sufficientlyVisible(), nil); |
| 48 } |
| 49 |
| 50 } // namespace |
| 51 |
| 52 // Tests for the payment request picker view controller. |
| 53 @interface SCPaymentsPickerTestCase : ShowcaseTestCase |
| 54 @end |
| 55 |
| 56 @implementation SCPaymentsPickerTestCase |
| 57 |
| 58 - (void)setUp { |
| 59 [super setUp]; |
| 60 Open(@"PaymentRequestPickerViewController"); |
| 61 } |
| 62 |
| 63 - (void)tearDown { |
| 64 Close(); |
| 65 [super tearDown]; |
| 66 } |
| 67 |
| 68 // Tests if all the expected rows and sections are present and the expected row |
| 69 // is selected. |
| 70 - (void)testVerifyRowsAndSection { |
| 71 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"B")] |
| 72 assertWithMatcher:grey_notNil()]; |
| 73 |
| 74 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Belgium", NO)] |
| 75 assertWithMatcher:grey_notNil()]; |
| 76 |
| 77 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Brazil", NO)] |
| 78 assertWithMatcher:grey_notNil()]; |
| 79 |
| 80 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"C")] |
| 81 assertWithMatcher:grey_notNil()]; |
| 82 |
| 83 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", NO)] |
| 84 assertWithMatcher:grey_notNil()]; |
| 85 |
| 86 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Chile", NO)] |
| 87 assertWithMatcher:grey_notNil()]; |
| 88 |
| 89 // 'China' is selected. |
| 90 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", YES)] |
| 91 assertWithMatcher:grey_notNil()]; |
| 92 |
| 93 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"E")] |
| 94 assertWithMatcher:grey_notNil()]; |
| 95 |
| 96 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"España", NO)] |
| 97 assertWithMatcher:grey_notNil()]; |
| 98 |
| 99 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"M")] |
| 100 assertWithMatcher:grey_notNil()]; |
| 101 |
| 102 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"México", NO)] |
| 103 assertWithMatcher:grey_notNil()]; |
| 104 } |
| 105 |
| 106 // Tests if filtering works. |
| 107 - (void)testVerifyFiltering { |
| 108 // Type 'c' in the search bar. |
| 109 [[EarlGrey |
| 110 selectElementWithMatcher: |
| 111 grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)] |
| 112 performAction:grey_typeText(@"c")]; |
| 113 |
| 114 // Section 'B' should not be visible. |
| 115 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"B")] |
| 116 assertWithMatcher:grey_nil()]; |
| 117 |
| 118 // 'Belgium' should not be visible. |
| 119 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Belgium", NO)] |
| 120 assertWithMatcher:grey_nil()]; |
| 121 |
| 122 // 'Brazil' should not be visible. |
| 123 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Brazil", NO)] |
| 124 assertWithMatcher:grey_nil()]; |
| 125 |
| 126 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"C")] |
| 127 assertWithMatcher:grey_notNil()]; |
| 128 |
| 129 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", NO)] |
| 130 assertWithMatcher:grey_notNil()]; |
| 131 |
| 132 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Chile", NO)] |
| 133 assertWithMatcher:grey_notNil()]; |
| 134 |
| 135 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", YES)] |
| 136 assertWithMatcher:grey_notNil()]; |
| 137 |
| 138 // Section 'E' should not be visible. |
| 139 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"E")] |
| 140 assertWithMatcher:grey_nil()]; |
| 141 |
| 142 // 'España' should not be visible. |
| 143 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"España", NO)] |
| 144 assertWithMatcher:grey_nil()]; |
| 145 |
| 146 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"M")] |
| 147 assertWithMatcher:grey_notNil()]; |
| 148 |
| 149 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"México", NO)] |
| 150 assertWithMatcher:grey_notNil()]; |
| 151 |
| 152 // Type 'hi' in the search bar. So far we have typed "chi". |
| 153 [[EarlGrey |
| 154 selectElementWithMatcher: |
| 155 grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)] |
| 156 performAction:grey_typeText(@"hi")]; |
| 157 |
| 158 // Section 'B' should not be visible. |
| 159 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"B")] |
| 160 assertWithMatcher:grey_nil()]; |
| 161 |
| 162 // 'Belgium' should not be visible. |
| 163 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Belgium", NO)] |
| 164 assertWithMatcher:grey_nil()]; |
| 165 |
| 166 // 'Brazil' should not be visible. |
| 167 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Brazil", NO)] |
| 168 assertWithMatcher:grey_nil()]; |
| 169 |
| 170 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"C")] |
| 171 assertWithMatcher:grey_notNil()]; |
| 172 |
| 173 // 'Canada' should not be visible. |
| 174 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", NO)] |
| 175 assertWithMatcher:grey_nil()]; |
| 176 |
| 177 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Chile", NO)] |
| 178 assertWithMatcher:grey_notNil()]; |
| 179 |
| 180 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", YES)] |
| 181 assertWithMatcher:grey_notNil()]; |
| 182 |
| 183 // Section 'E' should not be visible. |
| 184 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"E")] |
| 185 assertWithMatcher:grey_nil()]; |
| 186 |
| 187 // 'España' should not be visible. |
| 188 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"España", NO)] |
| 189 assertWithMatcher:grey_nil()]; |
| 190 |
| 191 // Section 'M' should not be visible. |
| 192 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"M")] |
| 193 assertWithMatcher:grey_nil()]; |
| 194 |
| 195 // 'México' should not be visible. |
| 196 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"México", NO)] |
| 197 assertWithMatcher:grey_nil()]; |
| 198 |
| 199 // Type 'l' in the search bar. So far we have typed "chil". |
| 200 [[EarlGrey |
| 201 selectElementWithMatcher: |
| 202 grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)] |
| 203 performAction:grey_typeText(@"l")]; |
| 204 |
| 205 // Section 'B' should not be visible. |
| 206 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"B")] |
| 207 assertWithMatcher:grey_nil()]; |
| 208 |
| 209 // 'Belgium' should not be visible. |
| 210 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Belgium", NO)] |
| 211 assertWithMatcher:grey_nil()]; |
| 212 |
| 213 // 'Brazil' should not be visible. |
| 214 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Brazil", NO)] |
| 215 assertWithMatcher:grey_nil()]; |
| 216 |
| 217 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"C")] |
| 218 assertWithMatcher:grey_notNil()]; |
| 219 |
| 220 // 'Canada' should not be visible. |
| 221 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", NO)] |
| 222 assertWithMatcher:grey_nil()]; |
| 223 |
| 224 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Chile", NO)] |
| 225 assertWithMatcher:grey_notNil()]; |
| 226 |
| 227 // 'China' should not be visible. |
| 228 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", YES)] |
| 229 assertWithMatcher:grey_nil()]; |
| 230 |
| 231 // Section 'E' should not be visible. |
| 232 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"E")] |
| 233 assertWithMatcher:grey_nil()]; |
| 234 |
| 235 // 'España' should not be visible. |
| 236 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"España", NO)] |
| 237 assertWithMatcher:grey_nil()]; |
| 238 |
| 239 // Section 'M' should not be visible. |
| 240 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"M")] |
| 241 assertWithMatcher:grey_nil()]; |
| 242 |
| 243 // 'México' should not be visible. |
| 244 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"México", NO)] |
| 245 assertWithMatcher:grey_nil()]; |
| 246 |
| 247 // Cancel filtering the text in the search bar. |
| 248 [[EarlGrey selectElementWithMatcher:CancelButton()] performAction:grey_tap()]; |
| 249 |
| 250 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"B")] |
| 251 assertWithMatcher:grey_notNil()]; |
| 252 |
| 253 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Belgium", NO)] |
| 254 assertWithMatcher:grey_notNil()]; |
| 255 |
| 256 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Brazil", NO)] |
| 257 assertWithMatcher:grey_notNil()]; |
| 258 |
| 259 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"C")] |
| 260 assertWithMatcher:grey_notNil()]; |
| 261 |
| 262 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", NO)] |
| 263 assertWithMatcher:grey_notNil()]; |
| 264 |
| 265 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Chile", NO)] |
| 266 assertWithMatcher:grey_notNil()]; |
| 267 |
| 268 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", YES)] |
| 269 assertWithMatcher:grey_notNil()]; |
| 270 |
| 271 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"E")] |
| 272 assertWithMatcher:grey_notNil()]; |
| 273 |
| 274 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"España", NO)] |
| 275 assertWithMatcher:grey_notNil()]; |
| 276 |
| 277 [[EarlGrey selectElementWithMatcher:SectionWithTitle(@"M")] |
| 278 assertWithMatcher:grey_notNil()]; |
| 279 |
| 280 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"México", NO)] |
| 281 assertWithMatcher:grey_notNil()]; |
| 282 } |
| 283 |
| 284 // Tests that tapping a row should make it the selected row. |
| 285 - (void)testVerifySelection { |
| 286 // 'China' is selected. |
| 287 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", YES)] |
| 288 assertWithMatcher:grey_notNil()]; |
| 289 |
| 290 // 'Canada' is not selected. Tap it. |
| 291 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", NO)] |
| 292 performAction:grey_tap()]; |
| 293 |
| 294 // Confirm the delegate is informed. |
| 295 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( |
| 296 @"protocol_alerter_done")] |
| 297 performAction:grey_tap()]; |
| 298 |
| 299 // 'China' is not selected anymore. |
| 300 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", NO)] |
| 301 assertWithMatcher:grey_notNil()]; |
| 302 |
| 303 // Now 'Canada' is selected. Tap it again. |
| 304 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", YES)] |
| 305 performAction:grey_tap()]; |
| 306 |
| 307 // Confirm the delegate is informed. |
| 308 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( |
| 309 @"protocol_alerter_done")] |
| 310 performAction:grey_tap()]; |
| 311 |
| 312 // 'China' is still not selected. |
| 313 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"China", NO)] |
| 314 assertWithMatcher:grey_notNil()]; |
| 315 |
| 316 // 'Canada' is still selected. |
| 317 [[EarlGrey selectElementWithMatcher:RowWithLabel(@"Canada", YES)] |
| 318 assertWithMatcher:grey_notNil()]; |
| 319 } |
| 320 |
| 321 @end |
OLD | NEW |