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/guid.h" | 5 #include "base/guid.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 9 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
10 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 10 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 EXPECT_EQ(base::string16(), | 91 EXPECT_EQ(base::string16(), |
92 address_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 92 address_wrapper.GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
93 EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2)); | 93 EXPECT_FALSE(address_wrapper.GetDisplayText(&unused, &unused2)); |
94 } | 94 } |
95 | 95 |
96 TEST(DataModelWrapperTest, GetDisplayText) { | 96 TEST(DataModelWrapperTest, GetDisplayText) { |
97 AutofillProfile profile = test::GetFullProfile(); | 97 AutofillProfile profile = test::GetFullProfile(); |
98 base::string16 vertical, horizontal; | 98 base::string16 vertical, horizontal; |
99 EXPECT_TRUE( | 99 EXPECT_TRUE( |
100 AutofillProfileWrapper(&profile).GetDisplayText(&horizontal, &vertical)); | 100 AutofillProfileWrapper(&profile).GetDisplayText(&horizontal, &vertical)); |
101 EXPECT_EQ( | 101 EXPECT_EQ(ASCIIToUTF16( |
102 ASCIIToUTF16("John H. Doe, 666 Erebus St., Apt 8, Elysium, CA 91111\n" | 102 "John H. Doe, 666 Erebus St., Apt 8, Elysium, CA 91111\n" |
103 "johndoe@hades.com\n" | 103 "johndoe@hades.com\n" |
104 "+1 650-211-1111"), | 104 "1 650-211-1111"), |
105 horizontal); | 105 horizontal); |
106 EXPECT_EQ( | 106 EXPECT_EQ(ASCIIToUTF16( |
107 ASCIIToUTF16("John H. Doe\n" | 107 "John H. Doe\n" |
108 "666 Erebus St.\n" | 108 "666 Erebus St.\n" |
109 "Apt 8\n" | 109 "Apt 8\n" |
110 "Elysium, CA 91111\n" | 110 "Elysium, CA 91111\n" |
111 "johndoe@hades.com\n" | 111 "johndoe@hades.com\n" |
112 "+1 650-211-1111"), | 112 "1 650-211-1111"), |
113 vertical); | 113 vertical); |
114 | 114 |
115 // A Japanese address. | 115 // A Japanese address. |
116 AutofillProfile foreign_profile( | 116 AutofillProfile foreign_profile( |
117 base::GenerateGUID(), "http://www.example.com/"); | 117 base::GenerateGUID(), "http://www.example.com/"); |
118 foreign_profile.SetRawInfo( | 118 foreign_profile.SetRawInfo( |
119 ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP")); | 119 ADDRESS_HOME_COUNTRY, ASCIIToUTF16("JP")); |
120 foreign_profile.SetRawInfo( | 120 foreign_profile.SetRawInfo( |
121 ADDRESS_HOME_STATE, | 121 ADDRESS_HOME_STATE, |
122 base::WideToUTF16(L"\u6771\u4EAC\u90FD")); | 122 base::WideToUTF16(L"\u6771\u4EAC\u90FD")); |
123 foreign_profile.SetRawInfo( | 123 foreign_profile.SetRawInfo( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 WalletInstrumentWrapper wrapper(instrument.get()); | 163 WalletInstrumentWrapper wrapper(instrument.get()); |
164 EXPECT_EQ(model.GetItemAt(month), | 164 EXPECT_EQ(model.GetItemAt(month), |
165 wrapper.GetInfo(AutofillType(CREDIT_CARD_EXP_MONTH))); | 165 wrapper.GetInfo(AutofillType(CREDIT_CARD_EXP_MONTH))); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 TEST(DataModelWrapperTest, GetDisplayPhoneNumber) { | 169 TEST(DataModelWrapperTest, GetDisplayPhoneNumber) { |
170 const base::string16 national_unformatted = ASCIIToUTF16("3104567890"); | 170 const base::string16 national_unformatted = ASCIIToUTF16("3104567890"); |
171 const base::string16 national_formatted = ASCIIToUTF16("(310) 456-7890"); | 171 const base::string16 national_formatted = ASCIIToUTF16("(310) 456-7890"); |
172 const base::string16 international_unformatted = ASCIIToUTF16("13104567890"); | 172 const base::string16 international_unformatted = ASCIIToUTF16("13104567890"); |
173 const base::string16 international_formatted = | 173 const base::string16 international_unformatted_with_plus = |
174 ASCIIToUTF16("+1 310-456-7890"); | 174 ASCIIToUTF16("+13104567890"); |
| 175 const base::string16 international_formatted = ASCIIToUTF16("1 310-456-7890"); |
175 const base::string16 user_formatted = ASCIIToUTF16("310.456 78 90"); | 176 const base::string16 user_formatted = ASCIIToUTF16("310.456 78 90"); |
176 | 177 |
177 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( | 178 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( |
178 wallet::GetTestMaskedInstrument()); | 179 wallet::GetTestMaskedInstrument()); |
179 AutofillProfile profile(test::GetVerifiedProfile()); | 180 AutofillProfile profile(test::GetVerifiedProfile()); |
180 | 181 |
181 // No matter what format a wallet number is in, it gets formatted in a | 182 // No matter what format a wallet number is in, it gets formatted in a |
182 // standard way. | 183 // standard way. |
183 WalletInstrumentWrapper instrument_wrapper(instrument.get()); | 184 WalletInstrumentWrapper instrument_wrapper(instrument.get()); |
184 const_cast<wallet::Address*>(&instrument->address())-> | 185 const_cast<wallet::Address*>(&instrument->address())-> |
(...skipping 18 matching lines...) Expand all Loading... |
203 | 204 |
204 const_cast<wallet::Address*>(&instrument->address())-> | 205 const_cast<wallet::Address*>(&instrument->address())-> |
205 SetPhoneNumber(international_unformatted); | 206 SetPhoneNumber(international_unformatted); |
206 EXPECT_EQ(national_formatted, | 207 EXPECT_EQ(national_formatted, |
207 instrument_wrapper.GetInfoForDisplay( | 208 instrument_wrapper.GetInfoForDisplay( |
208 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 209 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
209 EXPECT_EQ(national_formatted, | 210 EXPECT_EQ(national_formatted, |
210 address_wrapper.GetInfoForDisplay( | 211 address_wrapper.GetInfoForDisplay( |
211 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 212 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
212 | 213 |
| 214 const_cast<wallet::Address*>(&instrument->address()) |
| 215 ->SetPhoneNumber(international_unformatted_with_plus); |
| 216 EXPECT_EQ(national_formatted, |
| 217 instrument_wrapper.GetInfoForDisplay( |
| 218 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 219 EXPECT_EQ( |
| 220 national_formatted, |
| 221 address_wrapper.GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 222 |
213 // Autofill numbers that are unformatted get formatted either nationally or | 223 // Autofill numbers that are unformatted get formatted either nationally or |
214 // internationally depending on the presence of a country code. Formatted | 224 // internationally depending on the presence of a country code. Formatted |
215 // numbers stay formatted. | 225 // numbers stay formatted. |
216 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, international_unformatted); | 226 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, international_unformatted); |
217 EXPECT_EQ(international_formatted, | 227 EXPECT_EQ(international_formatted, |
218 profile_wrapper.GetInfoForDisplay( | 228 profile_wrapper.GetInfoForDisplay( |
219 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 229 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 230 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 231 international_unformatted_with_plus); |
| 232 EXPECT_EQ( |
| 233 international_formatted, |
| 234 profile_wrapper.GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
220 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_unformatted); | 235 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_unformatted); |
221 EXPECT_EQ(national_formatted, | 236 EXPECT_EQ(national_formatted, |
222 profile_wrapper.GetInfoForDisplay( | 237 profile_wrapper.GetInfoForDisplay( |
223 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 238 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
224 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_formatted); | 239 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_formatted); |
225 EXPECT_EQ(national_formatted, | 240 EXPECT_EQ(national_formatted, |
226 profile_wrapper.GetInfoForDisplay( | 241 profile_wrapper.GetInfoForDisplay( |
227 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 242 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
228 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, user_formatted); | 243 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, user_formatted); |
229 EXPECT_EQ(user_formatted, | 244 EXPECT_EQ(user_formatted, |
230 profile_wrapper.GetInfoForDisplay( | 245 profile_wrapper.GetInfoForDisplay( |
231 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 246 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
232 | |
233 } | 247 } |
234 | 248 |
235 } // namespace autofill | 249 } // namespace autofill |
OLD | NEW |