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 #import <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
6 | 6 |
7 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
8 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
9 #import "ios/chrome/browser/ui/autofill/autofill_edit_accessory_view.h" | 9 #import "ios/chrome/browser/ui/autofill/autofill_edit_accessory_view.h" |
10 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" | 10 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 @"Expected first responder to be of kind %@, got %@.", | 57 @"Expected first responder to be of kind %@, got %@.", |
58 [UITextField class], [firstResponder class]); | 58 [UITextField class], [firstResponder class]); |
59 UITextField* textField = | 59 UITextField* textField = |
60 base::mac::ObjCCastStrict<UITextField>(firstResponder); | 60 base::mac::ObjCCastStrict<UITextField>(firstResponder); |
61 GREYAssertTrue( | 61 GREYAssertTrue( |
62 [[textField accessibilityIdentifier] isEqualToString:accessibilityID], | 62 [[textField accessibilityIdentifier] isEqualToString:accessibilityID], |
63 @"Expected accessibility identifier to be %@, got %@.", accessibilityID, | 63 @"Expected accessibility identifier to be %@, got %@.", accessibilityID, |
64 [textField accessibilityIdentifier]); | 64 [textField accessibilityIdentifier]); |
65 } | 65 } |
66 | 66 |
| 67 // Returns the GREYMatcher for the UIAlertView's message displayed for a call |
| 68 // that notifies the delegate of selection of a field. |
| 69 id<GREYMatcher> UIAlertViewMessageForDelegateCallWithArgument( |
| 70 NSString* argument) { |
| 71 return grey_allOf( |
| 72 grey_text([NSString |
| 73 stringWithFormat:@"paymentRequestEditViewController:" |
| 74 @"kPaymentRequestEditCollectionViewAccessibilityID " |
| 75 @"didSelectField:%@", |
| 76 argument]), |
| 77 grey_sufficientlyVisible(), nil); |
| 78 } |
| 79 |
67 } // namespace | 80 } // namespace |
68 | 81 |
69 // Tests for the payment request editor view controller. | 82 // Tests for the payment request editor view controller. |
70 @interface SCPaymentsEditorTestCase : ShowcaseTestCase | 83 @interface SCPaymentsEditorTestCase : ShowcaseTestCase |
71 @end | 84 @end |
72 | 85 |
73 @implementation SCPaymentsEditorTestCase | 86 @implementation SCPaymentsEditorTestCase |
74 | 87 |
75 - (void)setUp { | 88 - (void)setUp { |
76 [super setUp]; | 89 [super setUp]; |
77 Open(@"PaymentRequestEditViewController"); | 90 Open(@"PaymentRequestEditViewController"); |
78 } | 91 } |
79 | 92 |
80 - (void)tearDown { | 93 - (void)tearDown { |
81 Close(); | 94 Close(); |
82 [super tearDown]; | 95 [super tearDown]; |
83 } | 96 } |
84 | 97 |
85 // Tests if expected labels and textfields exist and have the expected values. | 98 // Tests if expected labels and fields exist and have the expected values. |
86 - (void)testVerifyLabelsAndTextFields { | 99 - (void)testVerifyLabelsAndFields { |
87 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Name*")] | 100 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Name*")] |
88 assertWithMatcher:grey_notNil()]; | 101 assertWithMatcher:grey_notNil()]; |
89 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Name_textField")] | 102 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"Name_textField")] |
90 assertWithMatcher:grey_text(@"John Doe")]; | 103 assertWithMatcher:grey_text(@"John Doe")]; |
91 | 104 |
| 105 [[EarlGrey |
| 106 selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Country*"), |
| 107 grey_accessibilityValue(@"Canada"), |
| 108 nil)] |
| 109 assertWithMatcher:grey_notNil()]; |
| 110 |
92 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Address*")] | 111 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Address*")] |
93 assertWithMatcher:grey_notNil()]; | 112 assertWithMatcher:grey_notNil()]; |
94 [[EarlGrey | 113 [[EarlGrey |
95 selectElementWithMatcher:grey_accessibilityID(@"Address_textField")] | 114 selectElementWithMatcher:grey_accessibilityID(@"Address_textField")] |
96 assertWithMatcher:grey_text(@"")]; | 115 assertWithMatcher:grey_text(@"")]; |
97 | 116 |
98 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Postal Code")] | 117 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Postal Code")] |
99 assertWithMatcher:grey_notNil()]; | 118 assertWithMatcher:grey_notNil()]; |
100 [[EarlGrey | 119 [[EarlGrey |
101 selectElementWithMatcher:grey_accessibilityID(@"Postal Code_textField")] | 120 selectElementWithMatcher:grey_accessibilityID(@"Postal Code_textField")] |
102 assertWithMatcher:grey_text(@"")]; | 121 assertWithMatcher:grey_text(@"")]; |
103 } | 122 } |
104 | 123 |
| 124 // Tests if tapping the selector field notifies the delegate. |
| 125 - (void)testVerifyTappingSelectorFieldNotifiesDelegate { |
| 126 // Tap the selector field. |
| 127 [[EarlGrey |
| 128 selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Country*"), |
| 129 grey_accessibilityValue(@"Canada"), |
| 130 nil)] performAction:grey_tap()]; |
| 131 |
| 132 // Confirm the delegate is informed. |
| 133 [[EarlGrey |
| 134 selectElementWithMatcher:UIAlertViewMessageForDelegateCallWithArgument( |
| 135 @"Label: Country, Value: CAN")] |
| 136 assertWithMatcher:grey_notNil()]; |
| 137 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( |
| 138 @"protocol_alerter_done")] |
| 139 performAction:grey_tap()]; |
| 140 } |
| 141 |
105 // Tests whether tapping the input accessory view's close button dismisses the | 142 // Tests whether tapping the input accessory view's close button dismisses the |
106 // input accessory view. | 143 // input accessory view. |
107 - (void)testInputAccessoryViewCloseButton { | 144 - (void)testInputAccessoryViewCloseButton { |
108 if (IsIPadIdiom()) { | 145 if (IsIPadIdiom()) { |
109 // TODO(crbug.com/602666): Investigate why the close button is hidden on | 146 // TODO(crbug.com/602666): Investigate why the close button is hidden on |
110 // iPad. | 147 // iPad. |
111 EARL_GREY_TEST_DISABLED( | 148 EARL_GREY_TEST_DISABLED( |
112 @"Input accessory view's close button is hidden on iPad"); | 149 @"Input accessory view's close button is hidden on iPad"); |
113 } | 150 } |
114 | 151 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 [[EarlGrey selectElementWithMatcher:InputAccessoryViewPreviousButton()] | 200 [[EarlGrey selectElementWithMatcher:InputAccessoryViewPreviousButton()] |
164 assertWithMatcher:grey_enabled()]; | 201 assertWithMatcher:grey_enabled()]; |
165 // Assert the input accessory view's next button is enabled and tap it. | 202 // Assert the input accessory view's next button is enabled and tap it. |
166 [[[EarlGrey selectElementWithMatcher:InputAccessoryViewNextButton()] | 203 [[[EarlGrey selectElementWithMatcher:InputAccessoryViewNextButton()] |
167 assertWithMatcher:grey_enabled()] performAction:grey_tap()]; | 204 assertWithMatcher:grey_enabled()] performAction:grey_tap()]; |
168 | 205 |
169 // Assert an error message is showing because the address textfield is | 206 // Assert an error message is showing because the address textfield is |
170 // required. | 207 // required. |
171 [[EarlGrey selectElementWithMatcher:grey_accessibilityID( | 208 [[EarlGrey selectElementWithMatcher:grey_accessibilityID( |
172 kWarningMessageAccessibilityID)] | 209 kWarningMessageAccessibilityID)] |
173 assertWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( | 210 assertWithMatcher:grey_accessibilityLabel(@"Field is required")]; |
174 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE))]; | |
175 | 211 |
176 // Assert the postal code textfield is focused. | 212 // Assert the postal code textfield is focused. |
177 AssertTextFieldWithAccessibilityIDIsFirstResponder(@"Postal Code_textField"); | 213 AssertTextFieldWithAccessibilityIDIsFirstResponder(@"Postal Code_textField"); |
178 | 214 |
179 // Assert the input accessory view's next button is disabled. | 215 // Assert the input accessory view's next button is disabled. |
180 [[EarlGrey selectElementWithMatcher:InputAccessoryViewNextButton()] | 216 [[EarlGrey selectElementWithMatcher:InputAccessoryViewNextButton()] |
181 assertWithMatcher:grey_not(grey_enabled())]; | 217 assertWithMatcher:grey_not(grey_enabled())]; |
182 // Assert the input accessory view's previous button is enabled and tap it. | 218 // Assert the input accessory view's previous button is enabled and tap it. |
183 [[[EarlGrey selectElementWithMatcher:InputAccessoryViewPreviousButton()] | 219 [[[EarlGrey selectElementWithMatcher:InputAccessoryViewPreviousButton()] |
184 assertWithMatcher:grey_enabled()] performAction:grey_tap()]; | 220 assertWithMatcher:grey_enabled()] performAction:grey_tap()]; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 283 |
248 // Expect non of the textfields to be focused. | 284 // Expect non of the textfields to be focused. |
249 UIResponder* firstResponder = | 285 UIResponder* firstResponder = |
250 [[UIApplication sharedApplication].keyWindow firstResponder]; | 286 [[UIApplication sharedApplication].keyWindow firstResponder]; |
251 GREYAssertFalse([firstResponder isKindOfClass:[UITextField class]], | 287 GREYAssertFalse([firstResponder isKindOfClass:[UITextField class]], |
252 @"Expected first responder not to be of kind %@.", | 288 @"Expected first responder not to be of kind %@.", |
253 [UITextField class]); | 289 [UITextField class]); |
254 } | 290 } |
255 | 291 |
256 @end | 292 @end |
OLD | NEW |