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 "base/time/time.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "components/autofill/core/browser/autofill_experiments.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" |
| 20 #include "components/variations/variations_params_manager.h" | |
| 19 #include "grit/components_scaled_resources.h" | 21 #include "grit/components_scaled_resources.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 23 |
| 22 using base::ASCIIToUTF16; | 24 using base::ASCIIToUTF16; |
| 23 using base::UTF8ToUTF16; | 25 using base::UTF8ToUTF16; |
| 24 | 26 |
| 25 namespace autofill { | 27 namespace autofill { |
| 26 | 28 |
| 27 const CreditCard::RecordType LOCAL_CARD = CreditCard::LOCAL_CARD; | 29 const CreditCard::RecordType LOCAL_CARD = CreditCard::LOCAL_CARD; |
| 28 const CreditCard::RecordType MASKED_SERVER_CARD = | 30 const CreditCard::RecordType MASKED_SERVER_CARD = |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 card.SetExpirationYear(test_case.year); | 882 card.SetExpirationYear(test_case.year); |
| 881 card.set_record_type(test_case.record_type); | 883 card.set_record_type(test_case.record_type); |
| 882 if (card.record_type() != CreditCard::LOCAL_CARD) | 884 if (card.record_type() != CreditCard::LOCAL_CARD) |
| 883 card.SetServerStatus(test_case.server_status); | 885 card.SetServerStatus(test_case.server_status); |
| 884 | 886 |
| 885 EXPECT_EQ(test_case.should_update_expiration, | 887 EXPECT_EQ(test_case.should_update_expiration, |
| 886 card.ShouldUpdateExpiration(now)); | 888 card.ShouldUpdateExpiration(now)); |
| 887 } | 889 } |
| 888 } | 890 } |
| 889 | 891 |
| 892 // Test that credit card last used date suggestion can be generated correctly | |
| 893 // in different variations. | |
| 894 TEST(CreditCardTest, GetLastUsedDateForDisplay) { | |
| 895 const base::Time::Exploded kTestDateTimeExploded = { | |
| 896 2016, 12, 6, 10, // Sat, Dec 10, 2016 | |
| 897 15, 42, 7, 0 // 15:42:07.000 | |
| 898 }; | |
| 899 base::Time kArbitraryTime; | |
| 900 EXPECT_TRUE( | |
| 901 base::Time::FromLocalExploded(kTestDateTimeExploded, &kArbitraryTime)); | |
| 902 | |
| 903 // Test for added to chrome/chromium. | |
| 904 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com"); | |
| 905 credit_card0.set_use_count(1); | |
| 906 credit_card0.set_use_date(kArbitraryTime - base::TimeDelta::FromDays(1)); | |
| 907 test::SetCreditCardInfo(&credit_card0, "John Dillinger", | |
| 908 "423456789012" /* Visa */, "01", "2021"); | |
| 909 | |
| 910 // Test for last used date. | |
| 911 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com"); | |
| 912 test::SetCreditCardInfo(&credit_card1, "Clyde Barrow", | |
| 913 "347666888555" /* American Express */, "04", "2021"); | |
| 914 credit_card1.set_use_count(10); | |
| 915 credit_card1.set_use_date(kArbitraryTime - base::TimeDelta::FromDays(10)); | |
| 916 | |
| 917 // Test for last used more than one year ago. | |
| 918 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com"); | |
| 919 credit_card2.set_use_count(5); | |
| 920 credit_card2.set_use_date(kArbitraryTime - base::TimeDelta::FromDays(366)); | |
| 921 test::SetCreditCardInfo(&credit_card2, "Bonnie Parker", | |
| 922 "518765432109" /* Mastercard */, "12", "2021"); | |
| 923 | |
| 924 static const struct { | |
| 925 const char* show_expiration_date; | |
| 926 const char* show_time_detail; | |
| 927 const std::string& app_locale; | |
| 928 base::string16 added_to_chrome_date; | |
| 929 base::string16 last_used_date; | |
| 930 base::string16 last_used_year_ago; | |
| 931 } kTestCases[] = { | |
| 932 #if defined(GOOGLE_CHROME_BUILD) | |
| 933 // only show last used date. | |
| 934 {"false", "false", "en_US", | |
| 935 ASCIIToUTF16("Added to Chrome: Dec 09"), | |
| 936 ASCIIToUTF16("Last used: Nov 30"), | |
| 937 ASCIIToUTF16("Last used over a year ago")}, | |
| 938 // show expiration date and last used date. | |
| 939 {"true", "false", "en_US", | |
| 940 ASCIIToUTF16("Exp: 01/21, added to Chrome: Dec 09"), | |
| 941 ASCIIToUTF16("Exp: 04/21, last used: Nov 30"), | |
| 942 ASCIIToUTF16("Exp: 12/21, last used over a year ago")}, | |
| 943 // show last used date detail. | |
| 944 {"false", "true", "en_US", | |
| 945 ASCIIToUTF16("Added to Chrome: Dec 09"), | |
| 946 ASCIIToUTF16("Last used: Nov 30, 3:42 PM"), | |
| 947 ASCIIToUTF16("Last used over a year ago")}, | |
| 948 // show expiration date and last used date detail. | |
| 949 {"true", "true", "en_US", | |
| 950 ASCIIToUTF16("Exp: 01/21, added to Chrome: Dec 09"), | |
| 951 ASCIIToUTF16("Exp: 04/21, last used: Nov 30, 3:42 PM"), | |
| 952 ASCIIToUTF16("Exp: 12/21, last used over a year ago")}, | |
| 953 #elif defined(CHROMIUM_BUILD) | |
| 954 // only show last used date. | |
| 955 {"false", "false", "en_US", | |
| 956 ASCIIToUTF16("Added to Chromium: Dec 09"), | |
| 957 ASCIIToUTF16("Last used: Nov 30"), | |
| 958 ASCIIToUTF16("Last used over a year ago")}, | |
| 959 // show expiration date and last used date. | |
| 960 {"true", "false", "en_US", | |
| 961 ASCIIToUTF16("Exp: 01/21, added to Chromium: Dec 09"), | |
| 962 ASCIIToUTF16("Exp: 04/21, last used: Nov 30"), | |
| 963 ASCIIToUTF16("Exp: 12/21, last used over a year ago")}, | |
| 964 // show last used date detail. | |
| 965 {"false", "true", "en_US", | |
| 966 ASCIIToUTF16("Added to Chromium: Dec 09"), | |
| 967 ASCIIToUTF16("Last used: Nov 30, 3:42 PM"), | |
| 968 ASCIIToUTF16("Last used over a year ago")}, | |
| 969 // show expiration date and last used date detail. | |
| 970 {"true", "true", "en_US", | |
| 971 ASCIIToUTF16("Exp: 01/21, added to Chromium: Dec 09"), | |
| 972 ASCIIToUTF16("Exp: 04/21, last used: Nov 30, 3:42 PM"), | |
| 973 ASCIIToUTF16("Exp: 12/21, last used over a year ago")}, | |
| 974 #endif | |
| 975 }; | |
| 976 | |
| 977 variations::testing::VariationParamsManager variation_params_; | |
| 978 | |
| 979 for (const auto& test_case : kTestCases) { | |
| 980 variation_params_.SetVariationParamsWithFeatureAssociations( | |
| 981 kAutofillCreditCardLastUsedDateDisplay.name, | |
| 982 {{kAutofillCreditCardLastUsedDateShowExpirationDateKey, | |
| 983 test_case.show_expiration_date}, | |
| 984 {kAutofillCreditCardLastUsedDateShowTimeDetailKey, | |
| 985 test_case.show_time_detail}}, | |
| 986 {kAutofillCreditCardLastUsedDateDisplay.name}); | |
| 987 | |
| 988 EXPECT_EQ(test_case.added_to_chrome_date, | |
| 989 credit_card0.GetLastUsedDateForDisplay(test_case.app_locale)); | |
| 990 EXPECT_EQ(test_case.last_used_date, | |
| 991 credit_card1.GetLastUsedDateForDisplay(test_case.app_locale)); | |
| 992 EXPECT_EQ(test_case.last_used_year_ago, | |
| 993 credit_card2.GetLastUsedDateForDisplay(test_case.app_locale)); | |
| 994 variation_params_.ClearAllVariationParams(); | |
|
Mathieu
2017/02/04 02:37:58
This should be called when |variation_params_| get
jiahuiguo
2017/02/08 01:21:39
Since this is in a loop, we are reusing the same |
| |
| 995 } | |
| 996 } | |
| 997 | |
| 890 } // namespace autofill | 998 } // namespace autofill |
| OLD | NEW |