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 typedef struct { | |
906 std::string starting_names[3]; | |
907 std::string additional_names[3]; | |
908 std::string expected_result[3]; | |
909 } TestCase; | |
Ilya Sherman
2014/06/03 00:25:32
nit: "typedef struct { ... } TestCase" -> "struct
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
910 | |
911 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 names middle and | |
Ilya Sherman
2014/06/03 00:25:32
nit: "the two names middle" -> "two middle names"
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
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"}}}; | |
Ilya Sherman
2014/06/03 00:25:32
Please also add test cases where the starting prof
Ilya Sherman
2014/06/03 00:25:32
Please also add a test case where the names do not
Ilya Sherman
2014/06/03 00:25:32
Please also include a test case for merging {"Mari
Pritam Nikam
2014/06/03 15:37:34
Done.
Added in end of the test case. Please have
Pritam Nikam
2014/06/03 15:37:34
Done.
Added in end of the test case. Please have
Pritam Nikam
2014/06/03 15:37:34
Done.
Added in end of the test case. Please have
| |
944 | |
945 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | |
946 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | |
947 | |
948 // Construct the starting_profile. | |
949 AutofillProfile starting_profile(base::GenerateGUID(), | |
950 "https://www.example.com/"); | |
951 starting_profile.SetRawInfo(NAME_FIRST, | |
952 ASCIIToUTF16(test_cases[i].starting_names[0])); | |
953 starting_profile.SetRawInfo(NAME_MIDDLE, | |
954 ASCIIToUTF16(test_cases[i].starting_names[1])); | |
955 starting_profile.SetRawInfo(NAME_LAST, | |
956 ASCIIToUTF16(test_cases[i].starting_names[2])); | |
957 | |
958 // Construct the additional_profile. | |
959 AutofillProfile additional_profile(base::GenerateGUID(), | |
960 "https://www.example.com/"); | |
961 additional_profile.SetRawInfo( | |
962 NAME_FIRST, ASCIIToUTF16(test_cases[i].additional_names[0])); | |
963 additional_profile.SetRawInfo( | |
964 NAME_MIDDLE, ASCIIToUTF16(test_cases[i].additional_names[1])); | |
965 additional_profile.SetRawInfo( | |
966 NAME_LAST, ASCIIToUTF16(test_cases[i].additional_names[2])); | |
967 | |
968 // test OverwriteOrAppendNames() via public helper interface | |
Ilya Sherman
2014/06/03 00:25:32
nit: "Merge the names from the |additional_profile
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
969 starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US"); | |
970 | |
971 // Verify the test expectations. | |
972 EXPECT_EQ(starting_profile.GetRawInfo(NAME_FIRST), | |
973 ASCIIToUTF16(test_cases[i].expected_result[0])); | |
974 EXPECT_EQ(starting_profile.GetRawInfo(NAME_MIDDLE), | |
975 ASCIIToUTF16(test_cases[i].expected_result[1])); | |
976 EXPECT_EQ(starting_profile.GetRawInfo(NAME_LAST), | |
977 ASCIIToUTF16(test_cases[i].expected_result[2])); | |
978 } | |
979 } | |
Ilya Sherman
2014/06/03 00:25:32
nit: Please leave a blank line after this one.
Pritam Nikam
2014/06/03 15:37:34
Done.
| |
901 } // namespace autofill | 980 } // namespace autofill |
OLD | NEW |