Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: components/autofill/core/browser/credit_card_unittest.cc

Issue 2534413006: [Credit Card] Uses 4 dots in ellipsis (Closed)
Patch Set: Updates Java tests with new format for masked card numbers Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 "6331101999990016", 52 "6331101999990016",
53 "6247130048162403", 53 "6247130048162403",
54 }; 54 };
55 const char* const kInvalidNumbers[] = { 55 const char* const kInvalidNumbers[] = {
56 "4111 1111 112", /* too short */ 56 "4111 1111 112", /* too short */
57 "41111111111111111115", /* too long */ 57 "41111111111111111115", /* too long */
58 "4111-1111-1111-1110", /* wrong Luhn checksum */ 58 "4111-1111-1111-1110", /* wrong Luhn checksum */
59 "3056 9309 0259 04aa", /* non-digit characters */ 59 "3056 9309 0259 04aa", /* non-digit characters */
60 }; 60 };
61 61
62 const std::string kUTF8MidlineEllipsis =
63 " "
64 "\xE2\x80\xA2\xE2\x80\x86"
65 "\xE2\x80\xA2\xE2\x80\x86"
66 "\xE2\x80\xA2\xE2\x80\x86"
67 "\xE2\x80\xA2\xE2\x80\x86";
68
62 } // namespace 69 } // namespace
63 70
64 // Tests credit card summary string generation. This test simulates a variety 71 // Tests credit card summary string generation. This test simulates a variety
65 // of different possible summary strings. Variations occur based on the 72 // of different possible summary strings. Variations occur based on the
66 // existence of credit card number, month, and year fields. 73 // existence of credit card number, month, and year fields.
67 TEST(CreditCardTest, PreviewSummaryAndTypeAndLastFourDigitsStrings) { 74 TEST(CreditCardTest, PreviewSummaryAndTypeAndLastFourDigitsStrings) {
68 // Case 0: empty credit card. 75 // Case 0: empty credit card.
69 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/"); 76 CreditCard credit_card0(base::GenerateGUID(), "https://www.example.com/");
70 base::string16 summary0 = credit_card0.Label(); 77 base::string16 summary0 = credit_card0.Label();
71 EXPECT_EQ(base::string16(), summary0); 78 EXPECT_EQ(base::string16(), summary0);
(...skipping 14 matching lines...) Expand all
86 base::string16 summary1 = credit_card1.Label(); 93 base::string16 summary1 = credit_card1.Label();
87 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary1); 94 EXPECT_EQ(base::string16(ASCIIToUTF16("John Dillinger")), summary1);
88 base::string16 obfuscated1 = credit_card1.TypeAndLastFourDigits(); 95 base::string16 obfuscated1 = credit_card1.TypeAndLastFourDigits();
89 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated1); 96 EXPECT_EQ(ASCIIToUTF16("Card"), obfuscated1);
90 97
91 // Case 2: No month. 98 // Case 2: No month.
92 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/"); 99 CreditCard credit_card2(base::GenerateGUID(), "https://www.example.com/");
93 test::SetCreditCardInfo( 100 test::SetCreditCardInfo(
94 &credit_card2, "John Dillinger", "5105 1051 0510 5100", "", "2010"); 101 &credit_card2, "John Dillinger", "5105 1051 0510 5100", "", "2010");
95 base::string16 summary2 = credit_card2.Label(); 102 base::string16 summary2 = credit_card2.Label();
96 EXPECT_EQ(UTF8ToUTF16( 103 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "5100"),
97 "MasterCard\xC2\xA0\xE2\x8B\xAF"
98 "5100"),
99 summary2); 104 summary2);
100 base::string16 obfuscated2 = credit_card2.TypeAndLastFourDigits(); 105 base::string16 obfuscated2 = credit_card2.TypeAndLastFourDigits();
101 EXPECT_EQ(UTF8ToUTF16( 106 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "5100"),
102 "MasterCard\xC2\xA0\xE2\x8B\xAF"
103 "5100"),
104 obfuscated2); 107 obfuscated2);
105 108
106 // Case 3: No year. 109 // Case 3: No year.
107 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com/"); 110 CreditCard credit_card3(base::GenerateGUID(), "https://www.example.com/");
108 test::SetCreditCardInfo( 111 test::SetCreditCardInfo(
109 &credit_card3, "John Dillinger", "5105 1051 0510 5100", "01", ""); 112 &credit_card3, "John Dillinger", "5105 1051 0510 5100", "01", "");
110 base::string16 summary3 = credit_card3.Label(); 113 base::string16 summary3 = credit_card3.Label();
111 EXPECT_EQ(UTF8ToUTF16( 114 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "5100"),
112 "MasterCard\xC2\xA0\xE2\x8B\xAF"
113 "5100"),
114 summary3); 115 summary3);
115 base::string16 obfuscated3 = credit_card3.TypeAndLastFourDigits(); 116 base::string16 obfuscated3 = credit_card3.TypeAndLastFourDigits();
116 EXPECT_EQ(UTF8ToUTF16( 117 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "5100"),
117 "MasterCard\xC2\xA0\xE2\x8B\xAF"
118 "5100"),
119 obfuscated3); 118 obfuscated3);
120 119
121 // Case 4: Have everything. 120 // Case 4: Have everything.
122 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com/"); 121 CreditCard credit_card4(base::GenerateGUID(), "https://www.example.com/");
123 test::SetCreditCardInfo( 122 test::SetCreditCardInfo(
124 &credit_card4, "John Dillinger", "5105 1051 0510 5100", "01", "2010"); 123 &credit_card4, "John Dillinger", "5105 1051 0510 5100", "01", "2010");
125 base::string16 summary4 = credit_card4.Label(); 124 base::string16 summary4 = credit_card4.Label();
126 EXPECT_EQ(UTF8ToUTF16( 125 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "5100, 01/2010"),
127 "MasterCard\xC2\xA0\xE2\x8B\xAF"
128 "5100, 01/2010"),
129 summary4); 126 summary4);
130 base::string16 obfuscated4 = credit_card4.TypeAndLastFourDigits(); 127 base::string16 obfuscated4 = credit_card4.TypeAndLastFourDigits();
131 EXPECT_EQ(UTF8ToUTF16( 128 EXPECT_EQ(UTF8ToUTF16("MasterCard" + kUTF8MidlineEllipsis + "5100"),
132 "MasterCard\xC2\xA0\xE2\x8B\xAF"
133 "5100"),
134 obfuscated4); 129 obfuscated4);
135 130
136 // Case 5: Very long credit card 131 // Case 5: Very long credit card
137 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com/"); 132 CreditCard credit_card5(base::GenerateGUID(), "https://www.example.com/");
138 test::SetCreditCardInfo( 133 test::SetCreditCardInfo(
139 &credit_card5, 134 &credit_card5,
140 "John Dillinger", 135 "John Dillinger",
141 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010"); 136 "0123456789 0123456789 0123456789 5105 1051 0510 5100", "01", "2010");
142 base::string16 summary5 = credit_card5.Label(); 137 base::string16 summary5 = credit_card5.Label();
143 EXPECT_EQ(UTF8ToUTF16( 138 EXPECT_EQ(UTF8ToUTF16("Card" + kUTF8MidlineEllipsis + "5100, 01/2010"),
144 "Card\xC2\xA0\xE2\x8B\xAF"
145 "5100, 01/2010"),
146 summary5); 139 summary5);
147 base::string16 obfuscated5 = credit_card5.TypeAndLastFourDigits(); 140 base::string16 obfuscated5 = credit_card5.TypeAndLastFourDigits();
148 EXPECT_EQ(UTF8ToUTF16( 141 EXPECT_EQ(UTF8ToUTF16("Card" + kUTF8MidlineEllipsis + "5100"),
149 "Card\xC2\xA0\xE2\x8B\xAF"
150 "5100"),
151 obfuscated5); 142 obfuscated5);
152 } 143 }
153 144
154 TEST(CreditCardTest, AssignmentOperator) { 145 TEST(CreditCardTest, AssignmentOperator) {
155 CreditCard a(base::GenerateGUID(), "some origin"); 146 CreditCard a(base::GenerateGUID(), "some origin");
156 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010"); 147 test::SetCreditCardInfo(&a, "John Dillinger", "123456789012", "01", "2010");
157 148
158 // Result of assignment should be logically equal to the original profile. 149 // Result of assignment should be logically equal to the original profile.
159 CreditCard b(base::GenerateGUID(), "some other origin"); 150 CreditCard b(base::GenerateGUID(), "some other origin");
160 b = a; 151 b = a;
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 card.set_record_type(test_case.record_type); 881 card.set_record_type(test_case.record_type);
891 if (card.record_type() != CreditCard::LOCAL_CARD) 882 if (card.record_type() != CreditCard::LOCAL_CARD)
892 card.SetServerStatus(test_case.server_status); 883 card.SetServerStatus(test_case.server_status);
893 884
894 EXPECT_EQ(test_case.should_update_expiration, 885 EXPECT_EQ(test_case.should_update_expiration,
895 card.ShouldUpdateExpiration(now)); 886 card.ShouldUpdateExpiration(now));
896 } 887 }
897 } 888 }
898 889
899 } // namespace autofill 890 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/credit_card.cc ('k') | components/autofill/core/browser/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698