• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/autofill_profile.h"
7 #include "chrome/browser/autofill/autofill_type.h"
8 #include "chrome/browser/autofill/credit_card.h"
9 #include "chrome/browser/autofill/select_control_handler.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/glue/form_field.h"
12 
TEST(SelectControlHandlerTest,CreditCardMonthExact)13 TEST(SelectControlHandlerTest, CreditCardMonthExact) {
14   const char* const kMonthsNumeric[] = {
15     "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
16   };
17   std::vector<string16> options(arraysize(kMonthsNumeric));
18   for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i)
19     options[i] = ASCIIToUTF16(kMonthsNumeric[i]);
20 
21   webkit_glue::FormField field;
22   field.form_control_type = ASCIIToUTF16("select-one");
23   field.option_strings = options;
24 
25   CreditCard credit_card;
26   credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01"));
27   autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field);
28   EXPECT_EQ(ASCIIToUTF16("01"), field.value);
29 }
30 
TEST(SelectControlHandlerTest,CreditCardMonthAbbreviated)31 TEST(SelectControlHandlerTest, CreditCardMonthAbbreviated) {
32   const char* const kMonthsAbbreviated[] = {
33     "Jan", "Feb", "Mar", "Apr", "May", "Jun",
34     "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
35   };
36   std::vector<string16> options(arraysize(kMonthsAbbreviated));
37   for (size_t i = 0; i < arraysize(kMonthsAbbreviated); ++i)
38     options[i] = ASCIIToUTF16(kMonthsAbbreviated[i]);
39 
40   webkit_glue::FormField field;
41   field.form_control_type = ASCIIToUTF16("select-one");
42   field.option_strings = options;
43 
44   CreditCard credit_card;
45   credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01"));
46   autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field);
47   EXPECT_EQ(ASCIIToUTF16("Jan"), field.value);
48 }
49 
TEST(SelectControlHandlerTest,CreditCardMonthFull)50 TEST(SelectControlHandlerTest, CreditCardMonthFull) {
51   const char* const kMonthsFull[] = {
52     "January", "February", "March", "April", "May", "June",
53     "July", "August", "September", "October", "November", "December",
54   };
55   std::vector<string16> options(arraysize(kMonthsFull));
56   for (size_t i = 0; i < arraysize(kMonthsFull); ++i)
57     options[i] = ASCIIToUTF16(kMonthsFull[i]);
58 
59   webkit_glue::FormField field;
60   field.form_control_type = ASCIIToUTF16("select-one");
61   field.option_strings = options;
62 
63   CreditCard credit_card;
64   credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01"));
65   autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field);
66   EXPECT_EQ(ASCIIToUTF16("January"), field.value);
67 }
68 
TEST(SelectControlHandlerTest,CreditCardMonthNumeric)69 TEST(SelectControlHandlerTest, CreditCardMonthNumeric) {
70   const char* const kMonthsNumeric[] = {
71     "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",
72   };
73   std::vector<string16> options(arraysize(kMonthsNumeric));
74   for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i)
75     options[i] = ASCIIToUTF16(kMonthsNumeric[i]);
76 
77   webkit_glue::FormField field;
78   field.form_control_type = ASCIIToUTF16("select-one");
79   field.option_strings = options;
80 
81   CreditCard credit_card;
82   credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01"));
83   autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field);
84   EXPECT_EQ(ASCIIToUTF16("1"), field.value);
85 }
86 
TEST(SelectControlHandlerTest,AddressCountryFull)87 TEST(SelectControlHandlerTest, AddressCountryFull) {
88   const char* const kCountries[] = {
89     "Albania", "Canada"
90   };
91   std::vector<string16> options(arraysize(kCountries));
92   for (size_t i = 0; i < arraysize(kCountries); ++i)
93     options[i] = ASCIIToUTF16(kCountries[i]);
94 
95   webkit_glue::FormField field;
96   field.form_control_type = ASCIIToUTF16("select-one");
97   field.option_strings = options;
98 
99   AutofillProfile profile;
100   profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA"));
101   autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field);
102   EXPECT_EQ(ASCIIToUTF16("Canada"), field.value);
103 }
104 
TEST(SelectControlHandlerTest,AddressCountryAbbrev)105 TEST(SelectControlHandlerTest, AddressCountryAbbrev) {
106   const char* const kCountries[] = {
107     "AL", "CA"
108   };
109   std::vector<string16> options(arraysize(kCountries));
110   for (size_t i = 0; i < arraysize(kCountries); ++i)
111     options[i] = ASCIIToUTF16(kCountries[i]);
112 
113   webkit_glue::FormField field;
114   field.form_control_type = ASCIIToUTF16("select-one");
115   field.option_strings = options;
116 
117   AutofillProfile profile;
118   profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada"));
119   autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field);
120   EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
121 }
122 
TEST(SelectControlHandlerTest,AddressStateFull)123 TEST(SelectControlHandlerTest, AddressStateFull) {
124   const char* const kStates[] = {
125     "Alabama", "California"
126   };
127   std::vector<string16> options(arraysize(kStates));
128   for (size_t i = 0; i < arraysize(kStates); ++i)
129     options[i] = ASCIIToUTF16(kStates[i]);
130 
131   webkit_glue::FormField field;
132   field.form_control_type = ASCIIToUTF16("select-one");
133   field.option_strings = options;
134 
135   AutofillProfile profile;
136   profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA"));
137   autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field);
138   EXPECT_EQ(ASCIIToUTF16("California"), field.value);
139 }
140 
TEST(SelectControlHandlerTest,AddressStateAbbrev)141 TEST(SelectControlHandlerTest, AddressStateAbbrev) {
142   const char* const kStates[] = {
143     "AL", "CA"
144   };
145   std::vector<string16> options(arraysize(kStates));
146   for (size_t i = 0; i < arraysize(kStates); ++i)
147     options[i] = ASCIIToUTF16(kStates[i]);
148 
149   webkit_glue::FormField field;
150   field.form_control_type = ASCIIToUTF16("select-one");
151   field.option_strings = options;
152 
153   AutofillProfile profile;
154   profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California"));
155   autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field);
156   EXPECT_EQ(ASCIIToUTF16("CA"), field.value);
157 }
158