| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "components/autofill/core/browser/autofill_clock.h" |
| 13 #include "components/autofill/core/browser/autofill_test_utils.h" | 14 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 14 #include "components/autofill/core/browser/autofill_type.h" | 15 #include "components/autofill/core/browser/autofill_type.h" |
| 15 #include "components/autofill/core/browser/credit_card.h" | 16 #include "components/autofill/core/browser/credit_card.h" |
| 16 #include "components/autofill/core/browser/validation.h" | 17 #include "components/autofill/core/browser/validation.h" |
| 17 #include "components/autofill/core/common/autofill_constants.h" | 18 #include "components/autofill/core/common/autofill_constants.h" |
| 18 #include "components/autofill/core/common/form_field_data.h" | 19 #include "components/autofill/core/common/form_field_data.h" |
| 19 #include "grit/components_scaled_resources.h" | 20 #include "grit/components_scaled_resources.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 a = original_card; | 504 a = original_card; |
| 504 b.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); | 505 b.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); |
| 505 | 506 |
| 506 EXPECT_FALSE(a.UpdateFromImportedCard(b, "en-US")); | 507 EXPECT_FALSE(a.UpdateFromImportedCard(b, "en-US")); |
| 507 EXPECT_EQ(original_card, a); | 508 EXPECT_EQ(original_card, a); |
| 508 } | 509 } |
| 509 | 510 |
| 510 TEST(CreditCardTest, IsValid) { | 511 TEST(CreditCardTest, IsValid) { |
| 511 CreditCard card; | 512 CreditCard card; |
| 512 // Invalid because expired | 513 // Invalid because expired |
| 513 const base::Time now(base::Time::Now()); | 514 const base::Time now(AutofillClock::Now()); |
| 514 base::Time::Exploded now_exploded; | 515 base::Time::Exploded now_exploded; |
| 515 now.LocalExplode(&now_exploded); | 516 now.LocalExplode(&now_exploded); |
| 516 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, | 517 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, |
| 517 base::IntToString16(now_exploded.month)); | 518 base::IntToString16(now_exploded.month)); |
| 518 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 519 card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 519 base::IntToString16(now_exploded.year - 1)); | 520 base::IntToString16(now_exploded.year - 1)); |
| 520 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); | 521 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("4111111111111111")); |
| 521 EXPECT_FALSE(card.IsValid()); | 522 EXPECT_FALSE(card.IsValid()); |
| 522 | 523 |
| 523 // Invalid because card number is not complete | 524 // Invalid because card number is not complete |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 | 784 |
| 784 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("3489")); | 785 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("3489")); |
| 785 ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits()); | 786 ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits()); |
| 786 | 787 |
| 787 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("489")); | 788 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("489")); |
| 788 ASSERT_EQ(base::ASCIIToUTF16("489"), card.LastFourDigits()); | 789 ASSERT_EQ(base::ASCIIToUTF16("489"), card.LastFourDigits()); |
| 789 } | 790 } |
| 790 | 791 |
| 791 // Verifies that a credit card should be updated. | 792 // Verifies that a credit card should be updated. |
| 792 TEST(CreditCardTest, ShouldUpdateExpiration) { | 793 TEST(CreditCardTest, ShouldUpdateExpiration) { |
| 793 base::Time now = base::Time::Now(); | 794 base::Time now = AutofillClock::Now(); |
| 794 | 795 |
| 795 base::Time::Exploded last_year; | 796 base::Time::Exploded last_year; |
| 796 (now - base::TimeDelta::FromDays(365)).LocalExplode(&last_year); | 797 (now - base::TimeDelta::FromDays(365)).LocalExplode(&last_year); |
| 797 | 798 |
| 798 base::Time::Exploded last_month; | 799 base::Time::Exploded last_month; |
| 799 (now - base::TimeDelta::FromDays(31)).LocalExplode(&last_month); | 800 (now - base::TimeDelta::FromDays(31)).LocalExplode(&last_month); |
| 800 | 801 |
| 801 base::Time::Exploded current; | 802 base::Time::Exploded current; |
| 802 now.LocalExplode(¤t); | 803 now.LocalExplode(¤t); |
| 803 | 804 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 card.set_record_type(test_case.record_type); | 882 card.set_record_type(test_case.record_type); |
| 882 if (card.record_type() != CreditCard::LOCAL_CARD) | 883 if (card.record_type() != CreditCard::LOCAL_CARD) |
| 883 card.SetServerStatus(test_case.server_status); | 884 card.SetServerStatus(test_case.server_status); |
| 884 | 885 |
| 885 EXPECT_EQ(test_case.should_update_expiration, | 886 EXPECT_EQ(test_case.should_update_expiration, |
| 886 card.ShouldUpdateExpiration(now)); | 887 card.ShouldUpdateExpiration(now)); |
| 887 } | 888 } |
| 888 } | 889 } |
| 889 | 890 |
| 890 } // namespace autofill | 891 } // namespace autofill |
| OLD | NEW |