Chromium Code Reviews| Index: components/autofill/core/browser/credit_card_unittest.cc |
| diff --git a/components/autofill/core/browser/credit_card_unittest.cc b/components/autofill/core/browser/credit_card_unittest.cc |
| index 993862f6d6dfef412c860a3acec4f91ef57d710b..db214047634d866b1a03cc6bd020dfcc13bbcfbc 100644 |
| --- a/components/autofill/core/browser/credit_card_unittest.cc |
| +++ b/components/autofill/core/browser/credit_card_unittest.cc |
| @@ -158,77 +158,90 @@ TEST(CreditCardTest, AssignmentOperator) { |
| EXPECT_TRUE(a == b); |
| } |
| -TEST(CreditCardTest, SetExpirationYearFromString) { |
| - static const struct { |
| - std::string expiration_year; |
| - int expected_year; |
| - } kTestCases[] = { |
| - // Valid values. |
| - {"2040", 2040}, |
| - {"45", 2045}, |
| - {"045", 2045}, |
| - {"9", 2009}, |
| - |
| - // Unrecognized year values. |
| - {"052045", 0}, |
| - {"123", 0}, |
| - {"y2045", 0}, |
| - }; |
| +struct SetExpirationYearFromStringTestCase { |
| + std::string expiration_year; |
| + int expected_year; |
| +}; |
| - for (const auto& test_case : kTestCases) { |
| - CreditCard card(base::GenerateGUID(), "some origin"); |
| - card.SetExpirationYearFromString(ASCIIToUTF16(test_case.expiration_year)); |
| +class SetExpirationYearFromStringTest |
| + : public testing::TestWithParam<SetExpirationYearFromStringTestCase> {}; |
| - EXPECT_EQ(test_case.expected_year, card.expiration_year()) |
| - << test_case.expiration_year << " " << test_case.expected_year; |
| - } |
| +TEST_P(SetExpirationYearFromStringTest, SetExpirationYearFromString) { |
| + auto test_case = GetParam(); |
| + CreditCard card(base::GenerateGUID(), "some origin"); |
| + card.SetExpirationYearFromString(ASCIIToUTF16(test_case.expiration_year)); |
| + |
| + EXPECT_EQ(test_case.expected_year, card.expiration_year()) |
| + << test_case.expiration_year << " " << test_case.expected_year; |
| } |
| -TEST(CreditCardTest, SetExpirationDateFromString) { |
| - static const struct { |
| - std::string expiration_date; |
| - int expected_month; |
| - int expected_year; |
| - } kTestCases[] = {{"10", 0, 0}, // Too small. |
| - {"1020451", 0, 0}, // Too long. |
| - |
| - // No separators. |
| - {"105", 0, 0}, // Too ambiguous. |
| - {"0545", 5, 2045}, |
| - {"52045", 0, 0}, // Too ambiguous. |
| - {"052045", 5, 2045}, |
| - |
| - // "/" separator. |
| - {"05/45", 5, 2045}, |
| - {"5/2045", 5, 2045}, |
| - {"05/2045", 5, 2045}, |
| - |
| - // "-" separator. |
| - {"05-45", 5, 2045}, |
| - {"5-2045", 5, 2045}, |
| - {"05-2045", 5, 2045}, |
| - |
| - // "|" separator. |
| - {"05|45", 5, 2045}, |
| - {"5|2045", 5, 2045}, |
| - {"05|2045", 5, 2045}, |
| - |
| - // Invalid values. |
| - {"13/2016", 0, 2016}, |
| - {"16/13", 0, 2013}, |
| - {"May-2015", 0, 0}, |
| - {"05-/2045", 0, 0}, |
| - {"05_2045", 0, 0}}; |
| +INSTANTIATE_TEST_CASE_P(CreditCardTest, |
| + SetExpirationYearFromStringTest, |
| + testing::Values( |
| + // Valid values. |
| + SetExpirationYearFromStringTestCase{"2040", 2040}, |
| + SetExpirationYearFromStringTestCase{"45", 2045}, |
| + SetExpirationYearFromStringTestCase{"045", 2045}, |
| + SetExpirationYearFromStringTestCase{"9", 2009}, |
| + |
| + // Unrecognized year values. |
| + SetExpirationYearFromStringTestCase{"052045", 0}, |
| + SetExpirationYearFromStringTestCase{"123", 0}, |
| + SetExpirationYearFromStringTestCase{"y2045", 0})); |
| + |
| +struct SetExpirationDateFromStringTestCase { |
| + std::string expiration_date; |
| + int expected_month; |
| + int expected_year; |
| +}; |
| - for (const auto& test_case : kTestCases) { |
| - CreditCard card(base::GenerateGUID(), "some origin"); |
| - card.SetExpirationDateFromString(ASCIIToUTF16(test_case.expiration_date)); |
| +class SetExpirationDateFromStringTest |
| + : public testing::TestWithParam<SetExpirationDateFromStringTestCase> {}; |
| - EXPECT_EQ(test_case.expected_month, card.expiration_month()); |
| - EXPECT_EQ(test_case.expected_year, card.expiration_year()); |
| - } |
| +TEST_P(SetExpirationDateFromStringTest, SetExpirationDateFromString) { |
| + auto test_case = GetParam(); |
| + CreditCard card(base::GenerateGUID(), "some origin"); |
| + card.SetExpirationDateFromString(ASCIIToUTF16(test_case.expiration_date)); |
| + |
| + EXPECT_EQ(test_case.expected_month, card.expiration_month()); |
| + EXPECT_EQ(test_case.expected_year, card.expiration_year()); |
| } |
| +INSTANTIATE_TEST_CASE_P( |
| + CreditCardTest, |
| + SetExpirationDateFromStringTest, |
| + testing::Values( |
| + SetExpirationDateFromStringTestCase{"10", 0, 0}, // Too small. |
| + SetExpirationDateFromStringTestCase{"1020451", 0, 0}, // Too long. |
| + |
| + // No separators. |
| + SetExpirationDateFromStringTestCase{"105", 0, 0}, // Too ambiguous. |
| + SetExpirationDateFromStringTestCase{"0545", 5, 2045}, |
| + SetExpirationDateFromStringTestCase{"52045", 0, 0}, // Too ambiguous. |
| + SetExpirationDateFromStringTestCase{"052045", 5, 2045}, |
| + |
| + // "/" separator. |
| + SetExpirationDateFromStringTestCase{"05/45", 5, 2045}, |
| + SetExpirationDateFromStringTestCase{"5/2045", 5, 2045}, |
| + SetExpirationDateFromStringTestCase{"05/2045", 5, 2045}, |
| + |
| + // "-" separator. |
| + SetExpirationDateFromStringTestCase{"05-45", 5, 2045}, |
| + SetExpirationDateFromStringTestCase{"5-2045", 5, 2045}, |
| + SetExpirationDateFromStringTestCase{"05-2045", 5, 2045}, |
| + |
| + // "|" separator. |
| + SetExpirationDateFromStringTestCase{"05|45", 5, 2045}, |
| + SetExpirationDateFromStringTestCase{"5|2045", 5, 2045}, |
| + SetExpirationDateFromStringTestCase{"05|2045", 5, 2045}, |
| + |
| + // Invalid values. |
| + SetExpirationDateFromStringTestCase{"13/2016", 0, 2016}, |
| + SetExpirationDateFromStringTestCase{"16/13", 0, 2013}, |
| + SetExpirationDateFromStringTestCase{"May-2015", 0, 0}, |
| + SetExpirationDateFromStringTestCase{"05-/2045", 0, 0}, |
| + SetExpirationDateFromStringTestCase{"05_2045", 0, 0})); |
| + |
| TEST(CreditCardTest, Copy) { |
| CreditCard a(base::GenerateGUID(), "https://www.example.com"); |
| test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); |
| @@ -238,73 +251,85 @@ TEST(CreditCardTest, Copy) { |
| EXPECT_TRUE(a == b); |
| } |
| -TEST(CreditCardTest, IsLocalDuplicateOfServerCard) { |
| - struct { |
| - CreditCard::RecordType first_card_record_type; |
| - const char* first_card_name; |
| - const char* first_card_number; |
| - const char* first_card_exp_mo; |
| - const char* first_card_exp_yr; |
| - |
| - CreditCard::RecordType second_card_record_type; |
| - const char* second_card_name; |
| - const char* second_card_number; |
| - const char* second_card_exp_mo; |
| - const char* second_card_exp_yr; |
| - const char* second_card_type; |
| - |
| - bool is_local_duplicate; |
| - } test_cases[] = { |
| - { LOCAL_CARD, "", "", "", "", |
| - LOCAL_CARD, "", "", "", "", nullptr, false }, |
| - { LOCAL_CARD, "", "", "", "", |
| - FULL_SERVER_CARD, "", "", "", "", nullptr, true}, |
| - { FULL_SERVER_CARD, "", "", "", "", |
| - FULL_SERVER_CARD, "", "", "", "", nullptr, false}, |
| - { LOCAL_CARD, "John Dillinger", "423456789012", "01", "2010", |
| - FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", nullptr, |
| - true }, |
| - { LOCAL_CARD, "J Dillinger", "423456789012", "01", "2010", |
| - FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", nullptr, |
| - false }, |
| - { LOCAL_CARD, "", "423456789012", "01", "2010", |
| - FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", nullptr, |
| - true }, |
| - { LOCAL_CARD, "", "423456789012", "", "", |
| - FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", nullptr, |
| - true }, |
| - { LOCAL_CARD, "", "423456789012", "", "", |
| - MASKED_SERVER_CARD, "John Dillinger", "9012", "01", "2010", kVisaCard, |
| - true }, |
| - { LOCAL_CARD, "", "423456789012", "", "", |
| - MASKED_SERVER_CARD, "John Dillinger", "9012", "01", "2010", kMasterCard, |
| - false }, |
| - { LOCAL_CARD, "John Dillinger", "4234-5678-9012", "01", "2010", |
| - FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", nullptr, |
| - true }, |
| - }; |
| +struct IsLocalDuplicateOfServerCardTestCase { |
| + CreditCard::RecordType first_card_record_type; |
| + const char* first_card_name; |
| + const char* first_card_number; |
| + const char* first_card_exp_mo; |
| + const char* first_card_exp_yr; |
| + |
| + CreditCard::RecordType second_card_record_type; |
| + const char* second_card_name; |
| + const char* second_card_number; |
| + const char* second_card_exp_mo; |
| + const char* second_card_exp_yr; |
| + const char* second_card_type; |
| + |
| + bool is_local_duplicate; |
| +}; |
| - for (const auto& test_case : test_cases) { |
| - CreditCard a(base::GenerateGUID(), std::string()); |
| - a.set_record_type(test_case.first_card_record_type); |
| - test::SetCreditCardInfo( |
| - &a, test_case.first_card_name, test_case.first_card_number, |
| - test_case.first_card_exp_mo, test_case.first_card_exp_yr); |
| +class IsLocalDuplicateOfServerCardTest |
| + : public testing::TestWithParam<IsLocalDuplicateOfServerCardTestCase> {}; |
| - CreditCard b(base::GenerateGUID(), std::string()); |
| - b.set_record_type(test_case.second_card_record_type); |
| - test::SetCreditCardInfo( |
| - &b, test_case.second_card_name, test_case.second_card_number, |
| - test_case.second_card_exp_mo, test_case.second_card_exp_yr); |
| +TEST_P(IsLocalDuplicateOfServerCardTest, IsLocalDuplicateOfServerCard) { |
| + auto test_case = GetParam(); |
| + CreditCard a(base::GenerateGUID(), std::string()); |
| + a.set_record_type(test_case.first_card_record_type); |
| + test::SetCreditCardInfo( |
| + &a, test_case.first_card_name, test_case.first_card_number, |
| + test_case.first_card_exp_mo, test_case.first_card_exp_yr); |
| - if (test_case.second_card_record_type == CreditCard::MASKED_SERVER_CARD) |
| - b.SetTypeForMaskedCard(test_case.second_card_type); |
| + CreditCard b(base::GenerateGUID(), std::string()); |
| + b.set_record_type(test_case.second_card_record_type); |
| + test::SetCreditCardInfo( |
| + &b, test_case.second_card_name, test_case.second_card_number, |
| + test_case.second_card_exp_mo, test_case.second_card_exp_yr); |
| - EXPECT_EQ(test_case.is_local_duplicate, a.IsLocalDuplicateOfServerCard(b)) |
| - << " when comparing cards " << a.Label() << " and " << b.Label(); |
| - } |
| + if (test_case.second_card_record_type == CreditCard::MASKED_SERVER_CARD) |
| + b.SetTypeForMaskedCard(test_case.second_card_type); |
| + |
| + EXPECT_EQ(test_case.is_local_duplicate, a.IsLocalDuplicateOfServerCard(b)) |
| + << " when comparing cards " << a.Label() << " and " << b.Label(); |
| } |
| +INSTANTIATE_TEST_CASE_P( |
| + CreditCardTest, |
| + IsLocalDuplicateOfServerCardTest, |
| + testing::Values( |
| + IsLocalDuplicateOfServerCardTestCase{LOCAL_CARD, "", "", "", "", |
| + LOCAL_CARD, "", "", "", "", |
| + nullptr, false}, |
| + IsLocalDuplicateOfServerCardTestCase{LOCAL_CARD, "", "", "", "", |
| + FULL_SERVER_CARD, "", "", "", "", |
| + nullptr, true}, |
| + IsLocalDuplicateOfServerCardTestCase{FULL_SERVER_CARD, "", "", "", "", |
| + FULL_SERVER_CARD, "", "", "", "", |
| + nullptr, false}, |
| + IsLocalDuplicateOfServerCardTestCase{ |
| + LOCAL_CARD, "John Dillinger", "423456789012", "01", "2010", |
| + FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", |
| + nullptr, true}, |
| + IsLocalDuplicateOfServerCardTestCase{ |
| + LOCAL_CARD, "J Dillinger", "423456789012", "01", "2010", |
| + FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", |
| + nullptr, false}, |
| + IsLocalDuplicateOfServerCardTestCase{ |
| + LOCAL_CARD, "", "423456789012", "01", "2010", FULL_SERVER_CARD, |
| + "John Dillinger", "423456789012", "01", "2010", nullptr, true}, |
| + IsLocalDuplicateOfServerCardTestCase{ |
| + LOCAL_CARD, "", "423456789012", "", "", FULL_SERVER_CARD, |
| + "John Dillinger", "423456789012", "01", "2010", nullptr, true}, |
| + IsLocalDuplicateOfServerCardTestCase{ |
| + LOCAL_CARD, "", "423456789012", "", "", MASKED_SERVER_CARD, |
| + "John Dillinger", "9012", "01", "2010", kVisaCard, true}, |
| + IsLocalDuplicateOfServerCardTestCase{ |
| + LOCAL_CARD, "", "423456789012", "", "", MASKED_SERVER_CARD, |
| + "John Dillinger", "9012", "01", "2010", kMasterCard, false}, |
| + IsLocalDuplicateOfServerCardTestCase{ |
| + LOCAL_CARD, "John Dillinger", "4234-5678-9012", "01", "2010", |
| + FULL_SERVER_CARD, "John Dillinger", "423456789012", "01", "2010", |
| + nullptr, true})); |
| + |
| TEST(CreditCardTest, HasSameNumberAs) { |
| CreditCard a(base::GenerateGUID(), std::string()); |
| CreditCard b(base::GenerateGUID(), std::string()); |
| @@ -603,178 +628,223 @@ TEST(CreditCardTest, CreditCardVerificationCode) { |
| EXPECT_EQ(base::string16(), card.GetRawInfo(CREDIT_CARD_VERIFICATION_CODE)); |
| } |
| +struct GetCreditCardTypeTestCase { |
| + std::string card_number; |
| + std::string type; |
| + bool is_valid; |
| +}; |
| -TEST(CreditCardTest, GetCreditCardType) { |
| - struct { |
| - std::string card_number; |
| - std::string type; |
| - bool is_valid; |
| - } test_cases[] = { |
| - // The relevant sample numbers from |
| - // http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm |
| - { "378282246310005", kAmericanExpressCard, true }, |
| - { "371449635398431", kAmericanExpressCard, true }, |
| - { "378734493671000", kAmericanExpressCard, true }, |
| - { "30569309025904", kDinersCard, true }, |
| - { "38520000023237", kDinersCard, true }, |
| - { "6011111111111117", kDiscoverCard, true }, |
| - { "6011000990139424", kDiscoverCard, true }, |
| - { "3530111333300000", kJCBCard, true }, |
| - { "3566002020360505", kJCBCard, true }, |
| - { "5555555555554444", kMasterCard, true }, |
| - { "5105105105105100", kMasterCard, true }, |
| - { "4111111111111111", kVisaCard, true }, |
| - { "4012888888881881", kVisaCard, true }, |
| - { "4222222222222", kVisaCard, true }, |
| - |
| - // The relevant sample numbers from |
| - // https://www.auricsystems.com/sample-credit-card-numbers/ |
| - { "343434343434343", kAmericanExpressCard, true }, |
| - { "371144371144376", kAmericanExpressCard, true }, |
| - { "341134113411347", kAmericanExpressCard, true }, |
| - { "36438936438936", kDinersCard, true }, |
| - { "36110361103612", kDinersCard, true }, |
| - { "36111111111111", kDinersCard, true }, |
| - { "6011016011016011", kDiscoverCard, true }, |
| - { "6011000990139424", kDiscoverCard, true }, |
| - { "6011000000000004", kDiscoverCard, true }, |
| - { "6011000995500000", kDiscoverCard, true }, |
| - { "6500000000000002", kDiscoverCard, true }, |
| - { "3566002020360505", kJCBCard, true }, |
| - { "3528000000000007", kJCBCard, true }, |
| - { "5500005555555559", kMasterCard, true }, |
| - { "5555555555555557", kMasterCard, true }, |
| - { "5454545454545454", kMasterCard, true }, |
| - { "5555515555555551", kMasterCard, true }, |
| - { "5405222222222226", kMasterCard, true }, |
| - { "5478050000000007", kMasterCard, true }, |
| - { "5111005111051128", kMasterCard, true }, |
| - { "5112345112345114", kMasterCard, true }, |
| - { "5115915115915118", kMasterCard, true }, |
| - { "6247130048162403", kUnionPay, true }, |
| - { "6247130048162403", kUnionPay, true }, |
| - { "622384452162063648", kUnionPay, true }, |
| - { "2204883716636153", kMirCard, true }, |
| - { "2200111234567898", kMirCard, true }, |
| - { "2200481349288130", kMirCard, true }, |
| - |
| - // Empty string |
| - { std::string(), kGenericCard, false }, |
| - |
| - // Non-numeric |
| - { "garbage", kGenericCard, false }, |
| - { "4garbage", kVisaCard, false }, |
| - |
| - // Fails Luhn check. |
| - { "4111111111111112", kVisaCard, false }, |
| - { "6247130048162413", kUnionPay, false }, |
| - { "2204883716636154", kMirCard, false }, |
| - |
| - // Invalid length. |
| - { "3434343434343434", kAmericanExpressCard, false }, |
| - { "411111111111116", kVisaCard, false }, |
| - { "220011123456783", kMirCard, false }, |
| - |
| - // Issuer Identification Numbers (IINs) that Chrome recognizes. |
| - { "4", kVisaCard, false }, |
| - { "22", kMirCard, false }, |
| - { "34", kAmericanExpressCard, false }, |
| - { "37", kAmericanExpressCard, false }, |
| - { "300", kDinersCard, false }, |
| - { "301", kDinersCard, false }, |
| - { "302", kDinersCard, false }, |
| - { "303", kDinersCard, false }, |
| - { "304", kDinersCard, false }, |
| - { "305", kDinersCard, false }, |
| - { "3095", kDinersCard, false }, |
| - { "36", kDinersCard, false }, |
| - { "38", kDinersCard, false }, |
| - { "39", kDinersCard, false }, |
| - { "6011", kDiscoverCard, false }, |
| - { "644", kDiscoverCard, false }, |
| - { "645", kDiscoverCard, false }, |
| - { "646", kDiscoverCard, false }, |
| - { "647", kDiscoverCard, false }, |
| - { "648", kDiscoverCard, false }, |
| - { "649", kDiscoverCard, false }, |
| - { "65", kDiscoverCard, false }, |
| - { "3528", kJCBCard, false }, |
| - { "3531", kJCBCard, false }, |
| - { "3589", kJCBCard, false }, |
| - { "51", kMasterCard, false }, |
| - { "52", kMasterCard, false }, |
| - { "53", kMasterCard, false }, |
| - { "54", kMasterCard, false }, |
| - { "55", kMasterCard, false }, |
| - { "62", kUnionPay, false }, |
| - |
| - // Not enough data to determine an IIN uniquely. |
| - { "2", kGenericCard, false }, |
| - { "3", kGenericCard, false }, |
| - { "30", kGenericCard, false }, |
| - { "309", kGenericCard, false }, |
| - { "35", kGenericCard, false }, |
| - { "5", kGenericCard, false }, |
| - { "6", kGenericCard, false }, |
| - { "60", kGenericCard, false }, |
| - { "601", kGenericCard, false }, |
| - { "64", kGenericCard, false }, |
| - |
| - // Unknown IINs. |
| - { "0", kGenericCard, false }, |
| - { "1", kGenericCard, false }, |
| - { "306", kGenericCard, false }, |
| - { "307", kGenericCard, false }, |
| - { "308", kGenericCard, false }, |
| - { "3091", kGenericCard, false }, |
| - { "3094", kGenericCard, false }, |
| - { "3096", kGenericCard, false }, |
| - { "31", kGenericCard, false }, |
| - { "32", kGenericCard, false }, |
| - { "33", kGenericCard, false }, |
| - { "351", kGenericCard, false }, |
| - { "3527", kGenericCard, false }, |
| - { "359", kGenericCard, false }, |
| - { "50", kGenericCard, false }, |
| - { "56", kGenericCard, false }, |
| - { "57", kGenericCard, false }, |
| - { "58", kGenericCard, false }, |
| - { "59", kGenericCard, false }, |
| - { "600", kGenericCard, false }, |
| - { "602", kGenericCard, false }, |
| - { "603", kGenericCard, false }, |
| - { "604", kGenericCard, false }, |
| - { "605", kGenericCard, false }, |
| - { "606", kGenericCard, false }, |
| - { "607", kGenericCard, false }, |
| - { "608", kGenericCard, false }, |
| - { "609", kGenericCard, false }, |
| - { "61", kGenericCard, false }, |
| - { "63", kGenericCard, false }, |
| - { "640", kGenericCard, false }, |
| - { "641", kGenericCard, false }, |
| - { "642", kGenericCard, false }, |
| - { "643", kGenericCard, false }, |
| - { "66", kGenericCard, false }, |
| - { "67", kGenericCard, false }, |
| - { "68", kGenericCard, false }, |
| - { "69", kGenericCard, false }, |
| - { "7", kGenericCard, false }, |
| - { "8", kGenericCard, false }, |
| - { "9", kGenericCard, false }, |
| - |
| - // Oddball case: Unknown issuer, but valid Luhn check and plausible length. |
| - { "7000700070007000", kGenericCard, true }, |
| - }; |
| +// We are doing batches here because INSTANTIATE_TEST_CASE_P has a |
| +// 50 upper limit. |
| +class GetCreditCardTypeTestBatch1 |
| + : public testing::TestWithParam<GetCreditCardTypeTestCase> {}; |
| + |
| +TEST_P(GetCreditCardTypeTestBatch1, GetCreditCardType) { |
| + auto test_case = GetParam(); |
| + base::string16 card_number = ASCIIToUTF16(test_case.card_number); |
| + SCOPED_TRACE(card_number); |
| + EXPECT_EQ(test_case.type, CreditCard::GetCreditCardType(card_number)); |
| + EXPECT_EQ(test_case.is_valid, IsValidCreditCardNumber(card_number)); |
| +} |
| - for (const auto& test_case : test_cases) { |
| - base::string16 card_number = ASCIIToUTF16(test_case.card_number); |
| - SCOPED_TRACE(card_number); |
| - EXPECT_EQ(test_case.type, CreditCard::GetCreditCardType(card_number)); |
| - EXPECT_EQ(test_case.is_valid, IsValidCreditCardNumber(card_number)); |
| - } |
| +INSTANTIATE_TEST_CASE_P( |
| + CreditCardTest, |
| + GetCreditCardTypeTestBatch1, |
| + testing::Values( |
| + // The relevant sample numbers from |
| + // http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm |
| + GetCreditCardTypeTestCase{"378282246310005", kAmericanExpressCard, |
| + true}, |
| + GetCreditCardTypeTestCase{"371449635398431", kAmericanExpressCard, |
| + true}, |
| + GetCreditCardTypeTestCase{"378734493671000", kAmericanExpressCard, |
| + true}, |
| + GetCreditCardTypeTestCase{"30569309025904", kDinersCard, true}, |
| + GetCreditCardTypeTestCase{"38520000023237", kDinersCard, true}, |
| + GetCreditCardTypeTestCase{"6011111111111117", kDiscoverCard, true}, |
| + GetCreditCardTypeTestCase{"6011000990139424", kDiscoverCard, true}, |
| + GetCreditCardTypeTestCase{"3530111333300000", kJCBCard, true}, |
| + GetCreditCardTypeTestCase{"3566002020360505", kJCBCard, true}, |
| + GetCreditCardTypeTestCase{"5555555555554444", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5105105105105100", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"4111111111111111", kVisaCard, true}, |
| + GetCreditCardTypeTestCase{"4012888888881881", kVisaCard, true}, |
| + GetCreditCardTypeTestCase{"4222222222222", kVisaCard, true}, |
| + |
| + // The relevant sample numbers from |
| + // https://www.auricsystems.com/sample-credit-card-numbers/ |
| + GetCreditCardTypeTestCase{"343434343434343", kAmericanExpressCard, |
| + true}, |
| + GetCreditCardTypeTestCase{"371144371144376", kAmericanExpressCard, |
| + true}, |
| + GetCreditCardTypeTestCase{"341134113411347", kAmericanExpressCard, |
| + true}, |
| + GetCreditCardTypeTestCase{"36438936438936", kDinersCard, true}, |
| + GetCreditCardTypeTestCase{"36110361103612", kDinersCard, true}, |
| + GetCreditCardTypeTestCase{"36111111111111", kDinersCard, true}, |
| + GetCreditCardTypeTestCase{"6011016011016011", kDiscoverCard, true}, |
| + GetCreditCardTypeTestCase{"6011000990139424", kDiscoverCard, true}, |
| + GetCreditCardTypeTestCase{"6011000000000004", kDiscoverCard, true}, |
| + GetCreditCardTypeTestCase{"6011000995500000", kDiscoverCard, true}, |
| + GetCreditCardTypeTestCase{"6500000000000002", kDiscoverCard, true}, |
| + GetCreditCardTypeTestCase{"3566002020360505", kJCBCard, true}, |
| + GetCreditCardTypeTestCase{"3528000000000007", kJCBCard, true}, |
| + GetCreditCardTypeTestCase{"5500005555555559", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5555555555555557", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5454545454545454", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5555515555555551", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5405222222222226", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5478050000000007", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5111005111051128", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5112345112345114", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"5115915115915118", kMasterCard, true}, |
| + GetCreditCardTypeTestCase{"6247130048162403", kUnionPay, true}, |
| + GetCreditCardTypeTestCase{"6247130048162403", kUnionPay, true}, |
| + GetCreditCardTypeTestCase{"622384452162063648", kUnionPay, true}, |
| + GetCreditCardTypeTestCase{"2204883716636153", kMirCard, true}, |
| + GetCreditCardTypeTestCase{"2200111234567898", kMirCard, true}, |
| + GetCreditCardTypeTestCase{"2200481349288130", kMirCard, true}, |
| + |
| + // Empty string |
| + GetCreditCardTypeTestCase{std::string(), kGenericCard, false}, |
| + |
| + // Non-numeric |
| + GetCreditCardTypeTestCase{"garbage", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"4garbage", kVisaCard, false}, |
| + |
| + // Fails Luhn check. |
| + GetCreditCardTypeTestCase{"4111111111111112", kVisaCard, false}, |
| + GetCreditCardTypeTestCase{"6247130048162413", kUnionPay, false}, |
| + GetCreditCardTypeTestCase{"2204883716636154", kMirCard, false})); |
| + |
| +class GetCreditCardTypeTestBatch2 |
| + : public testing::TestWithParam<GetCreditCardTypeTestCase> {}; |
| + |
| +TEST_P(GetCreditCardTypeTestBatch2, GetCreditCardType) { |
| + auto test_case = GetParam(); |
| + base::string16 card_number = ASCIIToUTF16(test_case.card_number); |
| + SCOPED_TRACE(card_number); |
| + EXPECT_EQ(test_case.type, CreditCard::GetCreditCardType(card_number)); |
| + EXPECT_EQ(test_case.is_valid, IsValidCreditCardNumber(card_number)); |
| +} |
| + |
| +INSTANTIATE_TEST_CASE_P( |
| + CreditCardTest, |
| + GetCreditCardTypeTestBatch2, |
| + testing::Values( |
| + // Invalid length. |
| + GetCreditCardTypeTestCase{"3434343434343434", kAmericanExpressCard, |
| + false}, |
| + GetCreditCardTypeTestCase{"411111111111116", kVisaCard, false}, |
| + GetCreditCardTypeTestCase{"220011123456783", kMirCard, false}, |
| + |
| + // Issuer Identification Numbers (IINs) that Chrome recognizes. |
| + GetCreditCardTypeTestCase{"4", kVisaCard, false}, |
| + GetCreditCardTypeTestCase{"22", kMirCard, false}, |
| + GetCreditCardTypeTestCase{"34", kAmericanExpressCard, false}, |
| + GetCreditCardTypeTestCase{"37", kAmericanExpressCard, false}, |
| + GetCreditCardTypeTestCase{"300", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"301", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"302", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"303", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"304", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"305", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"3095", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"36", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"38", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"39", kDinersCard, false}, |
| + GetCreditCardTypeTestCase{"6011", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"644", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"645", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"646", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"647", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"648", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"649", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"65", kDiscoverCard, false}, |
| + GetCreditCardTypeTestCase{"3528", kJCBCard, false}, |
| + GetCreditCardTypeTestCase{"3531", kJCBCard, false}, |
| + GetCreditCardTypeTestCase{"3589", kJCBCard, false}, |
| + GetCreditCardTypeTestCase{"51", kMasterCard, false}, |
| + GetCreditCardTypeTestCase{"52", kMasterCard, false}, |
| + GetCreditCardTypeTestCase{"53", kMasterCard, false}, |
| + GetCreditCardTypeTestCase{"54", kMasterCard, false}, |
| + GetCreditCardTypeTestCase{"55", kMasterCard, false}, |
| + GetCreditCardTypeTestCase{"62", kUnionPay, false}, |
| + |
| + // Not enough data to determine an IIN uniquely. |
| + GetCreditCardTypeTestCase{"2", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"3", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"30", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"309", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"35", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"5", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"6", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"60", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"601", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"64", kGenericCard, false})); |
| + |
| +class GetCreditCardTypeTestBatch3 |
| + : public testing::TestWithParam<GetCreditCardTypeTestCase> {}; |
| + |
| +TEST_P(GetCreditCardTypeTestBatch3, GetCreditCardType) { |
| + auto test_case = GetParam(); |
| + base::string16 card_number = ASCIIToUTF16(test_case.card_number); |
| + SCOPED_TRACE(card_number); |
| + EXPECT_EQ(test_case.type, CreditCard::GetCreditCardType(card_number)); |
| + EXPECT_EQ(test_case.is_valid, IsValidCreditCardNumber(card_number)); |
| } |
| +INSTANTIATE_TEST_CASE_P( |
| + CreditCardTest, |
| + GetCreditCardTypeTestBatch3, |
| + testing::Values( |
| + // Unknown IINs. |
| + GetCreditCardTypeTestCase{"0", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"1", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"306", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"307", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"308", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"3091", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"3094", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"3096", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"31", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"32", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"33", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"351", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"3527", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"359", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"50", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"56", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"57", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"58", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"59", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"600", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"602", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"603", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"604", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"605", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"606", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"607", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"608", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"609", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"61", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"63", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"640", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"641", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"642", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"643", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"66", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"67", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"68", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"69", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"7", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"8", kGenericCard, false}, |
| + GetCreditCardTypeTestCase{"9", kGenericCard, false}, |
| + |
| + // Oddball case: Unknown issuer, but valid Luhn check and plausible |
| + // length. |
| + GetCreditCardTypeTestCase{"7000700070007000", kGenericCard, true})); |
| + |
| TEST(CreditCardTest, LastFourDigits) { |
| CreditCard card(base::GenerateGUID(), "https://www.example.com/"); |
| ASSERT_EQ(base::string16(), card.LastFourDigits()); |
| @@ -791,104 +861,221 @@ TEST(CreditCardTest, LastFourDigits) { |
| } |
| // Verifies that a credit card should be updated. |
| -TEST(CreditCardTest, ShouldUpdateExpiration) { |
| - base::Time now = base::Time::Now(); |
| - |
| - base::Time::Exploded last_year; |
| - (now - base::TimeDelta::FromDays(365)).LocalExplode(&last_year); |
| - |
| - base::Time::Exploded last_month; |
| - (now - base::TimeDelta::FromDays(31)).LocalExplode(&last_month); |
| - |
| - base::Time::Exploded current; |
| - now.LocalExplode(¤t); |
| - |
| - base::Time::Exploded next_month; |
| - (now + base::TimeDelta::FromDays(31)).LocalExplode(&next_month); |
| +struct ShouldUpdateExpirationTestCase { |
| + bool should_update_expiration; |
| + int month; |
| + int year; |
| + CreditCard::RecordType record_type; |
| + CreditCard::ServerStatus server_status; |
| +}; |
| - base::Time::Exploded next_year; |
| - (now + base::TimeDelta::FromDays(365)).LocalExplode(&next_year); |
| +class ShouldUpdateExpirationTest |
| + : public testing::TestWithParam<ShouldUpdateExpirationTestCase> {}; |
| + |
| +class TestingTimes { |
| + public: |
| + TestingTimes() { |
| + now_ = base::Time::Now(); |
| + (now_ - base::TimeDelta::FromDays(365)).LocalExplode(&last_year_); |
| + (now_ - base::TimeDelta::FromDays(31)).LocalExplode(&last_month_); |
| + now_.LocalExplode(¤t_); |
| + (now_ + base::TimeDelta::FromDays(31)).LocalExplode(&next_month_); |
| + (now_ + base::TimeDelta::FromDays(365)).LocalExplode(&next_year_); |
| + } |
| - static const struct { |
| - bool should_update_expiration; |
| - int month; |
| - int year; |
| - CreditCard::RecordType record_type; |
| - CreditCard::ServerStatus server_status; |
| - } kTestCases[] = { |
| + base::Time now_; |
| + base::Time::Exploded last_year_; |
| + base::Time::Exploded last_month_; |
| + base::Time::Exploded current_; |
| + base::Time::Exploded next_month_; |
| + base::Time::Exploded next_year_; |
| +}; |
| - // Cards that expired last year should always be updated. |
| - {true, last_year.month, last_year.year, CreditCard::LOCAL_CARD}, |
| - {true, last_year.month, last_year.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::OK}, |
| - {true, last_year.month, last_year.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::OK}, |
| - {true, last_year.month, last_year.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - {true, last_year.month, last_year.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - |
| - // Cards that expired last month should always be updated. |
| - {true, last_month.month, last_month.year, CreditCard::LOCAL_CARD}, |
| - {true, last_month.month, last_month.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::OK}, |
| - {true, last_month.month, last_month.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::OK}, |
| - {true, last_month.month, last_month.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - {true, last_month.month, last_month.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - |
| - // Cards that expire this month should be updated only if the server |
| - // status is EXPIRED. |
| - {false, current.month, current.year, CreditCard::LOCAL_CARD}, |
| - {false, current.month, current.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::OK}, |
| - {false, current.month, current.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::OK}, |
| - {true, current.month, current.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - {true, current.month, current.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - |
| - // Cards that expire next month should be updated only if the server |
| - // status is EXPIRED. |
| - {false, next_month.month, next_month.year, CreditCard::LOCAL_CARD}, |
| - {false, next_month.month, next_month.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::OK}, |
| - {false, next_month.month, next_month.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::OK}, |
| - {true, next_month.month, next_month.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - {true, next_month.month, next_month.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - |
| - // Cards that expire next year should be updated only if the server status |
| - // is EXPIRED. |
| - {false, next_year.month, next_year.year, CreditCard::LOCAL_CARD}, |
| - {false, next_year.month, next_year.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::OK}, |
| - {false, next_year.month, next_year.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::OK}, |
| - {true, next_year.month, next_year.year, CreditCard::MASKED_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - {true, next_year.month, next_year.year, CreditCard::FULL_SERVER_CARD, |
| - CreditCard::EXPIRED}, |
| - }; |
| +TestingTimes testingTimes; |
| - for (const auto& test_case : kTestCases) { |
| - CreditCard card; |
| - card.SetExpirationMonth(test_case.month); |
| - card.SetExpirationYear(test_case.year); |
| - card.set_record_type(test_case.record_type); |
| - if (card.record_type() != CreditCard::LOCAL_CARD) |
| - card.SetServerStatus(test_case.server_status); |
| - |
| - EXPECT_EQ(test_case.should_update_expiration, |
| - card.ShouldUpdateExpiration(now)); |
| - } |
| +TEST_P(ShouldUpdateExpirationTest, ShouldUpdateExpiration) { |
| + auto test_case = GetParam(); |
| + CreditCard card; |
| + card.SetExpirationMonth(test_case.month); |
| + card.SetExpirationYear(test_case.year); |
| + card.set_record_type(test_case.record_type); |
| + if (card.record_type() != CreditCard::LOCAL_CARD) |
| + card.SetServerStatus(test_case.server_status); |
| + |
| + EXPECT_EQ(test_case.should_update_expiration, |
| + card.ShouldUpdateExpiration(testingTimes.now_)); |
| } |
| +INSTANTIATE_TEST_CASE_P( |
| + CreditCardTest, |
| + ShouldUpdateExpirationTest, |
| + testing::Values( |
| + // Cards that expired last year should always be updated. |
| + ShouldUpdateExpirationTestCase{true, testingTimes.last_year_.month, |
| + testingTimes.last_year_.year, |
| + CreditCard::LOCAL_CARD}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_year_.month, testingTimes.last_year_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_year_.month, testingTimes.last_year_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_year_.month, testingTimes.last_year_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::EXPIRED}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_year_.month, testingTimes.last_year_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::EXPIRED}, |
| + |
| + // Cards that expired last month should always be updated. |
| + ShouldUpdateExpirationTestCase{true, testingTimes.last_month_.month, |
| + testingTimes.last_month_.year, |
| + CreditCard::LOCAL_CARD}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_month_.month, testingTimes.last_month_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_month_.month, testingTimes.last_month_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_month_.month, testingTimes.last_month_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::EXPIRED}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.last_month_.month, testingTimes.last_month_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::EXPIRED}, |
| + |
| + // Cards that expire this month should be updated only if the server |
| + // status is EXPIRED. |
| + ShouldUpdateExpirationTestCase{false, testingTimes.current_.month, |
| + testingTimes.current_.year, |
| + CreditCard::LOCAL_CARD}, |
| + ShouldUpdateExpirationTestCase{ |
| + false, testingTimes.current_.month, testingTimes.current_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + false, testingTimes.current_.month, testingTimes.current_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.current_.month, testingTimes.current_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::EXPIRED}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.current_.month, testingTimes.current_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::EXPIRED}, |
| + |
| + // Cards that expire next month should be updated only if the server |
| + // status is EXPIRED. |
| + ShouldUpdateExpirationTestCase{false, testingTimes.next_month_.month, |
| + testingTimes.next_month_.year, |
| + CreditCard::LOCAL_CARD}, |
| + ShouldUpdateExpirationTestCase{false, testingTimes.next_month_.month, |
| + testingTimes.next_month_.year, |
| + CreditCard::MASKED_SERVER_CARD, |
| + CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{false, testingTimes.next_month_.month, |
| + testingTimes.next_month_.year, |
| + CreditCard::FULL_SERVER_CARD, |
| + CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.next_month_.month, testingTimes.next_month_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::EXPIRED}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.next_month_.month, testingTimes.next_month_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::EXPIRED}, |
| + |
| + // Cards that expire next year should be updated only if the server |
| + // status is EXPIRED. |
| + ShouldUpdateExpirationTestCase{false, testingTimes.next_year_.month, |
| + testingTimes.next_year_.year, |
| + CreditCard::LOCAL_CARD}, |
| + ShouldUpdateExpirationTestCase{ |
| + false, testingTimes.next_year_.month, testingTimes.next_year_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + false, testingTimes.next_year_.month, testingTimes.next_year_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::OK}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.next_year_.month, testingTimes.next_year_.year, |
| + CreditCard::MASKED_SERVER_CARD, CreditCard::EXPIRED}, |
| + ShouldUpdateExpirationTestCase{ |
| + true, testingTimes.next_year_.month, testingTimes.next_year_.year, |
| + CreditCard::FULL_SERVER_CARD, CreditCard::EXPIRED})); |
| + |
| +// TODO(wuandy): rewriting this test with INSTANTIATE_TEST_CASE_P seems to |
|
sebsg
2017/03/14 19:15:24
Would you mind removing this from the file? Like s
wuandy
2017/03/14 19:27:44
Done.
|
| +// trigger a complaint on windows compilers. Comment it out and revert to |
| +// original test for now. |
| +// struct GetLastUsedDateForDisplayTestCase { |
| +// const char* show_expiration_date; |
| +// const std::string& app_locale; |
| +// base::string16 added_to_autofill_date; |
| +// base::string16 last_used_date; |
| +// base::string16 last_used_year_ago; |
| +//}; |
| +// |
| +// class GetLastUsedDateForDisplayTest |
| +// : public testing::TestWithParam<GetLastUsedDateForDisplayTestCase> {}; |
| +// |
| +// TEST_P(GetLastUsedDateForDisplayTest, GetLastUsedDateForDisplay) { |
| +// const base::Time::Exploded kTestDateTimeExploded = { |
| +// 2016, 12, 6, 10, // Sat, Dec 10, 2016 |
| +// 15, 42, 7, 0 // 15:42:07.000 |
| +// }; |
| +// base::Time kArbitraryTime; |
| +// EXPECT_TRUE( |
| +// base::Time::FromLocalExploded(kTestDateTimeExploded, &kArbitraryTime)); |
| +// |
| +// // Test for added to chrome/chromium. |
| +// CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); |
| +// credit_card0.set_use_count(1); |
| +// credit_card0.set_use_date(kArbitraryTime - base::TimeDelta::FromDays(1)); |
| +// test::SetCreditCardInfo(&credit_card0, "John Dillinger", |
| +// "423456789012" /* Visa */, "01", "2021"); |
| +// |
| +// // Test for last used date. |
| +// CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); |
| +// test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", |
| +// "347666888555" /* American Express */, "04", |
| +// "2021"); |
| +// credit_card1.set_use_count(10); |
| +// credit_card1.set_use_date(kArbitraryTime - base::TimeDelta::FromDays(10)); |
| +// |
| +// // Test for last used more than one year ago. |
| +// CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); |
| +// credit_card2.set_use_count(5); |
| +// credit_card2.set_use_date(kArbitraryTime - base::TimeDelta::FromDays(366)); |
| +// test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", |
| +// "518765432109" /* Mastercard */, "12", "2021"); |
| +// |
| +// variations::testing::VariationParamsManager variation_params_; |
| +// auto test_case = GetParam(); |
| +// variation_params_.SetVariationParamsWithFeatureAssociations( |
| +// kAutofillCreditCardLastUsedDateDisplay.name, |
| +// {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, |
| +// test_case.show_expiration_date}}, |
| +// {kAutofillCreditCardLastUsedDateDisplay.name}); |
| +// |
| +// EXPECT_EQ(test_case.added_to_autofill_date, |
| +// credit_card0.GetLastUsedDateForDisplay(test_case.app_locale)); |
| +// EXPECT_EQ(test_case.last_used_date, |
| +// credit_card1.GetLastUsedDateForDisplay(test_case.app_locale)); |
| +// EXPECT_EQ(test_case.last_used_year_ago, |
| +// credit_card2.GetLastUsedDateForDisplay(test_case.app_locale)); |
| +// variation_params_.ClearAllVariationParams(); |
| +//} |
| +// |
| +// INSTANTIATE_TEST_CASE_P(CreditCardTest, |
| +// GetLastUsedDateForDisplayTest, |
| +// testing::Values( |
| +// // only show last used date. |
| +// GetLastUsedDateForDisplayTestCase{ |
| +// "false", "en_US", ASCIIToUTF16("Added Dec |
| +// 09"), ASCIIToUTF16("Last used Nov 30"), |
| +// ASCIIToUTF16("Last used over a year ago")}, |
| +// // show expiration date and last used date. |
| +// GetLastUsedDateForDisplayTestCase{ |
| +// "true", "en_US", ASCIIToUTF16("Exp: 01/21, added Dec 09"), |
| +// ASCIIToUTF16("Exp: 04/21, last used Nov 30"), |
| +// ASCIIToUTF16("Exp: 12/21, last used over a year ago")}));*/ |
| + |
| // Test that credit card last used date suggestion can be generated correctly |
| // in different variations. |
| TEST(CreditCardTest, GetLastUsedDateForDisplay) { |