summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_credit_card_model_mac_unittest.mm
blob: e95c2dde274d81f3a3cb1e38a6268d4bf386a4e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/scoped_nsobject.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autofill/autofill_common_test.h"
#import "chrome/browser/autofill/autofill_credit_card_model_mac.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/cocoa/browser_test_helper.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

typedef CocoaTest AutoFillCreditCardModelTest;

TEST(AutoFillCreditCardModelTest, Basic) {
  // A basic test that creates a new instance and releases.
  // Aids valgrind leak detection.
  CreditCard credit_card;
  scoped_nsobject<AutoFillCreditCardModel> model(
      [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]);
  EXPECT_TRUE(model.get());
}

TEST(AutoFillCreditCardModelTest, InitializationFromCreditCard) {
  CreditCard credit_card;
  autofill_test::SetCreditCardInfo(&credit_card, "Corporate",
      "John Dillinger", "123456789012", "01", "2010");
  scoped_nsobject<AutoFillCreditCardModel> model(
      [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]);
  EXPECT_TRUE(model.get());

  EXPECT_TRUE([[model nameOnCard] isEqualToString:@"John Dillinger"]);
  EXPECT_TRUE([[model creditCardNumber] isEqualToString:@"123456789012"]);
  EXPECT_TRUE([[model expirationMonth] isEqualToString:@"01"]);
  EXPECT_TRUE([[model expirationYear] isEqualToString:@"2010"]);
}

TEST(AutoFillCreditCardModelTest, CopyModelToCreditCard) {
  CreditCard credit_card;
  autofill_test::SetCreditCardInfo(&credit_card, "Corporate",
      "John Dillinger", "123456789012", "01", "2010");
  scoped_nsobject<AutoFillCreditCardModel> model(
      [[AutoFillCreditCardModel alloc] initWithCreditCard:credit_card]);
  EXPECT_TRUE(model.get());

  [model setNameOnCard:@"John DillingerX"];
  [model setCreditCardNumber:@"223456789012"];
  [model setExpirationMonth:@"11"];
  [model setExpirationYear:@"2011"];

  [model copyModelToCreditCard:&credit_card];

  EXPECT_EQ(ASCIIToUTF16("John DillingerX"),
            credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME)));
  EXPECT_EQ(ASCIIToUTF16("223456789012"),
            credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)));
  EXPECT_EQ(ASCIIToUTF16("11"),
            credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)));
  EXPECT_EQ(ASCIIToUTF16("2011"),
            credit_card.GetFieldText(
                AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)));
}

}  // namespace