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

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

Issue 1867523003: [Autofill] Suggest expired credit cards last. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactored CC suggestions to use IsExpired Created 4 years, 8 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 f24726e2916fafd84ae072a9b3efc98aec7df807..ac29c97aa017e7a827cad509bcf4a5e81af0e3e2 100644
--- a/components/autofill/core/browser/credit_card_unittest.cc
+++ b/components/autofill/core/browser/credit_card_unittest.cc
@@ -709,4 +709,43 @@ TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) {
EXPECT_EQ(year, card.expiration_year());
}
+TEST(CreditCardTest, IsExpired) {
+ typedef struct {
+ int current_month;
+ int current_year;
+ int card_expiration_month;
+ int card_expiration_year;
+ bool is_expired;
+ } TestCase;
+
+ TestCase test_cases[] = {// Card expired by a month.
+ {3, 2016, 2, 2016, true},
+ // Card expired by a year.
+ {3, 2016, 3, 2015, true},
+ // Card expired by both month and year.
+ {3, 2016, 4, 2015, true},
+ // Card not expired.
+ {3, 2016, 4, 2016, false},
+ // Card expired at the end of the month.
+ {3, 2016, 3, 2016, false},
+ // Card expired - end of year edge case.
+ {1, 2017, 12, 2016, true},
+ // Card not expired - end of year edge case.
+ {12, 2016, 12, 2016, false},
+ // Card not expired if it has no expiration.
+ {12, 2016, 0, 0, false}};
+
+ for (TestCase test_case : test_cases) {
+ CreditCard card(base::ASCIIToUTF16("1234123412341234"),
+ test_case.card_expiration_month,
+ test_case.card_expiration_year);
+
+ base::Time::Exploded exploded;
+ exploded.month = test_case.current_month;
+ exploded.year = test_case.current_year;
+
+ EXPECT_EQ(test_case.is_expired, card.IsExpired(exploded));
+ }
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698