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.
4
5#include "components/autofill/core/browser/autofill_field.h"
6
7#include "base/format_macros.h"
8#include "base/strings/string_util.h"
9#include "base/strings/stringprintf.h"
10#include "base/strings/utf_string_conversions.h"
11#include "components/autofill/core/browser/autofill_type.h"
12#include "components/autofill/core/browser/field_types.h"
13#include "testing/gtest/include/gtest/gtest.h"
14
15using base::ASCIIToUTF16;
16using base::UTF8ToUTF16;
17
18namespace autofill {
19namespace {
20
21// Returns a FormFieldData object corresponding to a <select> field populated
22// with the given |options|.
23FormFieldData GenerateSelectFieldWithOptions(const char* const* options,
24                                             size_t options_size) {
25  std::vector<base::string16> options16(options_size);
26  for (size_t i = 0; i < options_size; ++i) {
27    options16[i] = ASCIIToUTF16(options[i]);
28  }
29
30  FormFieldData form_field;
31  form_field.form_control_type = "select-one";
32  form_field.option_values = options16;
33  form_field.option_contents = options16;
34  return form_field;
35}
36
37struct TestCase {
38  std::string card_number_;
39  size_t total_spilts_;
40  std::vector<int> splits_;
41  std::vector<std::string> expected_results_;
42};
43
44// Returns the offset to be set within the credit card number field.
45size_t GetNumberOffset(size_t index, const TestCase& test) {
46  size_t result = 0;
47  for (size_t i = 0; i < index; ++i)
48    result += test.splits_[i];
49  return result;
50}
51
52TEST(AutofillFieldTest, Type) {
53  AutofillField field;
54  ASSERT_EQ(NO_SERVER_DATA, field.server_type());
55  ASSERT_EQ(UNKNOWN_TYPE, field.heuristic_type());
56
57  // |server_type_| is NO_SERVER_DATA, so |heuristic_type_| is returned.
58  EXPECT_EQ(UNKNOWN_TYPE, field.Type().GetStorableType());
59
60  // Set the heuristic type and check it.
61  field.set_heuristic_type(NAME_FIRST);
62  EXPECT_EQ(NAME_FIRST, field.Type().GetStorableType());
63  EXPECT_EQ(NAME, field.Type().group());
64
65  // Set the server type and check it.
66  field.set_server_type(ADDRESS_BILLING_LINE1);
67  EXPECT_EQ(ADDRESS_HOME_LINE1, field.Type().GetStorableType());
68  EXPECT_EQ(ADDRESS_BILLING, field.Type().group());
69
70  // Remove the server type to make sure the heuristic type is preserved.
71  field.set_server_type(NO_SERVER_DATA);
72  EXPECT_EQ(NAME_FIRST, field.Type().GetStorableType());
73  EXPECT_EQ(NAME, field.Type().group());
74}
75
76TEST(AutofillFieldTest, IsEmpty) {
77  AutofillField field;
78  ASSERT_EQ(base::string16(), field.value);
79
80  // Field value is empty.
81  EXPECT_TRUE(field.IsEmpty());
82
83  // Field value is non-empty.
84  field.value = ASCIIToUTF16("Value");
85  EXPECT_FALSE(field.IsEmpty());
86}
87
88TEST(AutofillFieldTest, FieldSignature) {
89  AutofillField field;
90  ASSERT_EQ(base::string16(), field.name);
91  ASSERT_EQ(std::string(), field.form_control_type);
92
93  // Signature is empty.
94  EXPECT_EQ("2085434232", field.FieldSignature());
95
96  // Field name is set.
97  field.name = ASCIIToUTF16("Name");
98  EXPECT_EQ("1606968241", field.FieldSignature());
99
100  // Field form control type is set.
101  field.form_control_type = "text";
102  EXPECT_EQ("502192749", field.FieldSignature());
103
104  // Heuristic type does not affect FieldSignature.
105  field.set_heuristic_type(NAME_FIRST);
106  EXPECT_EQ("502192749", field.FieldSignature());
107
108  // Server type does not affect FieldSignature.
109  field.set_server_type(NAME_LAST);
110  EXPECT_EQ("502192749", field.FieldSignature());
111}
112
113TEST(AutofillFieldTest, IsFieldFillable) {
114  AutofillField field;
115  ASSERT_EQ(UNKNOWN_TYPE, field.Type().GetStorableType());
116
117  // Type is unknown.
118  EXPECT_FALSE(field.IsFieldFillable());
119
120  // Only heuristic type is set.
121  field.set_heuristic_type(NAME_FIRST);
122  EXPECT_TRUE(field.IsFieldFillable());
123
124  // Only server type is set.
125  field.set_heuristic_type(UNKNOWN_TYPE);
126  field.set_server_type(NAME_LAST);
127  EXPECT_TRUE(field.IsFieldFillable());
128
129  // Both types set.
130  field.set_heuristic_type(NAME_FIRST);
131  field.set_server_type(NAME_LAST);
132  EXPECT_TRUE(field.IsFieldFillable());
133
134  // Field has autocomplete="off" set.
135  field.should_autocomplete = false;
136  EXPECT_FALSE(field.IsFieldFillable());
137}
138
139TEST(AutofillFieldTest, FillPhoneNumber) {
140  AutofillField field;
141  field.SetHtmlType(HTML_TYPE_TEL_LOCAL_PREFIX, HtmlFieldMode());
142
143  // Fill with a non-phone number; should fill normally.
144  AutofillField::FillFormField(
145      field, ASCIIToUTF16("Oh hai"), "en-US", "en-US", &field);
146  EXPECT_EQ(ASCIIToUTF16("Oh hai"), field.value);
147
148  // Fill with a phone number; should fill just the prefix.
149  AutofillField::FillFormField(
150      field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field);
151  EXPECT_EQ(ASCIIToUTF16("555"), field.value);
152
153  // Now reset the type, and set a max-length instead.
154  field.SetHtmlType(HTML_TYPE_UNKNOWN, HtmlFieldMode());
155  field.set_heuristic_type(PHONE_HOME_NUMBER);
156  field.max_length = 4;
157
158  // Fill with a phone-number; should fill just the suffix.
159  AutofillField::FillFormField(
160      field, ASCIIToUTF16("5551234"), "en-US", "en-US", &field);
161  EXPECT_EQ(ASCIIToUTF16("1234"), field.value);
162}
163
164TEST(AutofillFieldTest, FillSelectControlByValue) {
165  const char* const kOptions[] = {
166    "Eenie", "Meenie", "Miney", "Mo",
167  };
168  AutofillField field(
169      GenerateSelectFieldWithOptions(kOptions, arraysize(kOptions)),
170      base::string16());
171
172  // Set semantically empty contents for each option, so that only the values
173  // can be used for matching.
174  for (size_t i = 0; i < field.option_contents.size(); ++i) {
175    field.option_contents[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i));
176  }
177
178  AutofillField::FillFormField(
179      field, ASCIIToUTF16("Meenie"), "en-US", "en-US", &field);
180  EXPECT_EQ(ASCIIToUTF16("Meenie"), field.value);
181}
182
183TEST(AutofillFieldTest, FillSelectControlByContents) {
184  const char* const kOptions[] = {
185    "Eenie", "Meenie", "Miney", "Mo",
186  };
187  AutofillField field(
188      GenerateSelectFieldWithOptions(kOptions, arraysize(kOptions)),
189      base::string16());
190
191  // Set semantically empty values for each option, so that only the contents
192  // can be used for matching.
193  for (size_t i = 0; i < field.option_values.size(); ++i) {
194    field.option_values[i] = ASCIIToUTF16(base::StringPrintf("%" PRIuS, i));
195  }
196
197  AutofillField::FillFormField(
198      field, ASCIIToUTF16("Miney"), "en-US", "en-US", &field);
199  EXPECT_EQ(ASCIIToUTF16("2"), field.value);  // Corresponds to "Miney".
200}
201
202TEST(AutofillFieldTest, FillSelectControlWithFullCountryNames) {
203  const char* const kCountries[] = {
204    "Albania", "Canada"
205  };
206  AutofillField field(
207      GenerateSelectFieldWithOptions(kCountries, arraysize(kCountries)),
208      base::string16());
209  field.set_heuristic_type(ADDRESS_HOME_COUNTRY);
210
211  AutofillField::FillFormField(
212      field, ASCIIToUTF16("CA"), "en-US", "en-US", &field);
213  EXPECT_EQ(ASCIIToUTF16("Canada"), field.value);
214}
215
216TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedCountryNames) {
217  const char* const kCountries[] = {
218    "AL", "CA"
219  };
220  AutofillField field(
221      GenerateSelectFieldWithOptions(kCountries, arraysize(kCountries)),
222      base::string16());
223  field.set_heuristic_type(ADDRESS_HOME_COUNTRY);
224
225  AutofillField::FillFormField(
226      field, ASCIIToUTF16("Canada"), "en-US", "en-US", &field);
227  EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
228}
229
230TEST(AutofillFieldTest, FillSelectControlWithFullStateNames) {
231  const char* const kStates[] = {
232    "Alabama", "California"
233  };
234  AutofillField field(
235      GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
236      base::string16());
237  field.set_heuristic_type(ADDRESS_HOME_STATE);
238
239  AutofillField::FillFormField(
240      field, ASCIIToUTF16("CA"), "en-US", "en-US", &field);
241  EXPECT_EQ(ASCIIToUTF16("California"), field.value);
242}
243
244TEST(AutofillFieldTest, FillSelectControlWithAbbreviateStateNames) {
245  const char* const kStates[] = {
246    "AL", "CA"
247  };
248  AutofillField field(
249      GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
250      base::string16());
251  field.set_heuristic_type(ADDRESS_HOME_STATE);
252
253  AutofillField::FillFormField(
254      field, ASCIIToUTF16("California"), "en-US", "en-US", &field);
255  EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
256}
257
258TEST(AutofillFieldTest, FillSelectControlWithInexactFullStateNames) {
259  {
260    const char* const kStates[] = {
261      "SC - South Carolina", "CA - California", "NC - North Carolina",
262    };
263    AutofillField field(
264        GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
265        base::string16());
266    field.set_heuristic_type(ADDRESS_HOME_STATE);
267
268    AutofillField::FillFormField(
269        field, ASCIIToUTF16("California"), "en-US", "en-US", &field);
270    EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value);
271  }
272
273  // Don't accidentally match "Virginia" to "West Virginia".
274  {
275    const char* const kStates[] = {
276      "WV - West Virginia", "VA - Virginia", "NV - North Virginia",
277    };
278    AutofillField field(
279        GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
280        base::string16());
281    field.set_heuristic_type(ADDRESS_HOME_STATE);
282
283    AutofillField::FillFormField(
284        field, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field);
285    EXPECT_EQ(ASCIIToUTF16("VA - Virginia"), field.value);
286  }
287
288  // Do accidentally match "Virginia" to "West Virginia". NB: Ideally, Chrome
289  // would fail this test. It's here to document behavior rather than enforce
290  // it.
291  {
292    const char* const kStates[] = {
293      "WV - West Virginia", "TX - Texas",
294    };
295    AutofillField field(
296        GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
297        base::string16());
298    field.set_heuristic_type(ADDRESS_HOME_STATE);
299
300    AutofillField::FillFormField(
301        field, ASCIIToUTF16("Virginia"), "en-US", "en-US", &field);
302    EXPECT_EQ(ASCIIToUTF16("WV - West Virginia"), field.value);
303  }
304
305  // Tests that substring matches work for full state names (a full token
306  // match isn't required). Also tests that matches work for states with
307  // whitespace in the middle.
308  {
309    const char* const kStates[] = {
310      "California.", "North Carolina.",
311    };
312    AutofillField field(
313        GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
314        base::string16());
315    field.set_heuristic_type(ADDRESS_HOME_STATE);
316
317    AutofillField::FillFormField(
318        field, ASCIIToUTF16("North Carolina"), "en-US", "en-US", &field);
319    EXPECT_EQ(ASCIIToUTF16("North Carolina."), field.value);
320  }
321}
322
323TEST(AutofillFieldTest, FillSelectControlWithInexactAbbreviations) {
324  {
325    const char* const kStates[] = {
326      "NC - North Carolina", "CA - California",
327    };
328    AutofillField field(
329        GenerateSelectFieldWithOptions(kStates, arraysize(kStates)),
330        base::string16());
331    field.set_heuristic_type(ADDRESS_HOME_STATE);
332
333    AutofillField::FillFormField(
334        field, ASCIIToUTF16("CA"), "en-US", "en-US", &field);
335    EXPECT_EQ(ASCIIToUTF16("CA - California"), field.value);
336  }
337
338  {
339    const char* const kNotStates[] = {
340      "NCNCA", "SCNCA",
341    };
342    AutofillField field(
343        GenerateSelectFieldWithOptions(kNotStates, arraysize(kNotStates)),
344        base::string16());
345    field.set_heuristic_type(ADDRESS_HOME_STATE);
346
347    AutofillField::FillFormField(
348        field, ASCIIToUTF16("NC"), "en-US", "en-US", &field);
349    EXPECT_EQ(base::string16(), field.value);
350  }
351}
352
353TEST(AutofillFieldTest, FillSelectControlWithNumericMonth) {
354  const char* const kMonthsNumeric[] = {
355    "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
356  };
357  AutofillField field(
358      GenerateSelectFieldWithOptions(kMonthsNumeric, arraysize(kMonthsNumeric)),
359      base::string16());
360  field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
361
362  // Try with a leading zero.
363  AutofillField::FillFormField(
364      field, ASCIIToUTF16("03"), "en-US", "en-US", &field);
365  EXPECT_EQ(ASCIIToUTF16("03"), field.value);
366
367  // Try without a leading zero.
368  AutofillField::FillFormField(
369      field, ASCIIToUTF16("4"), "en-US", "en-US", &field);
370  EXPECT_EQ(ASCIIToUTF16("04"), field.value);
371
372  // Try a two-digit month.
373  AutofillField::FillFormField(
374      field, ASCIIToUTF16("11"), "en-US", "en-US", &field);
375  EXPECT_EQ(ASCIIToUTF16("11"), field.value);
376}
377
378TEST(AutofillFieldTest, FillSelectControlWithAbbreviatedMonthName) {
379  const char* const kMonthsAbbreviated[] = {
380    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
381    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
382  };
383  AutofillField field(
384      GenerateSelectFieldWithOptions(
385          kMonthsAbbreviated, arraysize(kMonthsAbbreviated)),
386      base::string16());
387  field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
388
389  AutofillField::FillFormField(
390      field, ASCIIToUTF16("04"), "en-US", "en-US", &field);
391  EXPECT_EQ(ASCIIToUTF16("Apr"), field.value);
392}
393
394TEST(AutofillFieldTest, FillSelectControlWithFullMonthName) {
395  const char* const kMonthsFull[] = {
396    "January","February", "March", "April", "May", "June",
397    "July", "August", "September", "October", "November", "December",
398  };
399  AutofillField field(
400      GenerateSelectFieldWithOptions(kMonthsFull, arraysize(kMonthsFull)),
401      base::string16());
402  field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
403
404  AutofillField::FillFormField(
405      field, ASCIIToUTF16("04"), "en-US", "en-US", &field);
406  EXPECT_EQ(ASCIIToUTF16("April"), field.value);
407}
408
409TEST(AutofillFieldTest, FillSelectControlWithNumericMonthSansLeadingZero) {
410  const char* const kMonthsNumeric[] = {
411    "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
412  };
413  AutofillField field(
414      GenerateSelectFieldWithOptions(kMonthsNumeric, arraysize(kMonthsNumeric)),
415      base::string16());
416  field.set_heuristic_type(CREDIT_CARD_EXP_MONTH);
417
418  AutofillField::FillFormField(
419      field, ASCIIToUTF16("04"), "en-US", "en-US", &field);
420  EXPECT_EQ(ASCIIToUTF16("4"), field.value);
421}
422
423TEST(AutofillFieldTest, FillSelectControlWithTwoDigitCreditCardYear) {
424  const char* const kYears[] = {
425    "12", "13", "14", "15", "16", "17", "18", "19"
426  };
427  AutofillField field(GenerateSelectFieldWithOptions(kYears, arraysize(kYears)),
428                      base::string16());
429  field.set_heuristic_type(CREDIT_CARD_EXP_2_DIGIT_YEAR);
430
431  AutofillField::FillFormField(
432      field, ASCIIToUTF16("2017"), "en-US", "en-US", &field);
433  EXPECT_EQ(ASCIIToUTF16("17"), field.value);
434}
435
436TEST(AutofillFieldTest, FillSelectControlWithCreditCardType) {
437  const char* const kCreditCardTypes[] = {
438    "Visa", "Master Card", "AmEx", "discover"
439  };
440  AutofillField field(
441      GenerateSelectFieldWithOptions(
442          kCreditCardTypes, arraysize(kCreditCardTypes)),
443      base::string16());
444  field.set_heuristic_type(CREDIT_CARD_TYPE);
445
446  // Normal case:
447  AutofillField::FillFormField(
448      field, ASCIIToUTF16("Visa"), "en-US", "en-US", &field);
449  EXPECT_EQ(ASCIIToUTF16("Visa"), field.value);
450
451  // Filling should be able to handle intervening whitespace:
452  AutofillField::FillFormField(
453      field, ASCIIToUTF16("MasterCard"), "en-US", "en-US", &field);
454  EXPECT_EQ(ASCIIToUTF16("Master Card"), field.value);
455
456  // American Express is sometimes abbreviated as AmEx:
457  AutofillField::FillFormField(
458      field, ASCIIToUTF16("American Express"), "en-US", "en-US", &field);
459  EXPECT_EQ(ASCIIToUTF16("AmEx"), field.value);
460
461  // Case insensitivity:
462  AutofillField::FillFormField(
463      field, ASCIIToUTF16("Discover"), "en-US", "en-US", &field);
464  EXPECT_EQ(ASCIIToUTF16("discover"), field.value);
465}
466
467TEST(AutofillFieldTest, FillMonthControl) {
468  AutofillField field;
469  field.form_control_type = "month";
470
471  // Try a month with two digits.
472  AutofillField::FillFormField(
473      field, ASCIIToUTF16("12/2017"), "en-US", "en-US", &field);
474  EXPECT_EQ(ASCIIToUTF16("2017-12"), field.value);
475
476  // Try a month with a leading zero.
477  AutofillField::FillFormField(
478      field, ASCIIToUTF16("03/2019"), "en-US", "en-US", &field);
479  EXPECT_EQ(ASCIIToUTF16("2019-03"), field.value);
480
481  // Try a month without a leading zero.
482  AutofillField::FillFormField(
483      field, ASCIIToUTF16("4/2018"), "en-US", "en-US", &field);
484  EXPECT_EQ(ASCIIToUTF16("2018-04"), field.value);
485}
486
487TEST(AutofillFieldTest, FillStreetAddressTextArea) {
488  AutofillField field;
489  field.form_control_type = "textarea";
490
491  base::string16 value = ASCIIToUTF16("123 Fake St.\n"
492                                      "Apt. 42");
493  AutofillField::FillFormField(field, value, "en-US", "en-US", &field);
494  EXPECT_EQ(value, field.value);
495
496  base::string16 ja_value = UTF8ToUTF16("桜丘町26-1\n"
497                                        "セルリアンタワー6階");
498  AutofillField::FillFormField(field, ja_value, "ja-JP", "en-US", &field);
499  EXPECT_EQ(ja_value, field.value);
500}
501
502TEST(AutofillFieldTest, FillStreetAddressTextField) {
503  AutofillField field;
504  field.form_control_type = "text";
505  field.set_server_type(ADDRESS_HOME_STREET_ADDRESS);
506
507  base::string16 value = ASCIIToUTF16("123 Fake St.\n"
508                                      "Apt. 42");
509  AutofillField::FillFormField(field, value, "en-US", "en-US", &field);
510  EXPECT_EQ(ASCIIToUTF16("123 Fake St., Apt. 42"), field.value);
511
512  AutofillField::FillFormField(field,
513                               UTF8ToUTF16("桜丘町26-1\n"
514                                           "セルリアンタワー6階"),
515                               "ja-JP",
516                               "en-US",
517                               &field);
518  EXPECT_EQ(UTF8ToUTF16("桜丘町26-1セルリアンタワー6階"), field.value);
519}
520
521TEST(AutofillFieldTest, FillCreditCardNumberWithoutSplits) {
522  // Case 1: card number without any spilt.
523  AutofillField cc_number_full;
524  cc_number_full.set_heuristic_type(CREDIT_CARD_NUMBER);
525  AutofillField::FillFormField(cc_number_full,
526                               ASCIIToUTF16("4111111111111111"),
527                               "en-US",
528                               "en-US",
529                               &cc_number_full);
530
531  // Verify that full card-number shall get fill properly.
532  EXPECT_EQ(ASCIIToUTF16("4111111111111111"), cc_number_full.value);
533  EXPECT_EQ(0U, cc_number_full.credit_card_number_offset());
534}
535
536TEST(AutofillFieldTest, FillCreditCardNumberWithEqualSizeSplits) {
537  // Case 2: card number broken up into four equal groups, of length 4.
538  TestCase test;
539  test.card_number_ = "5187654321098765";
540  test.total_spilts_ = 4;
541  int splits[] = {4, 4, 4, 4};
542  test.splits_ = std::vector<int>(splits, splits + arraysize(splits));
543  std::string results[] = {"5187", "6543", "2109", "8765"};
544  test.expected_results_ =
545      std::vector<std::string>(results, results + arraysize(results));
546
547  for (size_t i = 0; i < test.total_spilts_; ++i) {
548    AutofillField cc_number_part;
549    cc_number_part.set_heuristic_type(CREDIT_CARD_NUMBER);
550    cc_number_part.max_length = test.splits_[i];
551    cc_number_part.set_credit_card_number_offset(4 * i);
552
553    // Fill with a card-number; should fill just the card_number_part.
554    AutofillField::FillFormField(cc_number_part,
555                                 ASCIIToUTF16(test.card_number_),
556                                 "en-US",
557                                 "en-US",
558                                 &cc_number_part);
559
560    // Verify for expected results.
561    EXPECT_EQ(ASCIIToUTF16(test.expected_results_[i]),
562              cc_number_part.value.substr(0, cc_number_part.max_length));
563    EXPECT_EQ(4 * i, cc_number_part.credit_card_number_offset());
564  }
565
566  // Verify that full card-number shall get fill properly as well.
567  AutofillField cc_number_full;
568  cc_number_full.set_heuristic_type(CREDIT_CARD_NUMBER);
569  AutofillField::FillFormField(cc_number_full,
570                               ASCIIToUTF16(test.card_number_),
571                               "en-US",
572                               "en-US",
573                               &cc_number_full);
574
575  // Verify for expected results.
576  EXPECT_EQ(ASCIIToUTF16(test.card_number_), cc_number_full.value);
577}
578
579TEST(AutofillFieldTest, FillCreditCardNumberWithUnequalSizeSplits) {
580  // Case 3: card with 15 digits number, broken up into three unequal groups, of
581  // lengths 4, 6, and 5.
582  TestCase test;
583  test.card_number_ = "423456789012345";
584  test.total_spilts_ = 3;
585  int splits[] = {4, 6, 5};
586  test.splits_ = std::vector<int>(splits, splits + arraysize(splits));
587  std::string results[] = {"4234", "567890", "12345"};
588  test.expected_results_ =
589      std::vector<std::string>(results, results + arraysize(results));
590
591  // Start executing test cases to verify parts and full credit card number.
592  for (size_t i = 0; i < test.total_spilts_; ++i) {
593    AutofillField cc_number_part;
594    cc_number_part.set_heuristic_type(CREDIT_CARD_NUMBER);
595    cc_number_part.max_length = test.splits_[i];
596    cc_number_part.set_credit_card_number_offset(GetNumberOffset(i, test));
597
598    // Fill with a card-number; should fill just the card_number_part.
599    AutofillField::FillFormField(cc_number_part,
600                                 ASCIIToUTF16(test.card_number_),
601                                 "en-US",
602                                 "en-US",
603                                 &cc_number_part);
604
605    // Verify for expected results.
606    EXPECT_EQ(ASCIIToUTF16(test.expected_results_[i]),
607              cc_number_part.value.substr(0, cc_number_part.max_length));
608    EXPECT_EQ(GetNumberOffset(i, test),
609              cc_number_part.credit_card_number_offset());
610  }
611
612  // Verify that full card-number shall get fill properly as well.
613  AutofillField cc_number_full;
614  cc_number_full.set_heuristic_type(CREDIT_CARD_NUMBER);
615  AutofillField::FillFormField(cc_number_full,
616                               ASCIIToUTF16(test.card_number_),
617                               "en-US",
618                               "en-US",
619                               &cc_number_full);
620
621  // Verify for expected results.
622  EXPECT_EQ(ASCIIToUTF16(test.card_number_), cc_number_full.value);
623}
624
625}  // namespace
626}  // namespace autofill
627