data_model_wrapper_unittest.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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. 4 5#include "base/memory/scoped_ptr.h" 6#include "base/strings/string_number_conversions.h" 7#include "chrome/browser/ui/autofill/autofill_dialog_models.h" 8#include "chrome/browser/ui/autofill/data_model_wrapper.h" 9#include "components/autofill/browser/autofill_common_test.h" 10#include "components/autofill/browser/autofill_profile.h" 11#include "components/autofill/browser/credit_card.h" 12#include "components/autofill/browser/field_types.h" 13#include "components/autofill/content/browser/wallet/wallet_items.h" 14#include "components/autofill/content/browser/wallet/wallet_test_util.h" 15#include "testing/gtest/include/gtest/gtest.h" 16 17namespace autofill { 18 19TEST(AutofillCreditCardWrapperTest, GetInfoCreditCardExpMonth) { 20 CreditCard card; 21 MonthComboboxModel model; 22 for (int month = 1; month <= 12; ++month) { 23 card.SetRawInfo(CREDIT_CARD_EXP_MONTH, base::IntToString16(month)); 24 AutofillCreditCardWrapper wrapper(&card); 25 EXPECT_EQ(model.GetItemAt(month), wrapper.GetInfo(CREDIT_CARD_EXP_MONTH)); 26 } 27} 28 29TEST(AutofillCreditCardWrapperTest, GetDisplayTextEmptyWhenExpired) { 30 CreditCard card; 31 AutofillCreditCardWrapper wrapper(&card); 32 EXPECT_TRUE(wrapper.GetDisplayText().empty()); 33} 34 35TEST(WalletInstrumentWrapperTest, GetInfoCreditCardExpMonth) { 36 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( 37 wallet::GetTestMaskedInstrument()); 38 MonthComboboxModel model; 39 for (int month = 1; month <= 12; ++month) { 40 instrument->expiration_month_ = month; 41 WalletInstrumentWrapper wrapper(instrument.get()); 42 EXPECT_EQ(model.GetItemAt(month), wrapper.GetInfo(CREDIT_CARD_EXP_MONTH)); 43 } 44} 45 46TEST(WalletInstrumentWrapperTest, GetDisplayTextEmptyWhenExpired) { 47 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( 48 wallet::GetTestMaskedInstrument()); 49 instrument->status_ = wallet::WalletItems::MaskedInstrument::EXPIRED; 50 WalletInstrumentWrapper wrapper(instrument.get()); 51 EXPECT_TRUE(wrapper.GetDisplayText().empty()); 52} 53 54TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) { 55 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( 56 wallet::GetTestMaskedInstrument()); 57 58 WalletInstrumentWrapper instrument_wrapper(instrument.get()); 59 ASSERT_FALSE(instrument_wrapper.GetDisplayText().empty()); 60 61 WalletAddressWrapper address_wrapper(&instrument->address()); 62 ASSERT_FALSE(address_wrapper.GetDisplayText().empty()); 63 64 const_cast<wallet::Address*>(&instrument->address())->set_phone_number( 65 string16()); 66 67 ASSERT_TRUE(instrument_wrapper.GetInfo(PHONE_HOME_WHOLE_NUMBER).empty()); 68 EXPECT_TRUE(instrument_wrapper.GetDisplayText().empty()); 69 70 ASSERT_TRUE(address_wrapper.GetInfo(PHONE_HOME_WHOLE_NUMBER).empty()); 71 EXPECT_TRUE(address_wrapper.GetDisplayText().empty()); 72} 73 74} // autofill 75