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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/guid.h" | 6 #include "base/guid.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/browser/autofill_test_utils.h" | 8 #include "components/autofill/core/browser/autofill_test_utils.h" |
9 #include "components/autofill/core/browser/autofill_type.h" | 9 #include "components/autofill/core/browser/autofill_type.h" |
10 #include "components/autofill/core/browser/credit_card.h" | 10 #include "components/autofill/core/browser/credit_card.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 "41111111111111111115", /* too long */ | 46 "41111111111111111115", /* too long */ |
47 "4111-1111-1111-1110", /* wrong Luhn checksum */ | 47 "4111-1111-1111-1110", /* wrong Luhn checksum */ |
48 "3056 9309 0259 04aa", /* non-digit characters */ | 48 "3056 9309 0259 04aa", /* non-digit characters */ |
49 }; | 49 }; |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 // Tests credit card summary string generation. This test simulates a variety | 53 // Tests credit card summary string generation. This test simulates a variety |
54 // of different possible summary strings. Variations occur based on the | 54 // of different possible summary strings. Variations occur based on the |
55 // existence of credit card number, month, and year fields. | 55 // existence of credit card number, month, and year fields. |
56 TEST(CreditCardTest, PreviewSummaryAndObfuscatedNumberStrings) { | 56 TEST(CreditCardTest, PreviewSummaryAndTypeAndLastFourDigitsStrings) { |
57 // Case 0: empty credit card. | 57 // Case 0: empty credit card. |
58 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/"); | 58 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/"); |
59 base::string16 summary0 = credit_card0.Label(); | 59 base::string16 summary0 = credit_card0.Label(); |
60 EXPECT_EQ(base::string16(), summary0); | 60 EXPECT_EQ(base::string16(), summary0); |
61 base::string16 obfuscated0 = credit_card0.ObfuscatedNumber(); | 61 base::string16 obfuscated0 = credit_card0.TypeAndLastFourDigits(); |
62 EXPECT_EQ(base::string16(), obfuscated0); | 62 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated0); |
63 | 63 |
64 // Case 00: Empty credit card with empty strings. | 64 // Case 00: Empty credit card with empty strings. |
65 CreditCard credit_card00(base::GenerateGUID(), "https://www.example.com/"); | 65 CreditCard credit_card00(base::GenerateGUID(), "https://www.example.com/"); |
66 test::SetCreditCardInfo(&credit_card00,"John Dillinger", "", "", ""); | 66 test::SetCreditCardInfo(&credit_card00,"John Dillinger", "", "", ""); |
67 base::string16 summary00 = credit_card00.Label(); | 67 base::string16 summary00 = credit_card00.Label(); |
68 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary00); | 68 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary00); |
69 base::string16 obfuscated00 = credit_card00.ObfuscatedNumber(); | 69 base::string16 obfuscated00 = credit_card00.TypeAndLastFourDigits(); |
70 EXPECT_EQ(base::string16(), obfuscated00); | 70 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated00); |
71 | 71 |
72 // Case 1: No credit card number. | 72 // Case 1: No credit card number. |
73 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com/"); | 73 CreditCard credit_card1(base::GenerateGUID(), "https://www.example.com/"); |
74 test::SetCreditCardInfo(&credit_card1,"John Dillinger", "", "01", "2010"); | 74 test::SetCreditCardInfo(&credit_card1,"John Dillinger", "", "01", "2010"); |
75 base::string16 summary1 = credit_card1.Label(); | 75 base::string16 summary1 = credit_card1.Label(); |
76 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary1); | 76 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary1); |
77 base::string16 obfuscated1 = credit_card1.ObfuscatedNumber(); | 77 base::string16 obfuscated1 = credit_card1.TypeAndLastFourDigits(); |
78 EXPECT_EQ(base::string16(), obfuscated1); | 78 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated1); |
79 | 79 |
80 // Case 2: No month. | 80 // Case 2: No month. |
81 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/"); | 81 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/"); |
82 test::SetCreditCardInfo( | 82 test::SetCreditCardInfo( |
83 &credit_card2, "John Dillinger", "5105 1051 0510 5100", "", "2010"); | 83 &credit_card2, "John Dillinger", "5105 1051 0510 5100", "", "2010"); |
84 base::string16 summary2 = credit_card2.Label(); | 84 base::string16 summary2 = credit_card2.Label(); |
85 EXPECT_EQ(ASCIIToUTF16("************5100"), summary2); | 85 EXPECT_EQ(ASCIIToUTF16("MasterCard - 5100"), summary2); |
86 base::string16 obfuscated2 = credit_card2.ObfuscatedNumber(); | 86 base::string16 obfuscated2 = credit_card2.TypeAndLastFourDigits(); |
87 EXPECT_EQ(ASCIIToUTF16("************5100"), obfuscated2); | 87 EXPECT_EQ(ASCIIToUTF16("MasterCard - 5100"), obfuscated2); |
88 | 88 |
89 // Case 3: No year. | 89 // Case 3: No year. |
90 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com/"); | 90 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com/"); |
91 test::SetCreditCardInfo( | 91 test::SetCreditCardInfo( |
92 &credit_card3, "John Dillinger", "5105 1051 0510 5100", "01", ""); | 92 &credit_card3, "John Dillinger", "5105 1051 0510 5100", "01", ""); |
93 base::string16 summary3 = credit_card3.Label(); | 93 base::string16 summary3 = credit_card3.Label(); |
94 EXPECT_EQ(ASCIIToUTF16("************5100"), summary3); | 94 EXPECT_EQ(ASCIIToUTF16("MasterCard - 5100"), summary3); |
95 base::string16 obfuscated3 = credit_card3.ObfuscatedNumber(); | 95 base::string16 obfuscated3 = credit_card3.TypeAndLastFourDigits(); |
96 EXPECT_EQ(ASCIIToUTF16("************5100"), obfuscated3); | 96 EXPECT_EQ(ASCIIToUTF16("MasterCard - 5100"), obfuscated3); |
97 | 97 |
98 // Case 4: Have everything. | 98 // Case 4: Have everything. |
99 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com/"); | 99 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com/"); |
100 test::SetCreditCardInfo( | 100 test::SetCreditCardInfo( |
101 &credit_card4, "John Dillinger", "5105 1051 0510 5100", "01", "2010"); | 101 &credit_card4, "John Dillinger", "5105 1051 0510 5100", "01", "2010"); |
102 base::string16 summary4 = credit_card4.Label(); | 102 base::string16 summary4 = credit_card4.Label(); |
103 EXPECT_EQ(ASCIIToUTF16("************5100, Exp: 01/2010"), summary4); | 103 EXPECT_EQ(ASCIIToUTF16("MasterCard - 5100, Exp: 01/2010"), summary4); |
104 base::string16 obfuscated4 = credit_card4.ObfuscatedNumber(); | 104 base::string16 obfuscated4 = credit_card4.TypeAndLastFourDigits(); |
105 EXPECT_EQ(ASCIIToUTF16("************5100"), obfuscated4); | 105 EXPECT_EQ(ASCIIToUTF16("MasterCard - 5100"), obfuscated4); |
106 | 106 |
107 // Case 5: Very long credit card | 107 // Case 5: Very long credit card |
108 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com/"); | 108 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com/"); |
109 test::SetCreditCardInfo( | 109 test::SetCreditCardInfo( |
110 &credit_card5, | 110 &credit_card5, |
111 "John Dillinger", | 111 "John Dillinger", |
112 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010"); | 112 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010"); |
113 base::string16 summary5 = credit_card5.Label(); | 113 base::string16 summary5 = credit_card5.Label(); |
114 EXPECT_EQ(ASCIIToUTF16("********************5100, Exp: 01/2010"), summary5); | 114 EXPECT_EQ(ASCIIToUTF16("Card - 5100, Exp: 01/2010"), summary5); |
115 base::string16 obfuscated5 = credit_card5.ObfuscatedNumber(); | 115 base::string16 obfuscated5 = credit_card5.TypeAndLastFourDigits(); |
116 EXPECT_EQ(ASCIIToUTF16("********************5100"), obfuscated5); | 116 EXPECT_EQ(ASCIIToUTF16("Card - 5100"), obfuscated5); |
117 } | 117 } |
118 | 118 |
119 TEST(CreditCardTest, AssignmentOperator) { | 119 TEST(CreditCardTest, AssignmentOperator) { |
120 CreditCard a(base::GenerateGUID(), "some origin"); | 120 CreditCard a(base::GenerateGUID(), "some origin"); |
121 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); | 121 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); |
122 | 122 |
123 // Result of assignment should be logically equal to the original profile. | 123 // Result of assignment should be logically equal to the original profile. |
124 CreditCard b(base::GenerateGUID(), "some other origin"); | 124 CreditCard b(base::GenerateGUID(), "some other origin"); |
125 b = a; | 125 b = a; |
126 EXPECT_TRUE(a == b); | 126 EXPECT_TRUE(a == b); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 base::string16 card_number = base::ASCIIToUTF16("test"); | 549 base::string16 card_number = base::ASCIIToUTF16("test"); |
550 int month = 1; | 550 int month = 1; |
551 int year = 3000; | 551 int year = 3000; |
552 CreditCard card(card_number, month, year); | 552 CreditCard card(card_number, month, year); |
553 EXPECT_EQ(card_number, card.number()); | 553 EXPECT_EQ(card_number, card.number()); |
554 EXPECT_EQ(month, card.expiration_month()); | 554 EXPECT_EQ(month, card.expiration_month()); |
555 EXPECT_EQ(year, card.expiration_year()); | 555 EXPECT_EQ(year, card.expiration_year()); |
556 } | 556 } |
557 | 557 |
558 } // namespace autofill | 558 } // namespace autofill |
OLD | NEW |