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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 using base::ASCIIToUTF16; | 22 using base::ASCIIToUTF16; |
23 | 23 |
24 namespace autofill { | 24 namespace autofill { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 base::string16 GetLabel(AutofillProfile* profile) { | 28 base::string16 GetLabel(AutofillProfile* profile) { |
29 std::vector<AutofillProfile*> profiles; | 29 std::vector<AutofillProfile*> profiles; |
30 profiles.push_back(profile); | 30 profiles.push_back(profile); |
31 std::vector<base::string16> labels; | 31 std::vector<base::string16> labels; |
32 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); | 32 AutofillProfile::CreateDifferentiatingLabels(profiles, "en-US", &labels); |
33 return labels[0]; | 33 return labels[0]; |
34 } | 34 } |
35 | 35 |
36 // Holds the autofill profile |first|, |middle| and |last| names. | 36 // Holds the autofill profile |first|, |middle| and |last| names. |
37 struct NameParts { | 37 struct NameParts { |
38 NameParts(const std::string& first, | 38 NameParts(const std::string& first, |
39 const std::string& middle, | 39 const std::string& middle, |
40 const std::string& last) | 40 const std::string& last) |
41 : first(first), middle(middle), last(last) {} | 41 : first(first), middle(middle), last(last) {} |
42 | 42 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for | 169 // Case 7a: "<firstname> <lastname>, <address>" - same as #7, except for |
170 // e-mail. | 170 // e-mail. |
171 AutofillProfile profile7a(base::GenerateGUID(), "https://www.example.com/"); | 171 AutofillProfile profile7a(base::GenerateGUID(), "https://www.example.com/"); |
172 test::SetProfileInfo(&profile7a, "Marion", "Mitchell", | 172 test::SetProfileInfo(&profile7a, "Marion", "Mitchell", |
173 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 173 "Morrison", "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
174 "Hollywood", "CA", "91601", "US", "16505678910"); | 174 "Hollywood", "CA", "91601", "US", "16505678910"); |
175 std::vector<AutofillProfile*> profiles; | 175 std::vector<AutofillProfile*> profiles; |
176 profiles.push_back(&profile7); | 176 profiles.push_back(&profile7); |
177 profiles.push_back(&profile7a); | 177 profiles.push_back(&profile7a); |
178 std::vector<base::string16> labels; | 178 std::vector<base::string16> labels; |
179 AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); | 179 AutofillProfile::CreateDifferentiatingLabels(profiles, "en-US", &labels); |
180 ASSERT_EQ(profiles.size(), labels.size()); | 180 ASSERT_EQ(profiles.size(), labels.size()); |
181 summary7 = labels[0]; | 181 summary7 = labels[0]; |
182 base::string16 summary7a = labels[1]; | 182 base::string16 summary7a = labels[1]; |
183 EXPECT_EQ(ASCIIToUTF16( | 183 EXPECT_EQ(ASCIIToUTF16( |
184 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); | 184 "Marion Mitchell Morrison, 123 Zoo St., johnwayne@me.xyz"), summary7); |
185 EXPECT_EQ(ASCIIToUTF16( | 185 EXPECT_EQ(ASCIIToUTF16( |
186 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); | 186 "Marion Mitchell Morrison, 123 Zoo St., marion@me.xyz"), summary7a); |
187 } | 187 } |
188 | 188 |
189 TEST(AutofillProfileTest, AdjustInferredLabels) { | 189 TEST(AutofillProfileTest, AdjustInferredLabels) { |
(...skipping 22 matching lines...) Expand all Loading... |
212 "Doe", | 212 "Doe", |
213 "janedoe@tertium.com", | 213 "janedoe@tertium.com", |
214 "Pluto Inc.", | 214 "Pluto Inc.", |
215 "123 Letha Shore.", | 215 "123 Letha Shore.", |
216 "", | 216 "", |
217 "Dis", "CA", | 217 "Dis", "CA", |
218 "91222", | 218 "91222", |
219 "US", | 219 "US", |
220 "12345678910"); | 220 "12345678910"); |
221 std::vector<base::string16> labels; | 221 std::vector<base::string16> labels; |
222 AutofillProfile::CreateDifferentiatingLabels(profiles.get(), &labels); | 222 AutofillProfile::CreateDifferentiatingLabels( |
| 223 profiles.get(), "en-US", &labels); |
223 ASSERT_EQ(2U, labels.size()); | 224 ASSERT_EQ(2U, labels.size()); |
224 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); | 225 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); |
225 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); | 226 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); |
226 | 227 |
227 profiles.push_back( | 228 profiles.push_back( |
228 new AutofillProfile(base::GenerateGUID(), "Chrome settings")); | 229 new AutofillProfile(base::GenerateGUID(), "Chrome settings")); |
229 test::SetProfileInfo( | 230 test::SetProfileInfo( |
230 profiles[2], | 231 profiles[2], |
231 "John", | 232 "John", |
232 "", | 233 "", |
233 "Doe", | 234 "Doe", |
234 "johndoe@tertium.com", | 235 "johndoe@tertium.com", |
235 "Underworld", | 236 "Underworld", |
236 "666 Erebus St.", | 237 "666 Erebus St.", |
237 "", | 238 "", |
238 "Elysium", "CA", | 239 "Elysium", "CA", |
239 "91111", | 240 "91111", |
240 "US", | 241 "US", |
241 "16502111111"); | 242 "16502111111"); |
242 labels.clear(); | 243 labels.clear(); |
243 AutofillProfile::CreateDifferentiatingLabels(profiles.get(), &labels); | 244 AutofillProfile::CreateDifferentiatingLabels( |
| 245 profiles.get(), "en-US", &labels); |
244 | 246 |
245 // Profile 0 and 2 inferred label now includes an e-mail. | 247 // Profile 0 and 2 inferred label now includes an e-mail. |
246 ASSERT_EQ(3U, labels.size()); | 248 ASSERT_EQ(3U, labels.size()); |
247 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"), | 249 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@hades.com"), |
248 labels[0]); | 250 labels[0]); |
249 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); | 251 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); |
250 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"), | 252 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., johndoe@tertium.com"), |
251 labels[2]); | 253 labels[2]); |
252 | 254 |
253 profiles.resize(2); | 255 profiles.resize(2); |
254 | 256 |
255 profiles.push_back( | 257 profiles.push_back( |
256 new AutofillProfile(base::GenerateGUID(), std::string())); | 258 new AutofillProfile(base::GenerateGUID(), std::string())); |
257 test::SetProfileInfo( | 259 test::SetProfileInfo( |
258 profiles[2], | 260 profiles[2], |
259 "John", | 261 "John", |
260 "", | 262 "", |
261 "Doe", | 263 "Doe", |
262 "johndoe@hades.com", | 264 "johndoe@hades.com", |
263 "Underworld", | 265 "Underworld", |
264 "666 Erebus St.", | 266 "666 Erebus St.", |
265 "", | 267 "", |
266 "Elysium", "CO", // State is different | 268 "Elysium", "CO", // State is different |
267 "91111", | 269 "91111", |
268 "US", | 270 "US", |
269 "16502111111"); | 271 "16502111111"); |
270 | 272 |
271 labels.clear(); | 273 labels.clear(); |
272 AutofillProfile::CreateDifferentiatingLabels(profiles.get(), &labels); | 274 AutofillProfile::CreateDifferentiatingLabels( |
| 275 profiles.get(), "en-US", &labels); |
273 | 276 |
274 // Profile 0 and 2 inferred label now includes a state. | 277 // Profile 0 and 2 inferred label now includes a state. |
275 ASSERT_EQ(3U, labels.size()); | 278 ASSERT_EQ(3U, labels.size()); |
276 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); | 279 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); |
277 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); | 280 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); |
278 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO"), labels[2]); | 281 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO"), labels[2]); |
279 | 282 |
280 profiles.push_back( | 283 profiles.push_back( |
281 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 284 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
282 test::SetProfileInfo( | 285 test::SetProfileInfo( |
283 profiles[3], | 286 profiles[3], |
284 "John", | 287 "John", |
285 "", | 288 "", |
286 "Doe", | 289 "Doe", |
287 "johndoe@hades.com", | 290 "johndoe@hades.com", |
288 "Underworld", | 291 "Underworld", |
289 "666 Erebus St.", | 292 "666 Erebus St.", |
290 "", | 293 "", |
291 "Elysium", "CO", // State is different for some. | 294 "Elysium", "CO", // State is different for some. |
292 "91111", | 295 "91111", |
293 "US", | 296 "US", |
294 "16504444444"); // Phone is different for some. | 297 "16504444444"); // Phone is different for some. |
295 | 298 |
296 labels.clear(); | 299 labels.clear(); |
297 AutofillProfile::CreateDifferentiatingLabels(profiles.get(), &labels); | 300 AutofillProfile::CreateDifferentiatingLabels( |
| 301 profiles.get(), "en-US", &labels); |
298 ASSERT_EQ(4U, labels.size()); | 302 ASSERT_EQ(4U, labels.size()); |
299 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); | 303 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); |
300 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); | 304 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); |
301 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16502111111"), | 305 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16502111111"), |
302 labels[2]); | 306 labels[2]); |
303 // This one differs from other ones by unique phone, so no need for extra | 307 // This one differs from other ones by unique phone, so no need for extra |
304 // information. | 308 // information. |
305 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16504444444"), | 309 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, 16504444444"), |
306 labels[3]); | 310 labels[3]); |
307 | 311 |
308 profiles.push_back( | 312 profiles.push_back( |
309 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 313 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
310 test::SetProfileInfo( | 314 test::SetProfileInfo( |
311 profiles[4], | 315 profiles[4], |
312 "John", | 316 "John", |
313 "", | 317 "", |
314 "Doe", | 318 "Doe", |
315 "johndoe@styx.com", // E-Mail is different for some. | 319 "johndoe@styx.com", // E-Mail is different for some. |
316 "Underworld", | 320 "Underworld", |
317 "666 Erebus St.", | 321 "666 Erebus St.", |
318 "", | 322 "", |
319 "Elysium", "CO", // State is different for some. | 323 "Elysium", "CO", // State is different for some. |
320 "91111", | 324 "91111", |
321 "US", | 325 "US", |
322 "16504444444"); // Phone is different for some. | 326 "16504444444"); // Phone is different for some. |
323 | 327 |
324 labels.clear(); | 328 labels.clear(); |
325 AutofillProfile::CreateDifferentiatingLabels(profiles.get(), &labels); | 329 AutofillProfile::CreateDifferentiatingLabels( |
| 330 profiles.get(), "en-US", &labels); |
326 ASSERT_EQ(5U, labels.size()); | 331 ASSERT_EQ(5U, labels.size()); |
327 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); | 332 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CA"), labels[0]); |
328 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); | 333 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); |
329 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com," | 334 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com," |
330 " 16502111111"), labels[2]); | 335 " 16502111111"), labels[2]); |
331 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com," | 336 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@hades.com," |
332 " 16504444444"), labels[3]); | 337 " 16504444444"), labels[3]); |
333 // This one differs from other ones by unique e-mail, so no need for extra | 338 // This one differs from other ones by unique e-mail, so no need for extra |
334 // information. | 339 // information. |
335 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@styx.com"), | 340 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., CO, johndoe@styx.com"), |
(...skipping 26 matching lines...) Expand all Loading... |
362 "Pluto Inc.", | 367 "Pluto Inc.", |
363 "123 Letha Shore.", | 368 "123 Letha Shore.", |
364 "", | 369 "", |
365 "Dis", "CA", | 370 "Dis", "CA", |
366 "91222", | 371 "91222", |
367 "US", | 372 "US", |
368 "12345678910"); | 373 "12345678910"); |
369 std::vector<base::string16> labels; | 374 std::vector<base::string16> labels; |
370 // Two fields at least - no filter. | 375 // Two fields at least - no filter. |
371 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 2, | 376 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 2, |
372 &labels); | 377 "en-US", &labels); |
373 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); | 378 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St."), labels[0]); |
374 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); | 379 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore."), labels[1]); |
375 | 380 |
376 // Three fields at least - no filter. | 381 // Three fields at least - no filter. |
377 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 3, | 382 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 3, |
378 &labels); | 383 "en-US", &labels); |
379 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"), | 384 EXPECT_EQ(ASCIIToUTF16("John Doe, 666 Erebus St., Elysium"), |
380 labels[0]); | 385 labels[0]); |
381 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"), | 386 EXPECT_EQ(ASCIIToUTF16("Jane Doe, 123 Letha Shore., Dis"), |
382 labels[1]); | 387 labels[1]); |
383 | 388 |
384 std::vector<ServerFieldType> suggested_fields; | 389 std::vector<ServerFieldType> suggested_fields; |
385 suggested_fields.push_back(ADDRESS_HOME_CITY); | 390 suggested_fields.push_back(ADDRESS_HOME_CITY); |
386 suggested_fields.push_back(ADDRESS_HOME_STATE); | 391 suggested_fields.push_back(ADDRESS_HOME_STATE); |
387 suggested_fields.push_back(ADDRESS_HOME_ZIP); | 392 suggested_fields.push_back(ADDRESS_HOME_ZIP); |
388 | 393 |
389 // Two fields at least, from suggested fields - no filter. | 394 // Two fields at least, from suggested fields - no filter. |
390 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 395 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
391 UNKNOWN_TYPE, 2, &labels); | 396 UNKNOWN_TYPE, 2, "en-US", &labels); |
392 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]); | 397 EXPECT_EQ(ASCIIToUTF16("Elysium, CA"), labels[0]); |
393 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]); | 398 EXPECT_EQ(ASCIIToUTF16("Dis, CA"), labels[1]); |
394 | 399 |
395 // Three fields at least, from suggested fields - no filter. | 400 // Three fields at least, from suggested fields - no filter. |
396 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 401 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
397 UNKNOWN_TYPE, 3, &labels); | 402 UNKNOWN_TYPE, 3, "en-US", &labels); |
398 EXPECT_EQ(ASCIIToUTF16("Elysium, CA, 91111"), labels[0]); | 403 EXPECT_EQ(ASCIIToUTF16("Elysium, CA, 91111"), labels[0]); |
399 EXPECT_EQ(ASCIIToUTF16("Dis, CA, 91222"), labels[1]); | 404 EXPECT_EQ(ASCIIToUTF16("Dis, CA, 91222"), labels[1]); |
400 | 405 |
401 // Three fields at least, from suggested fields - but filter reduces available | 406 // Three fields at least, from suggested fields - but filter reduces available |
402 // fields to two. | 407 // fields to two. |
403 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 408 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
404 ADDRESS_HOME_STATE, 3, &labels); | 409 ADDRESS_HOME_STATE, 3, "en-US", |
| 410 &labels); |
405 EXPECT_EQ(ASCIIToUTF16("Elysium, 91111"), labels[0]); | 411 EXPECT_EQ(ASCIIToUTF16("Elysium, 91111"), labels[0]); |
406 EXPECT_EQ(ASCIIToUTF16("Dis, 91222"), labels[1]); | 412 EXPECT_EQ(ASCIIToUTF16("Dis, 91222"), labels[1]); |
407 | 413 |
408 suggested_fields.clear(); | 414 suggested_fields.clear(); |
409 // In our implementation we always display NAME_FULL for all NAME* fields... | 415 // In our implementation we always display NAME_FULL for all NAME* fields... |
410 suggested_fields.push_back(NAME_MIDDLE); | 416 suggested_fields.push_back(NAME_MIDDLE); |
411 // One field at least, from suggested fields - no filter. | 417 // One field at least, from suggested fields - no filter. |
412 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 418 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
413 UNKNOWN_TYPE, 1, &labels); | 419 UNKNOWN_TYPE, 1, "en-US", &labels); |
414 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); | 420 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); |
415 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); | 421 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); |
416 | 422 |
417 // One field at least, from suggested fields - filter the same as suggested | 423 // One field at least, from suggested fields - filter the same as suggested |
418 // field. | 424 // field. |
419 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 425 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
420 NAME_MIDDLE, 1, &labels); | 426 NAME_MIDDLE, 1, "en-US", &labels); |
421 EXPECT_EQ(base::string16(), labels[0]); | 427 EXPECT_EQ(base::string16(), labels[0]); |
422 EXPECT_EQ(base::string16(), labels[1]); | 428 EXPECT_EQ(base::string16(), labels[1]); |
423 | 429 |
424 suggested_fields.clear(); | 430 suggested_fields.clear(); |
425 // In our implementation we always display NAME_FULL for NAME_MIDDLE_INITIAL | 431 // In our implementation we always display NAME_FULL for NAME_MIDDLE_INITIAL |
426 suggested_fields.push_back(NAME_MIDDLE_INITIAL); | 432 suggested_fields.push_back(NAME_MIDDLE_INITIAL); |
427 // One field at least, from suggested fields - no filter. | 433 // One field at least, from suggested fields - no filter. |
428 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 434 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
429 UNKNOWN_TYPE, 1, &labels); | 435 UNKNOWN_TYPE, 1, "en-US", &labels); |
430 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); | 436 EXPECT_EQ(ASCIIToUTF16("John Doe"), labels[0]); |
431 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); | 437 EXPECT_EQ(ASCIIToUTF16("Jane Doe"), labels[1]); |
432 | 438 |
433 // One field at least, from suggested fields - filter same as the first non- | 439 // One field at least, from suggested fields - filter same as the first non- |
434 // unknown suggested field. | 440 // unknown suggested field. |
435 suggested_fields.clear(); | 441 suggested_fields.clear(); |
436 suggested_fields.push_back(UNKNOWN_TYPE); | 442 suggested_fields.push_back(UNKNOWN_TYPE); |
437 suggested_fields.push_back(NAME_FULL); | 443 suggested_fields.push_back(NAME_FULL); |
438 suggested_fields.push_back(ADDRESS_HOME_LINE1); | 444 suggested_fields.push_back(ADDRESS_HOME_LINE1); |
439 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 445 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
440 NAME_FULL, 1, &labels); | 446 NAME_FULL, 1, "en-US", &labels); |
441 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels[0]); | 447 EXPECT_EQ(base::string16(ASCIIToUTF16("666 Erebus St.")), labels[0]); |
442 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]); | 448 EXPECT_EQ(base::string16(ASCIIToUTF16("123 Letha Shore.")), labels[1]); |
443 } | 449 } |
444 | 450 |
445 // Test that we fall back to using the full name if there are no other | 451 // Test that we fall back to using the full name if there are no other |
446 // distinguishing fields, but only if it makes sense given the suggested fields. | 452 // distinguishing fields, but only if it makes sense given the suggested fields. |
447 TEST(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) { | 453 TEST(AutofillProfileTest, CreateInferredLabelsFallsBackToFullName) { |
448 ScopedVector<AutofillProfile> profiles; | 454 ScopedVector<AutofillProfile> profiles; |
449 profiles.push_back( | 455 profiles.push_back( |
450 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 456 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
451 test::SetProfileInfo(profiles[0], | 457 test::SetProfileInfo(profiles[0], |
452 "John", "", "Doe", "doe@example.com", "", | 458 "John", "", "Doe", "doe@example.com", "", |
453 "88 Nowhere Ave.", "", "", "", "", "", ""); | 459 "88 Nowhere Ave.", "", "", "", "", "", ""); |
454 profiles.push_back( | 460 profiles.push_back( |
455 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 461 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
456 test::SetProfileInfo(profiles[1], | 462 test::SetProfileInfo(profiles[1], |
457 "Johnny", "K", "Doe", "doe@example.com", "", | 463 "Johnny", "K", "Doe", "doe@example.com", "", |
458 "88 Nowhere Ave.", "", "", "", "", "", ""); | 464 "88 Nowhere Ave.", "", "", "", "", "", ""); |
459 | 465 |
460 // If the only name field in the suggested fields is the excluded field, we | 466 // If the only name field in the suggested fields is the excluded field, we |
461 // should not fall back to the full name as a distinguishing field. | 467 // should not fall back to the full name as a distinguishing field. |
462 std::vector<ServerFieldType> suggested_fields; | 468 std::vector<ServerFieldType> suggested_fields; |
463 suggested_fields.push_back(NAME_LAST); | 469 suggested_fields.push_back(NAME_LAST); |
464 suggested_fields.push_back(ADDRESS_HOME_LINE1); | 470 suggested_fields.push_back(ADDRESS_HOME_LINE1); |
465 suggested_fields.push_back(EMAIL_ADDRESS); | 471 suggested_fields.push_back(EMAIL_ADDRESS); |
466 std::vector<base::string16> labels; | 472 std::vector<base::string16> labels; |
467 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 473 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
468 NAME_LAST, 1, &labels); | 474 NAME_LAST, 1, "en-US", &labels); |
469 ASSERT_EQ(2U, labels.size()); | 475 ASSERT_EQ(2U, labels.size()); |
470 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]); | 476 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[0]); |
471 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]); | 477 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave."), labels[1]); |
472 | 478 |
473 // Otherwise, we should. | 479 // Otherwise, we should. |
474 suggested_fields.push_back(NAME_FIRST); | 480 suggested_fields.push_back(NAME_FIRST); |
475 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 481 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
476 NAME_LAST, 1, &labels); | 482 NAME_LAST, 1, "en-US", &labels); |
477 ASSERT_EQ(2U, labels.size()); | 483 ASSERT_EQ(2U, labels.size()); |
478 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]); | 484 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., John Doe"), labels[0]); |
479 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]); | 485 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Johnny K Doe"), labels[1]); |
480 } | 486 } |
481 | 487 |
482 // Test that we do not show duplicate fields in the labels. | 488 // Test that we do not show duplicate fields in the labels. |
483 TEST(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) { | 489 TEST(AutofillProfileTest, CreateInferredLabelsNoDuplicatedFields) { |
484 ScopedVector<AutofillProfile> profiles; | 490 ScopedVector<AutofillProfile> profiles; |
485 profiles.push_back( | 491 profiles.push_back( |
486 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 492 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
487 test::SetProfileInfo(profiles[0], | 493 test::SetProfileInfo(profiles[0], |
488 "John", "", "Doe", "doe@example.com", "", | 494 "John", "", "Doe", "doe@example.com", "", |
489 "88 Nowhere Ave.", "", "", "", "", "", ""); | 495 "88 Nowhere Ave.", "", "", "", "", "", ""); |
490 profiles.push_back( | 496 profiles.push_back( |
491 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 497 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
492 test::SetProfileInfo(profiles[1], | 498 test::SetProfileInfo(profiles[1], |
493 "John", "", "Doe", "dojo@example.com", "", | 499 "John", "", "Doe", "dojo@example.com", "", |
494 "88 Nowhere Ave.", "", "", "", "", "", ""); | 500 "88 Nowhere Ave.", "", "", "", "", "", ""); |
495 | 501 |
496 // If the only name field in the suggested fields is the excluded field, we | 502 // If the only name field in the suggested fields is the excluded field, we |
497 // should not fall back to the full name as a distinguishing field. | 503 // should not fall back to the full name as a distinguishing field. |
498 std::vector<ServerFieldType> suggested_fields; | 504 std::vector<ServerFieldType> suggested_fields; |
499 suggested_fields.push_back(ADDRESS_HOME_LINE1); | 505 suggested_fields.push_back(ADDRESS_HOME_LINE1); |
500 suggested_fields.push_back(ADDRESS_BILLING_LINE1); | 506 suggested_fields.push_back(ADDRESS_BILLING_LINE1); |
501 suggested_fields.push_back(EMAIL_ADDRESS); | 507 suggested_fields.push_back(EMAIL_ADDRESS); |
502 std::vector<base::string16> labels; | 508 std::vector<base::string16> labels; |
503 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 509 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
504 UNKNOWN_TYPE, 2, &labels); | 510 UNKNOWN_TYPE, 2, "en-US", &labels); |
505 ASSERT_EQ(2U, labels.size()); | 511 ASSERT_EQ(2U, labels.size()); |
506 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); | 512 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., doe@example.com"), labels[0]); |
507 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); | 513 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., dojo@example.com"), labels[1]); |
508 } | 514 } |
509 | 515 |
510 // Make sure that empty fields are not treated as distinguishing fields. | 516 // Make sure that empty fields are not treated as distinguishing fields. |
511 TEST(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) { | 517 TEST(AutofillProfileTest, CreateInferredLabelsSkipsEmptyFields) { |
512 ScopedVector<AutofillProfile> profiles; | 518 ScopedVector<AutofillProfile> profiles; |
513 profiles.push_back( | 519 profiles.push_back( |
514 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 520 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
515 test::SetProfileInfo(profiles[0], | 521 test::SetProfileInfo(profiles[0], |
516 "John", "", "Doe", "doe@example.com", | 522 "John", "", "Doe", "doe@example.com", |
517 "Gogole", "", "", "", "", "", "", ""); | 523 "Gogole", "", "", "", "", "", "", ""); |
518 profiles.push_back( | 524 profiles.push_back( |
519 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 525 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
520 test::SetProfileInfo(profiles[1], | 526 test::SetProfileInfo(profiles[1], |
521 "John", "", "Doe", "doe@example.com", | 527 "John", "", "Doe", "doe@example.com", |
522 "Ggoole", "", "", "", "", "", "", ""); | 528 "Ggoole", "", "", "", "", "", "", ""); |
523 profiles.push_back( | 529 profiles.push_back( |
524 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 530 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
525 test::SetProfileInfo(profiles[2], | 531 test::SetProfileInfo(profiles[2], |
526 "John", "", "Doe", "john.doe@example.com", | 532 "John", "", "Doe", "john.doe@example.com", |
527 "Goolge", "", "", "", "", "", "", ""); | 533 "Goolge", "", "", "", "", "", "", ""); |
528 | 534 |
529 std::vector<base::string16> labels; | 535 std::vector<base::string16> labels; |
530 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 3, | 536 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 3, |
531 &labels); | 537 "en-US", &labels); |
532 ASSERT_EQ(3U, labels.size()); | 538 ASSERT_EQ(3U, labels.size()); |
533 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); | 539 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); |
534 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels[1]); | 540 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Ggoole"), labels[1]); |
535 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels[2]); | 541 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com, Goolge"), labels[2]); |
536 | 542 |
537 // A field must have a non-empty value for each profile to be considered a | 543 // A field must have a non-empty value for each profile to be considered a |
538 // distinguishing field. | 544 // distinguishing field. |
539 profiles[1]->SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave.")); | 545 profiles[1]->SetRawInfo(ADDRESS_HOME_LINE1, ASCIIToUTF16("88 Nowhere Ave.")); |
540 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 1, | 546 AutofillProfile::CreateInferredLabels(profiles.get(), NULL, UNKNOWN_TYPE, 1, |
541 &labels); | 547 "en-US", &labels); |
542 ASSERT_EQ(3U, labels.size()); | 548 ASSERT_EQ(3U, labels.size()); |
543 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); | 549 EXPECT_EQ(ASCIIToUTF16("John Doe, doe@example.com, Gogole"), labels[0]); |
544 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"), | 550 EXPECT_EQ(ASCIIToUTF16("John Doe, 88 Nowhere Ave., doe@example.com, Ggoole"), |
545 labels[1]) << labels[1]; | 551 labels[1]) << labels[1]; |
546 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]); | 552 EXPECT_EQ(ASCIIToUTF16("John Doe, john.doe@example.com"), labels[2]); |
547 } | 553 } |
548 | 554 |
549 // Test that labels that would otherwise have multiline values are flattened. | 555 // Test that labels that would otherwise have multiline values are flattened. |
550 TEST(AutofillProfileTest, CreateInferredLabelsFlattensMultiLineValues) { | 556 TEST(AutofillProfileTest, CreateInferredLabelsFlattensMultiLineValues) { |
551 ScopedVector<AutofillProfile> profiles; | 557 ScopedVector<AutofillProfile> profiles; |
552 profiles.push_back( | 558 profiles.push_back( |
553 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 559 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
554 test::SetProfileInfo(profiles[0], | 560 test::SetProfileInfo(profiles[0], |
555 "John", "", "Doe", "doe@example.com", "", | 561 "John", "", "Doe", "doe@example.com", "", |
556 "88 Nowhere Ave.", "Apt. 42", "", "", "", "", ""); | 562 "88 Nowhere Ave.", "Apt. 42", "", "", "", "", ""); |
557 | 563 |
558 // If the only name field in the suggested fields is the excluded field, we | 564 // If the only name field in the suggested fields is the excluded field, we |
559 // should not fall back to the full name as a distinguishing field. | 565 // should not fall back to the full name as a distinguishing field. |
560 std::vector<ServerFieldType> suggested_fields; | 566 std::vector<ServerFieldType> suggested_fields; |
561 suggested_fields.push_back(NAME_FULL); | 567 suggested_fields.push_back(NAME_FULL); |
562 suggested_fields.push_back(ADDRESS_HOME_STREET_ADDRESS); | 568 suggested_fields.push_back(ADDRESS_HOME_STREET_ADDRESS); |
563 std::vector<base::string16> labels; | 569 std::vector<base::string16> labels; |
564 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, | 570 AutofillProfile::CreateInferredLabels(profiles.get(), &suggested_fields, |
565 NAME_FULL, 1, &labels); | 571 NAME_FULL, 1, "en-US", &labels); |
566 ASSERT_EQ(1U, labels.size()); | 572 ASSERT_EQ(1U, labels.size()); |
567 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Apt. 42"), labels[0]); | 573 EXPECT_EQ(ASCIIToUTF16("88 Nowhere Ave., Apt. 42"), labels[0]); |
568 } | 574 } |
569 | 575 |
570 TEST(AutofillProfileTest, IsSubsetOf) { | 576 TEST(AutofillProfileTest, IsSubsetOf) { |
571 scoped_ptr<AutofillProfile> a, b; | 577 scoped_ptr<AutofillProfile> a, b; |
572 | 578 |
573 // |a| is a subset of |b|. | 579 // |a| is a subset of |b|. |
574 a.reset( | 580 a.reset( |
575 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); | 581 new AutofillProfile(base::GenerateGUID(), "https://www.example.com/")); |
(...skipping 26 matching lines...) Expand all Loading... |
602 NULL); | 608 NULL); |
603 EXPECT_FALSE(a->IsSubsetOf(*b, "en-US")); | 609 EXPECT_FALSE(a->IsSubsetOf(*b, "en-US")); |
604 } | 610 } |
605 | 611 |
606 TEST(AutofillProfileTest, OverwriteWithOrAddTo) { | 612 TEST(AutofillProfileTest, OverwriteWithOrAddTo) { |
607 AutofillProfile a(base::GenerateGUID(), "https://www.example.com"); | 613 AutofillProfile a(base::GenerateGUID(), "https://www.example.com"); |
608 test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", | 614 test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", |
609 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", | 615 "marion@me.xyz", "Fox", "123 Zoo St.", "unit 5", |
610 "Hollywood", "CA", "91601", "US", | 616 "Hollywood", "CA", "91601", "US", |
611 "12345678910"); | 617 "12345678910"); |
612 std::vector<base::string16> names; | 618 std::vector<base::string16> first_names; |
613 a.GetRawMultiInfo(NAME_FULL, &names); | 619 a.GetRawMultiInfo(NAME_FIRST, &first_names); |
614 names.push_back(ASCIIToUTF16("Marion Morrison")); | 620 first_names.push_back(ASCIIToUTF16("Marion")); |
615 a.SetRawMultiInfo(NAME_FULL, names); | 621 a.SetRawMultiInfo(NAME_FIRST, first_names); |
| 622 |
| 623 std::vector<base::string16> last_names; |
| 624 a.GetRawMultiInfo(NAME_LAST, &last_names); |
| 625 last_names[last_names.size() - 1] = ASCIIToUTF16("Morrison"); |
| 626 a.SetRawMultiInfo(NAME_LAST, last_names); |
616 | 627 |
617 // Create an identical profile except that the new profile: | 628 // Create an identical profile except that the new profile: |
618 // (1) Has a different origin, | 629 // (1) Has a different origin, |
619 // (2) Has a different address line 2, | 630 // (2) Has a different address line 2, |
620 // (3) Lacks a company name, | 631 // (3) Lacks a company name, |
621 // (4) Has a different full name variant, and | 632 // (4) Has a different full name variant, and |
622 // (5) Has a language code. | 633 // (5) Has a language code. |
623 AutofillProfile b = a; | 634 AutofillProfile b = a; |
624 b.set_guid(base::GenerateGUID()); | 635 b.set_guid(base::GenerateGUID()); |
625 b.set_origin("Chrome settings"); | 636 b.set_origin("Chrome settings"); |
626 b.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("area 51")); | 637 b.SetRawInfo(ADDRESS_HOME_LINE2, ASCIIToUTF16("area 51")); |
627 b.SetRawInfo(COMPANY_NAME, base::string16()); | 638 b.SetRawInfo(COMPANY_NAME, base::string16()); |
628 b.GetRawMultiInfo(NAME_FULL, &names); | 639 |
| 640 std::vector<base::string16> names; |
| 641 b.GetMultiInfo(AutofillType(NAME_FULL), "en-US", &names); |
629 names.push_back(ASCIIToUTF16("Marion M. Morrison")); | 642 names.push_back(ASCIIToUTF16("Marion M. Morrison")); |
630 b.SetRawMultiInfo(NAME_FULL, names); | 643 b.SetRawMultiInfo(NAME_FULL, names); |
631 b.set_language_code("en"); | 644 b.set_language_code("en"); |
632 | 645 |
633 a.OverwriteWithOrAddTo(b, "en-US"); | 646 a.OverwriteWithOrAddTo(b, "en-US"); |
634 EXPECT_EQ("Chrome settings", a.origin()); | 647 EXPECT_EQ("Chrome settings", a.origin()); |
635 EXPECT_EQ(ASCIIToUTF16("area 51"), a.GetRawInfo(ADDRESS_HOME_LINE2)); | 648 EXPECT_EQ(ASCIIToUTF16("area 51"), a.GetRawInfo(ADDRESS_HOME_LINE2)); |
636 EXPECT_EQ(ASCIIToUTF16("Fox"), a.GetRawInfo(COMPANY_NAME)); | 649 EXPECT_EQ(ASCIIToUTF16("Fox"), a.GetRawInfo(COMPANY_NAME)); |
637 a.GetRawMultiInfo(NAME_FULL, &names); | 650 a.GetMultiInfo(AutofillType(NAME_FULL), "en-US", &names); |
638 ASSERT_EQ(3U, names.size()); | 651 ASSERT_EQ(3U, names.size()); |
639 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison"), names[0]); | 652 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison"), names[0]); |
640 EXPECT_EQ(ASCIIToUTF16("Marion Morrison"), names[1]); | 653 EXPECT_EQ(ASCIIToUTF16("Marion Morrison"), names[1]); |
641 EXPECT_EQ(ASCIIToUTF16("Marion M. Morrison"), names[2]); | 654 EXPECT_EQ(ASCIIToUTF16("Marion M. Morrison"), names[2]); |
642 EXPECT_EQ("en", a.language_code()); | 655 EXPECT_EQ("en", a.language_code()); |
643 } | 656 } |
644 | 657 |
645 TEST(AutofillProfileTest, AssignmentOperator) { | 658 TEST(AutofillProfileTest, AssignmentOperator) { |
646 AutofillProfile a(base::GenerateGUID(), "https://www.example.com/"); | 659 AutofillProfile a(base::GenerateGUID(), "https://www.example.com/"); |
647 test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", | 660 test::SetProfileInfo(&a, "Marion", "Mitchell", "Morrison", |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 | 1116 |
1104 for (size_t i = 0; i < current_case.expected_result.size(); ++i) { | 1117 for (size_t i = 0; i < current_case.expected_result.size(); ++i) { |
1105 EXPECT_EQ(first_names[i], merged_first_names[i]); | 1118 EXPECT_EQ(first_names[i], merged_first_names[i]); |
1106 EXPECT_EQ(middle_names[i], merged_middle_names[i]); | 1119 EXPECT_EQ(middle_names[i], merged_middle_names[i]); |
1107 EXPECT_EQ(last_names[i], merged_last_names[i]); | 1120 EXPECT_EQ(last_names[i], merged_last_names[i]); |
1108 } | 1121 } |
1109 } | 1122 } |
1110 } | 1123 } |
1111 | 1124 |
1112 } // namespace autofill | 1125 } // namespace autofill |
OLD | NEW |