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 4129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4140 // If there are no merge changes to verify, make sure that two profiles were | 4140 // If there are no merge changes to verify, make sure that two profiles were |
4141 // saved. | 4141 // saved. |
4142 if (test_case.changed_field_values.empty()) { | 4142 if (test_case.changed_field_values.empty()) { |
4143 EXPECT_EQ(2U, saved_profiles.size()); | 4143 EXPECT_EQ(2U, saved_profiles.size()); |
4144 } else { | 4144 } else { |
4145 // Make sure the new information was merged correctly. | 4145 // Make sure the new information was merged correctly. |
4146 for (ProfileField changed_field : test_case.changed_field_values) { | 4146 for (ProfileField changed_field : test_case.changed_field_values) { |
4147 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), | 4147 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), |
4148 saved_profiles.front()->GetRawInfo(changed_field.field_type)); | 4148 saved_profiles.front()->GetRawInfo(changed_field.field_type)); |
4149 } | 4149 } |
4150 // Verify that the merged profile's modification and use dates were | 4150 // Verify that the merged profile's use count, use date and modification |
4151 // updated. | 4151 // date were updated. |
| 4152 EXPECT_EQ(2U, saved_profiles.front()->use_count()); |
| 4153 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4154 base::Time::Now() - saved_profiles.front()->use_date()); |
4152 EXPECT_GT( | 4155 EXPECT_GT( |
4153 base::TimeDelta::FromMilliseconds(500), | 4156 base::TimeDelta::FromMilliseconds(500), |
4154 base::Time::Now() - saved_profiles.front()->modification_date()); | 4157 base::Time::Now() - saved_profiles.front()->modification_date()); |
4155 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), | |
4156 base::Time::Now() - saved_profiles.front()->use_date()); | |
4157 } | 4158 } |
4158 | 4159 |
4159 // Erase the profiles for the next test. | 4160 // Erase the profiles for the next test. |
4160 ResetProfiles(); | 4161 ResetProfiles(); |
4161 } | 4162 } |
4162 } | 4163 } |
4163 | 4164 |
4164 // Tests that MergeProfile tries to merge the imported profile into the | 4165 // Tests that MergeProfile tries to merge the imported profile into the |
4165 // existing profile in decreasing order of frecency. | 4166 // existing profile in decreasing order of frecency. |
4166 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { | 4167 TEST_F(PersonalDataManagerTest, MergeProfile_Frecency) { |
(...skipping 24 matching lines...) Expand all Loading... |
4191 | 4192 |
4192 // Merge the imported profile into the existing profiles. | 4193 // Merge the imported profile into the existing profiles. |
4193 std::vector<AutofillProfile> profiles; | 4194 std::vector<AutofillProfile> profiles; |
4194 std::string guid = personal_data_->MergeProfile( | 4195 std::string guid = personal_data_->MergeProfile( |
4195 imported_profile, existing_profiles, "US-EN", &profiles); | 4196 imported_profile, existing_profiles, "US-EN", &profiles); |
4196 | 4197 |
4197 // The new profile should be merged into the "fox" profile. | 4198 // The new profile should be merged into the "fox" profile. |
4198 EXPECT_EQ(profile2.guid(), guid); | 4199 EXPECT_EQ(profile2.guid(), guid); |
4199 } | 4200 } |
4200 | 4201 |
| 4202 // Tests that MergeProfile produces a merged profile with the expected usage |
| 4203 // statistics. |
| 4204 TEST_F(PersonalDataManagerTest, MergeProfile_UsageStats) { |
| 4205 // Create an initial profile with a use count of 10, an old use date and an |
| 4206 // old modification date of 4 days ago. |
| 4207 AutofillProfile profile(base::GenerateGUID(), "https://www.example.com"); |
| 4208 test::SetProfileInfo(&profile, "Homer", "Jay", "Simpson", |
| 4209 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", |
| 4210 "", "Springfield", "IL", "91601", "US", "12345678910"); |
| 4211 profile.set_use_count(4U); |
| 4212 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(4)); |
| 4213 profile.set_modification_date(base::Time::Now() - |
| 4214 base::TimeDelta::FromDays(4)); |
| 4215 |
| 4216 // Create the |existing_profiles| vector. |
| 4217 std::vector<AutofillProfile*> existing_profiles; |
| 4218 existing_profiles.push_back(&profile); |
| 4219 |
| 4220 // Create a new imported profile that will get merged with the existing one. |
| 4221 AutofillProfile imported_profile(base::GenerateGUID(), |
| 4222 "https://www.example.com"); |
| 4223 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", |
| 4224 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", |
| 4225 "Springfield", "IL", "91601", "US", "12345678910"); |
| 4226 |
| 4227 // Merge the imported profile into the existing profiles. |
| 4228 std::vector<AutofillProfile> profiles; |
| 4229 std::string guid = personal_data_->MergeProfile( |
| 4230 imported_profile, existing_profiles, "US-EN", &profiles); |
| 4231 |
| 4232 // The new profile should be merged into the existing profile. |
| 4233 EXPECT_EQ(profile.guid(), guid); |
| 4234 // The use count should have been incremented by one. |
| 4235 EXPECT_EQ(5U, profile.use_count()); |
| 4236 // The use date and modification dates should have been set to less than 500 |
| 4237 // milliseconds ago. |
| 4238 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4239 base::Time::Now() - profile.use_date()); |
| 4240 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), |
| 4241 base::Time::Now() - profile.modification_date()); |
| 4242 } |
| 4243 |
4201 } // namespace autofill | 4244 } // namespace autofill |
OLD | NEW |