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 aaee3655bd2c07ab269a209a29e6772e1d3f6442..0eeb089ee60c484806b4c3f66afab8cd4d680f66 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,181 @@ TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) { |
| EXPECT_EQ(year, card.expiration_year()); |
| } |
| +// A card that has expired last year should be updated. |
|
sebsg
2016/04/27 14:59:02
These tests seem to have a lot in common. Do you t
please use gerrit instead
2016/04/27 18:05:44
Done. Sorry for the wall of tests. I attempted to
|
| +TEST(CreditCardTest, CardExpiringLastYear) { |
| + base::Time::Exploded today; |
| + base::Time::Now().LocalExplode(&today); |
| + |
| + // Local expired card. |
| + CreditCard card(base::ASCIIToUTF16("1234"), 12, today.year - 1); |
| + EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked expired server card with OK server status. |
| + card.set_record_type(CreditCard::MASKED_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked expired server card with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Full expired server card with OK server status. |
| + card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Full expired server card with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| +} |
| + |
| +// A card that has expired last month should be updated. |
| +TEST(CreditCardTest, CardExpiringLastMonth) { |
| + base::Time::Exploded last_month; |
| + (base::Time::Now() - base::TimeDelta::FromDays(31)).LocalExplode(&last_month); |
| + |
| + // Local expired card. |
| + CreditCard card(base::ASCIIToUTF16("1234"), last_month.month, |
| + last_month.year); |
| + EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked expired server card with OK server status. |
| + card.set_record_type(CreditCard::MASKED_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked expired server card with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Full expired server card with OK server status. |
| + card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Full expired server card with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| +} |
| + |
| +// A card expiring this month should not be updated, unless it has EXPIRED |
| +// server status. |
| +TEST(CreditCardTest, CardExpiringThisMonth) { |
| + base::Time::Exploded this_month; |
| + base::Time::Now().LocalExplode(&this_month); |
| + |
| + // Local card expiring this month. |
| + CreditCard card(base::ASCIIToUTF16("1234"), this_month.month, |
| + this_month.year); |
| + EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked server card expiring this month with OK server status. |
| + card.set_record_type(CreditCard::MASKED_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked server card expiring this month with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Full server card expiring this month with OK server status. |
| + card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Full server card expiring this month with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| +} |
| + |
| +// A card expiring next month should not be updated, unless it has EXPIRED |
| +// server status. |
| +TEST(CreditCardTest, CardExpiringNextMonth) { |
| + base::Time::Exploded next_month; |
| + (base::Time::Now() + base::TimeDelta::FromDays(31)).LocalExplode(&next_month); |
| + |
| + // Local card expiring next month. |
| + CreditCard card(base::ASCIIToUTF16("1234"), next_month.month, |
| + next_month.year); |
| + EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked server card expiring next month with OK server status. |
| + card.set_record_type(CreditCard::MASKED_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked server card expiring next month with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Full server card expiring next month with OK server status. |
| + card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Full server card expiring next month with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| +} |
| + |
| +// A card expiring next year should not be updated, unless it has EXPIRED server |
| +// status. |
| +TEST(CreditCardTest, CardExpiringNextYear) { |
| + base::Time::Exploded today; |
| + base::Time::Now().LocalExplode(&today); |
| + |
| + // Local card expiring next year. |
| + CreditCard card(base::ASCIIToUTF16("1234"), 1, today.year + 1); |
| + EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked server card expiring next year with OK server status. |
| + card.set_record_type(CreditCard::MASKED_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Masked server card expiring next year with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| + |
| + // Full server card expiring next year with OK server status. |
| + card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| + card.SetServerStatus(CreditCard::OK); |
| + |
| + EXPECT_FALSE(card.ShouldUpdateExpiration()); |
| + |
| + // Full server card expiring next year with EXPIRED server status. |
| + card.SetServerStatus(CreditCard::EXPIRED); |
| + |
| + EXPECT_TRUE(card.ShouldUpdateExpiration()); |
| +} |
| + |
| + |
| } // namespace autofill |