| 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 // The new name's values overwrite the exsiting name values if they are |
| 272 // different |
| 273 { |
| 274 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 275 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, |
| 276 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, |
| 277 }, |
| 278 // An existing name values do not get replaced with empty values. |
| 279 { |
| 280 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 281 {"", "", "", ""}, |
| 282 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 283 }, |
| 284 // An existing full middle not does not get replaced by a middle name |
| 285 // initial. |
| 286 { |
| 287 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 288 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, |
| 289 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 290 }, |
| 291 // An existing middle name initial is overwritten by the new profile's |
| 292 // middle name value. |
| 293 { |
| 294 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, |
| 295 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 296 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 297 }, |
| 298 // A NameInfo with only the full name set overwritten with a NameInfo |
| 299 // with only the name parts set result in a NameInfo with all the name |
| 300 // parts and name full set. |
| 301 { |
| 302 {"", "", "", "Marion Mitchell Morrison"}, |
| 303 {"Marion", "Mitchell", "Morrison", ""}, |
| 304 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 305 }, |
| 306 // A NameInfo with only the name parts set overwritten with a NameInfo |
| 307 // with only the full name set result in a NameInfo with all the name |
| 308 // parts and name full set. |
| 309 { |
| 310 {"Marion", "Mitchell", "Morrison", ""}, |
| 311 {"", "", "", "Marion Mitchell Morrison"}, |
| 312 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 313 }, |
| 314 }; |
| 315 |
| 316 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 317 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); |
| 318 |
| 319 // Construct the starting_profile. |
| 320 NameInfo existing_name; |
| 321 existing_name.SetRawInfo(NAME_FIRST, |
| 322 UTF8ToUTF16(test_cases[i].existing_name[0])); |
| 323 existing_name.SetRawInfo(NAME_MIDDLE, |
| 324 UTF8ToUTF16(test_cases[i].existing_name[1])); |
| 325 existing_name.SetRawInfo(NAME_LAST, |
| 326 UTF8ToUTF16(test_cases[i].existing_name[2])); |
| 327 existing_name.SetRawInfo(NAME_FULL, |
| 328 UTF8ToUTF16(test_cases[i].existing_name[3])); |
| 329 |
| 330 // Construct the additional_profile. |
| 331 NameInfo new_name; |
| 332 new_name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].new_name[0])); |
| 333 new_name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].new_name[1])); |
| 334 new_name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].new_name[2])); |
| 335 new_name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].new_name[3])); |
| 336 |
| 337 existing_name.OverwriteName(new_name); |
| 338 |
| 339 // Verify the test expectations. |
| 340 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[0]), |
| 341 existing_name.GetRawInfo(NAME_FIRST)); |
| 342 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[1]), |
| 343 existing_name.GetRawInfo(NAME_MIDDLE)); |
| 344 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[2]), |
| 345 existing_name.GetRawInfo(NAME_LAST)); |
| 346 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[3]), |
| 347 existing_name.GetRawInfo(NAME_FULL)); |
| 348 } |
| 349 } |
| 350 |
| 351 TEST(NameInfoTest, NamePartsAreEmpty) { |
| 352 struct TestCase { |
| 353 std::string first; |
| 354 std::string middle; |
| 355 std::string last; |
| 356 std::string full; |
| 357 bool expected_result; |
| 358 }; |
| 359 |
| 360 struct TestCase test_cases[] = { |
| 361 {"", "", "", "", true}, |
| 362 {"", "", "", "Marion Mitchell Morrison", true}, |
| 363 {"Marion", "", "", "", false}, |
| 364 {"", "Mitchell", "", "", false}, |
| 365 {"", "", "Morrison", "", false}, |
| 366 }; |
| 367 |
| 368 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 369 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); |
| 370 |
| 371 // Construct the NameInfo. |
| 372 NameInfo name; |
| 373 name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].first)); |
| 374 name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].middle)); |
| 375 name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].last)); |
| 376 name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].full)); |
| 377 |
| 378 // Verify the test expectations. |
| 379 EXPECT_EQ(test_cases[i].expected_result, name.NamePartsAreEmpty()); |
| 380 } |
| 381 } |
| 382 |
| 256 } // namespace autofill | 383 } // namespace autofill |
| OLD | NEW |