Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / autofill / content / browser / wallet / full_wallet_unittest.cc
blob990bdcd6b21282fd63fb9dfc70a7b37739bb0095
1 // Copyright 2013 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.
5 #include "base/json/json_reader.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/values.h"
10 #include "components/autofill/content/browser/wallet/full_wallet.h"
11 #include "components/autofill/content/browser/wallet/wallet_test_util.h"
12 #include "components/autofill/core/browser/autofill_type.h"
13 #include "components/autofill/core/browser/field_types.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using base::ASCIIToUTF16;
18 namespace autofill {
19 namespace wallet {
21 class FullWalletTest : public testing::Test {
22 public:
23 FullWalletTest() {}
25 private:
26 DISALLOW_COPY_AND_ASSIGN(FullWalletTest);
29 TEST_F(FullWalletTest, RestLengthCorrectDecryptionTest) {
30 FullWallet full_wallet(12, 2012, "528512", "5ec4feecf9d6", GetTestAddress(),
31 GetTestShippingAddress());
32 std::vector<uint8> one_time_pad;
33 EXPECT_TRUE(base::HexStringToBytes("5F04A8704183", &one_time_pad));
34 full_wallet.set_one_time_pad(one_time_pad);
35 EXPECT_EQ(ASCIIToUTF16("5285121925598459"),
36 full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
37 EXPECT_EQ(ASCIIToUTF16("989"),
38 full_wallet.GetInfo(
39 "", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
42 TEST_F(FullWalletTest, RestLengthUnderDecryptionTest) {
43 FullWallet full_wallet(12, 2012, "528512", "4c567667e6", GetTestAddress(),
44 GetTestShippingAddress());
45 std::vector<uint8> one_time_pad;
46 EXPECT_TRUE(base::HexStringToBytes("063AD35324BF", &one_time_pad));
47 full_wallet.set_one_time_pad(one_time_pad);
48 EXPECT_EQ(ASCIIToUTF16("5285127106109719"),
49 full_wallet.GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
50 EXPECT_EQ(ASCIIToUTF16("385"),
51 full_wallet.GetInfo(
52 "", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
55 TEST_F(FullWalletTest, GetCreditCardInfo) {
56 FullWallet full_wallet(12, 2015, "528512", "1a068673eb0", GetTestAddress(),
57 GetTestShippingAddress());
59 EXPECT_EQ(ASCIIToUTF16("15"),
60 full_wallet.GetInfo(
61 "", AutofillType(CREDIT_CARD_EXP_2_DIGIT_YEAR)));
63 EXPECT_EQ(ASCIIToUTF16("12/15"),
64 full_wallet.GetInfo(
65 "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
67 EXPECT_EQ(ASCIIToUTF16("12/2015"),
68 full_wallet.GetInfo(
69 "", AutofillType(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR)));
71 std::vector<uint8> one_time_pad;
72 EXPECT_TRUE(base::HexStringToBytes("075DA779F98B", &one_time_pad));
73 full_wallet.set_one_time_pad(one_time_pad);
74 EXPECT_EQ(ASCIIToUTF16("MasterCard"),
75 full_wallet.GetInfo("", AutofillType(CREDIT_CARD_TYPE)));
78 TEST_F(FullWalletTest, CreateFullWalletFromClearTextData) {
79 scoped_ptr<FullWallet> full_wallet =
80 FullWallet::CreateFullWalletFromClearText(
81 11, 2012,
82 "5555555555554444", "123",
83 GetTestAddress(), GetTestShippingAddress());
84 EXPECT_EQ(ASCIIToUTF16("5555555555554444"),
85 full_wallet->GetInfo("", AutofillType(CREDIT_CARD_NUMBER)));
86 EXPECT_EQ(ASCIIToUTF16("MasterCard"),
87 full_wallet->GetInfo("", AutofillType(CREDIT_CARD_TYPE)));
88 EXPECT_EQ(ASCIIToUTF16("123"),
89 full_wallet->GetInfo(
90 "", AutofillType(CREDIT_CARD_VERIFICATION_CODE)));
91 EXPECT_EQ(ASCIIToUTF16("11/12"),
92 full_wallet->GetInfo(
93 "", AutofillType(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)));
94 EXPECT_TRUE(GetTestAddress()->EqualsIgnoreID(
95 *full_wallet->billing_address()));
96 EXPECT_TRUE(GetTestShippingAddress()->EqualsIgnoreID(
97 *full_wallet->shipping_address()));
100 } // namespace wallet
101 } // namespace autofill