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

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

Issue 2589583003: Upstream Chrome on iOS source code [7/11]. (Closed)
Patch Set: Created 4 years 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 2016 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 <XCTest/XCTest.h>
6
7 #include "base/mac/bind_objc_block.h"
8 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h"
9 #include "ios/chrome/grit/ios_strings.h"
10 #import "ios/chrome/test/app/web_view_interaction_test_util.h"
11 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
12 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
13 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
14 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
15 #import "ios/web/public/test/http_server.h"
16 #import "ios/web/public/test/http_server_util.h"
17 #include "ui/base/l10n/l10n_util.h"
18
19 using chrome_test_util::buttonWithAccessibilityLabel;
20 using chrome_test_util::buttonWithAccessibilityLabelId;
21
22 namespace {
23
24 // Expectation of how the saved autofill profile looks like, a map from cell
25 // name IDs to expected contents.
26 struct DisplayStringIDToExpectedResult {
27 int display_string_id;
28 NSString* expected_result;
29 };
30
31 const DisplayStringIDToExpectedResult kExpectedFields[] = {
32 {IDS_IOS_AUTOFILL_FULLNAME, @"George Washington"},
33 {IDS_IOS_AUTOFILL_COMPANY_NAME, @""},
34 {IDS_IOS_AUTOFILL_ADDRESS1, @"1600 Pennsylvania Ave NW"},
35 {IDS_IOS_AUTOFILL_ADDRESS2, @""},
36 {IDS_IOS_AUTOFILL_CITY, @"Washington"},
37 {IDS_IOS_AUTOFILL_STATE, @"DC"},
38 {IDS_IOS_AUTOFILL_ZIP, @"20500"},
39 {IDS_IOS_AUTOFILL_PHONE, @""},
40 {IDS_IOS_AUTOFILL_EMAIL, @""}};
41
42 // Expectation of how user-typed country names should be canonicalized.
43 struct UserTypedCountryExpectedResultPair {
44 NSString* user_typed_country;
45 NSString* expected_result;
46 };
47
48 const UserTypedCountryExpectedResultPair kCountryTests[] = {
49 {@"Brasil", @"Brazil"},
50 {@"China", @"China"},
51 {@"DEUTSCHLAND", @"Germany"},
52 {@"GREAT BRITAIN", @"United Kingdom"},
53 {@"IN", @"India"},
54 {@"JaPaN", @"Japan"},
55 {@"JP", @"Japan"},
56 {@"Nigeria", @"Nigeria"},
57 {@"TW", @"Taiwan"},
58 {@"U.S.A.", @"United States"},
59 {@"UK", @"United Kingdom"},
60 {@"USA", @"United States"},
61 {@"Nonexistia", @""},
62 };
63
64 // Given a resource ID of a category of an address profile, it returns a
65 // NSString consisting of the resource string concatenated with "_textField".
66 // This is the a11y ID of the text field corresponding to the category in the
67 // edit dialog of the address profile.
68 NSString* GetTextFieldForID(int categoryId) {
69 return [NSString
70 stringWithFormat:@"%@_textField", l10n_util::GetNSString(categoryId)];
71 }
72
73 // Call this in the "Edit Address" view to clear the Country value. The case
74 // of the value being empty is handled gracefully.
75 void ClearCountryValue() {
76 // Switch on edit mode.
77 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId(
78 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)]
79 performAction:grey_tap()];
80
81 // The test only can tap "Select All" if there is a text to select. Type "a"
82 // to ensure that.
83 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID(
84 IDS_IOS_AUTOFILL_COUNTRY))]
85 performAction:grey_typeText(@"a")];
86 // Remove the country value by select all + cut.
87 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID(
88 IDS_IOS_AUTOFILL_COUNTRY))]
89 performAction:grey_longPress()];
90 [[EarlGrey
91 selectElementWithMatcher:grey_allOf(
92 grey_accessibilityLabel(@"Select All"),
93 grey_accessibilityTrait(
94 UIAccessibilityTraitStaticText),
95 nil)] performAction:grey_tap()];
96 [[EarlGrey
97 selectElementWithMatcher:grey_allOf(grey_accessibilityLabel(@"Cut"),
98 grey_accessibilityTrait(
99 UIAccessibilityTraitStaticText),
100 nil)] performAction:grey_tap()];
101
102 // Switch off edit mode.
103 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId(
104 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
105 performAction:grey_tap()];
106 }
107
108 } // namespace
109
110 // Various tests for the Autofill section of the settings.
111 @interface AutofillSettingsTestCase : ChromeTestCase
112 @end
113
114 @implementation AutofillSettingsTestCase
115
116 // Helper to load a page with an address form and submit it.
117 - (void)loadAndSubmitTheForm {
118 web::test::SetUpFileBasedHttpServer();
119 const GURL URL = web::test::HttpServer::MakeUrl(
120 "http://ios/testing/data/http_server_files/autofill_smoke_test.html");
121
122 [ChromeEarlGrey loadURL:URL];
123
124 // Autofill one of the forms.
125 chrome_test_util::TapWebViewElementWithId("fill_profile_president");
126 chrome_test_util::TapWebViewElementWithId("submit_profile");
127 }
128
129 // Helper to open the settings page for the record with |address|.
130 - (void)openEditAddress:(NSString*)address {
131 // Open settings and verify data in the view controller.
132 [ChromeEarlGreyUI openToolsMenu];
133 [[EarlGrey
134 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)]
135 performAction:grey_tap()];
136 NSString* label = l10n_util::GetNSString(IDS_IOS_AUTOFILL);
137 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabel(label)]
138 performAction:grey_tap()];
139
140 // Tap on the 'George Washington' result.
141 NSString* cellLabel = address;
142 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(cellLabel)]
143 performAction:grey_tap()];
144 }
145
146 // Close the settings.
147 - (void)exitSettingsMenu {
148 NSString* backButtonA11yId = @"back_bar_button";
149 [[EarlGrey
150 selectElementWithMatcher:grey_allOf(
151 grey_accessibilityID(backButtonA11yId),
152 grey_accessibilityTrait(
153 UIAccessibilityTraitButton),
154 nil)] performAction:grey_tap()];
155 [[EarlGrey
156 selectElementWithMatcher:grey_allOf(
157 grey_accessibilityID(backButtonA11yId),
158 grey_accessibilityTrait(
159 UIAccessibilityTraitButton),
160 nil)] performAction:grey_tap()];
161 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId(
162 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
163 performAction:grey_tap()];
164 // Wait for UI components to finish loading.
165 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
166 }
167
168 // Test that submitting a form ensures saving the data as an autofill profile.
169 - (void)testAutofillProfileSaving {
170 [self loadAndSubmitTheForm];
171 [self openEditAddress:@"George Washington, 1600 Pennsylvania Ave NW"];
172
173 // Check that all fields and values match the expectations.
174 for (const DisplayStringIDToExpectedResult& expectation : kExpectedFields) {
175 [[EarlGrey
176 selectElementWithMatcher:
177 grey_accessibilityLabel([NSString
178 stringWithFormat:@"%@, %@", l10n_util::GetNSString(
179 expectation.display_string_id),
180 expectation.expected_result])]
181 assertWithMatcher:grey_notNil()];
182 }
183
184 [self exitSettingsMenu];
185 }
186
187 // Test that editing country names is followed by validating the value and
188 // replacing it with a canonical one.
189 - (void)testAutofillProfileEditing {
190 [self loadAndSubmitTheForm];
191 [self openEditAddress:@"George Washington, 1600 Pennsylvania Ave NW"];
192
193 // Keep editing the Country field and verify that validation works.
194 for (const UserTypedCountryExpectedResultPair& expectation : kCountryTests) {
195 ClearCountryValue();
196
197 // Switch on edit mode.
198 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId(
199 IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)]
200 performAction:grey_tap()];
201
202 // Type the user-version of the country.
203 [[EarlGrey selectElementWithMatcher:grey_accessibilityID(GetTextFieldForID(
204 IDS_IOS_AUTOFILL_COUNTRY))]
205 performAction:grey_typeText(expectation.user_typed_country)];
206
207 // Switch off edit mode.
208 [[EarlGrey selectElementWithMatcher:buttonWithAccessibilityLabelId(
209 IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)]
210 performAction:grey_tap()];
211
212 // Verify that the country value was changed to canonical.
213 [[EarlGrey
214 selectElementWithMatcher:
215 grey_accessibilityLabel([NSString
216 stringWithFormat:@"%@, %@", l10n_util::GetNSString(
217 IDS_IOS_AUTOFILL_COUNTRY),
218 expectation.expected_result])]
219 assertWithMatcher:grey_notNil()];
220 }
221
222 [self exitSettingsMenu];
223 }
224
225 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698