| 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 "components/autofill/core/browser/contact_info.h" | 5 #include "components/autofill/core/browser/contact_info.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/core/browser/autofill_type.h" | 14 #include "components/autofill/core/browser/autofill_type.h" |
| 15 #include "components/autofill/core/browser/field_types.h" | 15 #include "components/autofill/core/browser/field_types.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using base::ASCIIToUTF16; | 18 using base::ASCIIToUTF16; |
| 19 using base::UTF8ToUTF16; | 19 using base::UTF8ToUTF16; |
| 20 | 20 |
| 21 namespace autofill { | 21 namespace autofill { |
| 22 | 22 |
| 23 struct FullNameTestCase { | 23 struct FullNameTestCase { |
| 24 std::string full_name_input; | 24 std::string full_name_input; |
| 25 std::string given_name_output; | 25 std::string given_name_output; |
| 26 std::string middle_name_output; | 26 std::string middle_name_output; |
| 27 std::string family_name_output; | 27 std::string family_name_output; |
| 28 } full_name_test_cases[] = { | |
| 29 { "", "", "", "" }, | |
| 30 { "John Smith", "John", "", "Smith" }, | |
| 31 { "Julien van der Poel", "Julien", "", "van der Poel" }, | |
| 32 { "John J Johnson", "John", "J", "Johnson" }, | |
| 33 { "John Smith, Jr.", "John", "", "Smith" }, | |
| 34 { "Mr John Smith", "John", "", "Smith" }, | |
| 35 { "Mr. John Smith", "John", "", "Smith" }, | |
| 36 { "Mr. John Smith, M.D.", "John", "", "Smith" }, | |
| 37 { "Mr. John Smith, MD", "John", "", "Smith" }, | |
| 38 { "Mr. John Smith MD", "John", "", "Smith" }, | |
| 39 { "William Hubert J.R.", "William", "Hubert", "J.R." }, | |
| 40 { "John Ma", "John", "", "Ma" }, | |
| 41 { "John Smith, MA", "John", "", "Smith" }, | |
| 42 { "John Jacob Jingleheimer Smith", "John Jacob", "Jingleheimer", "Smith" }, | |
| 43 { "Virgil", "Virgil", "", "" }, | |
| 44 { "Murray Gell-Mann", "Murray", "", "Gell-Mann" }, | |
| 45 { "Mikhail Yevgrafovich Saltykov-Shchedrin", "Mikhail", "Yevgrafovich", | |
| 46 "Saltykov-Shchedrin" }, | |
| 47 { "Arthur Ignatius Conan Doyle", "Arthur Ignatius", "Conan", "Doyle" }, | |
| 48 }; | 28 }; |
| 49 | 29 |
| 50 TEST(NameInfoTest, SetFullName) { | 30 class SetFullNameTest : public testing::TestWithParam<FullNameTestCase> {}; |
| 51 for (const FullNameTestCase& test_case : full_name_test_cases) { | |
| 52 SCOPED_TRACE(test_case.full_name_input); | |
| 53 | 31 |
| 54 NameInfo name; | 32 TEST_P(SetFullNameTest, SetFullName) { |
| 55 name.SetInfo(AutofillType(NAME_FULL), | 33 auto test_case = GetParam(); |
| 56 ASCIIToUTF16(test_case.full_name_input), | 34 SCOPED_TRACE(test_case.full_name_input); |
| 57 "en-US"); | 35 |
| 58 EXPECT_EQ(ASCIIToUTF16(test_case.given_name_output), | 36 NameInfo name; |
| 59 name.GetInfo(AutofillType(NAME_FIRST), "en-US")); | 37 name.SetInfo(AutofillType(NAME_FULL), ASCIIToUTF16(test_case.full_name_input), |
| 60 EXPECT_EQ(ASCIIToUTF16(test_case.middle_name_output), | 38 "en-US"); |
| 61 name.GetInfo(AutofillType(NAME_MIDDLE), "en-US")); | 39 EXPECT_EQ(ASCIIToUTF16(test_case.given_name_output), |
| 62 EXPECT_EQ(ASCIIToUTF16(test_case.family_name_output), | 40 name.GetInfo(AutofillType(NAME_FIRST), "en-US")); |
| 63 name.GetInfo(AutofillType(NAME_LAST), "en-US")); | 41 EXPECT_EQ(ASCIIToUTF16(test_case.middle_name_output), |
| 64 EXPECT_EQ(ASCIIToUTF16(test_case.full_name_input), | 42 name.GetInfo(AutofillType(NAME_MIDDLE), "en-US")); |
| 65 name.GetInfo(AutofillType(NAME_FULL), "en-US")); | 43 EXPECT_EQ(ASCIIToUTF16(test_case.family_name_output), |
| 66 } | 44 name.GetInfo(AutofillType(NAME_LAST), "en-US")); |
| 45 EXPECT_EQ(ASCIIToUTF16(test_case.full_name_input), |
| 46 name.GetInfo(AutofillType(NAME_FULL), "en-US")); |
| 67 } | 47 } |
| 68 | 48 |
| 49 INSTANTIATE_TEST_CASE_P( |
| 50 ContactInfoTest, |
| 51 SetFullNameTest, |
| 52 testing::Values( |
| 53 FullNameTestCase{"", "", "", ""}, |
| 54 FullNameTestCase{"John Smith", "John", "", "Smith"}, |
| 55 FullNameTestCase{"Julien van der Poel", "Julien", "", "van der Poel"}, |
| 56 FullNameTestCase{"John J Johnson", "John", "J", "Johnson"}, |
| 57 FullNameTestCase{"John Smith, Jr.", "John", "", "Smith"}, |
| 58 FullNameTestCase{"Mr John Smith", "John", "", "Smith"}, |
| 59 FullNameTestCase{"Mr. John Smith", "John", "", "Smith"}, |
| 60 FullNameTestCase{"Mr. John Smith, M.D.", "John", "", "Smith"}, |
| 61 FullNameTestCase{"Mr. John Smith, MD", "John", "", "Smith"}, |
| 62 FullNameTestCase{"Mr. John Smith MD", "John", "", "Smith"}, |
| 63 FullNameTestCase{"William Hubert J.R.", "William", "Hubert", "J.R."}, |
| 64 FullNameTestCase{"John Ma", "John", "", "Ma"}, |
| 65 FullNameTestCase{"John Smith, MA", "John", "", "Smith"}, |
| 66 FullNameTestCase{"John Jacob Jingleheimer Smith", "John Jacob", |
| 67 "Jingleheimer", "Smith"}, |
| 68 FullNameTestCase{"Virgil", "Virgil", "", ""}, |
| 69 FullNameTestCase{"Murray Gell-Mann", "Murray", "", "Gell-Mann"}, |
| 70 FullNameTestCase{"Mikhail Yevgrafovich Saltykov-Shchedrin", "Mikhail", |
| 71 "Yevgrafovich", "Saltykov-Shchedrin"}, |
| 72 FullNameTestCase{"Arthur Ignatius Conan Doyle", "Arthur Ignatius", |
| 73 "Conan", "Doyle"})); |
| 74 |
| 69 TEST(NameInfoTest, GetFullName) { | 75 TEST(NameInfoTest, GetFullName) { |
| 70 NameInfo name; | 76 NameInfo name; |
| 71 name.SetRawInfo(NAME_FIRST, ASCIIToUTF16("First")); | 77 name.SetRawInfo(NAME_FIRST, ASCIIToUTF16("First")); |
| 72 name.SetRawInfo(NAME_MIDDLE, base::string16()); | 78 name.SetRawInfo(NAME_MIDDLE, base::string16()); |
| 73 name.SetRawInfo(NAME_LAST, base::string16()); | 79 name.SetRawInfo(NAME_LAST, base::string16()); |
| 74 EXPECT_EQ(ASCIIToUTF16("First"), name.GetRawInfo(NAME_FIRST)); | 80 EXPECT_EQ(ASCIIToUTF16("First"), name.GetRawInfo(NAME_FIRST)); |
| 75 EXPECT_EQ(base::string16(), name.GetRawInfo(NAME_MIDDLE)); | 81 EXPECT_EQ(base::string16(), name.GetRawInfo(NAME_MIDDLE)); |
| 76 EXPECT_EQ(base::string16(), name.GetRawInfo(NAME_LAST)); | 82 EXPECT_EQ(base::string16(), name.GetRawInfo(NAME_LAST)); |
| 77 EXPECT_EQ(base::string16(), name.GetRawInfo(NAME_FULL)); | 83 EXPECT_EQ(base::string16(), name.GetRawInfo(NAME_FULL)); |
| 78 EXPECT_EQ(ASCIIToUTF16("First"), | 84 EXPECT_EQ(ASCIIToUTF16("First"), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 173 |
| 168 // Changing something (e.g., the first name) clears the stored full name. | 174 // Changing something (e.g., the first name) clears the stored full name. |
| 169 name.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Third"), "en-US"); | 175 name.SetInfo(AutofillType(NAME_FIRST), ASCIIToUTF16("Third"), "en-US"); |
| 170 EXPECT_EQ(name.GetRawInfo(NAME_FIRST), ASCIIToUTF16("Third")); | 176 EXPECT_EQ(name.GetRawInfo(NAME_FIRST), ASCIIToUTF16("Third")); |
| 171 EXPECT_EQ(name.GetRawInfo(NAME_MIDDLE), ASCIIToUTF16("Middle")); | 177 EXPECT_EQ(name.GetRawInfo(NAME_MIDDLE), ASCIIToUTF16("Middle")); |
| 172 EXPECT_EQ(name.GetRawInfo(NAME_LAST), ASCIIToUTF16("Last")); | 178 EXPECT_EQ(name.GetRawInfo(NAME_LAST), ASCIIToUTF16("Last")); |
| 173 EXPECT_EQ(ASCIIToUTF16("Third Middle Last"), | 179 EXPECT_EQ(ASCIIToUTF16("Third Middle Last"), |
| 174 name.GetInfo(AutofillType(NAME_FULL), "en-US")); | 180 name.GetInfo(AutofillType(NAME_FULL), "en-US")); |
| 175 } | 181 } |
| 176 | 182 |
| 177 TEST(NameInfoTest, ParsedNamesAreEqual) { | 183 struct ParsedNamesAreEqualTestCase { |
| 178 struct TestCase { | 184 std::string starting_names[3]; |
| 179 std::string starting_names[3]; | 185 std::string additional_names[3]; |
| 180 std::string additional_names[3]; | 186 bool expected_result; |
| 181 bool expected_result; | |
| 182 }; | 187 }; |
| 183 | 188 |
| 184 struct TestCase test_cases[] = { | 189 class ParsedNamesAreEqualTest |
| 185 // Identical name comparison. | 190 : public testing::TestWithParam<ParsedNamesAreEqualTestCase> {}; |
| 186 {{"Marion", "Mitchell", "Morrison"}, | 191 |
| 187 {"Marion", "Mitchell", "Morrison"}, | 192 TEST_P(ParsedNamesAreEqualTest, ParsedNamesAreEqual) { |
| 188 true}, | 193 auto test_case = GetParam(); |
| 189 | |
| 190 // Case-sensitive comparisons. | |
| 191 {{"Marion", "Mitchell", "Morrison"}, | |
| 192 {"Marion", "Mitchell", "MORRISON"}, | |
| 193 false}, | |
| 194 {{"Marion", "Mitchell", "Morrison"}, | |
| 195 {"MARION", "Mitchell", "MORRISON"}, | |
| 196 false}, | |
| 197 {{"Marion", "Mitchell", "Morrison"}, | |
| 198 {"MARION", "MITCHELL", "MORRISON"}, | |
| 199 false}, | |
| 200 {{"Marion", "", "Mitchell Morrison"}, | |
| 201 {"MARION", "", "MITCHELL MORRISON"}, | |
| 202 false}, | |
| 203 {{"Marion Mitchell", "", "Morrison"}, | |
| 204 {"MARION MITCHELL", "", "MORRISON"}, | |
| 205 false}, | |
| 206 | |
| 207 // Identical full names but different canonical forms. | |
| 208 {{"Marion", "Mitchell", "Morrison"}, | |
| 209 {"Marion", "", "Mitchell Morrison"}, | |
| 210 false}, | |
| 211 {{"Marion", "Mitchell", "Morrison"}, | |
| 212 {"Marion Mitchell", "", "MORRISON"}, | |
| 213 false}, | |
| 214 | |
| 215 // Different names. | |
| 216 {{"Marion", "Mitchell", "Morrison"}, {"Marion", "M.", "Morrison"}, false}, | |
| 217 {{"Marion", "Mitchell", "Morrison"}, {"MARION", "M.", "MORRISON"}, false}, | |
| 218 {{"Marion", "Mitchell", "Morrison"}, | |
| 219 {"David", "Mitchell", "Morrison"}, | |
| 220 false}, | |
| 221 | |
| 222 // Non-ASCII characters. | |
| 223 {{"M\xc3\xa1rion Mitchell", "", "Morrison"}, | |
| 224 {"M\xc3\xa1rion Mitchell", "", "Morrison"}, | |
| 225 true}, | |
| 226 }; | |
| 227 | |
| 228 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
| 229 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | |
| 230 | 194 |
| 231 // Construct the starting_profile. | 195 // Construct the starting_profile. |
| 232 NameInfo starting_profile; | 196 NameInfo starting_profile; |
| 233 starting_profile.SetRawInfo(NAME_FIRST, | 197 starting_profile.SetRawInfo(NAME_FIRST, |
| 234 UTF8ToUTF16(test_cases[i].starting_names[0])); | 198 UTF8ToUTF16(test_case.starting_names[0])); |
| 235 starting_profile.SetRawInfo(NAME_MIDDLE, | 199 starting_profile.SetRawInfo(NAME_MIDDLE, |
| 236 UTF8ToUTF16(test_cases[i].starting_names[1])); | 200 UTF8ToUTF16(test_case.starting_names[1])); |
| 237 starting_profile.SetRawInfo(NAME_LAST, | 201 starting_profile.SetRawInfo(NAME_LAST, |
| 238 UTF8ToUTF16(test_cases[i].starting_names[2])); | 202 UTF8ToUTF16(test_case.starting_names[2])); |
| 239 | 203 |
| 240 // Construct the additional_profile. | 204 // Construct the additional_profile. |
| 241 NameInfo additional_profile; | 205 NameInfo additional_profile; |
| 242 additional_profile.SetRawInfo( | 206 additional_profile.SetRawInfo(NAME_FIRST, |
| 243 NAME_FIRST, UTF8ToUTF16(test_cases[i].additional_names[0])); | 207 UTF8ToUTF16(test_case.additional_names[0])); |
| 244 additional_profile.SetRawInfo( | 208 additional_profile.SetRawInfo(NAME_MIDDLE, |
| 245 NAME_MIDDLE, UTF8ToUTF16(test_cases[i].additional_names[1])); | 209 UTF8ToUTF16(test_case.additional_names[1])); |
| 246 additional_profile.SetRawInfo( | 210 additional_profile.SetRawInfo(NAME_LAST, |
| 247 NAME_LAST, UTF8ToUTF16(test_cases[i].additional_names[2])); | 211 UTF8ToUTF16(test_case.additional_names[2])); |
| 248 | 212 |
| 249 // Verify the test expectations. | 213 // Verify the test expectations. |
| 250 EXPECT_EQ(test_cases[i].expected_result, | 214 EXPECT_EQ(test_case.expected_result, |
| 251 starting_profile.ParsedNamesAreEqual(additional_profile)); | 215 starting_profile.ParsedNamesAreEqual(additional_profile)); |
| 252 } | 216 } |
| 253 } | 217 |
| 254 | 218 INSTANTIATE_TEST_CASE_P( |
| 255 TEST(NameInfoTest, OverwriteName) { | 219 ContactInfoTest, |
| 256 struct TestCase { | 220 ParsedNamesAreEqualTest, |
| 221 testing::Values( |
| 222 // Identical name comparison. |
| 223 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 224 {"Marion", "Mitchell", "Morrison"}, |
| 225 true}, |
| 226 |
| 227 // Case-sensitive comparisons. |
| 228 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 229 {"Marion", "Mitchell", "MORRISON"}, |
| 230 false}, |
| 231 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 232 {"MARION", "Mitchell", "MORRISON"}, |
| 233 false}, |
| 234 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 235 {"MARION", "MITCHELL", "MORRISON"}, |
| 236 false}, |
| 237 ParsedNamesAreEqualTestCase{{"Marion", "", "Mitchell Morrison"}, |
| 238 {"MARION", "", "MITCHELL MORRISON"}, |
| 239 false}, |
| 240 ParsedNamesAreEqualTestCase{{"Marion Mitchell", "", "Morrison"}, |
| 241 {"MARION MITCHELL", "", "MORRISON"}, |
| 242 false}, |
| 243 |
| 244 // Identical full names but different canonical forms. |
| 245 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 246 {"Marion", "", "Mitchell Morrison"}, |
| 247 false}, |
| 248 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 249 {"Marion Mitchell", "", "MORRISON"}, |
| 250 false}, |
| 251 |
| 252 // Different names. |
| 253 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 254 {"Marion", "M.", "Morrison"}, |
| 255 false}, |
| 256 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 257 {"MARION", "M.", "MORRISON"}, |
| 258 false}, |
| 259 ParsedNamesAreEqualTestCase{{"Marion", "Mitchell", "Morrison"}, |
| 260 {"David", "Mitchell", "Morrison"}, |
| 261 false}, |
| 262 |
| 263 // Non-ASCII characters. |
| 264 ParsedNamesAreEqualTestCase{ |
| 265 {"M\xc3\xa1rion Mitchell", "", "Morrison"}, |
| 266 {"M\xc3\xa1rion Mitchell", "", "Morrison"}, |
| 267 true})); |
| 268 |
| 269 struct OverwriteNameTestCase { |
| 257 std::string existing_name[4]; | 270 std::string existing_name[4]; |
| 258 std::string new_name[4]; | 271 std::string new_name[4]; |
| 259 std::string expected_name[4]; | 272 std::string expected_name[4]; |
| 260 }; | 273 }; |
| 261 | 274 |
| 262 struct TestCase test_cases[] = { | 275 class OverwriteNameTest |
| 263 // Missing information in the original name gets filled with the new | 276 : public testing::TestWithParam<OverwriteNameTestCase> {}; |
| 264 // name's information. | 277 |
| 265 { | 278 TEST_P(OverwriteNameTest, OverwriteName) { |
| 266 {"", "", "", ""}, | 279 auto test_case = GetParam(); |
| 267 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 268 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 269 }, | |
| 270 // The new name's values overwrite the exsiting name values if they are | |
| 271 // different | |
| 272 { | |
| 273 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 274 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, | |
| 275 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, | |
| 276 }, | |
| 277 // An existing name values do not get replaced with empty values. | |
| 278 { | |
| 279 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 280 {"", "", "", ""}, | |
| 281 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 282 }, | |
| 283 // An existing full middle not does not get replaced by a middle name | |
| 284 // initial. | |
| 285 { | |
| 286 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 287 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, | |
| 288 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 289 }, | |
| 290 // An existing middle name initial is overwritten by the new profile's | |
| 291 // middle name value. | |
| 292 { | |
| 293 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, | |
| 294 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 295 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 296 }, | |
| 297 // A NameInfo with only the full name set overwritten with a NameInfo | |
| 298 // with only the name parts set result in a NameInfo with all the name | |
| 299 // parts and name full set. | |
| 300 { | |
| 301 {"", "", "", "Marion Mitchell Morrison"}, | |
| 302 {"Marion", "Mitchell", "Morrison", ""}, | |
| 303 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 304 }, | |
| 305 // A NameInfo with only the name parts set overwritten with a NameInfo | |
| 306 // with only the full name set result in a NameInfo with all the name | |
| 307 // parts and name full set. | |
| 308 { | |
| 309 {"Marion", "Mitchell", "Morrison", ""}, | |
| 310 {"", "", "", "Marion Mitchell Morrison"}, | |
| 311 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, | |
| 312 }, | |
| 313 }; | |
| 314 | |
| 315 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
| 316 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | |
| 317 | |
| 318 // Construct the starting_profile. | 280 // Construct the starting_profile. |
| 319 NameInfo existing_name; | 281 NameInfo existing_name; |
| 320 existing_name.SetRawInfo(NAME_FIRST, | 282 existing_name.SetRawInfo(NAME_FIRST, |
| 321 UTF8ToUTF16(test_cases[i].existing_name[0])); | 283 UTF8ToUTF16(test_case.existing_name[0])); |
| 322 existing_name.SetRawInfo(NAME_MIDDLE, | 284 existing_name.SetRawInfo(NAME_MIDDLE, |
| 323 UTF8ToUTF16(test_cases[i].existing_name[1])); | 285 UTF8ToUTF16(test_case.existing_name[1])); |
| 324 existing_name.SetRawInfo(NAME_LAST, | 286 existing_name.SetRawInfo(NAME_LAST, |
| 325 UTF8ToUTF16(test_cases[i].existing_name[2])); | 287 UTF8ToUTF16(test_case.existing_name[2])); |
| 326 existing_name.SetRawInfo(NAME_FULL, | 288 existing_name.SetRawInfo(NAME_FULL, |
| 327 UTF8ToUTF16(test_cases[i].existing_name[3])); | 289 UTF8ToUTF16(test_case.existing_name[3])); |
| 328 | 290 |
| 329 // Construct the additional_profile. | 291 // Construct the additional_profile. |
| 330 NameInfo new_name; | 292 NameInfo new_name; |
| 331 new_name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].new_name[0])); | 293 new_name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_case.new_name[0])); |
| 332 new_name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].new_name[1])); | 294 new_name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_case.new_name[1])); |
| 333 new_name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].new_name[2])); | 295 new_name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_case.new_name[2])); |
| 334 new_name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].new_name[3])); | 296 new_name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_case.new_name[3])); |
| 335 | 297 |
| 336 existing_name.OverwriteName(new_name); | 298 existing_name.OverwriteName(new_name); |
| 337 | 299 |
| 338 // Verify the test expectations. | 300 // Verify the test expectations. |
| 339 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[0]), | 301 EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[0]), |
| 340 existing_name.GetRawInfo(NAME_FIRST)); | 302 existing_name.GetRawInfo(NAME_FIRST)); |
| 341 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[1]), | 303 EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[1]), |
| 342 existing_name.GetRawInfo(NAME_MIDDLE)); | 304 existing_name.GetRawInfo(NAME_MIDDLE)); |
| 343 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[2]), | 305 EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[2]), |
| 344 existing_name.GetRawInfo(NAME_LAST)); | 306 existing_name.GetRawInfo(NAME_LAST)); |
| 345 EXPECT_EQ(UTF8ToUTF16(test_cases[i].expected_name[3]), | 307 EXPECT_EQ(UTF8ToUTF16(test_case.expected_name[3]), |
| 346 existing_name.GetRawInfo(NAME_FULL)); | 308 existing_name.GetRawInfo(NAME_FULL)); |
| 347 } | |
| 348 } | 309 } |
| 349 | 310 |
| 350 TEST(NameInfoTest, NamePartsAreEmpty) { | 311 INSTANTIATE_TEST_CASE_P( |
| 351 struct TestCase { | 312 ContactInfoTest, |
| 352 std::string first; | 313 OverwriteNameTest, |
| 353 std::string middle; | 314 testing::Values( |
| 354 std::string last; | 315 // Missing information in the original name gets filled with the new |
| 355 std::string full; | 316 // name's information. |
| 356 bool expected_result; | 317 OverwriteNameTestCase{ |
| 318 {"", "", "", ""}, |
| 319 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 320 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 321 }, |
| 322 // The new name's values overwrite the exsiting name values if they are |
| 323 // different |
| 324 OverwriteNameTestCase{ |
| 325 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 326 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, |
| 327 {"Mario", "Mitchell", "Thompson", "Mario Mitchell Morrison"}, |
| 328 }, |
| 329 // An existing name values do not get replaced with empty values. |
| 330 OverwriteNameTestCase{ |
| 331 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 332 {"", "", "", ""}, |
| 333 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 334 }, |
| 335 // An existing full middle not does not get replaced by a middle name |
| 336 // initial. |
| 337 OverwriteNameTestCase{ |
| 338 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 339 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, |
| 340 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 341 }, |
| 342 // An existing middle name initial is overwritten by the new profile's |
| 343 // middle name value. |
| 344 OverwriteNameTestCase{ |
| 345 {"Marion", "M", "Morrison", "Marion Mitchell Morrison"}, |
| 346 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 347 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 348 }, |
| 349 // A NameInfo with only the full name set overwritten with a NameInfo |
| 350 // with only the name parts set result in a NameInfo with all the name |
| 351 // parts and name full set. |
| 352 OverwriteNameTestCase{ |
| 353 {"", "", "", "Marion Mitchell Morrison"}, |
| 354 {"Marion", "Mitchell", "Morrison", ""}, |
| 355 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 356 }, |
| 357 // A NameInfo with only the name parts set overwritten with a NameInfo |
| 358 // with only the full name set result in a NameInfo with all the name |
| 359 // parts and name full set. |
| 360 OverwriteNameTestCase{ |
| 361 {"Marion", "Mitchell", "Morrison", ""}, |
| 362 {"", "", "", "Marion Mitchell Morrison"}, |
| 363 {"Marion", "Mitchell", "Morrison", "Marion Mitchell Morrison"}, |
| 364 })); |
| 365 |
| 366 struct NamePartsAreEmptyTestCase { |
| 367 std::string first; |
| 368 std::string middle; |
| 369 std::string last; |
| 370 std::string full; |
| 371 bool expected_result; |
| 357 }; | 372 }; |
| 358 | 373 |
| 359 struct TestCase test_cases[] = { | 374 class NamePartsAreEmptyTest |
| 360 {"", "", "", "", true}, | 375 : public testing::TestWithParam<NamePartsAreEmptyTestCase> {}; |
| 361 {"", "", "", "Marion Mitchell Morrison", true}, | 376 |
| 362 {"Marion", "", "", "", false}, | 377 TEST_P(NamePartsAreEmptyTest, NamePartsAreEmpty) { |
| 363 {"", "Mitchell", "", "", false}, | 378 auto test_case = GetParam(); |
| 364 {"", "", "Morrison", "", false}, | |
| 365 }; | |
| 366 | |
| 367 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
| 368 SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i)); | |
| 369 | |
| 370 // Construct the NameInfo. | 379 // Construct the NameInfo. |
| 371 NameInfo name; | 380 NameInfo name; |
| 372 name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_cases[i].first)); | 381 name.SetRawInfo(NAME_FIRST, UTF8ToUTF16(test_case.first)); |
| 373 name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_cases[i].middle)); | 382 name.SetRawInfo(NAME_MIDDLE, UTF8ToUTF16(test_case.middle)); |
| 374 name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_cases[i].last)); | 383 name.SetRawInfo(NAME_LAST, UTF8ToUTF16(test_case.last)); |
| 375 name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_cases[i].full)); | 384 name.SetRawInfo(NAME_FULL, UTF8ToUTF16(test_case.full)); |
| 376 | 385 |
| 377 // Verify the test expectations. | 386 // Verify the test expectations. |
| 378 EXPECT_EQ(test_cases[i].expected_result, name.NamePartsAreEmpty()); | 387 EXPECT_EQ(test_case.expected_result, name.NamePartsAreEmpty()); |
| 379 } | |
| 380 } | 388 } |
| 381 | 389 |
| 390 INSTANTIATE_TEST_CASE_P( |
| 391 ContactInfoTest, |
| 392 NamePartsAreEmptyTest, |
| 393 testing::Values(NamePartsAreEmptyTestCase{"", "", "", "", true}, |
| 394 NamePartsAreEmptyTestCase{"", "", "", |
| 395 "Marion Mitchell Morrison", true}, |
| 396 NamePartsAreEmptyTestCase{"Marion", "", "", "", false}, |
| 397 NamePartsAreEmptyTestCase{"", "Mitchell", "", "", false}, |
| 398 NamePartsAreEmptyTestCase{"", "", "Morrison", "", false})); |
| 399 |
| 382 } // namespace autofill | 400 } // namespace autofill |
| OLD | NEW |