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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( |
102 ASCIIToUTF16("John H. Doe, 666 Erebus St., Apt 8, Elysium, CA 91111\n" | 102 ASCIIToUTF16("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( |
107 ASCIIToUTF16("John H. Doe\n" | 107 ASCIIToUTF16("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")); |
(...skipping 40 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_unformatted_with_plus = |
| 174 ASCIIToUTF16("+13104567890"); |
173 const base::string16 international_formatted = | 175 const base::string16 international_formatted = |
174 ASCIIToUTF16("+1 310-456-7890"); | 176 ASCIIToUTF16("1 310-456-7890"); |
175 const base::string16 user_formatted = ASCIIToUTF16("310.456 78 90"); | 177 const base::string16 user_formatted = ASCIIToUTF16("310.456 78 90"); |
176 | 178 |
177 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( | 179 scoped_ptr<wallet::WalletItems::MaskedInstrument> instrument( |
178 wallet::GetTestMaskedInstrument()); | 180 wallet::GetTestMaskedInstrument()); |
179 AutofillProfile profile(test::GetVerifiedProfile()); | 181 AutofillProfile profile(test::GetVerifiedProfile()); |
180 | 182 |
181 // No matter what format a wallet number is in, it gets formatted in a | 183 // No matter what format a wallet number is in, it gets formatted in a |
182 // standard way. | 184 // standard way. |
183 WalletInstrumentWrapper instrument_wrapper(instrument.get()); | 185 WalletInstrumentWrapper instrument_wrapper(instrument.get()); |
184 const_cast<wallet::Address*>(&instrument->address())-> | 186 const_cast<wallet::Address*>(&instrument->address())-> |
(...skipping 18 matching lines...) Expand all Loading... |
203 | 205 |
204 const_cast<wallet::Address*>(&instrument->address())-> | 206 const_cast<wallet::Address*>(&instrument->address())-> |
205 SetPhoneNumber(international_unformatted); | 207 SetPhoneNumber(international_unformatted); |
206 EXPECT_EQ(national_formatted, | 208 EXPECT_EQ(national_formatted, |
207 instrument_wrapper.GetInfoForDisplay( | 209 instrument_wrapper.GetInfoForDisplay( |
208 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 210 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
209 EXPECT_EQ(national_formatted, | 211 EXPECT_EQ(national_formatted, |
210 address_wrapper.GetInfoForDisplay( | 212 address_wrapper.GetInfoForDisplay( |
211 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 213 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
212 | 214 |
| 215 const_cast<wallet::Address*>(&instrument->address())-> |
| 216 SetPhoneNumber(international_unformatted_with_plus); |
| 217 EXPECT_EQ(national_formatted, |
| 218 instrument_wrapper.GetInfoForDisplay( |
| 219 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 220 EXPECT_EQ(national_formatted, |
| 221 address_wrapper.GetInfoForDisplay( |
| 222 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 223 |
213 // Autofill numbers that are unformatted get formatted either nationally or | 224 // Autofill numbers that are unformatted get formatted either nationally or |
214 // internationally depending on the presence of a country code. Formatted | 225 // internationally depending on the presence of a country code. Formatted |
215 // numbers stay formatted. | 226 // numbers stay formatted. |
216 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, international_unformatted); | 227 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, international_unformatted); |
217 EXPECT_EQ(international_formatted, | 228 EXPECT_EQ(international_formatted, |
218 profile_wrapper.GetInfoForDisplay( | 229 profile_wrapper.GetInfoForDisplay( |
219 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 230 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
| 231 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, |
| 232 international_unformatted_with_plus); |
| 233 EXPECT_EQ(international_formatted, |
| 234 profile_wrapper.GetInfoForDisplay( |
| 235 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
220 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_unformatted); | 236 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_unformatted); |
221 EXPECT_EQ(national_formatted, | 237 EXPECT_EQ(national_formatted, |
222 profile_wrapper.GetInfoForDisplay( | 238 profile_wrapper.GetInfoForDisplay( |
223 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 239 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
224 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_formatted); | 240 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, national_formatted); |
225 EXPECT_EQ(national_formatted, | 241 EXPECT_EQ(national_formatted, |
226 profile_wrapper.GetInfoForDisplay( | 242 profile_wrapper.GetInfoForDisplay( |
227 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 243 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
228 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, user_formatted); | 244 profile.SetRawInfo(PHONE_HOME_WHOLE_NUMBER, user_formatted); |
229 EXPECT_EQ(user_formatted, | 245 EXPECT_EQ(user_formatted, |
230 profile_wrapper.GetInfoForDisplay( | 246 profile_wrapper.GetInfoForDisplay( |
231 AutofillType(PHONE_HOME_WHOLE_NUMBER))); | 247 AutofillType(PHONE_HOME_WHOLE_NUMBER))); |
232 | |
233 } | 248 } |
234 | 249 |
235 } // namespace autofill | 250 } // namespace autofill |
OLD | NEW |