| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 std::vector<NameParts> starting_names; | 64 std::vector<NameParts> starting_names; |
| 65 std::vector<NameParts> additional_names; | 65 std::vector<NameParts> additional_names; |
| 66 std::vector<NameParts> expected_result; | 66 std::vector<NameParts> expected_result; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 // Populates |first_names|, |middle_names| and |last_names| from the list of | 69 // Populates |first_names|, |middle_names| and |last_names| from the list of |
| 70 // NameParts from |starting_names|, |additional_names| or |expected_result| | 70 // NameParts from |starting_names|, |additional_names| or |expected_result| |
| 71 // from the testcase to create and verify the autofill profile. | 71 // from the testcase to create and verify the autofill profile. |
| 72 void GetNamePartsList(const std::vector<NameParts>& names, | 72 void GetNamePartsList(const std::vector<NameParts>& names, |
| 73 std::vector<base::string16>& first_names, | 73 std::vector<base::string16>* first_names, |
| 74 std::vector<base::string16>& middle_names, | 74 std::vector<base::string16>* middle_names, |
| 75 std::vector<base::string16>& last_names) { | 75 std::vector<base::string16>* last_names) { |
| 76 for (size_t i = 0; i < names.size(); ++i) { | 76 for (size_t i = 0; i < names.size(); ++i) { |
| 77 first_names.push_back(ASCIIToUTF16(names[i].first)); | 77 first_names->push_back(ASCIIToUTF16(names[i].first)); |
| 78 middle_names.push_back(ASCIIToUTF16(names[i].middle)); | 78 middle_names->push_back(ASCIIToUTF16(names[i].middle)); |
| 79 last_names.push_back(ASCIIToUTF16(names[i].last)); | 79 last_names->push_back(ASCIIToUTF16(names[i].last)); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace | 83 } // namespace |
| 84 | 84 |
| 85 // Tests different possibilities for summary string generation. | 85 // Tests different possibilities for summary string generation. |
| 86 // Based on existence of first name, last name, and address line 1. | 86 // Based on existence of first name, last name, and address line 1. |
| 87 TEST(AutofillProfileTest, PreviewSummaryString) { | 87 TEST(AutofillProfileTest, PreviewSummaryString) { |
| 88 // Case 0/null: "" | 88 // Case 0/null: "" |
| 89 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com/"); | 89 AutofillProfile profile0(base::GenerateGUID(), "https://www.example.com/"); |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 | 982 |
| 983 // A parse that has a two-word first name should take precedence over a | 983 // A parse that has a two-word first name should take precedence over a |
| 984 // parse that assumes the two names are a first and a middle name. | 984 // parse that assumes the two names are a first and a middle name. |
| 985 test_cases.push_back(TestCase(NameParts("Marion", "Mitchell", "Morrison"), | 985 test_cases.push_back(TestCase(NameParts("Marion", "Mitchell", "Morrison"), |
| 986 NameParts("Marion Mitchell", "", "Morrison"), | 986 NameParts("Marion Mitchell", "", "Morrison"), |
| 987 NameParts("Marion Mitchell", "", "Morrison"))); | 987 NameParts("Marion Mitchell", "", "Morrison"))); |
| 988 test_cases.push_back(TestCase(NameParts("Marion Mitchell", "", "Morrison"), | 988 test_cases.push_back(TestCase(NameParts("Marion Mitchell", "", "Morrison"), |
| 989 NameParts("Marion", "Mitchell", "Morrison"), | 989 NameParts("Marion", "Mitchell", "Morrison"), |
| 990 NameParts("Marion Mitchell", "", "Morrison"))); | 990 NameParts("Marion Mitchell", "", "Morrison"))); |
| 991 | 991 |
| 992 // A parse that has a two-word first name and two-word last name should | 992 // Two names that are identical in full, but not in parts: the parse that |
| 993 // take precedence over a parse that assumes the two middle names and | 993 // does *not* match the heuristic parse should be preferred. |
| 994 // one last name. | |
| 995 test_cases.push_back( | 994 test_cases.push_back( |
| 996 TestCase(NameParts("Arthur", "Ignatius Conan", "Doyle"), | 995 TestCase(NameParts("Arthur", "Ignatius Conan", "Doyle"), |
| 997 NameParts("Arthur Ignatius", "", "Conan Doyle"), | 996 // Heurstic parse. |
| 998 NameParts("Arthur Ignatius", "", "Conan Doyle"))); | 997 NameParts("Arthur Ignatius", "Conan", "Doyle"), |
| 998 NameParts("Arthur", "Ignatius Conan", "Doyle"))); |
| 999 test_cases.push_back( | 999 test_cases.push_back( |
| 1000 TestCase(NameParts("Arthur Ignatius", "", "Conan Doyle"), | 1000 // Heuristic parse. |
| 1001 TestCase(NameParts("Arthur Ignatius", "Conan", "Doyle"), |
| 1001 NameParts("Arthur", "Ignatius Conan", "Doyle"), | 1002 NameParts("Arthur", "Ignatius Conan", "Doyle"), |
| 1002 NameParts("Arthur Ignatius", "", "Conan Doyle"))); | 1003 NameParts("Arthur", "Ignatius Conan", "Doyle"))); |
| 1003 | 1004 |
| 1004 // A parse that has a many-word first name and/or last name should take | 1005 // A parse that has a many-word first name and/or last name should take |
| 1005 // precedence over a heuristically parsed name into {first, middle1 | 1006 // precedence over a heuristically parsed name. |
| 1006 // middle2.. middlen, name}. | |
| 1007 test_cases.push_back( | 1007 test_cases.push_back( |
| 1008 TestCase(NameParts("Arthur Ignatius Conan", "", "Doyle"), | 1008 // Heuristic parse. |
| 1009 NameParts("Arthur", "Ignatius Conan", "Doyle"), | 1009 TestCase(NameParts("Roberto Carlos da", "Silva", "Rocha"), |
| 1010 NameParts("Arthur Ignatius Conan", "", "Doyle"))); | |
| 1011 test_cases.push_back( | |
| 1012 TestCase(NameParts("Roberto", "Carlos da Silva", "Rocha"), | |
| 1013 NameParts("Roberto Carlos da Silva", "", "Rocha"), | 1010 NameParts("Roberto Carlos da Silva", "", "Rocha"), |
| 1014 NameParts("Roberto Carlos da Silva", "", "Rocha"))); | 1011 NameParts("Roberto Carlos da Silva", "", "Rocha"))); |
| 1015 test_cases.push_back( | |
| 1016 TestCase(NameParts("Antonio", "Augusto", "Ribeiro Reis Jr."), | |
| 1017 NameParts("Antonio", "Augusto Ribeiro Reis", "Jr."), | |
| 1018 NameParts("Antonio", "Augusto", "Ribeiro Reis Jr."))); | |
| 1019 | 1012 |
| 1020 // Cases where merging 2 profiles with same full names but | 1013 // Cases where merging 2 profiles with same full names but |
| 1021 // different canonical forms appends instead of overwrites, | 1014 // different canonical forms appends instead of overwrites, |
| 1022 // provided they dont form heuristically parsed names. | 1015 // provided they dont form heuristically parsed names. |
| 1023 { | 1016 { |
| 1024 NameParts name1("Marion Mitchell", "", "Morrison"); | 1017 NameParts name1("Marion Mitchell", "", "Morrison"); |
| 1025 NameParts name2("Marion", "", "Mitchell Morrison"); | 1018 NameParts name2("Marion", "", "Mitchell Morrison"); |
| 1026 std::vector<NameParts> starting_names(1, name1); | 1019 std::vector<NameParts> starting_names(1, name1); |
| 1027 std::vector<NameParts> additional_names(1, name2); | 1020 std::vector<NameParts> additional_names(1, name2); |
| 1028 std::vector<NameParts> expected_result; | 1021 std::vector<NameParts> expected_result; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1052 expected_result.push_back(name3); | 1045 expected_result.push_back(name3); |
| 1053 expected_result.push_back(name4); | 1046 expected_result.push_back(name4); |
| 1054 test_cases.push_back( | 1047 test_cases.push_back( |
| 1055 TestCase(starting_names, additional_names, expected_result)); | 1048 TestCase(starting_names, additional_names, expected_result)); |
| 1056 } | 1049 } |
| 1057 | 1050 |
| 1058 for (std::vector<TestCase>::iterator it = test_cases.begin(); | 1051 for (std::vector<TestCase>::iterator it = test_cases.begin(); |
| 1059 it != test_cases.end(); | 1052 it != test_cases.end(); |
| 1060 ++it) { | 1053 ++it) { |
| 1061 TestCase current_case = *it; | 1054 TestCase current_case = *it; |
| 1055 SCOPED_TRACE(current_case.starting_names[0].first + " + " + |
| 1056 current_case.additional_names[0].first + " = " + |
| 1057 current_case.expected_result[0].first); |
| 1062 | 1058 |
| 1063 std::vector<base::string16> first_names, middle_names, last_names; | 1059 std::vector<base::string16> first_names, middle_names, last_names; |
| 1064 GetNamePartsList( | 1060 GetNamePartsList( |
| 1065 current_case.starting_names, first_names, middle_names, last_names); | 1061 current_case.starting_names, &first_names, &middle_names, &last_names); |
| 1066 | 1062 |
| 1067 // Construct the starting_profile. | 1063 // Construct the starting_profile. |
| 1068 AutofillProfile starting_profile(base::GenerateGUID(), | 1064 AutofillProfile starting_profile(base::GenerateGUID(), |
| 1069 "https://www.example.com/"); | 1065 "https://www.example.com/"); |
| 1070 | 1066 |
| 1071 starting_profile.SetRawMultiInfo(NAME_FIRST, first_names); | 1067 starting_profile.SetRawMultiInfo(NAME_FIRST, first_names); |
| 1072 starting_profile.SetRawMultiInfo(NAME_MIDDLE, middle_names); | 1068 starting_profile.SetRawMultiInfo(NAME_MIDDLE, middle_names); |
| 1073 starting_profile.SetRawMultiInfo(NAME_LAST, last_names); | 1069 starting_profile.SetRawMultiInfo(NAME_LAST, last_names); |
| 1074 | 1070 |
| 1075 first_names.clear(); | 1071 first_names.clear(); |
| 1076 middle_names.clear(); | 1072 middle_names.clear(); |
| 1077 last_names.clear(); | 1073 last_names.clear(); |
| 1078 GetNamePartsList( | 1074 GetNamePartsList( |
| 1079 current_case.additional_names, first_names, middle_names, last_names); | 1075 current_case.additional_names, &first_names, &middle_names, |
| 1076 &last_names); |
| 1080 | 1077 |
| 1081 // Construct the additional_profile. | 1078 // Construct the additional_profile. |
| 1082 AutofillProfile additional_profile(base::GenerateGUID(), | 1079 AutofillProfile additional_profile(base::GenerateGUID(), |
| 1083 "https://www.example.com/"); | 1080 "https://www.example.com/"); |
| 1084 additional_profile.SetRawMultiInfo(NAME_FIRST, first_names); | 1081 additional_profile.SetRawMultiInfo(NAME_FIRST, first_names); |
| 1085 additional_profile.SetRawMultiInfo(NAME_MIDDLE, middle_names); | 1082 additional_profile.SetRawMultiInfo(NAME_MIDDLE, middle_names); |
| 1086 additional_profile.SetRawMultiInfo(NAME_LAST, last_names); | 1083 additional_profile.SetRawMultiInfo(NAME_LAST, last_names); |
| 1087 | 1084 |
| 1088 // Merge the names from the |additional_profile| into the |starting_profile| | 1085 // Merge the names from the |additional_profile| into the |starting_profile| |
| 1089 starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); | 1086 starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); |
| 1090 | 1087 |
| 1091 // Verify the test expectations. | 1088 // Verify the test expectations. |
| 1092 first_names.clear(); | 1089 first_names.clear(); |
| 1093 middle_names.clear(); | 1090 middle_names.clear(); |
| 1094 last_names.clear(); | 1091 last_names.clear(); |
| 1095 GetNamePartsList( | 1092 GetNamePartsList( |
| 1096 current_case.expected_result, first_names, middle_names, last_names); | 1093 current_case.expected_result, &first_names, &middle_names, &last_names); |
| 1097 | 1094 |
| 1098 std::vector<base::string16> merged_first_names, merged_middle_names, | 1095 std::vector<base::string16> merged_first_names, merged_middle_names, |
| 1099 merged_last_names; | 1096 merged_last_names; |
| 1100 starting_profile.GetRawMultiInfo(NAME_FIRST, &merged_first_names); | 1097 starting_profile.GetRawMultiInfo(NAME_FIRST, &merged_first_names); |
| 1101 starting_profile.GetRawMultiInfo(NAME_MIDDLE, &merged_middle_names); | 1098 starting_profile.GetRawMultiInfo(NAME_MIDDLE, &merged_middle_names); |
| 1102 starting_profile.GetRawMultiInfo(NAME_LAST, &merged_last_names); | 1099 starting_profile.GetRawMultiInfo(NAME_LAST, &merged_last_names); |
| 1103 ASSERT_EQ(current_case.expected_result.size(), merged_first_names.size()); | 1100 ASSERT_EQ(current_case.expected_result.size(), merged_first_names.size()); |
| 1104 ASSERT_EQ(current_case.expected_result.size(), merged_middle_names.size()); | 1101 ASSERT_EQ(current_case.expected_result.size(), merged_middle_names.size()); |
| 1105 ASSERT_EQ(current_case.expected_result.size(), merged_last_names.size()); | 1102 ASSERT_EQ(current_case.expected_result.size(), merged_last_names.size()); |
| 1106 | 1103 |
| 1107 for (size_t i = 0; i < current_case.expected_result.size(); ++i) { | 1104 for (size_t i = 0; i < current_case.expected_result.size(); ++i) { |
| 1108 EXPECT_EQ(first_names[i], merged_first_names[i]); | 1105 EXPECT_EQ(first_names[i], merged_first_names[i]); |
| 1109 EXPECT_EQ(middle_names[i], merged_middle_names[i]); | 1106 EXPECT_EQ(middle_names[i], merged_middle_names[i]); |
| 1110 EXPECT_EQ(last_names[i], merged_last_names[i]); | 1107 EXPECT_EQ(last_names[i], merged_last_names[i]); |
| 1111 } | 1108 } |
| 1112 } | 1109 } |
| 1113 } | 1110 } |
| 1114 | 1111 |
| 1115 } // namespace autofill | 1112 } // namespace autofill |
| OLD | NEW |