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
3 // found in the LICENSE file.
5 #include "components/autofill/core/browser/autofill_field.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_type.h"
11 #include "components/autofill/core/browser/field_types.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 using base::ASCIIToUTF16
;
15 using base::UTF8ToUTF16
;
20 // Returns a FormFieldData object corresponding to a <select> field populated
21 // with the given |options|.
22 FormFieldData
GenerateSelectFieldWithOptions(const char* const* options
,
23 size_t options_size
) {
24 std::vector
<base::string16
> options16(options_size
);
25 for (size_t i
= 0; i
< options_size
; ++i
)
26 options16
[i
] = UTF8ToUTF16(options
[i
]);
28 FormFieldData form_field
;
29 form_field
.form_control_type
= "select-one";
30 form_field
.option_values
= options16
;
31 form_field
.option_contents
= options16
;
36 std::string card_number_
;
38 std::vector
<int> splits_
;
39 std::vector
<std::string
> expected_results_
;
42 // Returns the offset to be set within the credit card number field.
43 size_t GetNumberOffset(size_t index
, const TestCase
& test
) {
45 for (size_t i
= 0; i
< index
; ++i
)
46 result
+= test
.splits_
[i
];
50 TEST(AutofillFieldTest
, Type
) {
52 ASSERT_EQ(NO_SERVER_DATA
, field
.server_type());
53 ASSERT_EQ(UNKNOWN_TYPE
, field
.heuristic_type());
55 // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned.
56 EXPECT_EQ(UNKNOWN_TYPE
, field
.Type().GetStorableType());
58 // Set the heuristic type and check it.
59 field
.set_heuristic_type(NAME_FIRST
);
60 EXPECT_EQ(NAME_FIRST
, field
.Type().GetStorableType());
61 EXPECT_EQ(NAME
, field
.Type().group());
63 // Set the server type and check it.
64 field
.set_server_type(ADDRESS_BILLING_LINE1
);
65 EXPECT_EQ(ADDRESS_HOME_LINE1
, field
.Type().GetStorableType());
66 EXPECT_EQ(ADDRESS_BILLING
, field
.Type().group());
68 // Remove the server type to make sure the heuristic type is preserved.
69 field
.set_server_type(NO_SERVER_DATA
);
70 EXPECT_EQ(NAME_FIRST
, field
.Type().GetStorableType());
71 EXPECT_EQ(NAME
, field
.Type().group());
74 TEST(AutofillFieldTest
, IsEmpty
) {
76 ASSERT_EQ(base::string16(), field
.value
);
78 // Field value is empty.
79 EXPECT_TRUE(field
.IsEmpty());
81 // Field value is non-empty.
82 field
.value
= ASCIIToUTF16("Value");
83 EXPECT_FALSE(field
.IsEmpty());
86 TEST(AutofillFieldTest
, FieldSignature
) {
88 ASSERT_EQ(base::string16(), field
.name
);
89 ASSERT_EQ(std::string(), field
.form_control_type
);
91 // Signature is empty.
92 EXPECT_EQ("2085434232", field
.FieldSignature());
95 field
.name
= ASCIIToUTF16("Name");
96 EXPECT_EQ("1606968241", field
.FieldSignature());
98 // Field form control type is set.
99 field
.form_control_type
= "text";
100 EXPECT_EQ("502192749", field
.FieldSignature());
102 // Heuristic type does not affect FieldSignature.
103 field
.set_heuristic_type(NAME_FIRST
);
104 EXPECT_EQ("502192749", field
.FieldSignature());
106 // Server type does not affect FieldSignature.
107 field
.set_server_type(NAME_LAST
);
108 EXPECT_EQ("502192749", field
.FieldSignature());
111 TEST(AutofillFieldTest
, IsFieldFillable
) {
113 ASSERT_EQ(UNKNOWN_TYPE
, field
.Type().GetStorableType());
116 EXPECT_FALSE(field
.IsFieldFillable());
118 // Only heuristic type is set.
119 field
.set_heuristic_type(NAME_FIRST
);
120 EXPECT_TRUE(field
.IsFieldFillable());
122 // Only server type is set.
123 field
.set_heuristic_type(UNKNOWN_TYPE
);
124 field
.set_server_type(NAME_LAST
);
125 EXPECT_TRUE(field
.IsFieldFillable());
128 field
.set_heuristic_type(NAME_FIRST
);
129 field
.set_server_type(NAME_LAST
);
130 EXPECT_TRUE(field
.IsFieldFillable());
132 // Field has autocomplete="off" set. Chrome ignores the attribute.
133 field
.should_autocomplete
= false;
134 EXPECT_TRUE(field
.IsFieldFillable());
137 TEST(AutofillFieldTest
, FillPhoneNumber
) {
139 field
.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX
, HtmlFieldMode());
141 // Fill with a non-phone number; should fill normally.
142 AutofillField::FillFormField(
143 field
, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field
);
144 EXPECT_EQ(ASCIIToUTF16("Oh hai"), field
.value
);
146 // Fill with a phone number; should fill just the prefix.
147 AutofillField::FillFormField(
148 field
, ASCIIToUTF16("5551234"), "en-US", "en-US", &field
);
149 EXPECT_EQ(ASCIIToUTF16("555"), field
.value
);
151 // Now reset the type, and set a max-length instead.
152 field
.SetHtmlType(HTML_TYPE_UNKNOWN
, HtmlFieldMode());
153 field
.set_heuristic_type(PHONE_HOME_NUMBER
);
154 field
.max_length
= 4;
156 // Fill with a phone-number; should fill just the suffix.
157 AutofillField::FillFormField(
158 field
, ASCIIToUTF16("5551234"), "en-US", "en-US", &field
);
159 EXPECT_EQ(ASCIIToUTF16("1234"), field
.value
);
162 TEST(AutofillFieldTest
, FillSelectControlByValue
) {
163 const char* const kOptions
[] = {
164 "Eenie", "Meenie", "Miney", "Mo",
167 GenerateSelectFieldWithOptions(kOptions
, arraysize(kOptions
)),
170 // Set semantically empty contents for each option, so that only the values
171 // can be used for matching.
172 for (size_t i
= 0; i
< field
.option_contents
.size(); ++i
)
173 field
.option_contents
[i
] = base::SizeTToString16(i
);
175 AutofillField::FillFormField(
176 field
, ASCIIToUTF16("Meenie"), "en-US", "en-US", &field
);
177 EXPECT_EQ(ASCIIToUTF16("Meenie"), field
.value
);
180 TEST(AutofillFieldTest
, FillSelectControlByContents
) {
181 const char* const kOptions
[] = {
182 "Eenie", "Meenie", "Miney", "Mo",
185 GenerateSelectFieldWithOptions(kOptions
, arraysize(kOptions
)),
188 // Set semantically empty values for each option, so that only the contents
189 // can be used for matching.
190 for (size_t i
= 0; i
< field
.option_values
.size(); ++i
)
191 field
.option_values
[i
] = base::SizeTToString16(i
);
193 AutofillField::FillFormField(
194 field
, ASCIIToUTF16("Miney"), "en-US", "en-US", &field
);
195 EXPECT_EQ(ASCIIToUTF16("2"), field
.value
); // Corresponds to "Miney".
198 TEST(AutofillFieldTest
, FillSelectControlWithFullCountryNames
) {
199 const char* const kCountries
[] = {
203 GenerateSelectFieldWithOptions(kCountries
, arraysize(kCountries
)),
205 field
.set_heuristic_type(ADDRESS_HOME_COUNTRY
);
207 AutofillField::FillFormField(
208 field
, ASCIIToUTF16("CA"), "en-US", "en-US", &field
);
209 EXPECT_EQ(ASCIIToUTF16("Canada"), field
.value
);
212 TEST(AutofillFieldTest
, FillSelectControlWithAbbreviatedCountryNames
) {
213 const char* const kCountries
[] = {
217 GenerateSelectFieldWithOptions(kCountries
, arraysize(kCountries
)),
219 field
.set_heuristic_type(ADDRESS_HOME_COUNTRY
);
221 AutofillField::FillFormField(
222 field
, ASCIIToUTF16("Canada"), "en-US", "en-US", &field
);
223 EXPECT_EQ(ASCIIToUTF16("CA"), field
.value
);
226 TEST(AutofillFieldTest
, FillSelectControlWithFullStateNames
) {
227 const char* const kStates
[] = {
228 "Alabama", "California"
231 GenerateSelectFieldWithOptions(kStates
, arraysize(kStates
)),
233 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
235 AutofillField::FillFormField(
236 field
, ASCIIToUTF16("CA"), "en-US", "en-US", &field
);
237 EXPECT_EQ(ASCIIToUTF16("California"), field
.value
);
240 TEST(AutofillFieldTest
, FillSelectControlWithAbbreviateStateNames
) {
241 const char* const kStates
[] = {
245 GenerateSelectFieldWithOptions(kStates
, arraysize(kStates
)),
247 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
249 AutofillField::FillFormField(
250 field
, ASCIIToUTF16("California"), "en-US", "en-US", &field
);
251 EXPECT_EQ(ASCIIToUTF16("CA"), field
.value
);
254 TEST(AutofillFieldTest
, FillSelectControlWithInexactFullStateNames
) {
256 const char* const kStates
[] = {
257 "SC - South Carolina", "CA - California", "NC - North Carolina",
260 GenerateSelectFieldWithOptions(kStates
, arraysize(kStates
)),
262 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
264 AutofillField::FillFormField(
265 field
, ASCIIToUTF16("California"), "en-US", "en-US", &field
);
266 EXPECT_EQ(ASCIIToUTF16("CA - California"), field
.value
);
269 // Don't accidentally match "Virginia" to "West Virginia".
271 const char* const kStates
[] = {
272 "WV - West Virginia", "VA - Virginia", "NV - North Virginia",
275 GenerateSelectFieldWithOptions(kStates
, arraysize(kStates
)),
277 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
279 AutofillField::FillFormField(
280 field
, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field
);
281 EXPECT_EQ(ASCIIToUTF16("VA - Virginia"), field
.value
);
284 // Do accidentally match "Virginia" to "West Virginia". NB: Ideally, Chrome
285 // would fail this test. It's here to document behavior rather than enforce
288 const char* const kStates
[] = {
289 "WV - West Virginia", "TX - Texas",
292 GenerateSelectFieldWithOptions(kStates
, arraysize(kStates
)),
294 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
296 AutofillField::FillFormField(
297 field
, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field
);
298 EXPECT_EQ(ASCIIToUTF16("WV - West Virginia"), field
.value
);
301 // Tests that substring matches work for full state names (a full token
302 // match isn't required). Also tests that matches work for states with
303 // whitespace in the middle.
305 const char* const kStates
[] = {
306 "California.", "North Carolina.",
309 GenerateSelectFieldWithOptions(kStates
, arraysize(kStates
)),
311 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
313 AutofillField::FillFormField(
314 field
, ASCIIToUTF16("North Carolina"), "en-US", "en-US", &field
);
315 EXPECT_EQ(ASCIIToUTF16("North Carolina."), field
.value
);
319 TEST(AutofillFieldTest
, FillSelectControlWithInexactAbbreviations
) {
321 const char* const kStates
[] = {
322 "NC - North Carolina", "CA - California",
325 GenerateSelectFieldWithOptions(kStates
, arraysize(kStates
)),
327 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
329 AutofillField::FillFormField(
330 field
, ASCIIToUTF16("CA"), "en-US", "en-US", &field
);
331 EXPECT_EQ(ASCIIToUTF16("CA - California"), field
.value
);
335 const char* const kNotStates
[] = {
339 GenerateSelectFieldWithOptions(kNotStates
, arraysize(kNotStates
)),
341 field
.set_heuristic_type(ADDRESS_HOME_STATE
);
343 AutofillField::FillFormField(
344 field
, ASCIIToUTF16("NC"), "en-US", "en-US", &field
);
345 EXPECT_EQ(base::string16(), field
.value
);
349 TEST(AutofillFieldTest
, FillSelectControlWithNumericMonth
) {
350 const char* const kMonthsNumeric
[] = {
351 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
354 GenerateSelectFieldWithOptions(kMonthsNumeric
, arraysize(kMonthsNumeric
)),
356 field
.set_heuristic_type(CREDIT_CARD_EXP_MONTH
);
358 // Try with a leading zero.
359 AutofillField::FillFormField(
360 field
, ASCIIToUTF16("03"), "en-US", "en-US", &field
);
361 EXPECT_EQ(ASCIIToUTF16("03"), field
.value
);
363 // Try without a leading zero.
364 AutofillField::FillFormField(
365 field
, ASCIIToUTF16("4"), "en-US", "en-US", &field
);
366 EXPECT_EQ(ASCIIToUTF16("04"), field
.value
);
368 // Try a two-digit month.
369 AutofillField::FillFormField(
370 field
, ASCIIToUTF16("11"), "en-US", "en-US", &field
);
371 EXPECT_EQ(ASCIIToUTF16("11"), field
.value
);
374 TEST(AutofillFieldTest
, FillSelectControlWithAbbreviatedMonthName
) {
375 const char* const kMonthsAbbreviated
[] = {
376 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
377 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
380 GenerateSelectFieldWithOptions(
381 kMonthsAbbreviated
, arraysize(kMonthsAbbreviated
)),
383 field
.set_heuristic_type(CREDIT_CARD_EXP_MONTH
);
385 AutofillField::FillFormField(
386 field
, ASCIIToUTF16("04"), "en-US", "en-US", &field
);
387 EXPECT_EQ(ASCIIToUTF16("Apr"), field
.value
);
390 TEST(AutofillFieldTest
, FillSelectControlWithFullMonthName
) {
391 const char* const kMonthsFull
[] = {
392 "January", "February", "March", "April", "May", "June",
393 "July", "August", "September", "October", "November", "December",
396 GenerateSelectFieldWithOptions(kMonthsFull
, arraysize(kMonthsFull
)),
398 field
.set_heuristic_type(CREDIT_CARD_EXP_MONTH
);
400 AutofillField::FillFormField(
401 field
, ASCIIToUTF16("04"), "en-US", "en-US", &field
);
402 EXPECT_EQ(ASCIIToUTF16("April"), field
.value
);
405 TEST(AutofillFieldTest
, FillSelectControlWithFrenchMonthName
) {
406 const char* const kMonthsFrench
[] = {
407 "JANV", "FÉVR.", "MARS", "décembre"
410 GenerateSelectFieldWithOptions(kMonthsFrench
, arraysize(kMonthsFrench
)),
412 field
.set_heuristic_type(CREDIT_CARD_EXP_MONTH
);
414 AutofillField::FillFormField(
415 field
, ASCIIToUTF16("02"), "fr-FR", "fr-FR", &field
);
416 EXPECT_EQ(UTF8ToUTF16("FÉVR."), field
.value
);
418 AutofillField::FillFormField(
419 field
, ASCIIToUTF16("01"), "fr-FR", "fr-FR", &field
);
420 EXPECT_EQ(UTF8ToUTF16("JANV"), field
.value
);
422 AutofillField::FillFormField(
423 field
, ASCIIToUTF16("12"), "fr-FR", "fr-FR", &field
);
424 EXPECT_EQ(UTF8ToUTF16("décembre"), field
.value
);
427 TEST(AutofillFieldTest
, FillSelectControlWithNumericMonthSansLeadingZero
) {
428 const char* const kMonthsNumeric
[] = {
429 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
432 GenerateSelectFieldWithOptions(kMonthsNumeric
, arraysize(kMonthsNumeric
)),
434 field
.set_heuristic_type(CREDIT_CARD_EXP_MONTH
);
436 AutofillField::FillFormField(
437 field
, ASCIIToUTF16("04"), "en-US", "en-US", &field
);
438 EXPECT_EQ(ASCIIToUTF16("4"), field
.value
);
441 TEST(AutofillFieldTest
, FillSelectControlWithTwoDigitCreditCardYear
) {
442 const char* const kYears
[] = {
443 "12", "13", "14", "15", "16", "17", "18", "19"
445 AutofillField
field(GenerateSelectFieldWithOptions(kYears
, arraysize(kYears
)),
447 field
.set_heuristic_type(CREDIT_CARD_EXP_2_DIGIT_YEAR
);
449 AutofillField::FillFormField(
450 field
, ASCIIToUTF16("2017"), "en-US", "en-US", &field
);
451 EXPECT_EQ(ASCIIToUTF16("17"), field
.value
);
454 TEST(AutofillFieldTest
, FillSelectControlWithCreditCardType
) {
455 const char* const kCreditCardTypes
[] = {
456 "Visa", "Master Card", "AmEx", "discover"
459 GenerateSelectFieldWithOptions(
460 kCreditCardTypes
, arraysize(kCreditCardTypes
)),
462 field
.set_heuristic_type(CREDIT_CARD_TYPE
);
465 AutofillField::FillFormField(
466 field
, ASCIIToUTF16("Visa"), "en-US", "en-US", &field
);
467 EXPECT_EQ(ASCIIToUTF16("Visa"), field
.value
);
469 // Filling should be able to handle intervening whitespace:
470 AutofillField::FillFormField(
471 field
, ASCIIToUTF16("MasterCard"), "en-US", "en-US", &field
);
472 EXPECT_EQ(ASCIIToUTF16("Master Card"), field
.value
);
474 // American Express is sometimes abbreviated as AmEx:
475 AutofillField::FillFormField(
476 field
, ASCIIToUTF16("American Express"), "en-US", "en-US", &field
);
477 EXPECT_EQ(ASCIIToUTF16("AmEx"), field
.value
);
479 // Case insensitivity:
480 AutofillField::FillFormField(
481 field
, ASCIIToUTF16("Discover"), "en-US", "en-US", &field
);
482 EXPECT_EQ(ASCIIToUTF16("discover"), field
.value
);
485 TEST(AutofillFieldTest
, FillMonthControl
) {
487 field
.form_control_type
= "month";
489 // Try a month with two digits.
490 AutofillField::FillFormField(
491 field
, ASCIIToUTF16("12/2017"), "en-US", "en-US", &field
);
492 EXPECT_EQ(ASCIIToUTF16("2017-12"), field
.value
);
494 // Try a month with a leading zero.
495 AutofillField::FillFormField(
496 field
, ASCIIToUTF16("03/2019"), "en-US", "en-US", &field
);
497 EXPECT_EQ(ASCIIToUTF16("2019-03"), field
.value
);
499 // Try a month without a leading zero.
500 AutofillField::FillFormField(
501 field
, ASCIIToUTF16("4/2018"), "en-US", "en-US", &field
);
502 EXPECT_EQ(ASCIIToUTF16("2018-04"), field
.value
);
505 TEST(AutofillFieldTest
, FillStreetAddressTextArea
) {
507 field
.form_control_type
= "textarea";
509 base::string16 value
= ASCIIToUTF16("123 Fake St.\n"
511 AutofillField::FillFormField(field
, value
, "en-US", "en-US", &field
);
512 EXPECT_EQ(value
, field
.value
);
514 base::string16 ja_value
= UTF8ToUTF16("桜丘町26-1\n"
516 AutofillField::FillFormField(field
, ja_value
, "ja-JP", "en-US", &field
);
517 EXPECT_EQ(ja_value
, field
.value
);
520 TEST(AutofillFieldTest
, FillStreetAddressTextField
) {
522 field
.form_control_type
= "text";
523 field
.set_server_type(ADDRESS_HOME_STREET_ADDRESS
);
525 base::string16 value
= ASCIIToUTF16("123 Fake St.\n"
527 AutofillField::FillFormField(field
, value
, "en-US", "en-US", &field
);
528 EXPECT_EQ(ASCIIToUTF16("123 Fake St., Apt. 42"), field
.value
);
530 AutofillField::FillFormField(field
,
531 UTF8ToUTF16("桜丘町26-1\n"
536 EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field
.value
);
539 TEST(AutofillFieldTest
, FillCreditCardNumberWithoutSplits
) {
540 // Case 1: card number without any spilt.
541 AutofillField cc_number_full
;
542 cc_number_full
.set_heuristic_type(CREDIT_CARD_NUMBER
);
543 AutofillField::FillFormField(cc_number_full
,
544 ASCIIToUTF16("4111111111111111"),
549 // Verify that full card-number shall get fill properly.
550 EXPECT_EQ(ASCIIToUTF16("4111111111111111"), cc_number_full
.value
);
551 EXPECT_EQ(0U, cc_number_full
.credit_card_number_offset());
554 TEST(AutofillFieldTest
, FillCreditCardNumberWithEqualSizeSplits
) {
555 // Case 2: card number broken up into four equal groups, of length 4.
557 test
.card_number_
= "5187654321098765";
558 test
.total_spilts_
= 4;
559 int splits
[] = {4, 4, 4, 4};
560 test
.splits_
= std::vector
<int>(splits
, splits
+ arraysize(splits
));
561 std::string results
[] = {"5187", "6543", "2109", "8765"};
562 test
.expected_results_
=
563 std::vector
<std::string
>(results
, results
+ arraysize(results
));
565 for (size_t i
= 0; i
< test
.total_spilts_
; ++i
) {
566 AutofillField cc_number_part
;
567 cc_number_part
.set_heuristic_type(CREDIT_CARD_NUMBER
);
568 cc_number_part
.max_length
= test
.splits_
[i
];
569 cc_number_part
.set_credit_card_number_offset(4 * i
);
571 // Fill with a card-number; should fill just the card_number_part.
572 AutofillField::FillFormField(cc_number_part
,
573 ASCIIToUTF16(test
.card_number_
),
578 // Verify for expected results.
579 EXPECT_EQ(ASCIIToUTF16(test
.expected_results_
[i
]),
580 cc_number_part
.value
.substr(0, cc_number_part
.max_length
));
581 EXPECT_EQ(4 * i
, cc_number_part
.credit_card_number_offset());
584 // Verify that full card-number shall get fill properly as well.
585 AutofillField cc_number_full
;
586 cc_number_full
.set_heuristic_type(CREDIT_CARD_NUMBER
);
587 AutofillField::FillFormField(cc_number_full
,
588 ASCIIToUTF16(test
.card_number_
),
593 // Verify for expected results.
594 EXPECT_EQ(ASCIIToUTF16(test
.card_number_
), cc_number_full
.value
);
597 TEST(AutofillFieldTest
, FillCreditCardNumberWithUnequalSizeSplits
) {
598 // Case 3: card with 15 digits number, broken up into three unequal groups, of
599 // lengths 4, 6, and 5.
601 test
.card_number_
= "423456789012345";
602 test
.total_spilts_
= 3;
603 int splits
[] = {4, 6, 5};
604 test
.splits_
= std::vector
<int>(splits
, splits
+ arraysize(splits
));
605 std::string results
[] = {"4234", "567890", "12345"};
606 test
.expected_results_
=
607 std::vector
<std::string
>(results
, results
+ arraysize(results
));
609 // Start executing test cases to verify parts and full credit card number.
610 for (size_t i
= 0; i
< test
.total_spilts_
; ++i
) {
611 AutofillField cc_number_part
;
612 cc_number_part
.set_heuristic_type(CREDIT_CARD_NUMBER
);
613 cc_number_part
.max_length
= test
.splits_
[i
];
614 cc_number_part
.set_credit_card_number_offset(GetNumberOffset(i
, test
));
616 // Fill with a card-number; should fill just the card_number_part.
617 AutofillField::FillFormField(cc_number_part
,
618 ASCIIToUTF16(test
.card_number_
),
623 // Verify for expected results.
624 EXPECT_EQ(ASCIIToUTF16(test
.expected_results_
[i
]),
625 cc_number_part
.value
.substr(0, cc_number_part
.max_length
));
626 EXPECT_EQ(GetNumberOffset(i
, test
),
627 cc_number_part
.credit_card_number_offset());
630 // Verify that full card-number shall get fill properly as well.
631 AutofillField cc_number_full
;
632 cc_number_full
.set_heuristic_type(CREDIT_CARD_NUMBER
);
633 AutofillField::FillFormField(cc_number_full
,
634 ASCIIToUTF16(test
.card_number_
),
639 // Verify for expected results.
640 EXPECT_EQ(ASCIIToUTF16(test
.card_number_
), cc_number_full
.value
);
643 TEST(AutofillFieldTest
, FindValueInSelectControl
) {
644 const size_t kBadIndex
= 1000;
647 const char* const kCountries
[] = {
651 GenerateSelectFieldWithOptions(kCountries
, arraysize(kCountries
)));
652 size_t index
= kBadIndex
;
653 bool ret
= AutofillField::FindValueInSelectControl(
654 field
, ASCIIToUTF16("Canada"), &index
);
656 EXPECT_EQ(1U, index
);
659 ret
= AutofillField::FindValueInSelectControl(
660 field
, ASCIIToUTF16("CANADA"), &index
);
662 EXPECT_EQ(1U, index
);
665 ret
= AutofillField::FindValueInSelectControl(
666 field
, ASCIIToUTF16("Canadia"), &index
);
668 EXPECT_EQ(kBadIndex
, index
);
672 const char* const kProvinces
[] = {
673 "ALBERTA", "QUÉBEC", "NOVA SCOTIA",
676 GenerateSelectFieldWithOptions(kProvinces
, arraysize(kProvinces
)));
677 size_t index
= kBadIndex
;
678 bool ret
= AutofillField::FindValueInSelectControl(
679 field
, ASCIIToUTF16("alberta"), &index
);
681 EXPECT_EQ(0U, index
);
684 ret
= AutofillField::FindValueInSelectControl(
685 field
, UTF8ToUTF16("québec"), &index
);
687 EXPECT_EQ(1U, index
);
690 ret
= AutofillField::FindValueInSelectControl(
691 field
, UTF8ToUTF16("NoVaScOtIa"), &index
);
693 EXPECT_EQ(2U, index
);
698 } // namespace autofill