Chromium Code Reviews| Index: ios/showcase/payments/sc_payments_picker_egtest.mm |
| diff --git a/ios/showcase/payments/sc_payments_picker_egtest.mm b/ios/showcase/payments/sc_payments_picker_egtest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4046c4e5e2dac5eac25b69286e5d98d299d802aa |
| --- /dev/null |
| +++ b/ios/showcase/payments/sc_payments_picker_egtest.mm |
| @@ -0,0 +1,305 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import <EarlGrey/EarlGrey.h> |
| + |
| +#import "ios/chrome/browser/payments/payment_request_picker_view_controller.h" |
| +#import "ios/showcase/test/showcase_eg_utils.h" |
| +#import "ios/showcase/test/showcase_test_case.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace { |
| +using ::showcase_utils::Open; |
| +using ::showcase_utils::Close; |
| + |
| +// Returns the GREYMatcher for the section with the given title. |
| +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.
|
| + return grey_allOf(grey_text(title), grey_kindOfClass([UILabel class]), |
| + grey_sufficientlyVisible(), nil); |
| +} |
| + |
| +// Returns the GREYMatcher for the picker row with the given label. |selected| |
| +// states whether or not the row must be selected. |
| +id<GREYMatcher> matcherForRowWithLabel(NSString* label, BOOL selected) { |
| + NSString* accessibilityID = |
| + 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.
|
| + : kPaymentRequestPickerRowAccessibilityID; |
| + return grey_allOf(grey_ancestor(grey_accessibilityID(accessibilityID)), |
| + grey_text(label), grey_kindOfClass([UILabel class]), |
| + grey_sufficientlyVisible(), nil); |
| +} |
| + |
| +// Returns the GREYMatcher for the search bar's cancel button. |
| +id<GREYMatcher> cancelButtonMatcher() { |
| + return grey_allOf(grey_accessibilityLabel(@"Cancel"), |
| + grey_accessibilityTrait(UIAccessibilityTraitButton), |
| + grey_sufficientlyVisible(), nil); |
| +} |
| + |
| +} // namespace |
| + |
| +// Tests for the payment request picker view controller. |
| +@interface SCPaymentsPickerTestCase : ShowcaseTestCase |
| +@end |
| + |
| +@implementation SCPaymentsPickerTestCase |
| + |
| +- (void)setUp { |
| + [super setUp]; |
| + Open(@"PaymentRequestPickerViewController"); |
| +} |
| + |
| +- (void)tearDown { |
| + Close(); |
| + [super tearDown]; |
| +} |
| + |
| +// Tests if all the expected rows and sections are present and the expected row |
| +// is selected. |
| +- (void)testVerifyRowsAndSection { |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // 'China' is selected. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests if filtering works. |
| +- (void)testVerifyFiltering { |
| + // Type 'c' in the search bar. |
| + [[EarlGrey |
| + selectElementWithMatcher: |
| + grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)] |
| + performAction:grey_typeText(@"c")]; |
| + |
| + // Section 'B' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'Belgium' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'Brazil' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Section 'E' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'España' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Type 'hi' in the search bar. So far we have typed "chi". |
| + [[EarlGrey |
| + selectElementWithMatcher: |
| + grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)] |
| + performAction:grey_typeText(@"hi")]; |
| + |
| + // Section 'B' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'Belgium' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'Brazil' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // 'Canada' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Section 'E' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'España' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // Section 'M' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'México' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // Type 'l' in the search bar. So far we have typed "chil". |
| + [[EarlGrey |
| + selectElementWithMatcher: |
| + grey_accessibilityID(kPaymentRequestPickerSearchBarAccessibilityID)] |
| + performAction:grey_typeText(@"l")]; |
| + |
| + // Section 'B' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'Belgium' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'Brazil' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // 'Canada' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // 'China' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // Section 'E' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'España' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // Section 'M' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // 'México' should not be visible. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // Cancel filtering the text in the search bar. |
| + [[EarlGrey selectElementWithMatcher:cancelButtonMatcher()] |
| + performAction:grey_tap()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"B")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Belgium", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Brazil", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"C")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Chile", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"E")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"España", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForSectionWithTitle(@"M")] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"México", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests that tapping a row should make it the selected row. |
| +- (void)testVerifySelection { |
| + // 'China' is selected. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", YES)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // 'Canada' is not selected. Tap it. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", NO)] |
| + performAction:grey_tap()]; |
| + |
| + // 'China' is not selected anymore. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Now 'Canada' is selected. Tap it again. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", YES)] |
| + performAction:grey_tap()]; |
| + |
| + // 'China' is still not selected. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"China", NO)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // 'Canada' is still selected. |
| + [[EarlGrey selectElementWithMatcher:matcherForRowWithLabel(@"Canada", YES)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +@end |