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

Side by Side Diff: ios/chrome/browser/ui/settings/autofill_settings_egtest.mm

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 10 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <XCTest/XCTest.h> 5 #import <XCTest/XCTest.h>
6 6
7 #import "base/mac/bind_objc_block.h" 7 #import "base/mac/bind_objc_block.h"
8 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" 8 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
9 #include "ios/chrome/grit/ios_strings.h" 9 #include "ios/chrome/grit/ios_strings.h"
10 #include "ios/chrome/test/app/web_view_interaction_test_util.h" 10 #include "ios/chrome/test/app/web_view_interaction_test_util.h"
11 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 11 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
12 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" 12 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
13 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 13 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
14 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 14 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
15 #import "ios/web/public/test/http_server.h" 15 #import "ios/web/public/test/http_server.h"
16 #include "ios/web/public/test/http_server_util.h" 16 #include "ios/web/public/test/http_server_util.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 18
19 using chrome_test_util::buttonWithAccessibilityLabel; 19 using chrome_test_util::ButtonWithAccessibilityLabel;
20 using chrome_test_util::buttonWithAccessibilityLabelId; 20 using chrome_test_util::ButtonWithAccessibilityLabelId;
21 21
22 namespace { 22 namespace {
23 23
24 // Expectation of how the saved autofill profile looks like, a map from cell 24 // Expectation of how the saved autofill profile looks like, a map from cell
25 // name IDs to expected contents. 25 // name IDs to expected contents.
26 struct DisplayStringIDToExpectedResult { 26 struct DisplayStringIDToExpectedResult {
27 int display_string_id; 27 int display_string_id;
28 NSString* expected_result; 28 NSString* expected_result;
29 }; 29 };
30 30
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // edit dialog of the address profile. 67 // edit dialog of the address profile.
68 NSString* GetTextFieldForID(int categoryId) { 68 NSString* GetTextFieldForID(int categoryId) {
69 return [NSString 69 return [NSString
70 stringWithFormat:@"%@_textField", l10n_util::GetNSString(categoryId)]; 70 stringWithFormat:@"%@_textField", l10n_util::GetNSString(categoryId)];
71 } 71 }
72 72
73 // Call this in the "Edit Address" view to clear the Country value. The case 73 // Call this in the "Edit Address" view to clear the Country value. The case
74 // of the value being empty is handled gracefully. 74 // of the value being empty is handled gracefully.
75 void ClearCountryValue() { 75 void ClearCountryValue() {
76 // Switch on edit mode. 76 // Switch on edit mode.
77 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId( 77 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
78 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)] 78 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)]
79 performAction:grey_tap()]; 79 performAction:grey_tap()];
80 80
81 // The test only can tap "Select All" if there is a text to select. Type "a" 81 // The test only can tap "Select All" if there is a text to select. Type "a"
82 // to ensure that. 82 // to ensure that.
83 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID( 83 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID(
84 IDS_IOS_AUTOFILL_COUNTRY))] 84 IDS_IOS_AUTOFILL_COUNTRY))]
85 performAction:grey_typeText(@"a")]; 85 performAction:grey_typeText(@"a")];
86 // Remove the country value by select all + cut. 86 // Remove the country value by select all + cut.
87 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID( 87 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID(
88 IDS_IOS_AUTOFILL_COUNTRY))] 88 IDS_IOS_AUTOFILL_COUNTRY))]
89 performAction:grey_longPress()]; 89 performAction:grey_longPress()];
90 [[EarlGrey 90 [[EarlGrey
91 selectElementWithMatcher:grey_allOf( 91 selectElementWithMatcher:grey_allOf(
92 grey_accessibilityLabel(@"Select All"), 92 grey_accessibilityLabel(@"Select All"),
93 grey_accessibilityTrait( 93 grey_accessibilityTrait(
94 UIAccessibilityTraitStaticText), 94 UIAccessibilityTraitStaticText),
95 nil)] performAction:grey_tap()]; 95 nil)] performAction:grey_tap()];
96 [[EarlGrey 96 [[EarlGrey
97 selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Cut"), 97 selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Cut"),
98 grey_accessibilityTrait( 98 grey_accessibilityTrait(
99 UIAccessibilityTraitStaticText), 99 UIAccessibilityTraitStaticText),
100 nil)] performAction:grey_tap()]; 100 nil)] performAction:grey_tap()];
101 101
102 // Switch off edit mode. 102 // Switch off edit mode.
103 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId( 103 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
104 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] 104 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
105 performAction:grey_tap()]; 105 performAction:grey_tap()];
106 } 106 }
107 107
108 } // namespace 108 } // namespace
109 109
110 // Various tests for the Autofill section of the settings. 110 // Various tests for the Autofill section of the settings.
111 @interface AutofillSettingsTestCase : ChromeTestCase 111 @interface AutofillSettingsTestCase : ChromeTestCase
112 @end 112 @end
113 113
(...skipping 13 matching lines...) Expand all
127 } 127 }
128 128
129 // Helper to open the settings page for the record with |address|. 129 // Helper to open the settings page for the record with |address|.
130 - (void)openEditAddress:(NSString*)address { 130 - (void)openEditAddress:(NSString*)address {
131 // Open settings and verify data in the view controller. 131 // Open settings and verify data in the view controller.
132 [ChromeEarlGreyUI openToolsMenu]; 132 [ChromeEarlGreyUI openToolsMenu];
133 [[EarlGrey 133 [[EarlGrey
134 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] 134 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
135 performAction:grey_tap()]; 135 performAction:grey_tap()];
136 NSString* label = l10n_util::GetNSString(IDS_IOS_AUTOFILL); 136 NSString* label = l10n_util::GetNSString(IDS_IOS_AUTOFILL);
137 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabel(label)] 137 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabel(label)]
138 performAction:grey_tap()]; 138 performAction:grey_tap()];
139 139
140 // Tap on the 'George Washington' result. 140 // Tap on the 'George Washington' result.
141 NSString* cellLabel = address; 141 NSString* cellLabel = address;
142 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(cellLabel)] 142 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(cellLabel)]
143 performAction:grey_tap()]; 143 performAction:grey_tap()];
144 } 144 }
145 145
146 // Close the settings. 146 // Close the settings.
147 - (void)exitSettingsMenu { 147 - (void)exitSettingsMenu {
148 NSString* backButtonA11yId = @"ic_arrow_back"; 148 NSString* backButtonA11yId = @"ic_arrow_back";
149 [[EarlGrey 149 [[EarlGrey
150 selectElementWithMatcher:grey_allOf( 150 selectElementWithMatcher:grey_allOf(
151 grey_accessibilityID(backButtonA11yId), 151 grey_accessibilityID(backButtonA11yId),
152 grey_accessibilityTrait( 152 grey_accessibilityTrait(
153 UIAccessibilityTraitButton), 153 UIAccessibilityTraitButton),
154 nil)] performAction:grey_tap()]; 154 nil)] performAction:grey_tap()];
155 [[EarlGrey 155 [[EarlGrey
156 selectElementWithMatcher:grey_allOf( 156 selectElementWithMatcher:grey_allOf(
157 grey_accessibilityID(backButtonA11yId), 157 grey_accessibilityID(backButtonA11yId),
158 grey_accessibilityTrait( 158 grey_accessibilityTrait(
159 UIAccessibilityTraitButton), 159 UIAccessibilityTraitButton),
160 nil)] performAction:grey_tap()]; 160 nil)] performAction:grey_tap()];
161 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId( 161 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
162 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] 162 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
163 performAction:grey_tap()]; 163 performAction:grey_tap()];
164 // Wait for UI components to finish loading. 164 // Wait for UI components to finish loading.
165 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; 165 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
166 } 166 }
167 167
168 // Test that submitting a form ensures saving the data as an autofill profile. 168 // Test that submitting a form ensures saving the data as an autofill profile.
169 - (void)testAutofillProfileSaving { 169 - (void)testAutofillProfileSaving {
170 [self loadAndSubmitTheForm]; 170 [self loadAndSubmitTheForm];
171 [self openEditAddress:@"George Washington, 1600 Pennsylvania Ave NW"]; 171 [self openEditAddress:@"George Washington, 1600 Pennsylvania Ave NW"];
(...skipping 16 matching lines...) Expand all
188 // replacing it with a canonical one. 188 // replacing it with a canonical one.
189 - (void)testAutofillProfileEditing { 189 - (void)testAutofillProfileEditing {
190 [self loadAndSubmitTheForm]; 190 [self loadAndSubmitTheForm];
191 [self openEditAddress:@"George Washington, 1600 Pennsylvania Ave NW"]; 191 [self openEditAddress:@"George Washington, 1600 Pennsylvania Ave NW"];
192 192
193 // Keep editing the Country field and verify that validation works. 193 // Keep editing the Country field and verify that validation works.
194 for (const UserTypedCountryExpectedResultPair& expectation : kCountryTests) { 194 for (const UserTypedCountryExpectedResultPair& expectation : kCountryTests) {
195 ClearCountryValue(); 195 ClearCountryValue();
196 196
197 // Switch on edit mode. 197 // Switch on edit mode.
198 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId( 198 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
199 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)] 199 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)]
200 performAction:grey_tap()]; 200 performAction:grey_tap()];
201 201
202 // Type the user-version of the country. 202 // Type the user-version of the country.
203 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID( 203 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID(
204 IDS_IOS_AUTOFILL_COUNTRY))] 204 IDS_IOS_AUTOFILL_COUNTRY))]
205 performAction:grey_typeText(expectation.user_typed_country)]; 205 performAction:grey_typeText(expectation.user_typed_country)];
206 206
207 // Switch off edit mode. 207 // Switch off edit mode.
208 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId( 208 [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId(
209 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)] 209 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
210 performAction:grey_tap()]; 210 performAction:grey_tap()];
211 211
212 // Verify that the country value was changed to canonical. 212 // Verify that the country value was changed to canonical.
213 [[EarlGrey 213 [[EarlGrey
214 selectElementWithMatcher: 214 selectElementWithMatcher:
215 grey_accessibilityLabel([NSString 215 grey_accessibilityLabel([NSString
216 stringWithFormat:@"%@, %@", l10n_util::GetNSString( 216 stringWithFormat:@"%@, %@", l10n_util::GetNSString(
217 IDS_IOS_AUTOFILL_COUNTRY), 217 IDS_IOS_AUTOFILL_COUNTRY),
218 expectation.expected_result])] 218 expectation.expected_result])]
219 assertWithMatcher:grey_notNil()]; 219 assertWithMatcher:grey_notNil()];
220 } 220 }
221 221
222 [self exitSettingsMenu]; 222 [self exitSettingsMenu];
223 } 223 }
224 224
225 @end 225 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/settings/accounts_collection_egtest.mm ('k') | ios/chrome/browser/ui/settings/block_popups_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698