Index: components/autofill/core/browser/autofill_profile_unittest.cc |
diff --git a/components/autofill/core/browser/autofill_profile_unittest.cc b/components/autofill/core/browser/autofill_profile_unittest.cc |
index de550bd827bd869c9966a9a650fba85111e746db..9a99963ce84f5b9c478e559fcee062ae749c6f5f 100644 |
--- a/components/autofill/core/browser/autofill_profile_unittest.cc |
+++ b/components/autofill/core/browser/autofill_profile_unittest.cc |
@@ -3,15 +3,18 @@ |
// found in the LICENSE file. |
#include "base/basictypes.h" |
+#include "base/format_macros.h" |
#include "base/guid.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/scoped_vector.h" |
#include "base/stl_util.h" |
#include "base/strings/string16.h" |
+#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "components/autofill/core/browser/autofill_profile.h" |
#include "components/autofill/core/browser/autofill_test_utils.h" |
#include "components/autofill/core/browser/autofill_type.h" |
+#include "components/autofill/core/browser/field_types.h" |
#include "components/autofill/core/common/form_field_data.h" |
#include "grit/components_strings.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -898,4 +901,161 @@ TEST(AutofillProfileTest, FullAddress) { |
EXPECT_TRUE(profile.GetInfo(full_address, "en-US").empty()); |
} |
+TEST(AutofillProfileTest, OverwriteOrAppendNames) { |
+ struct TestCase { |
+ std::string starting_names[3]; |
+ std::string additional_names[3]; |
+ std::string expected_result[3]; |
+ }; |
+ |
+ struct TestCase test_cases[] = { |
+ // Identical name. |
+ {{"Marion", "Mitchell", "Morrison"}, |
+ {"Marion", "Mitchell", "Morrison"}, |
+ {"Marion", "Mitchell", "Morrison"}}, |
+ |
+ // A parse that has a two-word last name should take precedence over a |
+ // parse that assumes the two names are a middle and a last name. |
+ {{"Marion", "Mitchell", "Morrison"}, |
+ {"Marion", "", "Mitchell Morrison"}, |
+ {"Marion", "", "Mitchell Morrison"}}, |
+ {{"Marion", "", "Mitchell Morrison"}, |
+ {"Marion", "Mitchell", "Morrison"}, |
+ {"Marion", "", "Mitchell Morrison"}}, |
+ |
+ // A parse that has a two-word first name should take precedence over a |
+ // parse that assumes the two names are a first and a middle name. |
+ {{"Marion", "Mitchell", "Morrison"}, |
+ {"Marion Mitchell", "", "Morrison"}, |
+ {"Marion Mitchell", "", "Morrison"}}, |
+ {{"Marion Mitchell", "", "Morrison"}, |
+ {"Marion", "Mitchell", "Morrison"}, |
+ {"Marion Mitchell", "", "Morrison"}}, |
+ |
+ // A parse that has a two-word first name and two-word last name should |
+ // take precedence over a parse that assumes the two middle names and |
+ // one last name. |
+ {{"Arthur", "Ignatius Conan", "Doyle"}, |
+ {"Arthur Ignatius", "", "Conan Doyle"}, |
+ {"Arthur Ignatius", "", "Conan Doyle"}}, |
+ {{"Arthur Ignatius", "", "Conan Doyle"}, |
+ {"Arthur", "Ignatius Conan", "Doyle"}, |
+ {"Arthur Ignatius", "", "Conan Doyle"}}, |
+ |
+ // A parse that has a many-word first name and/or last name should take |
+ // precedence over a heuristically parsed name into {first, middle1 |
+ // middle2.. middlen, name}. |
+ {{"Arthur Ignatius Conan", "", "Doyle"}, |
+ {"Arthur", "Ignatius Conan", "Doyle"}, |
+ {"Arthur Ignatius Conan", "", "Doyle"}}, |
+ {{"Roberto", "Carlos da Silva", "Rocha"}, |
+ {"Roberto Carlos da Silva", "", "Rocha"}, |
+ {"Roberto Carlos da Silva", "", "Rocha"}}, |
+ {{"Antonio", "Augusto", "Ribeiro Reis Jr."}, |
+ {"Antonio", "Augusto Ribeiro Reis ", "Jr."}, |
+ {"Antonio", "Augusto", "Ribeiro Reis Jr."}}, |
+ }; |
+ |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
+ SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); |
+ |
+ // Construct the starting_profile. |
+ AutofillProfile starting_profile(base::GenerateGUID(), |
+ "https://www.example.com/"); |
+ starting_profile.SetRawInfo(NAME_FIRST, |
+ ASCIIToUTF16(test_cases[i].starting_names[0])); |
+ starting_profile.SetRawInfo(NAME_MIDDLE, |
+ ASCIIToUTF16(test_cases[i].starting_names[1])); |
+ starting_profile.SetRawInfo(NAME_LAST, |
+ ASCIIToUTF16(test_cases[i].starting_names[2])); |
+ |
+ // Construct the additional_profile. |
+ AutofillProfile additional_profile(base::GenerateGUID(), |
+ "https://www.example.com/"); |
+ additional_profile.SetRawInfo( |
+ NAME_FIRST, ASCIIToUTF16(test_cases[i].additional_names[0])); |
+ additional_profile.SetRawInfo( |
+ NAME_MIDDLE, ASCIIToUTF16(test_cases[i].additional_names[1])); |
+ additional_profile.SetRawInfo( |
+ NAME_LAST, ASCIIToUTF16(test_cases[i].additional_names[2])); |
+ |
+ // Merge the names from the |additional_profile| into the |starting_profile| |
+ starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); |
+ |
+ // Verify the test expectations. |
+ EXPECT_EQ(starting_profile.GetRawInfo(NAME_FIRST), |
+ ASCIIToUTF16(test_cases[i].expected_result[0])); |
+ EXPECT_EQ(starting_profile.GetRawInfo(NAME_MIDDLE), |
+ ASCIIToUTF16(test_cases[i].expected_result[1])); |
+ EXPECT_EQ(starting_profile.GetRawInfo(NAME_LAST), |
+ ASCIIToUTF16(test_cases[i].expected_result[2])); |
+ } |
+ |
+ // Cases where merging 2 profiles with same fullnames but |
+ // different canonical forms appends instead of overwrites, |
+ // provided they dont form heuristically parsed names. |
+ { |
+ // Construct the starting_profile. |
+ AutofillProfile starting_profile(base::GenerateGUID(), |
+ "https://www.example.com/"); |
+ starting_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Marion Mitchell")); |
+ starting_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Morrison")); |
+ |
+ // Construct the additional_profile. |
+ AutofillProfile additional_profile(base::GenerateGUID(), |
+ "https://www.example.com/"); |
+ additional_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Marion")); |
+ additional_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Mitchell Morrison")); |
+ |
+ EXPECT_EQ(starting_profile.GetRawInfo(NAME_FULL), |
+ additional_profile.GetRawInfo(NAME_FULL)); |
+ |
+ // Merge the names from the |additional_profile| into the |starting_profile| |
+ starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); |
+ |
+ std::vector<base::string16> first_names, last_names; |
+ starting_profile.GetRawMultiInfo(NAME_FIRST, &first_names); |
+ starting_profile.GetRawMultiInfo(NAME_LAST, &last_names); |
+ ASSERT_EQ(2U, first_names.size()); |
+ ASSERT_EQ(2U, last_names.size()); |
+ EXPECT_EQ(ASCIIToUTF16("Marion Mitchell"), first_names[0]); |
+ EXPECT_EQ(ASCIIToUTF16("Marion"), first_names[1]); |
+ EXPECT_EQ(ASCIIToUTF16("Morrison"), last_names[0]); |
+ EXPECT_EQ(ASCIIToUTF16("Mitchell Morrison"), last_names[1]); |
+ } |
+ |
+ // Cases where the names do not have the same full name strings, |
+ // i.e. the list of merged names is longer than either of the incoming |
+ // lists. |
+ { |
+ // Construct the starting_profile. |
+ AutofillProfile starting_profile(base::GenerateGUID(), |
+ "https://www.example.com/"); |
+ |
+ std::vector<base::string16> names; |
+ names.push_back(ASCIIToUTF16("Antonio Augusto Ribeiro Reis Jr.")); |
+ names.push_back(ASCIIToUTF16("Juninho Pernambucano")); |
+ starting_profile.SetRawMultiInfo(NAME_FULL, names); |
+ names.clear(); |
+ |
+ // Construct the additional_profile. |
+ AutofillProfile additional_profile(base::GenerateGUID(), |
+ "https://www.example.com/"); |
+ names.push_back(ASCIIToUTF16("Marion Mitchell Morrison")); |
+ names.push_back(ASCIIToUTF16("Marion M. Morrison")); |
+ additional_profile.SetRawMultiInfo(NAME_FULL, names); |
+ names.clear(); |
+ |
+ // Merge the names from the |additional_profile| into the |starting_profile| |
+ starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); |
+ |
+ starting_profile.GetRawMultiInfo(NAME_FULL, &names); |
+ ASSERT_EQ(4U, names.size()); |
+ EXPECT_EQ(ASCIIToUTF16("Antonio Augusto Ribeiro Reis Jr."), names[0]); |
+ EXPECT_EQ(ASCIIToUTF16("Juninho Pernambucano"), names[1]); |
+ EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison"), names[2]); |
+ EXPECT_EQ(ASCIIToUTF16("Marion M. Morrison"), names[3]); |
+ } |
Ilya Sherman
2014/06/03 22:09:52
Please include these in the list of cases at the t
Pritam Nikam
2014/06/04 06:54:44
As i understand adding multiple-name in starting &
Ilya Sherman
2014/06/04 22:38:27
Hmm, it looks like you're right that there's no wa
Pritam Nikam
2014/06/07 06:25:12
Done.
|
+} |
+ |
} // namespace autofill |