Chromium Code Reviews| 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/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 3993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4004 // For tests with profile merging, makes sure that these fields' values are | 4004 // For tests with profile merging, makes sure that these fields' values are |
| 4005 // the ones we expect (depending on the test). | 4005 // the ones we expect (depending on the test). |
| 4006 ProfileFields changed_field_values; | 4006 ProfileFields changed_field_values; |
| 4007 } TestCase; | 4007 } TestCase; |
| 4008 | 4008 |
| 4009 TestCase test_cases[] = { | 4009 TestCase test_cases[] = { |
| 4010 // Test that saving an identical profile except for the name results in | 4010 // Test that saving an identical profile except for the name results in |
| 4011 // two profiles being saved. | 4011 // two profiles being saved. |
| 4012 {ProfileFields(), {{NAME_FIRST, "Marionette"}}}, | 4012 {ProfileFields(), {{NAME_FIRST, "Marionette"}}}, |
| 4013 | 4013 |
| 4014 // Test that saving an identical profile except with the middle name | |
| 4015 // initial instead of the full middle name results in the profiles | |
| 4016 // getting merged and the full middle name being kept. | |
| 4017 {ProfileFields(), {{NAME_MIDDLE, "M"}}, {{NAME_MIDDLE, "Mitchell"}}}, | |
| 4018 | |
| 4019 // Test that saving an identical profile except with the full middle name | |
| 4020 // instead of the middle name initial results in the profiles getting | |
| 4021 // merged and the full middle name replacing the initial. | |
| 4022 {{{NAME_MIDDLE, "M"}}, | |
| 4023 {{NAME_MIDDLE, "Mitchell"}}, | |
| 4024 {{NAME_MIDDLE, "Mitchell"}}}, | |
| 4025 | |
| 4026 // Test that saving an identical profile except with no middle name | |
| 4027 // results in the profiles getting merged and the full middle name being | |
| 4028 // kept. | |
| 4029 {ProfileFields(), {{NAME_MIDDLE, ""}}, {{NAME_MIDDLE, "Mitchell"}}}, | |
| 4030 | |
| 4031 // Test that saving an identical profile except with a middle name initial | |
| 4032 // results in the profiles getting merged and the middle name initial | |
| 4033 // being saved. | |
| 4034 {{{NAME_MIDDLE, ""}}, {{NAME_MIDDLE, "M"}}, {{NAME_MIDDLE, "M"}}}, | |
| 4035 | |
| 4036 // Test that saving an identical profile except with a middle name | |
| 4037 // results in the profiles getting merged and the full middle name being | |
| 4038 // saved. | |
| 4039 {{{NAME_MIDDLE, ""}}, | |
| 4040 {{NAME_MIDDLE, "Mitchell"}}, | |
| 4041 {{NAME_MIDDLE, "Mitchell"}}}, | |
| 4042 | |
| 4043 // Test that saving a identical profile except with the full name set | |
| 4044 // instead of the name parts results in the two profiles being merged and | |
| 4045 // all the name parts kept and the full name being added. | |
| 4046 { | |
| 4047 { | |
| 4048 {NAME_FIRST, "Marion"}, | |
| 4049 {NAME_MIDDLE, "Mitchell"}, | |
| 4050 {NAME_LAST, "Morrison"}, | |
| 4051 {NAME_FULL, ""}, | |
| 4052 }, | |
| 4053 { | |
| 4054 {NAME_FIRST, ""}, | |
| 4055 {NAME_MIDDLE, ""}, | |
| 4056 {NAME_LAST, ""}, | |
| 4057 {NAME_FULL, "Marion Mitchell Morrison"}, | |
| 4058 }, | |
| 4059 { | |
| 4060 {NAME_FIRST, "Marion"}, | |
| 4061 {NAME_MIDDLE, "Mitchell"}, | |
| 4062 {NAME_LAST, "Morrison"}, | |
| 4063 {NAME_FULL, "Marion Mitchell Morrison"}, | |
| 4064 }, | |
| 4065 }, | |
| 4066 | |
| 4067 // Test that saving a identical profile except with the name parts set | |
|
Mathieu
2016/05/13 13:32:52
Can we add a test where it's clear that the full n
sebsg
2016/05/13 17:20:02
Done.
| |
| 4068 // instead of the full name results in the two profiles being merged and | |
| 4069 // the full name being kept and all the name parts being added. | |
| 4070 { | |
| 4071 { | |
| 4072 {NAME_FIRST, ""}, | |
| 4073 {NAME_MIDDLE, ""}, | |
| 4074 {NAME_LAST, ""}, | |
| 4075 {NAME_FULL, "Marion Mitchell Morrison"}, | |
| 4076 }, | |
| 4077 { | |
| 4078 {NAME_FIRST, "Marion"}, | |
| 4079 {NAME_MIDDLE, "Mitchell"}, | |
| 4080 {NAME_LAST, "Morrison"}, | |
| 4081 {NAME_FULL, ""}, | |
| 4082 }, | |
| 4083 { | |
| 4084 {NAME_FIRST, "Marion"}, | |
| 4085 {NAME_MIDDLE, "Mitchell"}, | |
| 4086 {NAME_LAST, "Morrison"}, | |
| 4087 {NAME_FULL, "Marion Mitchell Morrison"}, | |
| 4088 }, | |
| 4089 }, | |
| 4090 | |
| 4014 // Test that saving an identical profile except for the first address line | 4091 // Test that saving an identical profile except for the first address line |
| 4015 // results in two profiles being saved. | 4092 // results in two profiles being saved. |
| 4016 {ProfileFields(), {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}}, | 4093 {ProfileFields(), {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}}, |
| 4017 | 4094 |
| 4018 // Test that saving an identical profile except for the second address | 4095 // Test that saving an identical profile except for the second address |
| 4019 // line results in two profiles being saved. | 4096 // line results in two profiles being saved. |
| 4020 {ProfileFields(), {{ADDRESS_HOME_LINE2, "unit 7"}}}, | 4097 {ProfileFields(), {{ADDRESS_HOME_LINE2, "unit 7"}}}, |
| 4021 | 4098 |
| 4022 // Tests that saving an identical profile that has a new piece of | 4099 // Tests that saving an identical profile that has a new piece of |
| 4023 // information (company name) results in a merge and that the original | 4100 // information (company name) results in a merge and that the original |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4145 personal_data_->SaveImportedProfile(profile2); | 4222 personal_data_->SaveImportedProfile(profile2); |
| 4146 | 4223 |
| 4147 const std::vector<AutofillProfile*>& saved_profiles = | 4224 const std::vector<AutofillProfile*>& saved_profiles = |
| 4148 personal_data_->GetProfiles(); | 4225 personal_data_->GetProfiles(); |
| 4149 | 4226 |
| 4150 // If there are no merge changes to verify, make sure that two profiles were | 4227 // If there are no merge changes to verify, make sure that two profiles were |
| 4151 // saved. | 4228 // saved. |
| 4152 if (test_case.changed_field_values.empty()) { | 4229 if (test_case.changed_field_values.empty()) { |
| 4153 EXPECT_EQ(2U, saved_profiles.size()); | 4230 EXPECT_EQ(2U, saved_profiles.size()); |
| 4154 } else { | 4231 } else { |
| 4232 EXPECT_EQ(1U, saved_profiles.size()); | |
| 4233 | |
| 4155 // Make sure the new information was merged correctly. | 4234 // Make sure the new information was merged correctly. |
| 4156 for (ProfileField changed_field : test_case.changed_field_values) { | 4235 for (ProfileField changed_field : test_case.changed_field_values) { |
| 4157 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), | 4236 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), |
| 4158 saved_profiles.front()->GetRawInfo(changed_field.field_type)); | 4237 saved_profiles.front()->GetRawInfo(changed_field.field_type)); |
| 4159 } | 4238 } |
| 4160 // Verify that the merged profile's use count, use date and modification | 4239 // Verify that the merged profile's use count, use date and modification |
| 4161 // date were updated. | 4240 // date were updated. |
| 4162 EXPECT_EQ(2U, saved_profiles.front()->use_count()); | 4241 EXPECT_EQ(2U, saved_profiles.front()->use_count()); |
| 4163 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4242 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4164 base::Time::Now() - saved_profiles.front()->use_date()); | 4243 base::Time::Now() - saved_profiles.front()->use_date()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4245 EXPECT_EQ(5U, profile.use_count()); | 4324 EXPECT_EQ(5U, profile.use_count()); |
| 4246 // The use date and modification dates should have been set to less than 500 | 4325 // The use date and modification dates should have been set to less than 500 |
| 4247 // milliseconds ago. | 4326 // milliseconds ago. |
| 4248 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4327 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4249 base::Time::Now() - profile.use_date()); | 4328 base::Time::Now() - profile.use_date()); |
| 4250 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | 4329 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4251 base::Time::Now() - profile.modification_date()); | 4330 base::Time::Now() - profile.modification_date()); |
| 4252 } | 4331 } |
| 4253 | 4332 |
| 4254 } // namespace autofill | 4333 } // namespace autofill |
| OLD | NEW |