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/guid.h" | 7 #include "base/guid.h" |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/stringprintf.h" | |
11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/core/browser/autofill_profile.h" | 14 #include "components/autofill/core/browser/autofill_profile.h" |
13 #include "components/autofill/core/browser/autofill_test_utils.h" | 15 #include "components/autofill/core/browser/autofill_test_utils.h" |
14 #include "components/autofill/core/browser/autofill_type.h" | 16 #include "components/autofill/core/browser/autofill_type.h" |
17 #include "components/autofill/core/browser/field_types.h" | |
15 #include "components/autofill/core/common/form_field_data.h" | 18 #include "components/autofill/core/common/form_field_data.h" |
16 #include "grit/components_strings.h" | 19 #include "grit/components_strings.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
18 | 21 |
19 using base::ASCIIToUTF16; | 22 using base::ASCIIToUTF16; |
20 | 23 |
21 namespace autofill { | 24 namespace autofill { |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), | 894 profile.SetInfo(AutofillType(ADDRESS_HOME_STATE), |
892 ASCIIToUTF16("CA"), | 895 ASCIIToUTF16("CA"), |
893 "en-US"); | 896 "en-US"); |
894 EXPECT_FALSE(profile.GetInfo(full_address, "en-US").empty()); | 897 EXPECT_FALSE(profile.GetInfo(full_address, "en-US").empty()); |
895 profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), | 898 profile.SetInfo(AutofillType(ADDRESS_HOME_COUNTRY), |
896 base::string16(), | 899 base::string16(), |
897 "en-US"); | 900 "en-US"); |
898 EXPECT_TRUE(profile.GetInfo(full_address, "en-US").empty()); | 901 EXPECT_TRUE(profile.GetInfo(full_address, "en-US").empty()); |
899 } | 902 } |
900 | 903 |
904 TEST(AutofillProfileTest, OverwriteOrAppendNames) { | |
905 struct TestCase { | |
906 std::string starting_names[3]; | |
907 std::string additional_names[3]; | |
908 std::string expected_result[3]; | |
909 }; | |
910 | |
911 struct TestCase test_cases[] = { | |
912 // Identical name. | |
913 {{"Marion", "Mitchell", "Morrison"}, | |
914 {"Marion", "Mitchell", "Morrison"}, | |
915 {"Marion", "Mitchell", "Morrison"}}, | |
916 | |
917 // A parse that has a two-word last name should take precedence over a | |
918 // parse that assumes the two names are a middle and a last name. | |
919 {{"Marion", "Mitchell", "Morrison"}, | |
920 {"Marion", "", "Mitchell Morrison"}, | |
921 {"Marion", "", "Mitchell Morrison"}}, | |
922 {{"Marion", "", "Mitchell Morrison"}, | |
923 {"Marion", "Mitchell", "Morrison"}, | |
924 {"Marion", "", "Mitchell Morrison"}}, | |
925 | |
926 // A parse that has a two-word first name should take precedence over a | |
927 // parse that assumes the two names are a first and a middle name. | |
928 {{"Marion", "Mitchell", "Morrison"}, | |
929 {"Marion Mitchell", "", "Morrison"}, | |
930 {"Marion Mitchell", "", "Morrison"}}, | |
931 {{"Marion Mitchell", "", "Morrison"}, | |
932 {"Marion", "Mitchell", "Morrison"}, | |
933 {"Marion Mitchell", "", "Morrison"}}, | |
934 | |
935 // A parse that has a two-word first name and two-word last name should | |
936 // take precedence over a parse that assumes the two middle names and | |
937 // one last name. | |
938 {{"Arthur", "Ignatius Conan", "Doyle"}, | |
939 {"Arthur Ignatius", "", "Conan Doyle"}, | |
940 {"Arthur Ignatius", "", "Conan Doyle"}}, | |
941 {{"Arthur Ignatius", "", "Conan Doyle"}, | |
942 {"Arthur", "Ignatius Conan", "Doyle"}, | |
943 {"Arthur Ignatius", "", "Conan Doyle"}}, | |
944 | |
945 // A parse that has a many-word first name and/or last name should take | |
946 // precedence over a heuristically parsed name into {first, middle1 | |
947 // middle2.. middlen, name}. | |
948 {{"Arthur Ignatius Conan", "", "Doyle"}, | |
949 {"Arthur", "Ignatius Conan", "Doyle"}, | |
950 {"Arthur Ignatius Conan", "", "Doyle"}}, | |
951 {{"Roberto", "Carlos da Silva", "Rocha"}, | |
952 {"Roberto Carlos da Silva", "", "Rocha"}, | |
953 {"Roberto Carlos da Silva", "", "Rocha"}}, | |
954 {{"Antonio", "Augusto", "Ribeiro Reis Jr."}, | |
955 {"Antonio", "Augusto Ribeiro Reis ", "Jr."}, | |
956 {"Antonio", "Augusto", "Ribeiro Reis Jr."}}, | |
957 }; | |
958 | |
959 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | |
960 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | |
961 | |
962 // Construct the starting_profile. | |
963 AutofillProfile starting_profile(base::GenerateGUID(), | |
964 "https://www.example.com/"); | |
965 starting_profile.SetRawInfo(NAME_FIRST, | |
966 ASCIIToUTF16(test_cases[i].starting_names[0])); | |
967 starting_profile.SetRawInfo(NAME_MIDDLE, | |
968 ASCIIToUTF16(test_cases[i].starting_names[1])); | |
969 starting_profile.SetRawInfo(NAME_LAST, | |
970 ASCIIToUTF16(test_cases[i].starting_names[2])); | |
971 | |
972 // Construct the additional_profile. | |
973 AutofillProfile additional_profile(base::GenerateGUID(), | |
974 "https://www.example.com/"); | |
975 additional_profile.SetRawInfo( | |
976 NAME_FIRST, ASCIIToUTF16(test_cases[i].additional_names[0])); | |
977 additional_profile.SetRawInfo( | |
978 NAME_MIDDLE, ASCIIToUTF16(test_cases[i].additional_names[1])); | |
979 additional_profile.SetRawInfo( | |
980 NAME_LAST, ASCIIToUTF16(test_cases[i].additional_names[2])); | |
981 | |
982 // Merge the names from the |additional_profile| into the |starting_profile| | |
983 starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); | |
984 | |
985 // Verify the test expectations. | |
986 EXPECT_EQ(starting_profile.GetRawInfo(NAME_FIRST), | |
987 ASCIIToUTF16(test_cases[i].expected_result[0])); | |
988 EXPECT_EQ(starting_profile.GetRawInfo(NAME_MIDDLE), | |
989 ASCIIToUTF16(test_cases[i].expected_result[1])); | |
990 EXPECT_EQ(starting_profile.GetRawInfo(NAME_LAST), | |
991 ASCIIToUTF16(test_cases[i].expected_result[2])); | |
992 } | |
993 | |
994 // Cases where merging 2 profiles with same fullnames but | |
995 // different canonical forms appends instead of overwrites, | |
996 // provided they dont form heuristically parsed names. | |
997 { | |
998 // Construct the starting_profile. | |
999 AutofillProfile starting_profile(base::GenerateGUID(), | |
1000 "https://www.example.com/"); | |
1001 starting_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Marion Mitchell")); | |
1002 starting_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Morrison")); | |
1003 | |
1004 // Construct the additional_profile. | |
1005 AutofillProfile additional_profile(base::GenerateGUID(), | |
1006 "https://www.example.com/"); | |
1007 additional_profile.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Marion")); | |
1008 additional_profile.SetRawInfo(NAME_LAST, ASCIIToUTF16("Mitchell Morrison")); | |
1009 | |
1010 EXPECT_EQ(starting_profile.GetRawInfo(NAME_FULL), | |
1011 additional_profile.GetRawInfo(NAME_FULL)); | |
1012 | |
1013 // Merge the names from the |additional_profile| into the |starting_profile| | |
1014 starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); | |
1015 | |
1016 std::vector<base::string16> first_names, last_names; | |
1017 starting_profile.GetRawMultiInfo(NAME_FIRST, &first_names); | |
1018 starting_profile.GetRawMultiInfo(NAME_LAST, &last_names); | |
1019 ASSERT_EQ(2U, first_names.size()); | |
1020 ASSERT_EQ(2U, last_names.size()); | |
1021 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell"), first_names[0]); | |
1022 EXPECT_EQ(ASCIIToUTF16("Marion"), first_names[1]); | |
1023 EXPECT_EQ(ASCIIToUTF16("Morrison"), last_names[0]); | |
1024 EXPECT_EQ(ASCIIToUTF16("Mitchell Morrison"), last_names[1]); | |
1025 } | |
1026 | |
1027 // Cases where the names do not have the same full name strings, | |
1028 // i.e. the list of merged names is longer than either of the incoming | |
1029 // lists. | |
1030 { | |
1031 // Construct the starting_profile. | |
1032 AutofillProfile starting_profile(base::GenerateGUID(), | |
1033 "https://www.example.com/"); | |
1034 | |
1035 std::vector<base::string16> names; | |
1036 names.push_back(ASCIIToUTF16("Antonio Augusto Ribeiro Reis Jr.")); | |
1037 names.push_back(ASCIIToUTF16("Juninho Pernambucano")); | |
1038 starting_profile.SetRawMultiInfo(NAME_FULL, names); | |
1039 names.clear(); | |
1040 | |
1041 // Construct the additional_profile. | |
1042 AutofillProfile additional_profile(base::GenerateGUID(), | |
1043 "https://www.example.com/"); | |
1044 names.push_back(ASCIIToUTF16("Marion Mitchell Morrison")); | |
1045 names.push_back(ASCIIToUTF16("Marion M. Morrison")); | |
1046 additional_profile.SetRawMultiInfo(NAME_FULL, names); | |
1047 names.clear(); | |
1048 | |
1049 // Merge the names from the |additional_profile| into the |starting_profile| | |
1050 starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); | |
1051 | |
1052 starting_profile.GetRawMultiInfo(NAME_FULL, &names); | |
1053 ASSERT_EQ(4U, names.size()); | |
1054 EXPECT_EQ(ASCIIToUTF16("Antonio Augusto Ribeiro Reis Jr."), names[0]); | |
1055 EXPECT_EQ(ASCIIToUTF16("Juninho Pernambucano"), names[1]); | |
1056 EXPECT_EQ(ASCIIToUTF16("Marion Mitchell Morrison"), names[2]); | |
1057 EXPECT_EQ(ASCIIToUTF16("Marion M. Morrison"), names[3]); | |
1058 } | |
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.
| |
1059 } | |
1060 | |
901 } // namespace autofill | 1061 } // namespace autofill |
OLD | NEW |