Chromium Code Reviews| 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 "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "components/autofill/core/browser/autofill_test_utils.h" | 13 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 13 #include "components/autofill/core/browser/autofill_type.h" | 14 #include "components/autofill/core/browser/autofill_type.h" |
| 14 #include "components/autofill/core/browser/credit_card.h" | 15 #include "components/autofill/core/browser/credit_card.h" |
| 15 #include "components/autofill/core/browser/validation.h" | 16 #include "components/autofill/core/browser/validation.h" |
| 16 #include "components/autofill/core/common/form_field_data.h" | 17 #include "components/autofill/core/common/form_field_data.h" |
| 17 #include "grit/components_scaled_resources.h" | 18 #include "grit/components_scaled_resources.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 using base::ASCIIToUTF16; | 21 using base::ASCIIToUTF16; |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) { | 726 TEST(CreditCardTest, CanBuildFromCardNumberAndExpirationDate) { |
| 726 base::string16 card_number = base::ASCIIToUTF16("test"); | 727 base::string16 card_number = base::ASCIIToUTF16("test"); |
| 727 int month = 1; | 728 int month = 1; |
| 728 int year = 3000; | 729 int year = 3000; |
| 729 CreditCard card(card_number, month, year); | 730 CreditCard card(card_number, month, year); |
| 730 EXPECT_EQ(card_number, card.number()); | 731 EXPECT_EQ(card_number, card.number()); |
| 731 EXPECT_EQ(month, card.expiration_month()); | 732 EXPECT_EQ(month, card.expiration_month()); |
| 732 EXPECT_EQ(year, card.expiration_year()); | 733 EXPECT_EQ(year, card.expiration_year()); |
| 733 } | 734 } |
| 734 | 735 |
| 736 // 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
| |
| 737 TEST(CreditCardTest, CardExpiringLastYear) { | |
| 738 base::Time::Exploded today; | |
| 739 base::Time::Now().LocalExplode(&today); | |
| 740 | |
| 741 // Local expired card. | |
| 742 CreditCard card(base::ASCIIToUTF16("1234"), 12, today.year - 1); | |
| 743 EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); | |
| 744 | |
| 745 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 746 | |
| 747 // Masked expired server card with OK server status. | |
| 748 card.set_record_type(CreditCard::MASKED_SERVER_CARD); | |
| 749 card.SetServerStatus(CreditCard::OK); | |
| 750 | |
| 751 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 752 | |
| 753 // Masked expired server card with EXPIRED server status. | |
| 754 card.SetServerStatus(CreditCard::EXPIRED); | |
| 755 | |
| 756 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 757 | |
| 758 // Full expired server card with OK server status. | |
| 759 card.set_record_type(CreditCard::FULL_SERVER_CARD); | |
| 760 card.SetServerStatus(CreditCard::OK); | |
| 761 | |
| 762 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 763 | |
| 764 // Full expired server card with EXPIRED server status. | |
| 765 card.SetServerStatus(CreditCard::EXPIRED); | |
| 766 | |
| 767 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 768 } | |
| 769 | |
| 770 // A card that has expired last month should be updated. | |
| 771 TEST(CreditCardTest, CardExpiringLastMonth) { | |
| 772 base::Time::Exploded last_month; | |
| 773 (base::Time::Now() - base::TimeDelta::FromDays(31)).LocalExplode(&last_month); | |
| 774 | |
| 775 // Local expired card. | |
| 776 CreditCard card(base::ASCIIToUTF16("1234"), last_month.month, | |
| 777 last_month.year); | |
| 778 EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); | |
| 779 | |
| 780 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 781 | |
| 782 // Masked expired server card with OK server status. | |
| 783 card.set_record_type(CreditCard::MASKED_SERVER_CARD); | |
| 784 card.SetServerStatus(CreditCard::OK); | |
| 785 | |
| 786 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 787 | |
| 788 // Masked expired server card with EXPIRED server status. | |
| 789 card.SetServerStatus(CreditCard::EXPIRED); | |
| 790 | |
| 791 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 792 | |
| 793 // Full expired server card with OK server status. | |
| 794 card.set_record_type(CreditCard::FULL_SERVER_CARD); | |
| 795 card.SetServerStatus(CreditCard::OK); | |
| 796 | |
| 797 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 798 | |
| 799 // Full expired server card with EXPIRED server status. | |
| 800 card.SetServerStatus(CreditCard::EXPIRED); | |
| 801 | |
| 802 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 803 } | |
| 804 | |
| 805 // A card expiring this month should not be updated, unless it has EXPIRED | |
| 806 // server status. | |
| 807 TEST(CreditCardTest, CardExpiringThisMonth) { | |
| 808 base::Time::Exploded this_month; | |
| 809 base::Time::Now().LocalExplode(&this_month); | |
| 810 | |
| 811 // Local card expiring this month. | |
| 812 CreditCard card(base::ASCIIToUTF16("1234"), this_month.month, | |
| 813 this_month.year); | |
| 814 EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); | |
| 815 | |
| 816 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 817 | |
| 818 // Masked server card expiring this month with OK server status. | |
| 819 card.set_record_type(CreditCard::MASKED_SERVER_CARD); | |
| 820 card.SetServerStatus(CreditCard::OK); | |
| 821 | |
| 822 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 823 | |
| 824 // Masked server card expiring this month with EXPIRED server status. | |
| 825 card.SetServerStatus(CreditCard::EXPIRED); | |
| 826 | |
| 827 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 828 | |
| 829 // Full server card expiring this month with OK server status. | |
| 830 card.set_record_type(CreditCard::FULL_SERVER_CARD); | |
| 831 card.SetServerStatus(CreditCard::OK); | |
| 832 | |
| 833 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 834 | |
| 835 // Full server card expiring this month with EXPIRED server status. | |
| 836 card.SetServerStatus(CreditCard::EXPIRED); | |
| 837 | |
| 838 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 839 } | |
| 840 | |
| 841 // A card expiring next month should not be updated, unless it has EXPIRED | |
| 842 // server status. | |
| 843 TEST(CreditCardTest, CardExpiringNextMonth) { | |
| 844 base::Time::Exploded next_month; | |
| 845 (base::Time::Now() + base::TimeDelta::FromDays(31)).LocalExplode(&next_month); | |
| 846 | |
| 847 // Local card expiring next month. | |
| 848 CreditCard card(base::ASCIIToUTF16("1234"), next_month.month, | |
| 849 next_month.year); | |
| 850 EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); | |
| 851 | |
| 852 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 853 | |
| 854 // Masked server card expiring next month with OK server status. | |
| 855 card.set_record_type(CreditCard::MASKED_SERVER_CARD); | |
| 856 card.SetServerStatus(CreditCard::OK); | |
| 857 | |
| 858 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 859 | |
| 860 // Masked server card expiring next month with EXPIRED server status. | |
| 861 card.SetServerStatus(CreditCard::EXPIRED); | |
| 862 | |
| 863 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 864 | |
| 865 // Full server card expiring next month with OK server status. | |
| 866 card.set_record_type(CreditCard::FULL_SERVER_CARD); | |
| 867 card.SetServerStatus(CreditCard::OK); | |
| 868 | |
| 869 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 870 | |
| 871 // Full server card expiring next month with EXPIRED server status. | |
| 872 card.SetServerStatus(CreditCard::EXPIRED); | |
| 873 | |
| 874 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 875 } | |
| 876 | |
| 877 // A card expiring next year should not be updated, unless it has EXPIRED server | |
| 878 // status. | |
| 879 TEST(CreditCardTest, CardExpiringNextYear) { | |
| 880 base::Time::Exploded today; | |
| 881 base::Time::Now().LocalExplode(&today); | |
| 882 | |
| 883 // Local card expiring next year. | |
| 884 CreditCard card(base::ASCIIToUTF16("1234"), 1, today.year + 1); | |
| 885 EXPECT_EQ(CreditCard::LOCAL_CARD, card.record_type()); | |
| 886 | |
| 887 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 888 | |
| 889 // Masked server card expiring next year with OK server status. | |
| 890 card.set_record_type(CreditCard::MASKED_SERVER_CARD); | |
| 891 card.SetServerStatus(CreditCard::OK); | |
| 892 | |
| 893 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 894 | |
| 895 // Masked server card expiring next year with EXPIRED server status. | |
| 896 card.SetServerStatus(CreditCard::EXPIRED); | |
| 897 | |
| 898 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 899 | |
| 900 // Full server card expiring next year with OK server status. | |
| 901 card.set_record_type(CreditCard::FULL_SERVER_CARD); | |
| 902 card.SetServerStatus(CreditCard::OK); | |
| 903 | |
| 904 EXPECT_FALSE(card.ShouldUpdateExpiration()); | |
| 905 | |
| 906 // Full server card expiring next year with EXPIRED server status. | |
| 907 card.SetServerStatus(CreditCard::EXPIRED); | |
| 908 | |
| 909 EXPECT_TRUE(card.ShouldUpdateExpiration()); | |
| 910 } | |
| 911 | |
| 912 | |
| 735 } // namespace autofill | 913 } // namespace autofill |
| OLD | NEW |