Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: components/autofill/core/browser/personal_data_manager_unittest.cc

Issue 1973873002: [Autofill] Improve the merging of two profiles' names. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/autofill/core/browser/contact_info_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
4091 // Test that saving a profile that has only a full name set does not get
4092 // merged with a profile with only the name parts set if the names are
4093 // different.
4094 {
4095 {
4096 {NAME_FIRST, "Marion"},
4097 {NAME_MIDDLE, "Mitchell"},
4098 {NAME_LAST, "Morrison"},
4099 {NAME_FULL, ""},
4100 },
4101 {
4102 {NAME_FIRST, ""},
4103 {NAME_MIDDLE, ""},
4104 {NAME_LAST, ""},
4105 {NAME_FULL, "John Thompson Smith"},
4106 },
4107 },
4108
4109 // Test that saving a profile that has only the name parts set does not
4110 // get merged with a profile with only the full name set if the names are
4111 // different.
4112 {
4113 {
4114 {NAME_FIRST, ""},
4115 {NAME_MIDDLE, ""},
4116 {NAME_LAST, ""},
4117 {NAME_FULL, "John Thompson Smith"},
4118 },
4119 {
4120 {NAME_FIRST, "Marion"},
4121 {NAME_MIDDLE, "Mitchell"},
4122 {NAME_LAST, "Morrison"},
4123 {NAME_FULL, ""},
4124 },
4125 },
4126
4014 // Test that saving an identical profile except for the first address line 4127 // Test that saving an identical profile except for the first address line
4015 // results in two profiles being saved. 4128 // results in two profiles being saved.
4016 {ProfileFields(), {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}}, 4129 {ProfileFields(), {{ADDRESS_HOME_LINE1, "123 Aquarium St."}}},
4017 4130
4018 // Test that saving an identical profile except for the second address 4131 // Test that saving an identical profile except for the second address
4019 // line results in two profiles being saved. 4132 // line results in two profiles being saved.
4020 {ProfileFields(), {{ADDRESS_HOME_LINE2, "unit 7"}}}, 4133 {ProfileFields(), {{ADDRESS_HOME_LINE2, "unit 7"}}},
4021 4134
4022 // Tests that saving an identical profile that has a new piece of 4135 // Tests that saving an identical profile that has a new piece of
4023 // information (company name) results in a merge and that the original 4136 // information (company name) results in a merge and that the original
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
4145 personal_data_->SaveImportedProfile(profile2); 4258 personal_data_->SaveImportedProfile(profile2);
4146 4259
4147 const std::vector<AutofillProfile*>& saved_profiles = 4260 const std::vector<AutofillProfile*>& saved_profiles =
4148 personal_data_->GetProfiles(); 4261 personal_data_->GetProfiles();
4149 4262
4150 // If there are no merge changes to verify, make sure that two profiles were 4263 // If there are no merge changes to verify, make sure that two profiles were
4151 // saved. 4264 // saved.
4152 if (test_case.changed_field_values.empty()) { 4265 if (test_case.changed_field_values.empty()) {
4153 EXPECT_EQ(2U, saved_profiles.size()); 4266 EXPECT_EQ(2U, saved_profiles.size());
4154 } else { 4267 } else {
4268 EXPECT_EQ(1U, saved_profiles.size());
4269
4155 // Make sure the new information was merged correctly. 4270 // Make sure the new information was merged correctly.
4156 for (ProfileField changed_field : test_case.changed_field_values) { 4271 for (ProfileField changed_field : test_case.changed_field_values) {
4157 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), 4272 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value),
4158 saved_profiles.front()->GetRawInfo(changed_field.field_type)); 4273 saved_profiles.front()->GetRawInfo(changed_field.field_type));
4159 } 4274 }
4160 // Verify that the merged profile's use count, use date and modification 4275 // Verify that the merged profile's use count, use date and modification
4161 // date were updated. 4276 // date were updated.
4162 EXPECT_EQ(2U, saved_profiles.front()->use_count()); 4277 EXPECT_EQ(2U, saved_profiles.front()->use_count());
4163 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 4278 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
4164 base::Time::Now() - saved_profiles.front()->use_date()); 4279 base::Time::Now() - saved_profiles.front()->use_date());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
4245 EXPECT_EQ(5U, profile.use_count()); 4360 EXPECT_EQ(5U, profile.use_count());
4246 // The use date and modification dates should have been set to less than 500 4361 // The use date and modification dates should have been set to less than 500
4247 // milliseconds ago. 4362 // milliseconds ago.
4248 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 4363 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
4249 base::Time::Now() - profile.use_date()); 4364 base::Time::Now() - profile.use_date());
4250 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 4365 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
4251 base::Time::Now() - profile.modification_date()); 4366 base::Time::Now() - profile.modification_date());
4252 } 4367 }
4253 4368
4254 } // namespace autofill 4369 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/contact_info_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698