| 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/scoped_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
| 6 #include "chrome/browser/autofill/autofill_common_unittest.h" | 6 #include "chrome/browser/autofill/autofill_common_unittest.h" |
| 7 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | 7 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" |
| 8 #include "chrome/browser/autofill/credit_card.h" | 8 #include "chrome/browser/autofill/credit_card.h" |
| 9 #include "chrome/browser/cocoa/browser_test_helper.h" | 9 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 typedef CocoaTest AutoFillCreditCardModelTest; | 15 typedef CocoaTest AutoFillCreditCardModelTest; |
| 16 | 16 |
| 17 TEST(AutoFillCreditCardModelTest, Basic) { | 17 TEST(AutoFillCreditCardModelTest, Basic) { |
| 18 // A basic test that creates a new instance and releases. | 18 // A basic test that creates a new instance and releases. |
| 19 // Aids valgrind leak detection. | 19 // Aids valgrind leak detection. |
| 20 CreditCard credit_card(ASCIIToUTF16("myCC"), 0); | 20 CreditCard credit_card(ASCIIToUTF16("myCC"), 0); |
| 21 scoped_nsobject<AutoFillCreditCardModel> model( | 21 scoped_nsobject<AutoFillCreditCardModel> model( |
| 22 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); | 22 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); |
| 23 EXPECT_TRUE(model.get()); | 23 EXPECT_TRUE(model.get()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 TEST(AutoFillCreditCardModelTest, InitializationFromCreditCard) { | 26 TEST(AutoFillCreditCardModelTest, InitializationFromCreditCard) { |
| 27 CreditCard credit_card(string16(), 0); | 27 CreditCard credit_card(string16(), 0); |
| 28 autofill_unittest::SetCreditCardInfo( | 28 autofill_unittest::SetCreditCardInfo(&credit_card, "Corporate", |
| 29 &credit_card, | 29 "John Dillinger", "Visa", "123456789012", "01", "2010", "Chicago"); |
| 30 "Corporate", | |
| 31 "John Dillinger", | |
| 32 "Visa", | |
| 33 "123456789012", | |
| 34 "01", | |
| 35 "2010", | |
| 36 "123", | |
| 37 "Chicago", | |
| 38 "Indianapolis"); | |
| 39 scoped_nsobject<AutoFillCreditCardModel> model( | 30 scoped_nsobject<AutoFillCreditCardModel> model( |
| 40 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); | 31 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); |
| 41 EXPECT_TRUE(model.get()); | 32 EXPECT_TRUE(model.get()); |
| 42 | 33 |
| 43 EXPECT_TRUE([[model label] isEqualToString:@"Corporate"]); | 34 EXPECT_TRUE([[model label] isEqualToString:@"Corporate"]); |
| 44 EXPECT_TRUE([[model nameOnCard] isEqualToString:@"John Dillinger"]); | 35 EXPECT_TRUE([[model nameOnCard] isEqualToString:@"John Dillinger"]); |
| 45 EXPECT_TRUE([[model creditCardNumber] isEqualToString:@"123456789012"]); | 36 EXPECT_TRUE([[model creditCardNumber] isEqualToString:@"123456789012"]); |
| 46 EXPECT_TRUE([[model expirationMonth] isEqualToString:@"01"]); | 37 EXPECT_TRUE([[model expirationMonth] isEqualToString:@"01"]); |
| 47 EXPECT_TRUE([[model expirationYear] isEqualToString:@"2010"]); | 38 EXPECT_TRUE([[model expirationYear] isEqualToString:@"2010"]); |
| 48 EXPECT_TRUE([[model billingAddress] isEqualToString:@"Chicago"]); | 39 EXPECT_TRUE([[model billingAddress] isEqualToString:@"Chicago"]); |
| 49 } | 40 } |
| 50 | 41 |
| 51 TEST(AutoFillCreditCardModelTest, CopyModelToCreditCard) { | 42 TEST(AutoFillCreditCardModelTest, CopyModelToCreditCard) { |
| 52 CreditCard credit_card(string16(), 0); | 43 CreditCard credit_card(string16(), 0); |
| 53 autofill_unittest::SetCreditCardInfo( | 44 autofill_unittest::SetCreditCardInfo(&credit_card, "Corporate", |
| 54 &credit_card, | 45 "John Dillinger", "Visa", "123456789012", "01", "2010", "Chicago"); |
| 55 "Corporate", | |
| 56 "John Dillinger", | |
| 57 "Visa", | |
| 58 "123456789012", | |
| 59 "01", | |
| 60 "2010", | |
| 61 "123", | |
| 62 "Chicago", | |
| 63 "Indianapolis"); | |
| 64 scoped_nsobject<AutoFillCreditCardModel> model( | 46 scoped_nsobject<AutoFillCreditCardModel> model( |
| 65 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); | 47 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); |
| 66 EXPECT_TRUE(model.get()); | 48 EXPECT_TRUE(model.get()); |
| 67 | 49 |
| 68 [model setLabel:@"CorporateX"]; | 50 [model setLabel:@"CorporateX"]; |
| 69 [model setNameOnCard:@"John DillingerX"]; | 51 [model setNameOnCard:@"John DillingerX"]; |
| 70 [model setCreditCardNumber:@"223456789012"]; | 52 [model setCreditCardNumber:@"223456789012"]; |
| 71 [model setExpirationMonth:@"11"]; | 53 [model setExpirationMonth:@"11"]; |
| 72 [model setExpirationYear:@"2011"]; | 54 [model setExpirationYear:@"2011"]; |
| 73 [model setBillingAddress:@"New York"]; | 55 [model setBillingAddress:@"New York"]; |
| 74 | 56 |
| 75 [model copyModelToCreditCard:&credit_card]; | 57 [model copyModelToCreditCard:&credit_card]; |
| 76 | 58 |
| 77 EXPECT_EQ(ASCIIToUTF16("CorporateX"), credit_card.Label()); | 59 EXPECT_EQ(ASCIIToUTF16("CorporateX"), credit_card.Label()); |
| 78 EXPECT_EQ(ASCIIToUTF16("John DillingerX"), | 60 EXPECT_EQ(ASCIIToUTF16("John DillingerX"), |
| 79 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME))); | 61 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME))); |
| 80 EXPECT_EQ(ASCIIToUTF16("223456789012"), | 62 EXPECT_EQ(ASCIIToUTF16("223456789012"), |
| 81 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))); | 63 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))); |
| 82 EXPECT_EQ(ASCIIToUTF16("11"), | 64 EXPECT_EQ(ASCIIToUTF16("11"), |
| 83 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH))); | 65 credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH))); |
| 84 EXPECT_EQ(ASCIIToUTF16("2011"), | 66 EXPECT_EQ(ASCIIToUTF16("2011"), |
| 85 credit_card.GetFieldText( | 67 credit_card.GetFieldText( |
| 86 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); | 68 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); |
| 87 EXPECT_EQ(ASCIIToUTF16("New York"), credit_card.billing_address()); | 69 EXPECT_EQ(ASCIIToUTF16("New York"), credit_card.billing_address()); |
| 88 } | 70 } |
| 89 | 71 |
| 90 } // namespace | 72 } // namespace |
| OLD | NEW |