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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "components/autofill/browser/autofill_common_test.h" | 7 #include "components/autofill/browser/autofill_common_test.h" |
8 #include "components/autofill/browser/credit_card.h" | 8 #include "components/autofill/browser/credit_card.h" |
9 #include "components/autofill/common/form_field_data.h" | 9 #include "components/autofill/common/form_field_data.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); | 216 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); |
217 } | 217 } |
218 | 218 |
219 FormFieldData field; | 219 FormFieldData field; |
220 field.form_control_type = "select-one"; | 220 field.form_control_type = "select-one"; |
221 field.option_values = options; | 221 field.option_values = options; |
222 field.option_contents = options; | 222 field.option_contents = options; |
223 | 223 |
224 CreditCard credit_card; | 224 CreditCard credit_card; |
225 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 225 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
226 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, &field); | 226 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, "en-US", &field); |
227 EXPECT_EQ(ASCIIToUTF16("01"), field.value); | 227 EXPECT_EQ(ASCIIToUTF16("01"), field.value); |
228 } | 228 } |
229 | 229 |
230 TEST(CreditCardTest, CreditCardMonthAbbreviated) { | 230 TEST(CreditCardTest, CreditCardMonthAbbreviated) { |
231 const char* const kMonthsAbbreviated[] = { | 231 const char* const kMonthsAbbreviated[] = { |
232 "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 232 "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
233 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", | 233 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", |
234 }; | 234 }; |
235 std::vector<string16> options(arraysize(kMonthsAbbreviated)); | 235 std::vector<string16> options(arraysize(kMonthsAbbreviated)); |
236 for (size_t i = 0; i < arraysize(kMonthsAbbreviated); ++i) { | 236 for (size_t i = 0; i < arraysize(kMonthsAbbreviated); ++i) { |
237 options[i] = ASCIIToUTF16(kMonthsAbbreviated[i]); | 237 options[i] = ASCIIToUTF16(kMonthsAbbreviated[i]); |
238 } | 238 } |
239 | 239 |
240 FormFieldData field; | 240 FormFieldData field; |
241 field.form_control_type = "select-one"; | 241 field.form_control_type = "select-one"; |
242 field.option_values = options; | 242 field.option_values = options; |
243 field.option_contents = options; | 243 field.option_contents = options; |
244 | 244 |
245 CreditCard credit_card; | 245 CreditCard credit_card; |
246 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 246 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
247 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, &field); | 247 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, "en-US", &field); |
248 EXPECT_EQ(ASCIIToUTF16("Jan"), field.value); | 248 EXPECT_EQ(ASCIIToUTF16("Jan"), field.value); |
249 } | 249 } |
250 | 250 |
251 TEST(CreditCardTest, CreditCardMonthFull) { | 251 TEST(CreditCardTest, CreditCardMonthFull) { |
252 const char* const kMonthsFull[] = { | 252 const char* const kMonthsFull[] = { |
253 "January", "February", "March", "April", "May", "June", | 253 "January", "February", "March", "April", "May", "June", |
254 "July", "August", "September", "October", "November", "December", | 254 "July", "August", "September", "October", "November", "December", |
255 }; | 255 }; |
256 std::vector<string16> options(arraysize(kMonthsFull)); | 256 std::vector<string16> options(arraysize(kMonthsFull)); |
257 for (size_t i = 0; i < arraysize(kMonthsFull); ++i) { | 257 for (size_t i = 0; i < arraysize(kMonthsFull); ++i) { |
258 options[i] = ASCIIToUTF16(kMonthsFull[i]); | 258 options[i] = ASCIIToUTF16(kMonthsFull[i]); |
259 } | 259 } |
260 | 260 |
261 FormFieldData field; | 261 FormFieldData field; |
262 field.form_control_type = "select-one"; | 262 field.form_control_type = "select-one"; |
263 field.option_values = options; | 263 field.option_values = options; |
264 field.option_contents = options; | 264 field.option_contents = options; |
265 | 265 |
266 CreditCard credit_card; | 266 CreditCard credit_card; |
267 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 267 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
268 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, &field); | 268 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, "en-US", &field); |
269 EXPECT_EQ(ASCIIToUTF16("January"), field.value); | 269 EXPECT_EQ(ASCIIToUTF16("January"), field.value); |
270 } | 270 } |
271 | 271 |
272 TEST(CreditCardTest, CreditCardMonthNumeric) { | 272 TEST(CreditCardTest, CreditCardMonthNumeric) { |
273 const char* const kMonthsNumeric[] = { | 273 const char* const kMonthsNumeric[] = { |
274 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", | 274 "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", |
275 }; | 275 }; |
276 std::vector<string16> options(arraysize(kMonthsNumeric)); | 276 std::vector<string16> options(arraysize(kMonthsNumeric)); |
277 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) { | 277 for (size_t i = 0; i < arraysize(kMonthsNumeric); ++i) { |
278 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); | 278 options[i] = ASCIIToUTF16(kMonthsNumeric[i]); |
279 } | 279 } |
280 | 280 |
281 FormFieldData field; | 281 FormFieldData field; |
282 field.form_control_type = "select-one"; | 282 field.form_control_type = "select-one"; |
283 field.option_values = options; | 283 field.option_values = options; |
284 field.option_contents = options; | 284 field.option_contents = options; |
285 | 285 |
286 CreditCard credit_card; | 286 CreditCard credit_card; |
287 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); | 287 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("01")); |
288 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, &field); | 288 credit_card.FillSelectControl(CREDIT_CARD_EXP_MONTH, "en-US", &field); |
289 EXPECT_EQ(ASCIIToUTF16("1"), field.value); | 289 EXPECT_EQ(ASCIIToUTF16("1"), field.value); |
290 } | 290 } |
291 | 291 |
292 TEST(CreditCardTest, CreditCardTwoDigitYear) { | 292 TEST(CreditCardTest, CreditCardTwoDigitYear) { |
293 const char* const kYears[] = { | 293 const char* const kYears[] = { |
294 "12", "13", "14", "15", "16", "17", "18", "19" | 294 "12", "13", "14", "15", "16", "17", "18", "19" |
295 }; | 295 }; |
296 std::vector<string16> options(arraysize(kYears)); | 296 std::vector<string16> options(arraysize(kYears)); |
297 for (size_t i = 0; i < arraysize(kYears); ++i) { | 297 for (size_t i = 0; i < arraysize(kYears); ++i) { |
298 options[i] = ASCIIToUTF16(kYears[i]); | 298 options[i] = ASCIIToUTF16(kYears[i]); |
299 } | 299 } |
300 | 300 |
301 FormFieldData field; | 301 FormFieldData field; |
302 field.form_control_type = "select-one"; | 302 field.form_control_type = "select-one"; |
303 field.option_values = options; | 303 field.option_values = options; |
304 field.option_contents = options; | 304 field.option_contents = options; |
305 | 305 |
306 CreditCard credit_card; | 306 CreditCard credit_card; |
307 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2017")); | 307 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2017")); |
308 credit_card.FillSelectControl(CREDIT_CARD_EXP_4_DIGIT_YEAR, &field); | 308 credit_card.FillSelectControl(CREDIT_CARD_EXP_4_DIGIT_YEAR, "en-US", &field); |
309 EXPECT_EQ(ASCIIToUTF16("17"), field.value); | 309 EXPECT_EQ(ASCIIToUTF16("17"), field.value); |
310 EXPECT_EQ(2017, credit_card.expiration_year()); | 310 EXPECT_EQ(2017, credit_card.expiration_year()); |
311 } | 311 } |
312 | 312 |
313 TEST(CreditCardTest, CreditCardTypeSelectControl) { | 313 TEST(CreditCardTest, CreditCardTypeSelectControl) { |
314 const char* const kCreditCardTypes[] = { | 314 const char* const kCreditCardTypes[] = { |
315 "Visa", "Master Card", "AmEx", "discover" | 315 "Visa", "Master Card", "AmEx", "discover" |
316 }; | 316 }; |
317 std::vector<string16> options(arraysize(kCreditCardTypes)); | 317 std::vector<string16> options(arraysize(kCreditCardTypes)); |
318 for (size_t i = 0; i < arraysize(kCreditCardTypes); ++i) { | 318 for (size_t i = 0; i < arraysize(kCreditCardTypes); ++i) { |
319 options[i] = ASCIIToUTF16(kCreditCardTypes[i]); | 319 options[i] = ASCIIToUTF16(kCreditCardTypes[i]); |
320 } | 320 } |
321 | 321 |
322 FormFieldData field; | 322 FormFieldData field; |
323 field.form_control_type = "select-one"; | 323 field.form_control_type = "select-one"; |
324 field.option_values = options; | 324 field.option_values = options; |
325 field.option_contents = options; | 325 field.option_contents = options; |
326 | 326 |
327 // Credit card types are inferred from the numbers, so we use test numbers for | 327 // Credit card types are inferred from the numbers, so we use test numbers for |
328 // each card type. Test card numbers are drawn from | 328 // each card type. Test card numbers are drawn from |
329 // http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_num
bers.htm | 329 // http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_num
bers.htm |
330 | 330 |
331 { | 331 { |
332 // Normal case: | 332 // Normal case: |
333 CreditCard credit_card; | 333 CreditCard credit_card; |
334 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, | 334 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, |
335 ASCIIToUTF16("4111111111111111")); | 335 ASCIIToUTF16("4111111111111111")); |
336 credit_card.FillSelectControl(CREDIT_CARD_TYPE, &field); | 336 credit_card.FillSelectControl(CREDIT_CARD_TYPE, "en-US", &field); |
337 EXPECT_EQ(ASCIIToUTF16("Visa"), field.value); | 337 EXPECT_EQ(ASCIIToUTF16("Visa"), field.value); |
338 } | 338 } |
339 | 339 |
340 { | 340 { |
341 // Filling should be able to handle intervening whitespace: | 341 // Filling should be able to handle intervening whitespace: |
342 CreditCard credit_card; | 342 CreditCard credit_card; |
343 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, | 343 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, |
344 ASCIIToUTF16("5105105105105100")); | 344 ASCIIToUTF16("5105105105105100")); |
345 credit_card.FillSelectControl(CREDIT_CARD_TYPE, &field); | 345 credit_card.FillSelectControl(CREDIT_CARD_TYPE, "en-US", &field); |
346 EXPECT_EQ(ASCIIToUTF16("Master Card"), field.value); | 346 EXPECT_EQ(ASCIIToUTF16("Master Card"), field.value); |
347 } | 347 } |
348 | 348 |
349 { | 349 { |
350 // American Express is sometimes abbreviated as AmEx: | 350 // American Express is sometimes abbreviated as AmEx: |
351 CreditCard credit_card; | 351 CreditCard credit_card; |
352 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("371449635398431")); | 352 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("371449635398431")); |
353 credit_card.FillSelectControl(CREDIT_CARD_TYPE, &field); | 353 credit_card.FillSelectControl(CREDIT_CARD_TYPE, "en-US", &field); |
354 EXPECT_EQ(ASCIIToUTF16("AmEx"), field.value); | 354 EXPECT_EQ(ASCIIToUTF16("AmEx"), field.value); |
355 } | 355 } |
356 | 356 |
357 { | 357 { |
358 // Case insensitivity: | 358 // Case insensitivity: |
359 CreditCard credit_card; | 359 CreditCard credit_card; |
360 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, | 360 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, |
361 ASCIIToUTF16("6011111111111117")); | 361 ASCIIToUTF16("6011111111111117")); |
362 credit_card.FillSelectControl(CREDIT_CARD_TYPE, &field); | 362 credit_card.FillSelectControl(CREDIT_CARD_TYPE, "en-US", &field); |
363 EXPECT_EQ(ASCIIToUTF16("discover"), field.value); | 363 EXPECT_EQ(ASCIIToUTF16("discover"), field.value); |
364 } | 364 } |
365 } | 365 } |
OLD | NEW |