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/test/scoped_feature_list.h" | |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "components/autofill/core/browser/autofill_experiments.h" | 14 #include "components/autofill/core/browser/autofill_experiments.h" |
14 #include "components/autofill/core/browser/autofill_test_utils.h" | 15 #include "components/autofill/core/browser/autofill_test_utils.h" |
15 #include "components/autofill/core/browser/autofill_type.h" | 16 #include "components/autofill/core/browser/autofill_type.h" |
16 #include "components/autofill/core/browser/credit_card.h" | 17 #include "components/autofill/core/browser/credit_card.h" |
17 #include "components/autofill/core/browser/validation.h" | 18 #include "components/autofill/core/browser/validation.h" |
18 #include "components/autofill/core/common/autofill_constants.h" | 19 #include "components/autofill/core/common/autofill_constants.h" |
19 #include "components/autofill/core/common/form_field_data.h" | 20 #include "components/autofill/core/common/form_field_data.h" |
20 #include "components/grit/components_scaled_resources.h" | 21 #include "components/grit/components_scaled_resources.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 "John Dillinger", | 138 "John Dillinger", |
138 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010"); | 139 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010"); |
139 base::string16 summary5 = credit_card5.Label(); | 140 base::string16 summary5 = credit_card5.Label(); |
140 EXPECT_EQ(UTF8ToUTF16("Card" + kUTF8MidlineEllipsis + "5100, 01/2010"), | 141 EXPECT_EQ(UTF8ToUTF16("Card" + kUTF8MidlineEllipsis + "5100, 01/2010"), |
141 summary5); | 142 summary5); |
142 base::string16 obfuscated5 = credit_card5.TypeAndLastFourDigits(); | 143 base::string16 obfuscated5 = credit_card5.TypeAndLastFourDigits(); |
143 EXPECT_EQ(UTF8ToUTF16("Card" + kUTF8MidlineEllipsis + "5100"), | 144 EXPECT_EQ(UTF8ToUTF16("Card" + kUTF8MidlineEllipsis + "5100"), |
144 obfuscated5); | 145 obfuscated5); |
145 } | 146 } |
146 | 147 |
148 // Tests credit card bank name and last four digits string generation. | |
149 TEST(CreditCardTest, BankNameAndLastFourDigitsStrings) { | |
sebsg
2017/04/12 22:32:36
Could you please add a test with a bank name longe
Shanfeng
2017/04/13 18:29:09
Done.
| |
150 // Case 1: Have everything and show bank name | |
151 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com/"); | |
152 test::SetCreditCardInfo(&credit_card1, "John Dillinger", | |
153 "5105 1051 0510 5100", "01", "2010"); | |
154 credit_card1.SetBankName("Chase"); | |
155 base::string16 obfuscated1 = credit_card1.BankNameAndLastFourDigits(); | |
156 EXPECT_FALSE(credit_card1.bank_name().empty()); | |
157 EXPECT_EQ(UTF8ToUTF16("Chase" + kUTF8MidlineEllipsis + "5100"), obfuscated1); | |
158 | |
159 // Case 2: Have no bank name and not show bank name | |
160 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/"); | |
161 test::SetCreditCardInfo(&credit_card2, "John Dillinger", | |
162 "5105 1051 0510 5100", "01", "2010"); | |
163 base::string16 obfuscated2 = credit_card2.BankNameAndLastFourDigits(); | |
164 EXPECT_TRUE(credit_card2.bank_name().empty()); | |
165 EXPECT_EQ(UTF8ToUTF16(kUTF8MidlineEllipsis + "5100"), obfuscated2); | |
166 } | |
167 | |
147 TEST(CreditCardTest, AssignmentOperator) { | 168 TEST(CreditCardTest, AssignmentOperator) { |
148 CreditCard a(base::GenerateGUID(), "some origin"); | 169 CreditCard a(base::GenerateGUID(), "some origin"); |
149 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); | 170 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); |
150 | 171 |
151 // Result of assignment should be logically equal to the original profile. | 172 // Result of assignment should be logically equal to the original profile. |
152 CreditCard b(base::GenerateGUID(), "some other origin"); | 173 CreditCard b(base::GenerateGUID(), "some other origin"); |
153 b = a; | 174 b = a; |
154 EXPECT_TRUE(a == b); | 175 EXPECT_TRUE(a == b); |
155 | 176 |
156 // Assignment to self should not change the profile value. | 177 // Assignment to self should not change the profile value. |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1066 credit_card0.GetLastUsedDateForDisplay(test_case.app_locale)); | 1087 credit_card0.GetLastUsedDateForDisplay(test_case.app_locale)); |
1067 EXPECT_EQ(test_case.last_used_date, | 1088 EXPECT_EQ(test_case.last_used_date, |
1068 credit_card1.GetLastUsedDateForDisplay(test_case.app_locale)); | 1089 credit_card1.GetLastUsedDateForDisplay(test_case.app_locale)); |
1069 EXPECT_EQ(test_case.last_used_year_ago, | 1090 EXPECT_EQ(test_case.last_used_year_ago, |
1070 credit_card2.GetLastUsedDateForDisplay(test_case.app_locale)); | 1091 credit_card2.GetLastUsedDateForDisplay(test_case.app_locale)); |
1071 variation_params_.ClearAllVariationParams(); | 1092 variation_params_.ClearAllVariationParams(); |
1072 } | 1093 } |
1073 } | 1094 } |
1074 | 1095 |
1075 } // namespace autofill | 1096 } // namespace autofill |
OLD | NEW |