| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_common_unittest.h" | 6 #include "chrome/browser/autofill/autofill_common_unittest.h" |
| 7 #include "chrome/browser/autofill/credit_card.h" | 7 #include "chrome/browser/autofill/credit_card.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 // Tests credit card summary string generation. This test simulates a variety | 12 // Tests credit card summary string generation. This test simulates a variety |
| 13 // of different possible summary strings. Variations occur based on the | 13 // of different possible summary strings. Variations occur based on the |
| 14 // existence of credit card number, month, and year fields. | 14 // existence of credit card number, month, and year fields. |
| 15 TEST(CreditCardTest, PreviewSummaryString) { | 15 TEST(CreditCardTest, PreviewSummaryAndObfuscatedNumberStrings) { |
| 16 // Case 0: empty credit card. | 16 // Case 0: empty credit card. |
| 17 CreditCard credit_card0(string16(), 0); | 17 CreditCard credit_card0(string16(), 0); |
| 18 string16 summary0 = credit_card0.PreviewSummary(); | 18 string16 summary0 = credit_card0.PreviewSummary(); |
| 19 EXPECT_EQ(summary0, string16()); | 19 EXPECT_EQ(summary0, string16()); |
| 20 string16 obfuscated0 = credit_card0.ObfuscatedNumber(); |
| 21 EXPECT_EQ(obfuscated0, string16()); |
| 20 | 22 |
| 21 // Case 00: Empty credit card with empty strings. | 23 // Case 00: Empty credit card with empty strings. |
| 22 CreditCard credit_card00(string16(), 0); | 24 CreditCard credit_card00(string16(), 0); |
| 23 autofill_unittest::SetCreditCardInfo( | 25 autofill_unittest::SetCreditCardInfo( |
| 24 &credit_card00, | 26 &credit_card00, |
| 25 "Corporate", | 27 "Corporate", |
| 26 "John Dillinger", | 28 "John Dillinger", |
| 27 "Visa", | 29 "Visa", |
| 28 "", | 30 "", |
| 29 "", | 31 "", |
| 30 "", | 32 "", |
| 31 "123", | 33 "123", |
| 32 "Chicago", | 34 "Chicago", |
| 33 "Indianapolis"); | 35 "Indianapolis"); |
| 34 string16 summary00 = credit_card00.PreviewSummary(); | 36 string16 summary00 = credit_card00.PreviewSummary(); |
| 35 EXPECT_EQ(summary00, string16()); | 37 EXPECT_EQ(summary00, string16()); |
| 38 string16 obfuscated00 = credit_card00.ObfuscatedNumber(); |
| 39 EXPECT_EQ(obfuscated00, string16()); |
| 36 | 40 |
| 37 // Case 1: No credit card number. | 41 // Case 1: No credit card number. |
| 38 CreditCard credit_card1(string16(), 0); | 42 CreditCard credit_card1(string16(), 0); |
| 39 autofill_unittest::SetCreditCardInfo( | 43 autofill_unittest::SetCreditCardInfo( |
| 40 &credit_card1, | 44 &credit_card1, |
| 41 "Corporate", | 45 "Corporate", |
| 42 "John Dillinger", | 46 "John Dillinger", |
| 43 "Visa", | 47 "Visa", |
| 44 "", | 48 "", |
| 45 "01", | 49 "01", |
| 46 "2010", | 50 "2010", |
| 47 "123", | 51 "123", |
| 48 "Chicago", | 52 "Chicago", |
| 49 "Indianapolis"); | 53 "Indianapolis"); |
| 50 string16 summary1 = credit_card1.PreviewSummary(); | 54 string16 summary1 = credit_card1.PreviewSummary(); |
| 51 EXPECT_EQ(summary1, string16()); | 55 EXPECT_EQ(summary1, string16()); |
| 56 string16 obfuscated1 = credit_card1.ObfuscatedNumber(); |
| 57 EXPECT_EQ(obfuscated1, string16()); |
| 52 | 58 |
| 53 // Case 2: No month. | 59 // Case 2: No month. |
| 54 CreditCard credit_card2(string16(), 0); | 60 CreditCard credit_card2(string16(), 0); |
| 55 autofill_unittest::SetCreditCardInfo( | 61 autofill_unittest::SetCreditCardInfo( |
| 56 &credit_card2, | 62 &credit_card2, |
| 57 "Corporate", | 63 "Corporate", |
| 58 "John Dillinger", | 64 "John Dillinger", |
| 59 "Visa", | 65 "Visa", |
| 60 "123456789012", | 66 "123456789012", |
| 61 "", | 67 "", |
| 62 "2010", | 68 "2010", |
| 63 "123", | 69 "123", |
| 64 "Chicago", | 70 "Chicago", |
| 65 "Indianapolis"); | 71 "Indianapolis"); |
| 66 string16 summary2 = credit_card2.PreviewSummary(); | 72 string16 summary2 = credit_card2.PreviewSummary(); |
| 67 EXPECT_EQ(summary2, string16(ASCIIToUTF16("************9012"))); | 73 EXPECT_EQ(summary2, string16(ASCIIToUTF16("************9012"))); |
| 74 string16 obfuscated2 = credit_card2.ObfuscatedNumber(); |
| 75 EXPECT_EQ(obfuscated2, string16(ASCIIToUTF16("************9012"))); |
| 68 | 76 |
| 69 // Case 3: No year. | 77 // Case 3: No year. |
| 70 CreditCard credit_card3(string16(), 0); | 78 CreditCard credit_card3(string16(), 0); |
| 71 autofill_unittest::SetCreditCardInfo( | 79 autofill_unittest::SetCreditCardInfo( |
| 72 &credit_card3, | 80 &credit_card3, |
| 73 "Corporate", | 81 "Corporate", |
| 74 "John Dillinger", | 82 "John Dillinger", |
| 75 "Visa", | 83 "Visa", |
| 76 "123456789012", | 84 "123456789012", |
| 77 "01", | 85 "01", |
| 78 "", | 86 "", |
| 79 "123", | 87 "123", |
| 80 "Chicago", | 88 "Chicago", |
| 81 "Indianapolis"); | 89 "Indianapolis"); |
| 82 string16 summary3 = credit_card3.PreviewSummary(); | 90 string16 summary3 = credit_card3.PreviewSummary(); |
| 83 EXPECT_EQ(summary3, string16(ASCIIToUTF16("************9012"))); | 91 EXPECT_EQ(summary3, string16(ASCIIToUTF16("************9012"))); |
| 92 string16 obfuscated3 = credit_card3.ObfuscatedNumber(); |
| 93 EXPECT_EQ(obfuscated3, string16(ASCIIToUTF16("************9012"))); |
| 84 | 94 |
| 85 // Case 4: Have everything. | 95 // Case 4: Have everything. |
| 86 CreditCard credit_card4(string16(), 0); | 96 CreditCard credit_card4(string16(), 0); |
| 87 autofill_unittest::SetCreditCardInfo( | 97 autofill_unittest::SetCreditCardInfo( |
| 88 &credit_card4, | 98 &credit_card4, |
| 89 "Corporate", | 99 "Corporate", |
| 90 "John Dillinger", | 100 "John Dillinger", |
| 91 "Visa", | 101 "Visa", |
| 92 "123456789012", | 102 "123456789012", |
| 93 "01", | 103 "01", |
| 94 "2010", | 104 "2010", |
| 95 "123", | 105 "123", |
| 96 "Chicago", | 106 "Chicago", |
| 97 "Indianapolis"); | 107 "Indianapolis"); |
| 98 string16 summary4 = credit_card4.PreviewSummary(); | 108 string16 summary4 = credit_card4.PreviewSummary(); |
| 99 EXPECT_EQ(summary4, string16(ASCIIToUTF16("************9012, Exp: 01/2010"))); | 109 EXPECT_EQ(summary4, string16(ASCIIToUTF16("************9012, Exp: 01/2010"))); |
| 110 string16 obfuscated4 = credit_card4.ObfuscatedNumber(); |
| 111 EXPECT_EQ(obfuscated4, string16(ASCIIToUTF16("************9012"))); |
| 100 } | 112 } |
| 101 | 113 |
| 102 } // namespace | 114 } // namespace |
| 103 | 115 |
| OLD | NEW |