| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 // Tests credit card summary string generation. This test simulates a variety | 64 // Tests credit card summary string generation. This test simulates a variety |
| 65 // of different possible summary strings. Variations occur based on the | 65 // of different possible summary strings. Variations occur based on the |
| 66 // existence of credit card number, month, and year fields. | 66 // existence of credit card number, month, and year fields. |
| 67 TEST(CreditCardTest, PreviewSummaryAndTypeAndLastFourDigitsStrings) { | 67 TEST(CreditCardTest, PreviewSummaryAndTypeAndLastFourDigitsStrings) { |
| 68 // Case 0: empty credit card. | 68 // Case 0: empty credit card. |
| 69 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/"); | 69 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/"); |
| 70 base::string16 summary0 = credit_card0.Label(); | 70 base::string16 summary0 = credit_card0.Label(); |
| 71 EXPECT_EQ(base::string16(), summary0); | 71 EXPECT_EQ(base::string16(), summary0); |
| 72 base::string16 obfuscated0 = credit_card0.TypeAndLastFourDigits(); | 72 base::string16 obfuscated0 = credit_card0.TypeAndLastFourDigitsForDisplay(); |
| 73 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated0); | 73 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated0); |
| 74 | 74 |
| 75 // Case 00: Empty credit card with empty strings. | 75 // Case 00: Empty credit card with empty strings. |
| 76 CreditCard credit_card00(base::GenerateGUID(), "https://www.example.com/"); | 76 CreditCard credit_card00(base::GenerateGUID(), "https://www.example.com/"); |
| 77 test::SetCreditCardInfo(&credit_card00,"John Dillinger", "", "", ""); | 77 test::SetCreditCardInfo(&credit_card00,"John Dillinger", "", "", ""); |
| 78 base::string16 summary00 = credit_card00.Label(); | 78 base::string16 summary00 = credit_card00.Label(); |
| 79 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary00); | 79 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary00); |
| 80 base::string16 obfuscated00 = credit_card00.TypeAndLastFourDigits(); | 80 base::string16 obfuscated00 = credit_card00.TypeAndLastFourDigitsForDisplay(); |
| 81 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated00); | 81 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated00); |
| 82 | 82 |
| 83 // Case 1: No credit card number. | 83 // Case 1: No credit card number. |
| 84 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com/"); | 84 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com/"); |
| 85 test::SetCreditCardInfo(&credit_card1,"John Dillinger", "", "01", "2010"); | 85 test::SetCreditCardInfo(&credit_card1,"John Dillinger", "", "01", "2010"); |
| 86 base::string16 summary1 = credit_card1.Label(); | 86 base::string16 summary1 = credit_card1.Label(); |
| 87 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary1); | 87 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary1); |
| 88 base::string16 obfuscated1 = credit_card1.TypeAndLastFourDigits(); | 88 base::string16 obfuscated1 = credit_card1.TypeAndLastFourDigitsForDisplay(); |
| 89 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated1); | 89 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated1); |
| 90 | 90 |
| 91 // Case 2: No month. | 91 // Case 2: No month. |
| 92 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/"); | 92 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/"); |
| 93 test::SetCreditCardInfo( | 93 test::SetCreditCardInfo( |
| 94 &credit_card2, "John Dillinger", "5105 1051 0510 5100", "", "2010"); | 94 &credit_card2, "John Dillinger", "5105 1051 0510 5100", "", "2010"); |
| 95 base::string16 summary2 = credit_card2.Label(); | 95 base::string16 summary2 = credit_card2.Label(); |
| 96 EXPECT_EQ(UTF8ToUTF16( | 96 EXPECT_EQ(UTF8ToUTF16( |
| 97 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 97 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 98 "5100"), | 98 "5100"), |
| 99 summary2); | 99 summary2); |
| 100 base::string16 obfuscated2 = credit_card2.TypeAndLastFourDigits(); | 100 base::string16 obfuscated2 = credit_card2.TypeAndLastFourDigitsForDisplay(); |
| 101 EXPECT_EQ(UTF8ToUTF16( | 101 EXPECT_EQ(UTF8ToUTF16( |
| 102 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 102 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 103 "5100"), | 103 "5100"), |
| 104 obfuscated2); | 104 obfuscated2); |
| 105 | 105 |
| 106 // Case 3: No year. | 106 // Case 3: No year. |
| 107 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com/"); | 107 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com/"); |
| 108 test::SetCreditCardInfo( | 108 test::SetCreditCardInfo( |
| 109 &credit_card3, "John Dillinger", "5105 1051 0510 5100", "01", ""); | 109 &credit_card3, "John Dillinger", "5105 1051 0510 5100", "01", ""); |
| 110 base::string16 summary3 = credit_card3.Label(); | 110 base::string16 summary3 = credit_card3.Label(); |
| 111 EXPECT_EQ(UTF8ToUTF16( | 111 EXPECT_EQ(UTF8ToUTF16( |
| 112 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 112 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 113 "5100"), | 113 "5100"), |
| 114 summary3); | 114 summary3); |
| 115 base::string16 obfuscated3 = credit_card3.TypeAndLastFourDigits(); | 115 base::string16 obfuscated3 = credit_card3.TypeAndLastFourDigitsForDisplay(); |
| 116 EXPECT_EQ(UTF8ToUTF16( | 116 EXPECT_EQ(UTF8ToUTF16( |
| 117 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 117 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 118 "5100"), | 118 "5100"), |
| 119 obfuscated3); | 119 obfuscated3); |
| 120 | 120 |
| 121 // Case 4: Have everything. | 121 // Case 4: Have everything. |
| 122 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com/"); | 122 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com/"); |
| 123 test::SetCreditCardInfo( | 123 test::SetCreditCardInfo( |
| 124 &credit_card4, "John Dillinger", "5105 1051 0510 5100", "01", "2010"); | 124 &credit_card4, "John Dillinger", "5105 1051 0510 5100", "01", "2010"); |
| 125 base::string16 summary4 = credit_card4.Label(); | 125 base::string16 summary4 = credit_card4.Label(); |
| 126 EXPECT_EQ(UTF8ToUTF16( | 126 EXPECT_EQ(UTF8ToUTF16( |
| 127 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 127 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 128 "5100, 01/2010"), | 128 "5100, 01/2010"), |
| 129 summary4); | 129 summary4); |
| 130 base::string16 obfuscated4 = credit_card4.TypeAndLastFourDigits(); | 130 base::string16 obfuscated4 = credit_card4.TypeAndLastFourDigitsForDisplay(); |
| 131 EXPECT_EQ(UTF8ToUTF16( | 131 EXPECT_EQ(UTF8ToUTF16( |
| 132 "MasterCard\xC2\xA0\xE2\x8B\xAF" | 132 "MasterCard\xC2\xA0\xE2\x8B\xAF" |
| 133 "5100"), | 133 "5100"), |
| 134 obfuscated4); | 134 obfuscated4); |
| 135 | 135 |
| 136 // Case 5: Very long credit card | 136 // Case 5: Very long credit card |
| 137 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com/"); | 137 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com/"); |
| 138 test::SetCreditCardInfo( | 138 test::SetCreditCardInfo( |
| 139 &credit_card5, | 139 &credit_card5, |
| 140 "John Dillinger", | 140 "John Dillinger", |
| 141 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010"); | 141 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010"); |
| 142 base::string16 summary5 = credit_card5.Label(); | 142 base::string16 summary5 = credit_card5.Label(); |
| 143 EXPECT_EQ(UTF8ToUTF16( | 143 EXPECT_EQ(UTF8ToUTF16( |
| 144 "Card\xC2\xA0\xE2\x8B\xAF" | 144 "Card\xC2\xA0\xE2\x8B\xAF" |
| 145 "5100, 01/2010"), | 145 "5100, 01/2010"), |
| 146 summary5); | 146 summary5); |
| 147 base::string16 obfuscated5 = credit_card5.TypeAndLastFourDigits(); | 147 base::string16 obfuscated5 = credit_card5.TypeAndLastFourDigitsForDisplay(); |
| 148 EXPECT_EQ(UTF8ToUTF16( | 148 EXPECT_EQ(UTF8ToUTF16( |
| 149 "Card\xC2\xA0\xE2\x8B\xAF" | 149 "Card\xC2\xA0\xE2\x8B\xAF" |
| 150 "5100"), | 150 "5100"), |
| 151 obfuscated5); | 151 obfuscated5); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST(CreditCardTest, AssignmentOperator) { | 154 TEST(CreditCardTest, AssignmentOperator) { |
| 155 CreditCard a(base::GenerateGUID(), "some origin"); | 155 CreditCard a(base::GenerateGUID(), "some origin"); |
| 156 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); | 156 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); |
| 157 | 157 |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 base::string16 card_number = base::ASCIIToUTF16("test"); | 666 base::string16 card_number = base::ASCIIToUTF16("test"); |
| 667 int month = 1; | 667 int month = 1; |
| 668 int year = 3000; | 668 int year = 3000; |
| 669 CreditCard card(card_number, month, year); | 669 CreditCard card(card_number, month, year); |
| 670 EXPECT_EQ(card_number, card.number()); | 670 EXPECT_EQ(card_number, card.number()); |
| 671 EXPECT_EQ(month, card.expiration_month()); | 671 EXPECT_EQ(month, card.expiration_month()); |
| 672 EXPECT_EQ(year, card.expiration_year()); | 672 EXPECT_EQ(year, card.expiration_year()); |
| 673 } | 673 } |
| 674 | 674 |
| 675 } // namespace autofill | 675 } // namespace autofill |
| OLD | NEW |