Chromium Code Reviews| 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 "components/autofill/core/browser/contact_info.h" | 5 #include "components/autofill/core/browser/contact_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 NAME_MIDDLE, UTF8ToUTF16(test_cases[i].additional_names[1])); | 246 NAME_MIDDLE, UTF8ToUTF16(test_cases[i].additional_names[1])); |
| 247 additional_profile.SetRawInfo( | 247 additional_profile.SetRawInfo( |
| 248 NAME_LAST, UTF8ToUTF16(test_cases[i].additional_names[2])); | 248 NAME_LAST, UTF8ToUTF16(test_cases[i].additional_names[2])); |
| 249 | 249 |
| 250 // Verify the test expectations. | 250 // Verify the test expectations. |
| 251 EXPECT_EQ(test_cases[i].expected_result, | 251 EXPECT_EQ(test_cases[i].expected_result, |
| 252 starting_profile.ParsedNamesAreEqual(additional_profile)); | 252 starting_profile.ParsedNamesAreEqual(additional_profile)); |
| 253 } | 253 } |
| 254 } | 254 } |
| 255 | 255 |
| 256 TEST(NameInfoTest, OverwriteName) { | |
| 257 struct TestCase { | |
| 258 std::string existing_name[4]; | |
| 259 std::string new_name[4]; | |
| 260 std::string expected_name[4]; | |
| 261 }; | |
| 262 | |
| 263 struct TestCase test_cases[] = { | |
| 264 // Missing information in the original name gets filled with the new | |
| 265 // name's information. | |
| 266 { | |
| 267 {"", "", "", ""}, | |
| 268 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 269 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 270 }, | |
| 271 | |
|
Mathieu
2016/05/13 13:32:52
nit: feel free to remove empty lines between test
sebsg
2016/05/13 17:20:02
Done.
| |
| 272 // The new name's values overwrite the exsiting name values if they are | |
| 273 // different | |
| 274 { | |
| 275 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 276 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, | |
| 277 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, | |
| 278 }, | |
| 279 | |
| 280 // An existing name values do not get replaced with empty values. | |
| 281 { | |
| 282 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 283 {"", "", "", ""}, | |
| 284 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 285 }, | |
| 286 | |
| 287 // An existing full middle not does not get replaced by a middle name | |
| 288 // initial. | |
| 289 { | |
| 290 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 291 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, | |
| 292 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 293 }, | |
| 294 | |
| 295 // An existing middle name initial is overwritten by the new profile's | |
| 296 // middle name value. | |
| 297 { | |
| 298 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, | |
| 299 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 300 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 301 }, | |
| 302 | |
| 303 // A NameInfo with only the full name set overwritten with a NameInfo | |
| 304 // with only the name parts set result in a NameInfo with all the name | |
| 305 // parts and name full set. | |
| 306 { | |
| 307 {"", "", "", "Marion Mitchell Morrison"}, | |
| 308 {"Marion", "Mitchell", "Morrison", ""}, | |
| 309 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 310 }, | |
| 311 | |
| 312 // A NameInfo with only the name parts set overwritten with a NameInfo | |
| 313 // with only the full name set result in a NameInfo with all the name | |
| 314 // parts and name full set. | |
| 315 { | |
| 316 {"Marion", "Mitchell", "Morrison", ""}, | |
| 317 {"", "", "", "Marion Mitchell Morrison"}, | |
| 318 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 319 }, | |
| 320 }; | |
| 321 | |
| 322 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
| 323 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | |
| 324 | |
| 325 // Construct the starting_profile. | |
| 326 NameInfo existing_name; | |
| 327 existing_name.SetRawInfo(NAME_FIRST, | |
| 328 UTF8ToUTF16(test_cases[i].existing_name[0])); | |
| 329 existing_name.SetRawInfo(NAME_MIDDLE, | |
| 330 UTF8ToUTF16(test_cases[i].existing_name[1])); | |
| 331 existing_name.SetRawInfo(NAME_LAST, | |
| 332 UTF8ToUTF16(test_cases[i].existing_name[2])); | |
| 333 existing_name.SetRawInfo(NAME_FULL, | |
| 334 UTF8ToUTF16(test_cases[i].existing_name[3])); | |
| 335 | |
| 336 // Construct the additional_profile. | |
| 337 NameInfo new_name; | |
| 338 new_name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].new_name[0])); | |
| 339 new_name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].new_name[1])); | |
| 340 new_name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].new_name[2])); | |
| 341 new_name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].new_name[3])); | |
| 342 | |
| 343 existing_name.OverwriteName(new_name); | |
| 344 | |
| 345 // Verify the test expectations. | |
| 346 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[0]), | |
| 347 existing_name.GetRawInfo(NAME_FIRST)); | |
| 348 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[1]), | |
| 349 existing_name.GetRawInfo(NAME_MIDDLE)); | |
| 350 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[2]), | |
| 351 existing_name.GetRawInfo(NAME_LAST)); | |
| 352 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[3]), | |
| 353 existing_name.GetRawInfo(NAME_FULL)); | |
| 354 } | |
| 355 } | |
| 356 | |
| 357 TEST(NameInfoTest, NamePartsAreEmpty) { | |
| 358 struct TestCase { | |
| 359 std::string first; | |
| 360 std::string middle; | |
| 361 std::string last; | |
| 362 std::string full; | |
| 363 bool expected_result; | |
| 364 }; | |
| 365 | |
| 366 struct TestCase test_cases[] = { | |
| 367 {"", "", "", "", true}, | |
| 368 | |
| 369 {"", "", "", "Marion Mitchell Morrison", true}, | |
| 370 | |
| 371 {"Marion", "", "", "", false}, | |
| 372 | |
| 373 {"", "Mitchell", "", "", false}, | |
| 374 | |
| 375 {"", "", "Morrison", "", false}, | |
| 376 }; | |
| 377 | |
| 378 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
| 379 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | |
| 380 | |
| 381 // Construct the NameInfo. | |
| 382 NameInfo name; | |
| 383 name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].first)); | |
| 384 name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].middle)); | |
| 385 name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].last)); | |
| 386 name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].full)); | |
| 387 | |
| 388 // Verify the test expectations. | |
| 389 EXPECT_EQ(test_cases[i].expected_result, name.NamePartsAreEmpty()); | |
| 390 } | |
| 391 } | |
| 392 | |
| 256 } // namespace autofill | 393 } // namespace autofill |
| OLD | NEW |