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