Commit 9af0021f authored by sebsg's avatar sebsg Committed by Commit bot

Update the expiration date of an expired credit card if the card number is the...

Update the expiration date of an expired credit card if the card number is the same and the name on the cards are an exact match.

BUG=606821
TEST=CreditCardTest

Review URL: https://codereview.chromium.org/1921003003

Cr-Commit-Position: refs/heads/master@{#389905}
parent 9aa61239
...@@ -534,12 +534,22 @@ bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card, ...@@ -534,12 +534,22 @@ bool CreditCard::UpdateFromImportedCard(const CreditCard& imported_card,
return false; return false;
} }
// Heuristically aggregated data should never overwrite verified data. // Heuristically aggregated data should never overwrite verified data, with
// Instead, discard any heuristically aggregated credit cards that disagree // the exception of expired verified cards. Instead, discard any heuristically
// with explicitly entered data, so that the UI is not cluttered with // aggregated credit cards that disagree with explicitly entered data, so that
// duplicate cards. // the UI is not cluttered with duplicate cards.
if (this->IsVerified() && !imported_card.IsVerified()) if (this->IsVerified() && !imported_card.IsVerified()) {
// If the original card is expired and the imported card is not, and the
// name on the cards are identical, update the expiration date.
if (this->IsExpired(base::Time::Now()) &&
!imported_card.IsExpired(base::Time::Now()) &&
(name_on_card_ == imported_card.name_on_card_)) {
DCHECK(imported_card.expiration_month_ && imported_card.expiration_year_);
expiration_month_ = imported_card.expiration_month_;
expiration_year_ = imported_card.expiration_year_;
}
return true; return true;
}
set_origin(imported_card.origin()); set_origin(imported_card.origin());
......
...@@ -340,6 +340,7 @@ TEST(CreditCardTest, UpdateFromImportedCard) { ...@@ -340,6 +340,7 @@ TEST(CreditCardTest, UpdateFromImportedCard) {
b.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("08")); b.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("08"));
b.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2019")); b.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2019"));
// |a| should be updated with the information from |b|.
EXPECT_TRUE(a.UpdateFromImportedCard(b, "en-US")); EXPECT_TRUE(a.UpdateFromImportedCard(b, "en-US"));
EXPECT_EQ("https://www.example.org", a.origin()); EXPECT_EQ("https://www.example.org", a.origin());
EXPECT_EQ(ASCIIToUTF16("J. Dillinger"), a.GetRawInfo(CREDIT_CARD_NAME_FULL)); EXPECT_EQ(ASCIIToUTF16("J. Dillinger"), a.GetRawInfo(CREDIT_CARD_NAME_FULL));
...@@ -347,6 +348,8 @@ TEST(CreditCardTest, UpdateFromImportedCard) { ...@@ -347,6 +348,8 @@ TEST(CreditCardTest, UpdateFromImportedCard) {
EXPECT_EQ(ASCIIToUTF16("2019"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); EXPECT_EQ(ASCIIToUTF16("2019"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
// Try again, but with no name set for |b|. // Try again, but with no name set for |b|.
// |a| should be updated with |b|'s expiration date and keep its original
// name.
a = original_card; a = original_card;
b.SetRawInfo(CREDIT_CARD_NAME_FULL, base::string16()); b.SetRawInfo(CREDIT_CARD_NAME_FULL, base::string16());
...@@ -370,7 +373,51 @@ TEST(CreditCardTest, UpdateFromImportedCard) { ...@@ -370,7 +373,51 @@ TEST(CreditCardTest, UpdateFromImportedCard) {
EXPECT_EQ(ASCIIToUTF16("09"), a.GetRawInfo(CREDIT_CARD_EXP_MONTH)); EXPECT_EQ(ASCIIToUTF16("09"), a.GetRawInfo(CREDIT_CARD_EXP_MONTH));
EXPECT_EQ(ASCIIToUTF16("2017"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); EXPECT_EQ(ASCIIToUTF16("2017"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
// Try again, but with using an expired verified original card.
// |a| should not be updated because the name on the cards are not identical.
a = original_card;
a.set_origin("Chrome settings");
a.SetExpirationYear(2010);
EXPECT_TRUE(a.UpdateFromImportedCard(b, "en-US"));
EXPECT_EQ("Chrome settings", a.origin());
EXPECT_EQ(ASCIIToUTF16("John Dillinger"),
a.GetRawInfo(CREDIT_CARD_NAME_FULL));
EXPECT_EQ(ASCIIToUTF16("09"), a.GetRawInfo(CREDIT_CARD_EXP_MONTH));
EXPECT_EQ(ASCIIToUTF16("2010"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
// Try again, but with using identical name on the cards.
// |a|'s expiration date should be updated.
a = original_card;
a.set_origin("Chrome settings");
a.SetExpirationYear(2010);
a.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("J. Dillinger"));
EXPECT_TRUE(a.UpdateFromImportedCard(b, "en-US"));
EXPECT_EQ("Chrome settings", a.origin());
EXPECT_EQ(ASCIIToUTF16("J. Dillinger"), a.GetRawInfo(CREDIT_CARD_NAME_FULL));
EXPECT_EQ(ASCIIToUTF16("08"), a.GetRawInfo(CREDIT_CARD_EXP_MONTH));
EXPECT_EQ(ASCIIToUTF16("2019"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
// Try again, but with |b| being expired.
// |a|'s expiration date should not be updated.
a = original_card;
a.set_origin("Chrome settings");
a.SetExpirationYear(2010);
a.SetRawInfo(CREDIT_CARD_NAME_FULL, ASCIIToUTF16("J. Dillinger"));
b.SetExpirationYear(2009);
EXPECT_TRUE(a.UpdateFromImportedCard(b, "en-US"));
EXPECT_EQ("Chrome settings", a.origin());
EXPECT_EQ(ASCIIToUTF16("J. Dillinger"), a.GetRawInfo(CREDIT_CARD_NAME_FULL));
EXPECT_EQ(ASCIIToUTF16("09"), a.GetRawInfo(CREDIT_CARD_EXP_MONTH));
EXPECT_EQ(ASCIIToUTF16("2010"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
// Put back |b|'s initial expiration date.
b.SetExpirationYear(2019);
// Try again, but with only the new card having a verified origin. // Try again, but with only the new card having a verified origin.
// |a| should be updated.
a = original_card; a = original_card;
b.set_origin("Chrome settings"); b.set_origin("Chrome settings");
...@@ -381,6 +428,7 @@ TEST(CreditCardTest, UpdateFromImportedCard) { ...@@ -381,6 +428,7 @@ TEST(CreditCardTest, UpdateFromImportedCard) {
EXPECT_EQ(ASCIIToUTF16("2019"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); EXPECT_EQ(ASCIIToUTF16("2019"), a.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
// Try again, with both cards having a verified origin. // Try again, with both cards having a verified origin.
// |a| should be updated.
a = original_card; a = original_card;
a.set_origin("Chrome Autofill dialog"); a.set_origin("Chrome Autofill dialog");
b.set_origin("Chrome settings"); b.set_origin("Chrome settings");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment