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" |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits()); | 790 ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits()); |
791 | 791 |
792 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("3489")); | 792 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("3489")); |
793 ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits()); | 793 ASSERT_EQ(base::ASCIIToUTF16("3489"), card.LastFourDigits()); |
794 | 794 |
795 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("489")); | 795 card.SetRawInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("489")); |
796 ASSERT_EQ(base::ASCIIToUTF16("489"), card.LastFourDigits()); | 796 ASSERT_EQ(base::ASCIIToUTF16("489"), card.LastFourDigits()); |
797 } | 797 } |
798 | 798 |
799 TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) { | 799 TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) { |
| 800 base::string16 name_on_card = base::ASCIIToUTF16("Alice"); |
800 base::string16 card_number = base::ASCIIToUTF16("test"); | 801 base::string16 card_number = base::ASCIIToUTF16("test"); |
801 int month = 1; | 802 int month = 1; |
802 int year = 2999; | 803 int year = 2999; |
803 CreditCard card(card_number, month, year); | 804 CreditCard card(name_on_card, card_number, month, year); |
| 805 EXPECT_EQ(name_on_card, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); |
804 EXPECT_EQ(card_number, card.number()); | 806 EXPECT_EQ(card_number, card.number()); |
805 EXPECT_EQ(month, card.expiration_month()); | 807 EXPECT_EQ(month, card.expiration_month()); |
806 EXPECT_EQ(year, card.expiration_year()); | 808 EXPECT_EQ(year, card.expiration_year()); |
807 } | 809 } |
808 | 810 |
809 // Verifies that a credit card should be updated. | 811 // Verifies that a credit card should be updated. |
810 TEST(CreditCardTest, ShouldUpdateExpiration) { | 812 TEST(CreditCardTest, ShouldUpdateExpiration) { |
811 base::Time now = base::Time::Now(); | 813 base::Time now = base::Time::Now(); |
812 | 814 |
813 base::Time::Exploded last_year; | 815 base::Time::Exploded last_year; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 CreditCard::OK}, | 888 CreditCard::OK}, |
887 {false, next_year.month, next_year.year, CreditCard::FULL_SERVER_CARD, | 889 {false, next_year.month, next_year.year, CreditCard::FULL_SERVER_CARD, |
888 CreditCard::OK}, | 890 CreditCard::OK}, |
889 {true, next_year.month, next_year.year, CreditCard::MASKED_SERVER_CARD, | 891 {true, next_year.month, next_year.year, CreditCard::MASKED_SERVER_CARD, |
890 CreditCard::EXPIRED}, | 892 CreditCard::EXPIRED}, |
891 {true, next_year.month, next_year.year, CreditCard::FULL_SERVER_CARD, | 893 {true, next_year.month, next_year.year, CreditCard::FULL_SERVER_CARD, |
892 CreditCard::EXPIRED}, | 894 CreditCard::EXPIRED}, |
893 }; | 895 }; |
894 | 896 |
895 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 897 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
896 CreditCard card(base::ASCIIToUTF16("1234"), kTestCases[i].month, | 898 CreditCard card(base::ASCIIToUTF16("Alice"), base::ASCIIToUTF16("1234"), |
897 kTestCases[i].year); | 899 kTestCases[i].month, kTestCases[i].year); |
898 card.set_record_type(kTestCases[i].record_type); | 900 card.set_record_type(kTestCases[i].record_type); |
899 if (card.record_type() != CreditCard::LOCAL_CARD) | 901 if (card.record_type() != CreditCard::LOCAL_CARD) |
900 card.SetServerStatus(kTestCases[i].server_status); | 902 card.SetServerStatus(kTestCases[i].server_status); |
901 | 903 |
902 EXPECT_EQ(kTestCases[i].should_update_expiration, | 904 EXPECT_EQ(kTestCases[i].should_update_expiration, |
903 card.ShouldUpdateExpiration(now)); | 905 card.ShouldUpdateExpiration(now)); |
904 } | 906 } |
905 } | 907 } |
906 | 908 |
907 } // namespace autofill | 909 } // namespace autofill |
OLD | NEW |