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/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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 "1"); | 149 "1"); |
| 149 base::string16 summary5 = credit_card5.Label(); | 150 base::string16 summary5 = credit_card5.Label(); |
| 150 EXPECT_EQ( | 151 EXPECT_EQ( |
| 151 UTF8ToUTF16(std::string("Card") + kUTF8MidlineEllipsis + "5100, 01/2010"), | 152 UTF8ToUTF16(std::string("Card") + kUTF8MidlineEllipsis + "5100, 01/2010"), |
| 152 summary5); | 153 summary5); |
| 153 base::string16 obfuscated5 = credit_card5.NetworkAndLastFourDigits(); | 154 base::string16 obfuscated5 = credit_card5.NetworkAndLastFourDigits(); |
| 154 EXPECT_EQ(UTF8ToUTF16(std::string("Card") + kUTF8MidlineEllipsis + "5100"), | 155 EXPECT_EQ(UTF8ToUTF16(std::string("Card") + kUTF8MidlineEllipsis + "5100"), |
| 155 obfuscated5); | 156 obfuscated5); |
| 156 } | 157 } |
| 157 | 158 |
| 159 // Tests credit card bank name and last four digits string generation. | |
| 160 TEST(CreditCardTest, BankNameAndLastFourDigitsStrings) { | |
| 161 // Case 1: Have everything and show bank name | |
| 162 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com/"); | |
| 163 test::SetCreditCardInfo(&credit_card1, "John Dillinger", | |
| 164 "5105 1051 0510 5100", "01", "2010", "1"); | |
| 165 credit_card1.SetBankName("Chase"); | |
| 166 base::string16 obfuscated1 = credit_card1.BankNameAndLastFourDigits(); | |
| 167 EXPECT_FALSE(credit_card1.bank_name().empty()); | |
| 168 EXPECT_EQ(UTF8ToUTF16(std::string("Chase") + kUTF8MidlineEllipsis + "5100"), | |
| 169 obfuscated1); | |
| 170 | |
| 171 // Case 2: Have no bank name and not show bank name | |
| 172 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/"); | |
| 173 test::SetCreditCardInfo(&credit_card2, "John Dillinger", | |
| 174 "5105 1051 0510 5100", "01", "2010", "1"); | |
| 175 base::string16 obfuscated2 = credit_card2.BankNameAndLastFourDigits(); | |
| 176 EXPECT_TRUE(credit_card2.bank_name().empty()); | |
| 177 EXPECT_EQ(UTF8ToUTF16(std::string(kUTF8MidlineEllipsis) + "5100"), obfuscated2 ); | |
|
Jared Saul
2017/06/07 01:22:59
+ test for bank name but not digits? Since your c
Shanfeng
2017/06/07 17:20:16
Done.
jiahuiguo
2017/06/14 05:51:28
Exceed 80 column limit?
Shanfeng
2017/06/14 17:48:25
Not valid.
| |
| 178 } | |
| 179 | |
| 158 TEST(CreditCardTest, AssignmentOperator) { | 180 TEST(CreditCardTest, AssignmentOperator) { |
| 159 CreditCard a(base::GenerateGUID(), "some origin"); | 181 CreditCard a(base::GenerateGUID(), "some origin"); |
| 160 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010", | 182 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010", |
| 161 "1"); | 183 "1"); |
| 162 | 184 |
| 163 // Result of assignment should be logically equal to the original profile. | 185 // Result of assignment should be logically equal to the original profile. |
| 164 CreditCard b(base::GenerateGUID(), "some other origin"); | 186 CreditCard b(base::GenerateGUID(), "some other origin"); |
| 165 b = a; | 187 b = a; |
| 166 EXPECT_TRUE(a == b); | 188 EXPECT_TRUE(a == b); |
| 167 | 189 |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1090 credit_card0.GetLastUsedDateForDisplay(test_case.app_locale)); | 1112 credit_card0.GetLastUsedDateForDisplay(test_case.app_locale)); |
| 1091 EXPECT_EQ(test_case.last_used_date, | 1113 EXPECT_EQ(test_case.last_used_date, |
| 1092 credit_card1.GetLastUsedDateForDisplay(test_case.app_locale)); | 1114 credit_card1.GetLastUsedDateForDisplay(test_case.app_locale)); |
| 1093 EXPECT_EQ(test_case.last_used_year_ago, | 1115 EXPECT_EQ(test_case.last_used_year_ago, |
| 1094 credit_card2.GetLastUsedDateForDisplay(test_case.app_locale)); | 1116 credit_card2.GetLastUsedDateForDisplay(test_case.app_locale)); |
| 1095 variation_params_.ClearAllVariationParams(); | 1117 variation_params_.ClearAllVariationParams(); |
| 1096 } | 1118 } |
| 1097 } | 1119 } |
| 1098 | 1120 |
| 1099 } // namespace autofill | 1121 } // namespace autofill |
| OLD | NEW |