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

Side by Side Diff: components/autofill/core/browser/autofill_field_unittest.cc

Issue 361833004: autofill: be more open minded about filling in states in <option>s. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "base/format_macros.h" 5 #include "base/format_macros.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_field.h" 9 #include "components/autofill/core/browser/autofill_field.h"
10 #include "components/autofill/core/browser/autofill_type.h" 10 #include "components/autofill/core/browser/autofill_type.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 }; 211 };
212 AutofillField field( 212 AutofillField field(
213 GenerateSelectFieldWithOptions(kStates, arraysize(kStates)), 213 GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
214 base::string16()); 214 base::string16());
215 field.set_heuristic_type(ADDRESS_HOME_STATE); 215 field.set_heuristic_type(ADDRESS_HOME_STATE);
216 216
217 AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", &field); 217 AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US", &field);
218 EXPECT_EQ(ASCIIToUTF16("California"), field.value); 218 EXPECT_EQ(ASCIIToUTF16("California"), field.value);
219 } 219 }
220 220
221 TEST(AutofillFieldTest, FillSelectControlWithWithAbbreviateStateNames) { 221 TEST(AutofillFieldTest, FillSelectControlWithAbbreviateStateNames) {
222 const char* const kStates[] = { 222 const char* const kStates[] = {
223 "AL", "CA" 223 "AL", "CA"
224 }; 224 };
225 AutofillField field( 225 AutofillField field(
226 GenerateSelectFieldWithOptions(kStates, arraysize(kStates)), 226 GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
227 base::string16()); 227 base::string16());
228 field.set_heuristic_type(ADDRESS_HOME_STATE); 228 field.set_heuristic_type(ADDRESS_HOME_STATE);
229 229
230 AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US", 230 AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US",
231 &field); 231 &field);
232 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); 232 EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
233 } 233 }
234 234
235 TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) {
236 {
237 const char* const kStates[] = {
238 "CA - California", "NC - North Carolina",
Dan Beam 2014/07/01 00:34:32 can you reverse the order of these?
Ilya Sherman 2014/07/01 00:59:08 (Or, alternately, include an empty default item.)
Evan Stade 2014/07/01 01:04:56 I don't understand the purpose of either request.
Ilya Sherman 2014/07/01 01:17:47 My reasoning, which might or might not match Dan's
Dan Beam 2014/07/01 01:18:46 it currently looks like this test will select "CA
Evan Stade 2014/07/01 18:59:26 The main point of the test is to make sure "CA - C
Evan Stade 2014/07/01 23:08:52 But other tests (such as the one that uses kNotSta
239 };
240 AutofillField field(
241 GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
242 base::string16());
243 field.set_heuristic_type(ADDRESS_HOME_STATE);
244
245 AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US",
246 &field);
247 EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value);
248 }
249
250 // Tests that substring matches work for full state names.
251 {
252 const char* const kStates[] = {
253 "California.", "North Carolina.",
254 };
255 AutofillField field(
256 GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
257 base::string16());
258 field.set_heuristic_type(ADDRESS_HOME_STATE);
259
260 AutofillField::FillFormField(field, ASCIIToUTF16("California"), "en-US",
261 &field);
262 EXPECT_EQ(ASCIIToUTF16("California."), field.value);
263 }
264 }
265
266 TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) {
267 {
268 const char* const kStates[] = {
269 "NC - North Carolina", "CA - California",
270 };
271 AutofillField field(
272 GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
273 base::string16());
274 field.set_heuristic_type(ADDRESS_HOME_STATE);
275
276 AutofillField::FillFormField(field, ASCIIToUTF16("CA"), "en-US",
277 &field);
278 EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value);
279 }
280
281 {
282 const char* const kNotStates[] = {
283 "NCNCA", "SCNCA",
284 };
285 AutofillField field(
286 GenerateSelectFieldWithOptions(kNotStates, arraysize(kNotStates)),
287 base::string16());
288 field.set_heuristic_type(ADDRESS_HOME_STATE);
289
290 AutofillField::FillFormField(field, ASCIIToUTF16("NC"), "en-US",
291 &field);
292 EXPECT_EQ(base::string16(), field.value);
293 }
294 }
295
235 TEST(AutofillFieldTest, FillSelectControlWithNumericMonth) { 296 TEST(AutofillFieldTest, FillSelectControlWithNumericMonth) {
236 const char* const kMonthsNumeric[] = { 297 const char* const kMonthsNumeric[] = {
237 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", 298 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
238 }; 299 };
239 AutofillField field( 300 AutofillField field(
240 GenerateSelectFieldWithOptions(kMonthsNumeric, arraysize(kMonthsNumeric)), 301 GenerateSelectFieldWithOptions(kMonthsNumeric, arraysize(kMonthsNumeric)),
241 base::string16()); 302 base::string16());
242 field.set_heuristic_type(CREDIT_CARD_EXP_MONTH); 303 field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
243 304
244 // Try with a leading zero. 305 // Try with a leading zero.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 field.set_server_type(ADDRESS_HOME_STREET_ADDRESS); 432 field.set_server_type(ADDRESS_HOME_STREET_ADDRESS);
372 433
373 base::string16 value = ASCIIToUTF16("123 Fake St.\n" 434 base::string16 value = ASCIIToUTF16("123 Fake St.\n"
374 "Apt. 42"); 435 "Apt. 42");
375 AutofillField::FillFormField(field, value, "en-US", &field); 436 AutofillField::FillFormField(field, value, "en-US", &field);
376 EXPECT_EQ(ASCIIToUTF16("123 Fake St., Apt. 42"), field.value); 437 EXPECT_EQ(ASCIIToUTF16("123 Fake St., Apt. 42"), field.value);
377 } 438 }
378 439
379 } // namespace 440 } // namespace
380 } // namespace autofill 441 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698