Commit 84da9bd3 authored by Matthias Körber's avatar Matthias Körber Committed by Commit Bot

Removed unused methods from |ContactInfo|.

Bug: 1007974
Change-Id: I997f1f694b1abdbd166b33f035c6514ff46358db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1826784
Commit-Queue: Matthias Körber <koerber@google.com>
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700225}
parent 45db51f3
......@@ -47,31 +47,6 @@ bool NameInfo::operator==(const NameInfo& other) const {
family_ == other.family_ && full_ == other.full_;
}
bool NameInfo::ParsedNamesAreEqual(const NameInfo& info) const {
return given_ == info.given_ && middle_ == info.middle_ &&
family_ == info.family_;
}
void NameInfo::OverwriteName(const NameInfo& new_name) {
if (!new_name.given_.empty())
given_ = new_name.given_;
// For the middle name, don't overwrite a full middle name with an initial.
if (!new_name.middle_.empty() &&
(middle_.size() <= 1 || new_name.middle_.size() > 1))
middle_ = new_name.middle_;
if (!new_name.family_.empty())
family_ = new_name.family_;
if (!new_name.full_.empty())
full_ = new_name.full_;
}
bool NameInfo::NamePartsAreEmpty() const {
return given_.empty() && middle_.empty() && family_.empty();
}
base::string16 NameInfo::GetRawInfo(ServerFieldType type) const {
DCHECK_EQ(NAME, AutofillType(type).group());
switch (type) {
......
......@@ -26,18 +26,6 @@ class NameInfo : public FormGroup {
bool operator==(const NameInfo& other) const;
bool operator!=(const NameInfo& other) const { return !operator==(other); }
// Compares |NameInfo| objects for |given_|, |middle_| and |family_| names.
// The comparison is case sensitive.
bool ParsedNamesAreEqual(const NameInfo& info) const;
// For every non-empty NameInfo part in |new_name|, the corresponding NameInfo
// part in | this | is overwritten.Special logic so that a middle initial may
// not overwrite a full middle name.
void OverwriteName(const NameInfo& new_name);
// Returns true if all the name parts (first, middle and last) are empty.
bool NamePartsAreEmpty() const;
// FormGroup:
base::string16 GetRawInfo(ServerFieldType type) const override;
void SetRawInfo(ServerFieldType type, const base::string16& value) override;
......
......@@ -183,219 +183,6 @@ TEST(NameInfoTest, GetFullName) {
name.GetInfo(AutofillType(NAME_FULL), "en-US"));
}
struct ParsedNamesAreEqualTestCase {
std::string starting_names[3];
std::string additional_names[3];
bool expected_result;
};
class ParsedNamesAreEqualTest
: public testing::TestWithParam<ParsedNamesAreEqualTestCase> {};
TEST_P(ParsedNamesAreEqualTest, ParsedNamesAreEqual) {
auto test_case = GetParam();
// Construct the starting_profile.
NameInfo starting_profile;
starting_profile.SetRawInfo(NAME_FIRST,
UTF8ToUTF16(test_case.starting_names[0]));
starting_profile.SetRawInfo(NAME_MIDDLE,
UTF8ToUTF16(test_case.starting_names[1]));
starting_profile.SetRawInfo(NAME_LAST,
UTF8ToUTF16(test_case.starting_names[2]));
// Construct the additional_profile.
NameInfo additional_profile;
additional_profile.SetRawInfo(NAME_FIRST,
UTF8ToUTF16(test_case.additional_names[0]));
additional_profile.SetRawInfo(NAME_MIDDLE,
UTF8ToUTF16(test_case.additional_names[1]));
additional_profile.SetRawInfo(NAME_LAST,
UTF8ToUTF16(test_case.additional_names[2]));
// Verify the test expectations.
EXPECT_EQ(test_case.expected_result,
starting_profile.ParsedNamesAreEqual(additional_profile));
}
INSTANTIATE_TEST_SUITE_P(
ContactInfoTest,
ParsedNamesAreEqualTest,
testing::Values(
// Identical name comparison.
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"Marion", "Mitchell", "Morrison"},
true},
// Case-sensitive comparisons.
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"Marion", "Mitchell", "MORRISON"},
false},
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"MARION", "Mitchell", "MORRISON"},
false},
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"MARION", "MITCHELL", "MORRISON"},
false},
ParsedNamesAreEqualTestCase{{"Marion", "", "Mitchell Morrison"},
{"MARION", "", "MITCHELL MORRISON"},
false},
ParsedNamesAreEqualTestCase{{"Marion Mitchell", "", "Morrison"},
{"MARION MITCHELL", "", "MORRISON"},
false},
// Identical full names but different canonical forms.
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"Marion", "", "Mitchell Morrison"},
false},
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"Marion Mitchell", "", "MORRISON"},
false},
// Different names.
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"Marion", "M.", "Morrison"},
false},
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"MARION", "M.", "MORRISON"},
false},
ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"},
{"David", "Mitchell", "Morrison"},
false},
// Non-ASCII characters.
ParsedNamesAreEqualTestCase{{"M\xc3\xa1rion Mitchell", "", "Morrison"},
{"M\xc3\xa1rion Mitchell", "", "Morrison"},
true}));
struct OverwriteNameTestCase {
std::string existing_name[4];
std::string new_name[4];
std::string expected_name[4];
};
class OverwriteNameTest : public testing::TestWithParam<OverwriteNameTestCase> {
};
TEST_P(OverwriteNameTest, OverwriteName) {
auto test_case = GetParam();
// Construct the starting_profile.
NameInfo existing_name;
existing_name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_case.existing_name[0]));
existing_name.SetRawInfo(NAME_MIDDLE,
UTF8ToUTF16(test_case.existing_name[1]));
existing_name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_case.existing_name[2]));
existing_name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_case.existing_name[3]));
// Construct the additional_profile.
NameInfo new_name;
new_name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_case.new_name[0]));
new_name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_case.new_name[1]));
new_name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_case.new_name[2]));
new_name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_case.new_name[3]));
existing_name.OverwriteName(new_name);
// Verify the test expectations.
EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[0]),
existing_name.GetRawInfo(NAME_FIRST));
EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[1]),
existing_name.GetRawInfo(NAME_MIDDLE));
EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[2]),
existing_name.GetRawInfo(NAME_LAST));
EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[3]),
existing_name.GetRawInfo(NAME_FULL));
}
INSTANTIATE_TEST_SUITE_P(
ContactInfoTest,
OverwriteNameTest,
testing::Values(
// Missing information in the original name gets filled with the new
// name's information.
OverwriteNameTestCase{
{"", "", "", ""},
{"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
OverwriteNameTestCase{
{"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.
OverwriteNameTestCase{
{"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.
OverwriteNameTestCase{
{"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.
OverwriteNameTestCase{
{"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.
OverwriteNameTestCase{
{"", "", "", "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.
OverwriteNameTestCase{
{"Marion", "Mitchell", "Morrison", ""},
{"", "", "", "Marion Mitchell Morrison"},
{"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"},
}));
struct NamePartsAreEmptyTestCase {
std::string first;
std::string middle;
std::string last;
std::string full;
bool expected_result;
};
class NamePartsAreEmptyTest
: public testing::TestWithParam<NamePartsAreEmptyTestCase> {};
TEST_P(NamePartsAreEmptyTest, NamePartsAreEmpty) {
auto test_case = GetParam();
// Construct the NameInfo.
NameInfo name;
name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_case.first));
name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_case.middle));
name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_case.last));
name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_case.full));
// Verify the test expectations.
EXPECT_EQ(test_case.expected_result, name.NamePartsAreEmpty());
}
INSTANTIATE_TEST_SUITE_P(
ContactInfoTest,
NamePartsAreEmptyTest,
testing::Values(NamePartsAreEmptyTestCase{"", "", "", "", true},
NamePartsAreEmptyTestCase{"", "", "",
"Marion Mitchell Morrison", true},
NamePartsAreEmptyTestCase{"Marion", "", "", "", false},
NamePartsAreEmptyTestCase{"", "Mitchell", "", "", false},
NamePartsAreEmptyTestCase{"", "", "Morrison", "", false}));
TEST(CompanyTest, CompanyNameYear) {
base::test::ScopedFeatureList scoped_features;
scoped_features.InitWithFeatures(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment