Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Unified Diff: components/autofill/core/browser/contact_info_unittest.cc

Issue 1973873002: [Autofill] Improve the merging of two profiles' names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a0001a3b91baa71e55328fcbd2e0e3e3d03c16d4 100644
--- a/components/autofill/core/browser/contact_info_unittest.cc
+++ b/components/autofill/core/browser/contact_info_unittest.cc
@@ -253,4 +253,131 @@ 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"},
+ },
+ // 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
« no previous file with comments | « components/autofill/core/browser/contact_info.cc ('k') | components/autofill/core/browser/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698