Chromium Code Reviews| Index: components/autofill/core/browser/contact_info_unittest.cc |
| diff --git a/components/autofill/core/browser/contact_info_unittest.cc b/components/autofill/core/browser/contact_info_unittest.cc |
| index c04f148892b3c5011e05f3086e0ed0fafa4e99fc..e8958a7f59609d60a9224b6866fa2d2afb7404ab 100644 |
| --- a/components/autofill/core/browser/contact_info_unittest.cc |
| +++ b/components/autofill/core/browser/contact_info_unittest.cc |
| @@ -253,4 +253,141 @@ TEST(NameInfoTest, ParsedNamesAreEqual) { |
| } |
| } |
| +TEST(NameInfoTest, OverwriteName) { |
| + struct TestCase { |
| + std::string existing_name[4]; |
| + std::string new_name[4]; |
| + std::string expected_name[4]; |
| + }; |
| + |
| + struct TestCase test_cases[] = { |
| + // Missing information in the original name gets filled with the new |
| + // name's information. |
| + { |
| + {"", "", "", ""}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + }, |
| + |
|
Mathieu
2016/05/13 13:32:52
nit: feel free to remove empty lines between test
sebsg
2016/05/13 17:20:02
Done.
|
| + // The new name's values overwrite the exsiting name values if they are |
| + // different |
| + { |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, |
| + {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, |
| + }, |
| + |
| + // An existing name values do not get replaced with empty values. |
| + { |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + {"", "", "", ""}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + }, |
| + |
| + // An existing full middle not does not get replaced by a middle name |
| + // initial. |
| + { |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + }, |
| + |
| + // An existing middle name initial is overwritten by the new profile's |
| + // middle name value. |
| + { |
| + {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + }, |
| + |
| + // A NameInfo with only the full name set overwritten with a NameInfo |
| + // with only the name parts set result in a NameInfo with all the name |
| + // parts and name full set. |
| + { |
| + {"", "", "", "Marion Mitchell Morrison"}, |
| + {"Marion", "Mitchell", "Morrison", ""}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + }, |
| + |
| + // A NameInfo with only the name parts set overwritten with a NameInfo |
| + // with only the full name set result in a NameInfo with all the name |
| + // parts and name full set. |
| + { |
| + {"Marion", "Mitchell", "Morrison", ""}, |
| + {"", "", "", "Marion Mitchell Morrison"}, |
| + {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| + }, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| + SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); |
| + |
| + // Construct the starting_profile. |
| + NameInfo existing_name; |
| + existing_name.SetRawInfo(NAME_FIRST, |
| + UTF8ToUTF16(test_cases[i].existing_name[0])); |
| + existing_name.SetRawInfo(NAME_MIDDLE, |
| + UTF8ToUTF16(test_cases[i].existing_name[1])); |
| + existing_name.SetRawInfo(NAME_LAST, |
| + UTF8ToUTF16(test_cases[i].existing_name[2])); |
| + existing_name.SetRawInfo(NAME_FULL, |
| + UTF8ToUTF16(test_cases[i].existing_name[3])); |
| + |
| + // Construct the additional_profile. |
| + NameInfo new_name; |
| + new_name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].new_name[0])); |
| + new_name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].new_name[1])); |
| + new_name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].new_name[2])); |
| + new_name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].new_name[3])); |
| + |
| + existing_name.OverwriteName(new_name); |
| + |
| + // Verify the test expectations. |
| + EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[0]), |
| + existing_name.GetRawInfo(NAME_FIRST)); |
| + EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[1]), |
| + existing_name.GetRawInfo(NAME_MIDDLE)); |
| + EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[2]), |
| + existing_name.GetRawInfo(NAME_LAST)); |
| + EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[3]), |
| + existing_name.GetRawInfo(NAME_FULL)); |
| + } |
| +} |
| + |
| +TEST(NameInfoTest, NamePartsAreEmpty) { |
| + struct TestCase { |
| + std::string first; |
| + std::string middle; |
| + std::string last; |
| + std::string full; |
| + bool expected_result; |
| + }; |
| + |
| + struct TestCase test_cases[] = { |
| + {"", "", "", "", true}, |
| + |
| + {"", "", "", "Marion Mitchell Morrison", true}, |
| + |
| + {"Marion", "", "", "", false}, |
| + |
| + {"", "Mitchell", "", "", false}, |
| + |
| + {"", "", "Morrison", "", false}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| + SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); |
| + |
| + // Construct the NameInfo. |
| + NameInfo name; |
| + name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].first)); |
| + name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].middle)); |
| + name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].last)); |
| + name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].full)); |
| + |
| + // Verify the test expectations. |
| + EXPECT_EQ(test_cases[i].expected_result, name.NamePartsAreEmpty()); |
| + } |
| +} |
| + |
| } // namespace autofill |