OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/autofill/autofill_profile.h" | 7 #include "chrome/browser/autofill/autofill_profile.h" |
8 #include "chrome/browser/autofill/autofill_type.h" | 8 #include "chrome/browser/autofill/autofill_type.h" |
9 #include "chrome/browser/autofill/credit_card.h" | 9 #include "chrome/browser/autofill/credit_card.h" |
10 #include "chrome/browser/autofill/select_control_handler.h" | 10 #include "chrome/browser/autofill/select_control_handler.h" |
11 #include "chrome/common/form_field_data.h" | 11 #include "chrome/common/form_field_data.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 TEST(SelectControlHandlerTest, CreditCardMonthExact) { | 14 TEST(SelectControlHandlerTest, CreditCardMonthExact) { |
15 const char* const kMonthsNumeric[] = { | 15 const char* const kMonthsNumeric[] = { |
16 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", | 16 "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", |
17 }; | 17 }; |
18 std::vector<string16> options(arraysize(kMonthsNumeric)); | 18 std::vector<string16> options(arraysize(kMonthsNumeric)); |
19 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) | 19 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) |
20 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); | 20 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); |
21 | 21 |
22 FormFieldData field; | 22 FormFieldData field; |
23 field.form_control_type = "select-one"; | 23 field.form_control_type = "select-one"; |
24 field.option_values = options; | 24 field.option_values = options; |
25 field.option_contents = options; | 25 field.option_contents = options; |
26 | 26 |
27 CreditCard credit_card; | 27 CreditCard credit_card; |
28 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 28 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
29 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 29 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
30 EXPECT_EQ(ASCIIToUTF16("01"), field.value); | 30 EXPECT_EQ(ASCIIToUTF16("01"), field.value); |
31 } | 31 } |
32 | 32 |
33 TEST(SelectControlHandlerTest, CreditCardMonthAbbreviated) { | 33 TEST(SelectControlHandlerTest, CreditCardMonthAbbreviated) { |
34 const char* const kMonthsAbbreviated[] = { | 34 const char* const kMonthsAbbreviated[] = { |
35 "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 35 "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
36 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | 36 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", |
37 }; | 37 }; |
38 std::vector<string16> options(arraysize(kMonthsAbbreviated)); | 38 std::vector<string16> options(arraysize(kMonthsAbbreviated)); |
39 for (size_t i = 0; i < arraysize(kMonthsAbbreviated); ++i) | 39 for (size_t i = 0; i < arraysize(kMonthsAbbreviated); ++i) |
40 options[i] = ASCIIToUTF16(kMonthsAbbreviated[i]); | 40 options[i] = ASCIIToUTF16(kMonthsAbbreviated[i]); |
41 | 41 |
42 FormFieldData field; | 42 FormFieldData field; |
43 field.form_control_type = "select-one"; | 43 field.form_control_type = "select-one"; |
44 field.option_values = options; | 44 field.option_values = options; |
45 field.option_contents = options; | 45 field.option_contents = options; |
46 | 46 |
47 CreditCard credit_card; | 47 CreditCard credit_card; |
48 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 48 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
49 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 49 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
50 EXPECT_EQ(ASCIIToUTF16("Jan"), field.value); | 50 EXPECT_EQ(ASCIIToUTF16("Jan"), field.value); |
51 } | 51 } |
52 | 52 |
53 TEST(SelectControlHandlerTest, CreditCardMonthFull) { | 53 TEST(SelectControlHandlerTest, CreditCardMonthFull) { |
54 const char* const kMonthsFull[] = { | 54 const char* const kMonthsFull[] = { |
55 "January", "February", "March", "April", "May", "June", | 55 "January", "February", "March", "April", "May", "June", |
56 "July", "August", "September", "October", "November", "December", | 56 "July", "August", "September", "October", "November", "December", |
57 }; | 57 }; |
58 std::vector<string16> options(arraysize(kMonthsFull)); | 58 std::vector<string16> options(arraysize(kMonthsFull)); |
59 for (size_t i = 0; i < arraysize(kMonthsFull); ++i) | 59 for (size_t i = 0; i < arraysize(kMonthsFull); ++i) |
60 options[i] = ASCIIToUTF16(kMonthsFull[i]); | 60 options[i] = ASCIIToUTF16(kMonthsFull[i]); |
61 | 61 |
62 FormFieldData field; | 62 FormFieldData field; |
63 field.form_control_type = "select-one"; | 63 field.form_control_type = "select-one"; |
64 field.option_values = options; | 64 field.option_values = options; |
65 field.option_contents = options; | 65 field.option_contents = options; |
66 | 66 |
67 CreditCard credit_card; | 67 CreditCard credit_card; |
68 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 68 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
69 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 69 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
70 EXPECT_EQ(ASCIIToUTF16("January"), field.value); | 70 EXPECT_EQ(ASCIIToUTF16("January"), field.value); |
71 } | 71 } |
72 | 72 |
73 TEST(SelectControlHandlerTest, CreditCardMonthNumeric) { | 73 TEST(SelectControlHandlerTest, CreditCardMonthNumeric) { |
74 const char* const kMonthsNumeric[] = { | 74 const char* const kMonthsNumeric[] = { |
75 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", | 75 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", |
76 }; | 76 }; |
77 std::vector<string16> options(arraysize(kMonthsNumeric)); | 77 std::vector<string16> options(arraysize(kMonthsNumeric)); |
78 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) | 78 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) |
79 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); | 79 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); |
80 | 80 |
81 FormFieldData field; | 81 FormFieldData field; |
82 field.form_control_type = "select-one"; | 82 field.form_control_type = "select-one"; |
83 field.option_values = options; | 83 field.option_values = options; |
84 field.option_contents = options; | 84 field.option_contents = options; |
85 | 85 |
86 CreditCard credit_card; | 86 CreditCard credit_card; |
87 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 87 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
88 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); | 88 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_MONTH, &field); |
89 EXPECT_EQ(ASCIIToUTF16("1"), field.value); | 89 EXPECT_EQ(ASCIIToUTF16("1"), field.value); |
90 } | 90 } |
91 | 91 |
92 TEST(SelectControlHandlerTest, CreditCardTwoDigitYear) { | 92 TEST(SelectControlHandlerTest, CreditCardTwoDigitYear) { |
93 const char* const kYears[] = { | 93 const char* const kYears[] = { |
94 "12", "13", "14", "15", "16", "17", "18", "19" | 94 "12", "13", "14", "15", "16", "17", "18", "19" |
95 }; | 95 }; |
96 std::vector<string16> options(arraysize(kYears)); | 96 std::vector<string16> options(arraysize(kYears)); |
97 for (size_t i = 0; i < arraysize(kYears); ++i) | 97 for (size_t i = 0; i < arraysize(kYears); ++i) |
98 options[i] = ASCIIToUTF16(kYears[i]); | 98 options[i] = ASCIIToUTF16(kYears[i]); |
99 | 99 |
100 FormFieldData field; | 100 FormFieldData field; |
101 field.form_control_type = "select-one"; | 101 field.form_control_type = "select-one"; |
102 field.option_values = options; | 102 field.option_values = options; |
103 field.option_contents = options; | 103 field.option_contents = options; |
104 | 104 |
105 CreditCard credit_card; | 105 CreditCard credit_card; |
106 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2017")); | 106 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2017")); |
107 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 107 autofill::FillSelectControl(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR, |
108 &field); | 108 &field); |
109 EXPECT_EQ(ASCIIToUTF16("17"), field.value); | 109 EXPECT_EQ(ASCIIToUTF16("17"), field.value); |
110 } | 110 } |
111 | 111 |
112 TEST(SelectControlHandlerTest, AddressCountryFull) { | 112 TEST(SelectControlHandlerTest, AddressCountryFull) { |
113 const char* const kCountries[] = { | 113 const char* const kCountries[] = { |
114 "Albania", "Canada" | 114 "Albania", "Canada" |
115 }; | 115 }; |
116 std::vector<string16> options(arraysize(kCountries)); | 116 std::vector<string16> options(arraysize(kCountries)); |
117 for (size_t i = 0; i < arraysize(kCountries); ++i) | 117 for (size_t i = 0; i < arraysize(kCountries); ++i) |
118 options[i] = ASCIIToUTF16(kCountries[i]); | 118 options[i] = ASCIIToUTF16(kCountries[i]); |
119 | 119 |
120 FormFieldData field; | 120 FormFieldData field; |
121 field.form_control_type = "select-one"; | 121 field.form_control_type = "select-one"; |
122 field.option_values = options; | 122 field.option_values = options; |
123 field.option_contents = options; | 123 field.option_contents = options; |
124 | 124 |
125 AutofillProfile profile; | 125 AutofillProfile profile; |
126 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); | 126 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("CA")); |
127 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); | 127 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); |
128 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); | 128 EXPECT_EQ(ASCIIToUTF16("Canada"), field.value); |
129 } | 129 } |
130 | 130 |
131 TEST(SelectControlHandlerTest, AddressCountryAbbrev) { | 131 TEST(SelectControlHandlerTest, AddressCountryAbbrev) { |
132 const char* const kCountries[] = { | 132 const char* const kCountries[] = { |
133 "AL", "CA" | 133 "AL", "CA" |
134 }; | 134 }; |
135 std::vector<string16> options(arraysize(kCountries)); | 135 std::vector<string16> options(arraysize(kCountries)); |
136 for (size_t i = 0; i < arraysize(kCountries); ++i) | 136 for (size_t i = 0; i < arraysize(kCountries); ++i) |
137 options[i] = ASCIIToUTF16(kCountries[i]); | 137 options[i] = ASCIIToUTF16(kCountries[i]); |
138 | 138 |
139 FormFieldData field; | 139 FormFieldData field; |
140 field.form_control_type = "select-one"; | 140 field.form_control_type = "select-one"; |
141 field.option_values = options; | 141 field.option_values = options; |
142 field.option_contents = options; | 142 field.option_contents = options; |
143 | 143 |
144 AutofillProfile profile; | 144 AutofillProfile profile; |
145 profile.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada")); | 145 profile.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("Canada")); |
146 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); | 146 autofill::FillSelectControl(profile, ADDRESS_HOME_COUNTRY, &field); |
147 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 147 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
148 } | 148 } |
149 | 149 |
150 TEST(SelectControlHandlerTest, AddressStateFull) { | 150 TEST(SelectControlHandlerTest, AddressStateFull) { |
151 const char* const kStates[] = { | 151 const char* const kStates[] = { |
152 "Alabama", "California" | 152 "Alabama", "California" |
153 }; | 153 }; |
154 std::vector<string16> options(arraysize(kStates)); | 154 std::vector<string16> options(arraysize(kStates)); |
155 for (size_t i = 0; i < arraysize(kStates); ++i) | 155 for (size_t i = 0; i < arraysize(kStates); ++i) |
156 options[i] = ASCIIToUTF16(kStates[i]); | 156 options[i] = ASCIIToUTF16(kStates[i]); |
157 | 157 |
158 FormFieldData field; | 158 FormFieldData field; |
159 field.form_control_type = "select-one"; | 159 field.form_control_type = "select-one"; |
160 field.option_values = options; | 160 field.option_values = options; |
161 field.option_contents = options; | 161 field.option_contents = options; |
162 | 162 |
163 AutofillProfile profile; | 163 AutofillProfile profile; |
164 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); | 164 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("CA")); |
165 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 165 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
166 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 166 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
167 } | 167 } |
168 | 168 |
169 TEST(SelectControlHandlerTest, AddressStateAbbrev) { | 169 TEST(SelectControlHandlerTest, AddressStateAbbrev) { |
170 const char* const kStates[] = { | 170 const char* const kStates[] = { |
171 "AL", "CA" | 171 "AL", "CA" |
172 }; | 172 }; |
173 std::vector<string16> options(arraysize(kStates)); | 173 std::vector<string16> options(arraysize(kStates)); |
174 for (size_t i = 0; i < arraysize(kStates); ++i) | 174 for (size_t i = 0; i < arraysize(kStates); ++i) |
175 options[i] = ASCIIToUTF16(kStates[i]); | 175 options[i] = ASCIIToUTF16(kStates[i]); |
176 | 176 |
177 FormFieldData field; | 177 FormFieldData field; |
178 field.form_control_type = "select-one"; | 178 field.form_control_type = "select-one"; |
179 field.option_values = options; | 179 field.option_values = options; |
180 field.option_contents = options; | 180 field.option_contents = options; |
181 | 181 |
182 AutofillProfile profile; | 182 AutofillProfile profile; |
183 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 183 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
184 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 184 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
185 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); | 185 EXPECT_EQ(ASCIIToUTF16("CA"), field.value); |
186 } | 186 } |
187 | 187 |
188 TEST(SelectControlHandlerTest, FillByValue) { | 188 TEST(SelectControlHandlerTest, FillByValue) { |
189 const char* const kStates[] = { | 189 const char* const kStates[] = { |
190 "Alabama", "California" | 190 "Alabama", "California" |
191 }; | 191 }; |
192 std::vector<string16> values(arraysize(kStates)); | 192 std::vector<string16> values(arraysize(kStates)); |
193 std::vector<string16> contents(arraysize(kStates)); | 193 std::vector<string16> contents(arraysize(kStates)); |
194 for (size_t i = 0; i < arraysize(kStates); ++i) { | 194 for (size_t i = 0; i < arraysize(kStates); ++i) { |
195 values[i] = ASCIIToUTF16(kStates[i]); | 195 values[i] = ASCIIToUTF16(kStates[i]); |
196 contents[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i))); | 196 contents[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i))); |
197 } | 197 } |
198 | 198 |
199 FormFieldData field; | 199 FormFieldData field; |
200 field.form_control_type = "select-one"; | 200 field.form_control_type = "select-one"; |
201 field.option_values = values; | 201 field.option_values = values; |
202 field.option_contents = contents; | 202 field.option_contents = contents; |
203 | 203 |
204 AutofillProfile profile; | 204 AutofillProfile profile; |
205 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 205 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
206 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 206 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
207 EXPECT_EQ(ASCIIToUTF16("California"), field.value); | 207 EXPECT_EQ(ASCIIToUTF16("California"), field.value); |
208 } | 208 } |
209 | 209 |
210 TEST(SelectControlHandlerTest, FillByContents) { | 210 TEST(SelectControlHandlerTest, FillByContents) { |
211 const char* const kStates[] = { | 211 const char* const kStates[] = { |
212 "Alabama", "California" | 212 "Alabama", "California" |
213 }; | 213 }; |
214 std::vector<string16> values(arraysize(kStates)); | 214 std::vector<string16> values(arraysize(kStates)); |
215 std::vector<string16> contents(arraysize(kStates)); | 215 std::vector<string16> contents(arraysize(kStates)); |
216 for (size_t i = 0; i < arraysize(kStates); ++i) { | 216 for (size_t i = 0; i < arraysize(kStates); ++i) { |
217 values[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i + 1))); | 217 values[i] = ASCIIToUTF16(base::StringPrintf("%d", static_cast<int>(i + 1))); |
218 contents[i] = ASCIIToUTF16(kStates[i]); | 218 contents[i] = ASCIIToUTF16(kStates[i]); |
219 } | 219 } |
220 | 220 |
221 FormFieldData field; | 221 FormFieldData field; |
222 field.form_control_type = "select-one"; | 222 field.form_control_type = "select-one"; |
223 field.option_values = values; | 223 field.option_values = values; |
224 field.option_contents = contents; | 224 field.option_contents = contents; |
225 | 225 |
226 AutofillProfile profile; | 226 AutofillProfile profile; |
227 profile.SetInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); | 227 profile.SetRawInfo(ADDRESS_HOME_STATE, ASCIIToUTF16("California")); |
228 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); | 228 autofill::FillSelectControl(profile, ADDRESS_HOME_STATE, &field); |
229 EXPECT_EQ(ASCIIToUTF16("2"), field.value); | 229 EXPECT_EQ(ASCIIToUTF16("2"), field.value); |
230 } | 230 } |
OLD | NEW |