Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: components/autofill/browser/credit_card_unittest.cc

Issue 16254010: [Autofill] Update credit card type detection logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a typo Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/guid.h" 6 #include "base/guid.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "components/autofill/browser/autofill_common_test.h" 8 #include "components/autofill/browser/autofill_common_test.h"
9 #include "components/autofill/browser/credit_card.h" 9 #include "components/autofill/browser/credit_card.h"
10 #include "components/autofill/common/form_field_data.h" 10 #include "components/autofill/common/form_field_data.h"
(...skipping 22 matching lines...) Expand all
33 "5019717010103742", 33 "5019717010103742",
34 "6331101999990016", 34 "6331101999990016",
35 }; 35 };
36 const char* const kInvalidNumbers[] = { 36 const char* const kInvalidNumbers[] = {
37 "4111 1111 112", /* too short */ 37 "4111 1111 112", /* too short */
38 "41111111111111111115", /* too long */ 38 "41111111111111111115", /* too long */
39 "4111-1111-1111-1110", /* wrong Luhn checksum */ 39 "4111-1111-1111-1110", /* wrong Luhn checksum */
40 "3056 9309 0259 04aa", /* non-digit characters */ 40 "3056 9309 0259 04aa", /* non-digit characters */
41 }; 41 };
42 42
43 // A simple wrapper function to handle string type conversion.
44 std::string GetCreditCardType(const std::string& number) {
45 return CreditCard::GetCreditCardType(ASCIIToUTF16(number));
46 }
47
43 } // namespace 48 } // namespace
44 49
45 // Tests credit card summary string generation. This test simulates a variety 50 // Tests credit card summary string generation. This test simulates a variety
46 // of different possible summary strings. Variations occur based on the 51 // of different possible summary strings. Variations occur based on the
47 // existence of credit card number, month, and year fields. 52 // existence of credit card number, month, and year fields.
48 TEST(CreditCardTest, PreviewSummaryAndObfuscatedNumberStrings) { 53 TEST(CreditCardTest, PreviewSummaryAndObfuscatedNumberStrings) {
49 // Case 0: empty credit card. 54 // Case 0: empty credit card.
50 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/"); 55 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/");
51 base::string16 summary0 = credit_card0.Label(); 56 base::string16 summary0 = credit_card0.Label();
52 EXPECT_EQ(base::string16(), summary0); 57 EXPECT_EQ(base::string16(), summary0);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 { 396 {
392 // Case insensitivity: 397 // Case insensitivity:
393 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); 398 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/");
394 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, 399 credit_card.SetRawInfo(CREDIT_CARD_NUMBER,
395 ASCIIToUTF16("6011111111111117")); 400 ASCIIToUTF16("6011111111111117"));
396 credit_card.FillSelectControl(CREDIT_CARD_TYPE, "en-US", &field); 401 credit_card.FillSelectControl(CREDIT_CARD_TYPE, "en-US", &field);
397 EXPECT_EQ(ASCIIToUTF16("discover"), field.value); 402 EXPECT_EQ(ASCIIToUTF16("discover"), field.value);
398 } 403 }
399 } 404 }
400 405
406 TEST(CreditCardTest, GetCreditCardType) {
407 // Verify the relevant sample numbers from
408 // http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_num bers.htm
409 EXPECT_EQ(kAmericanExpressCard, GetCreditCardType("378282246310005"));
Evan Stade 2013/06/10 18:59:47 I think the most common way to do this in tests is
Ilya Sherman 2013/06/18 03:37:38 Done.
410 EXPECT_EQ(kAmericanExpressCard, GetCreditCardType("371449635398431"));
411 EXPECT_EQ(kAmericanExpressCard, GetCreditCardType("378734493671000"));
412 EXPECT_EQ(kDinersCard, GetCreditCardType("30569309025904"));
413 EXPECT_EQ(kDinersCard, GetCreditCardType("38520000023237"));
414 EXPECT_EQ(kDiscoverCard, GetCreditCardType("6011111111111117"));
415 EXPECT_EQ(kDiscoverCard, GetCreditCardType("6011000990139424"));
416 EXPECT_EQ(kJCBCard, GetCreditCardType("3530111333300000"));
417 EXPECT_EQ(kJCBCard, GetCreditCardType("3566002020360505"));
418 EXPECT_EQ(kMasterCard, GetCreditCardType("5555555555554444"));
419 EXPECT_EQ(kMasterCard, GetCreditCardType("5105105105105100"));
420 EXPECT_EQ(kVisaCard, GetCreditCardType("4111111111111111"));
421 EXPECT_EQ(kVisaCard, GetCreditCardType("4012888888881881"));
422 EXPECT_EQ(kVisaCard, GetCreditCardType("4222222222222"));
423
424 // Verify the relevant sample numbers from
425 // http://auricsystems.com/support-center/sample-credit-card-numbers/
426 EXPECT_EQ(kAmericanExpressCard, GetCreditCardType("343434343434343"));
427 EXPECT_EQ(kAmericanExpressCard, GetCreditCardType("371144371144376"));
428 EXPECT_EQ(kAmericanExpressCard, GetCreditCardType("341134113411347"));
429 EXPECT_EQ(kDinersCard, GetCreditCardType("36438936438936"));
430 EXPECT_EQ(kDinersCard, GetCreditCardType("36110361103612"));
431 EXPECT_EQ(kDinersCard, GetCreditCardType("36111111111111"));
432 EXPECT_EQ(kDiscoverCard, GetCreditCardType("6011016011016011"));
433 EXPECT_EQ(kDiscoverCard, GetCreditCardType("6011000990139424"));
434 EXPECT_EQ(kDiscoverCard, GetCreditCardType("6011000000000004"));
435 EXPECT_EQ(kDiscoverCard, GetCreditCardType("6011000995500000"));
436 EXPECT_EQ(kDiscoverCard, GetCreditCardType("6500000000000002"));
437 EXPECT_EQ(kJCBCard, GetCreditCardType("3566003566003566"));
438 EXPECT_EQ(kJCBCard, GetCreditCardType("3528000000000007"));
439 EXPECT_EQ(kMasterCard, GetCreditCardType("5500005555555559"));
440 EXPECT_EQ(kMasterCard, GetCreditCardType("5555555555555557"));
441 EXPECT_EQ(kMasterCard, GetCreditCardType("5454545454545454"));
442 EXPECT_EQ(kMasterCard, GetCreditCardType("5555515555555551"));
443 EXPECT_EQ(kMasterCard, GetCreditCardType("5405222222222226"));
444 EXPECT_EQ(kMasterCard, GetCreditCardType("5478050000000007"));
445 EXPECT_EQ(kMasterCard, GetCreditCardType("5111005111051128"));
446 EXPECT_EQ(kMasterCard, GetCreditCardType("5112345112345114"));
447 EXPECT_EQ(kMasterCard, GetCreditCardType("5115915115915118"));
448 }
benquan 2013/06/08 07:27:57 Please add a test for kGenericCard and some negati
Ilya Sherman 2013/06/18 03:37:38 Good call -- done.
449
401 } // namespace autofill 450 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698