| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/scoped_nsobject.h" | |
| 6 #include "base/utf_string_conversions.h" | |
| 7 #include "chrome/browser/autofill/autofill_common_test.h" | |
| 8 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | |
| 9 #include "chrome/browser/autofill/credit_card.h" | |
| 10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | |
| 11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 typedef CocoaTest AutoFillCreditCardModelTest; | |
| 17 | |
| 18 TEST(AutoFillCreditCardModelTest, Basic) { | |
| 19 // A basic test that creates a new instance and releases. | |
| 20 // Aids valgrind leak detection. | |
| 21 CreditCard credit_card; | |
| 22 scoped_nsobject<AutoFillCreditCardModel> model( | |
| 23 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); | |
| 24 EXPECT_TRUE(model.get()); | |
| 25 } | |
| 26 | |
| 27 TEST(AutoFillCreditCardModelTest, InitializationFromCreditCard) { | |
| 28 CreditCard credit_card; | |
| 29 autofill_test::SetCreditCardInfo(&credit_card, | |
| 30 "John Dillinger", "123456789012", "01", "2010"); | |
| 31 scoped_nsobject<AutoFillCreditCardModel> model( | |
| 32 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); | |
| 33 EXPECT_TRUE(model.get()); | |
| 34 | |
| 35 EXPECT_TRUE([[model nameOnCard] isEqualToString:@"John Dillinger"]); | |
| 36 EXPECT_TRUE([[model creditCardNumber] isEqualToString:@"123456789012"]); | |
| 37 EXPECT_TRUE([[model expirationMonth] isEqualToString:@"01"]); | |
| 38 EXPECT_TRUE([[model expirationYear] isEqualToString:@"2010"]); | |
| 39 } | |
| 40 | |
| 41 TEST(AutoFillCreditCardModelTest, CopyModelToCreditCard) { | |
| 42 CreditCard credit_card; | |
| 43 autofill_test::SetCreditCardInfo(&credit_card, | |
| 44 "John Dillinger", "123456789012", "01", "2010"); | |
| 45 scoped_nsobject<AutoFillCreditCardModel> model( | |
| 46 [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]); | |
| 47 EXPECT_TRUE(model.get()); | |
| 48 | |
| 49 [model setNameOnCard:@"John DillingerX"]; | |
| 50 [model setCreditCardNumber:@"223456789012"]; | |
| 51 [model setExpirationMonth:@"11"]; | |
| 52 [model setExpirationYear:@"2011"]; | |
| 53 | |
| 54 [model copyModelToCreditCard:&credit_card]; | |
| 55 | |
| 56 EXPECT_EQ(ASCIIToUTF16("John DillingerX"), | |
| 57 credit_card.GetFieldText(AutofillType(CREDIT_CARD_NAME))); | |
| 58 EXPECT_EQ(ASCIIToUTF16("223456789012"), | |
| 59 credit_card.GetFieldText(AutofillType(CREDIT_CARD_NUMBER))); | |
| 60 EXPECT_EQ(ASCIIToUTF16("11"), | |
| 61 credit_card.GetFieldText(AutofillType(CREDIT_CARD_EXP_MONTH))); | |
| 62 EXPECT_EQ(ASCIIToUTF16("2011"), | |
| 63 credit_card.GetFieldText( | |
| 64 AutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| OLD | NEW |