OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 8 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
9 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 9 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
10 #include "components/autofill/content/browser/wallet/wallet_items.h" | 10 #include "components/autofill/content/browser/wallet/wallet_items.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 base::string16 unused, unused2; | 78 base::string16 unused, unused2; |
79 EXPECT_FALSE(wrapper.GetDisplayText(&unused, &unused2)); | 79 EXPECT_FALSE(wrapper.GetDisplayText(&unused, &unused2)); |
80 } | 80 } |
81 | 81 |
82 TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) { | 82 TEST(DataModelWrapperTest, GetDisplayTextEmptyWithoutPhone) { |
83 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( | 83 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( |
84 wallet::GetTestMaskedInstrument()); | 84 wallet::GetTestMaskedInstrument()); |
85 | 85 |
86 WalletInstrumentWrapper instrument_wrapper(instrument.get()); | 86 WalletInstrumentWrapper instrument_wrapper(instrument.get()); |
87 base::string16 unused, unused2; | 87 base::string16 unused, unused2; |
88 ASSERT_TRUE(instrument_wrapper.GetDisplayText(&unused, &unused2)); | 88 EXPECT_TRUE(instrument_wrapper.GetDisplayText(&unused, &unused2)); |
89 | 89 |
90 WalletAddressWrapper address_wrapper(&instrument->address()); | 90 WalletAddressWrapper address_wrapper(&instrument->address()); |
91 ASSERT_TRUE(address_wrapper.GetDisplayText(&unused, &unused2)); | 91 EXPECT_TRUE(address_wrapper.GetDisplayText(&unused, &unused2)); |
92 | 92 |
93 const_cast<wallet::Address*>(&instrument->address())->set_phone_number( | 93 const_cast<wallet::Address*>(&instrument->address())->SetPhoneNumber( |
94 string16()); | 94 string16()); |
95 | 95 |
96 ASSERT_TRUE( | 96 EXPECT_EQ(base::string16(), |
97 instrument_wrapper.GetInfo( | 97 instrument_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
98 AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()); | |
99 EXPECT_FALSE(instrument_wrapper.GetDisplayText(&unused, &unused2)); | 98 EXPECT_FALSE(instrument_wrapper.GetDisplayText(&unused, &unused2)); |
100 | 99 |
101 ASSERT_TRUE( | 100 EXPECT_EQ(base::string16(), |
102 address_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()); | 101 address_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
103 EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2)); | 102 EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2)); |
104 } | 103 } |
105 | 104 |
| 105 TEST(DataModelWrapperTest, GetDisplayPhoneNumber) { |
| 106 const base::string16 national_unformatted = ASCIIToUTF16("3104567890"); |
| 107 const base::string16 national_formatted = ASCIIToUTF16("(310) 456-7890"); |
| 108 const base::string16 international_unformatted = ASCIIToUTF16("13104567890"); |
| 109 const base::string16 international_formatted = |
| 110 ASCIIToUTF16("+1 310-456-7890"); |
| 111 const base::string16 user_formatted = ASCIIToUTF16("310.456 78 90"); |
| 112 |
| 113 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( |
| 114 wallet::GetTestMaskedInstrument()); |
| 115 AutofillProfile profile(test::GetVerifiedProfile()); |
| 116 |
| 117 // No matter what format a wallet number is in, it gets formatted in a |
| 118 // standard way. |
| 119 WalletInstrumentWrapper instrument_wrapper(instrument.get()); |
| 120 const_cast<wallet::Address*>(&instrument->address())-> |
| 121 SetPhoneNumber(national_unformatted); |
| 122 EXPECT_EQ(national_formatted, |
| 123 instrument_wrapper.GetInfoForDisplay( |
| 124 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 125 WalletAddressWrapper address_wrapper(&instrument->address()); |
| 126 EXPECT_EQ(national_formatted, |
| 127 address_wrapper.GetInfoForDisplay( |
| 128 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 129 AutofillProfileWrapper profile_wrapper(&profile); |
| 130 |
| 131 const_cast<wallet::Address*>(&instrument->address())-> |
| 132 SetPhoneNumber(national_formatted); |
| 133 EXPECT_EQ(national_formatted, |
| 134 instrument_wrapper.GetInfoForDisplay( |
| 135 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 136 EXPECT_EQ(national_formatted, |
| 137 address_wrapper.GetInfoForDisplay( |
| 138 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 139 |
| 140 const_cast<wallet::Address*>(&instrument->address())-> |
| 141 SetPhoneNumber(international_unformatted); |
| 142 EXPECT_EQ(national_formatted, |
| 143 instrument_wrapper.GetInfoForDisplay( |
| 144 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 145 EXPECT_EQ(national_formatted, |
| 146 address_wrapper.GetInfoForDisplay( |
| 147 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 148 |
| 149 // Autofill numbers that are unformatted get formatted either nationally or |
| 150 // internationally depending on the presence of a country code. Formatted |
| 151 // numbers stay formatted. |
| 152 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, international_unformatted); |
| 153 EXPECT_EQ(international_formatted, |
| 154 profile_wrapper.GetInfoForDisplay( |
| 155 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 156 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_unformatted); |
| 157 EXPECT_EQ(national_formatted, |
| 158 profile_wrapper.GetInfoForDisplay( |
| 159 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 160 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_formatted); |
| 161 EXPECT_EQ(national_formatted, |
| 162 profile_wrapper.GetInfoForDisplay( |
| 163 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 164 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, user_formatted); |
| 165 EXPECT_EQ(user_formatted, |
| 166 profile_wrapper.GetInfoForDisplay( |
| 167 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 168 |
| 169 } |
| 170 |
106 } // namespace autofill | 171 } // namespace autofill |
OLD | NEW |