| 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, PreviewSummaryAndObfuscatedNumberStrings) { | 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(string16(), summary0); |
| 20 string16 obfuscated0 = credit_card0.ObfuscatedNumber(); | 20 string16 obfuscated0 = credit_card0.ObfuscatedNumber(); |
| 21 EXPECT_EQ(obfuscated0, string16()); | 21 EXPECT_EQ(string16(), obfuscated0); |
| 22 | 22 |
| 23 // Case 00: Empty credit card with empty strings. | 23 // Case 00: Empty credit card with empty strings. |
| 24 CreditCard credit_card00(string16(), 0); | 24 CreditCard credit_card00(string16(), 0); |
| 25 autofill_unittest::SetCreditCardInfo(&credit_card00, "Corporate", | 25 autofill_unittest::SetCreditCardInfo(&credit_card00, "Corporate", |
| 26 "John Dillinger", "Visa", "", "", "", "Chicago"); | 26 "John Dillinger", "Visa", "", "", "", "Chicago"); |
| 27 string16 summary00 = credit_card00.PreviewSummary(); | 27 string16 summary00 = credit_card00.PreviewSummary(); |
| 28 EXPECT_EQ(summary00, string16()); | 28 EXPECT_EQ(string16(), summary00); |
| 29 string16 obfuscated00 = credit_card00.ObfuscatedNumber(); | 29 string16 obfuscated00 = credit_card00.ObfuscatedNumber(); |
| 30 EXPECT_EQ(obfuscated00, string16()); | 30 EXPECT_EQ(string16(), obfuscated00); |
| 31 | 31 |
| 32 // Case 1: No credit card number. | 32 // Case 1: No credit card number. |
| 33 CreditCard credit_card1(string16(), 0); | 33 CreditCard credit_card1(string16(), 0); |
| 34 autofill_unittest::SetCreditCardInfo(&credit_card1, "Corporate", | 34 autofill_unittest::SetCreditCardInfo(&credit_card1, "Corporate", |
| 35 "John Dillinger", "Visa", "", "01", "2010", "Chicago"); | 35 "John Dillinger", "Visa", "", "01", "2010", "Chicago"); |
| 36 string16 summary1 = credit_card1.PreviewSummary(); | 36 string16 summary1 = credit_card1.PreviewSummary(); |
| 37 EXPECT_EQ(summary1, string16()); | 37 EXPECT_EQ(string16(), summary1); |
| 38 string16 obfuscated1 = credit_card1.ObfuscatedNumber(); | 38 string16 obfuscated1 = credit_card1.ObfuscatedNumber(); |
| 39 EXPECT_EQ(obfuscated1, string16()); | 39 EXPECT_EQ(string16(), obfuscated1); |
| 40 | 40 |
| 41 // Case 2: No month. | 41 // Case 2: No month. |
| 42 CreditCard credit_card2(string16(), 0); | 42 CreditCard credit_card2(string16(), 0); |
| 43 autofill_unittest::SetCreditCardInfo(&credit_card2, "Corporate", | 43 autofill_unittest::SetCreditCardInfo(&credit_card2, "Corporate", |
| 44 "John Dillinger", "Visa", "123456789012", "", "2010", "Chicago"); | 44 "John Dillinger", "Visa", "123456789012", "", "2010", "Chicago"); |
| 45 string16 summary2 = credit_card2.PreviewSummary(); | 45 string16 summary2 = credit_card2.PreviewSummary(); |
| 46 EXPECT_EQ(summary2, string16(ASCIIToUTF16("************9012"))); | 46 EXPECT_EQ(string16(ASCIIToUTF16("************9012")), summary2); |
| 47 string16 obfuscated2 = credit_card2.ObfuscatedNumber(); | 47 string16 obfuscated2 = credit_card2.ObfuscatedNumber(); |
| 48 EXPECT_EQ(obfuscated2, string16(ASCIIToUTF16("************9012"))); | 48 EXPECT_EQ(string16(ASCIIToUTF16("************9012")), obfuscated2); |
| 49 | 49 |
| 50 // Case 3: No year. | 50 // Case 3: No year. |
| 51 CreditCard credit_card3(string16(), 0); | 51 CreditCard credit_card3(string16(), 0); |
| 52 autofill_unittest::SetCreditCardInfo(&credit_card3, "Corporate", | 52 autofill_unittest::SetCreditCardInfo(&credit_card3, "Corporate", |
| 53 "John Dillinger", "Visa", "123456789012", "01", "", "Chicago"); | 53 "John Dillinger", "Visa", "123456789012", "01", "", "Chicago"); |
| 54 string16 summary3 = credit_card3.PreviewSummary(); | 54 string16 summary3 = credit_card3.PreviewSummary(); |
| 55 EXPECT_EQ(summary3, string16(ASCIIToUTF16("************9012"))); | 55 EXPECT_EQ(string16(ASCIIToUTF16("************9012")), summary3); |
| 56 string16 obfuscated3 = credit_card3.ObfuscatedNumber(); | 56 string16 obfuscated3 = credit_card3.ObfuscatedNumber(); |
| 57 EXPECT_EQ(obfuscated3, string16(ASCIIToUTF16("************9012"))); | 57 EXPECT_EQ(string16(ASCIIToUTF16("************9012")), obfuscated3); |
| 58 | 58 |
| 59 // Case 4: Have everything. | 59 // Case 4: Have everything. |
| 60 CreditCard credit_card4(string16(), 0); | 60 CreditCard credit_card4(string16(), 0); |
| 61 autofill_unittest::SetCreditCardInfo(&credit_card4, "Corporate", | 61 autofill_unittest::SetCreditCardInfo(&credit_card4, "Corporate", |
| 62 "John Dillinger", "Visa", "123456789012", "01", "2010", "Chicago"); | 62 "John Dillinger", "Visa", "123456789012", "01", "2010", "Chicago"); |
| 63 string16 summary4 = credit_card4.PreviewSummary(); | 63 string16 summary4 = credit_card4.PreviewSummary(); |
| 64 EXPECT_EQ(summary4, string16(ASCIIToUTF16("************9012, Exp: 01/2010"))); | 64 EXPECT_EQ(string16(ASCIIToUTF16("************9012, Exp: 01/2010")), summary4); |
| 65 string16 obfuscated4 = credit_card4.ObfuscatedNumber(); | 65 string16 obfuscated4 = credit_card4.ObfuscatedNumber(); |
| 66 EXPECT_EQ(obfuscated4, string16(ASCIIToUTF16("************9012"))); | 66 EXPECT_EQ(string16(ASCIIToUTF16("************9012")), obfuscated4); |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| OLD | NEW |