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

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

Issue 1926553002: Prompt for expiration date for local cards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify the test cases 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 aaee3655bd2c07ab269a209a29e6772e1d3f6442..24be282920a38147bf58b546a542938d087f5768 100644
--- a/components/autofill/core/browser/credit_card_unittest.cc
+++ b/components/autofill/core/browser/credit_card_unittest.cc
@@ -8,6 +8,7 @@
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/autofill_type.h"
@@ -732,4 +733,102 @@ TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) {
EXPECT_EQ(year, card.expiration_year());
}
+// 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(&current);
+
+ base::Time::Exploded next_month;
+ (now + base::TimeDelta::FromDays(31)).LocalExplode(&next_month);
+
+ base::Time::Exploded next_year;
+ (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[] = {
+
+ // 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},
+ };
+
+ for (size_t i = 0; i < arraysize(kTestCases); ++i) {
+ CreditCard card(base::ASCIIToUTF16("1234"), kTestCases[i].month,
+ kTestCases[i].year);
+ card.set_record_type(kTestCases[i].record_type);
+ if (card.record_type() != CreditCard::LOCAL_CARD)
+ card.SetServerStatus(kTestCases[i].server_status);
+
+ EXPECT_EQ(kTestCases[i].should_update_expiration,
+ card.ShouldUpdateExpiration(now));
+ }
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/credit_card.cc ('k') | components/autofill/core/browser/payments/full_card_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698