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

Unified Diff: components/autofill/core/browser/credit_card_unittest.cc

Issue 2136453003: [Autofill] Improve support for various credit card expiration dates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final nits Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
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 2f282578a1514932b6c4e6a568542192d98d774b..52a23ba8605d70e17b63cc15c7563f732af691fe 100644
--- a/components/autofill/core/browser/credit_card_unittest.cc
+++ b/components/autofill/core/browser/credit_card_unittest.cc
@@ -167,6 +167,79 @@ 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},
+ };
+
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) {
+ CreditCard card(base::GenerateGUID(), "some origin");
+ card.SetExpirationYearFromString(
+ ASCIIToUTF16(kTestCases[i].expiration_year));
+
+ EXPECT_EQ(kTestCases[i].expected_year, card.expiration_year())
+ << kTestCases[i].expiration_year << " " << kTestCases[i].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}};
+
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) {
+ CreditCard card(base::GenerateGUID(), "some origin");
+ card.SetExpirationDateFromString(
+ ASCIIToUTF16(kTestCases[i].expiration_date));
+
+ EXPECT_EQ(kTestCases[i].expected_month, card.expiration_month());
+ EXPECT_EQ(kTestCases[i].expected_year, card.expiration_year());
+ }
+}
+
TEST(CreditCardTest, Copy) {
CreditCard a(base::GenerateGUID(), "https://www.example.com");
test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010");
@@ -465,7 +538,7 @@ TEST(CreditCardTest, IsValid) {
// Invalid because card number is not complete
card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("12"));
- card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("9999"));
+ card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2999"));
card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("41111"));
EXPECT_FALSE(card.IsValid());
@@ -727,7 +800,7 @@ TEST(CreditCardTest, LastFourDigits) {
TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) {
base::string16 card_number = base::ASCIIToUTF16("test");
int month = 1;
- int year = 3000;
+ int year = 2999;
CreditCard card(card_number, month, year);
EXPECT_EQ(card_number, card.number());
EXPECT_EQ(month, card.expiration_month());
« no previous file with comments | « components/autofill/core/browser/credit_card.cc ('k') | components/autofill/core/browser/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698