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

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

Issue 2164143002: Use the max use count on autofill profile merge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better documentation Created 4 years, 5 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
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 <list> 10 #include <list>
(...skipping 4370 matching lines...) Expand 10 before | Expand all | Expand 10 after
4381 EXPECT_EQ(2U, saved_profiles.size()); 4381 EXPECT_EQ(2U, saved_profiles.size());
4382 } else { 4382 } else {
4383 EXPECT_EQ(1U, saved_profiles.size()); 4383 EXPECT_EQ(1U, saved_profiles.size());
4384 4384
4385 // Make sure the new information was merged correctly. 4385 // Make sure the new information was merged correctly.
4386 for (ProfileField changed_field : test_case.changed_field_values) { 4386 for (ProfileField changed_field : test_case.changed_field_values) {
4387 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value), 4387 EXPECT_EQ(base::UTF8ToUTF16(changed_field.field_value),
4388 saved_profiles.front()->GetRawInfo(changed_field.field_type)); 4388 saved_profiles.front()->GetRawInfo(changed_field.field_type));
4389 } 4389 }
4390 // Verify that the merged profile's use count, use date and modification 4390 // Verify that the merged profile's use count, use date and modification
4391 // date were updated. 4391 // date were properly updated.
4392 EXPECT_EQ(2U, saved_profiles.front()->use_count()); 4392 EXPECT_EQ(1U, saved_profiles.front()->use_count());
4393 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 4393 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
4394 base::Time::Now() - saved_profiles.front()->use_date()); 4394 base::Time::Now() - saved_profiles.front()->use_date());
4395 EXPECT_GT( 4395 EXPECT_GT(
4396 base::TimeDelta::FromMilliseconds(500), 4396 base::TimeDelta::FromMilliseconds(500),
4397 base::Time::Now() - saved_profiles.front()->modification_date()); 4397 base::Time::Now() - saved_profiles.front()->modification_date());
4398 } 4398 }
4399 4399
4400 // Erase the profiles for the next test. 4400 // Erase the profiles for the next test.
4401 ResetProfiles(); 4401 ResetProfiles();
4402 } 4402 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
4464 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "", 4464 "homer.simpson@abc.com", "", "742 Evergreen Terrace", "",
4465 "Springfield", "IL", "91601", "US", "12345678910"); 4465 "Springfield", "IL", "91601", "US", "12345678910");
4466 4466
4467 // Merge the imported profile into the existing profiles. 4467 // Merge the imported profile into the existing profiles.
4468 std::vector<AutofillProfile> profiles; 4468 std::vector<AutofillProfile> profiles;
4469 std::string guid = personal_data_->MergeProfile( 4469 std::string guid = personal_data_->MergeProfile(
4470 imported_profile, existing_profiles, "US-EN", &profiles); 4470 imported_profile, existing_profiles, "US-EN", &profiles);
4471 4471
4472 // The new profile should be merged into the existing profile. 4472 // The new profile should be merged into the existing profile.
4473 EXPECT_EQ(profile.guid(), guid); 4473 EXPECT_EQ(profile.guid(), guid);
4474 // The use count should have been incremented by one. 4474 // The use count should have be max(4, 1) => 4.
4475 EXPECT_EQ(5U, profile.use_count()); 4475 EXPECT_EQ(4U, profile.use_count());
4476 // The use date and modification dates should have been set to less than 500 4476 // The use date and modification dates should have been set to less than 500
4477 // milliseconds ago. 4477 // milliseconds ago.
4478 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 4478 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
4479 base::Time::Now() - profile.use_date()); 4479 base::Time::Now() - profile.use_date());
4480 EXPECT_GT(base::TimeDelta::FromMilliseconds(500), 4480 EXPECT_GT(base::TimeDelta::FromMilliseconds(500),
4481 base::Time::Now() - profile.modification_date()); 4481 base::Time::Now() - profile.modification_date());
4482 } 4482 }
4483 4483
4484 // Tests that DedupeProfiles sets the correct profile guids to 4484 // Tests that DedupeProfiles sets the correct profile guids to
4485 // delete after merging similar profiles. 4485 // delete after merging similar profiles.
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
4635 // The specified phone number from profile1 should be kept (no loss of 4635 // The specified phone number from profile1 should be kept (no loss of
4636 // information). 4636 // information).
4637 EXPECT_EQ(UTF8ToUTF16("12345678910"), 4637 EXPECT_EQ(UTF8ToUTF16("12345678910"),
4638 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 4638 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
4639 // The specified company name from profile2 should be kept (no loss of 4639 // The specified company name from profile2 should be kept (no loss of
4640 // information). 4640 // information).
4641 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); 4641 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME));
4642 // The specified country from the imported profile shoudl be kept (no loss of 4642 // The specified country from the imported profile shoudl be kept (no loss of
4643 // information). 4643 // information).
4644 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); 4644 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY));
4645 // The use count that results from the merge should be the sum of the two 4645 // The use count that results from the merge should be the max of all the
4646 // saved profiles plus 1 (imported profile count). 4646 // profiles use counts.
4647 EXPECT_EQ(profile1.use_count() + profile2.use_count() + profile3.use_count(), 4647 EXPECT_EQ(10U, profiles[0]->use_count());
4648 profiles[0]->use_count());
4649 // The use date that results from the merge should be the one from the 4648 // The use date that results from the merge should be the one from the
4650 // profile1 since it was the most recently used profile. 4649 // profile1 since it was the most recently used profile.
4651 EXPECT_LT(profile1.use_date() - base::TimeDelta::FromSeconds(10), 4650 EXPECT_LT(profile1.use_date() - base::TimeDelta::FromSeconds(10),
4652 profiles[0]->use_date()); 4651 profiles[0]->use_date());
4653 } 4652 }
4654 4653
4655 // Tests that ApplyDedupingRoutine only keeps the verified profile with its 4654 // Tests that ApplyDedupingRoutine only keeps the verified profile with its
4656 // original data when deduping with similar profiles, even if it has a higher 4655 // original data when deduping with similar profiles, even if it has a higher
4657 // frecency score. 4656 // frecency score.
4658 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) { 4657 TEST_F(PersonalDataManagerTest, ApplyDedupingRoutine_VerifiedProfileFirst) {
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
5102 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); 5101 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
5103 // The middle name should be the full version found in |Homer2|, 5102 // The middle name should be the full version found in |Homer2|,
5104 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE)); 5103 EXPECT_EQ(UTF8ToUTF16("Jay"), profiles[0]->GetRawInfo(NAME_MIDDLE));
5105 // The phone number from |Homer2| should be kept (no loss of information). 5104 // The phone number from |Homer2| should be kept (no loss of information).
5106 EXPECT_EQ(UTF8ToUTF16("12345678910"), 5105 EXPECT_EQ(UTF8ToUTF16("12345678910"),
5107 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER)); 5106 profiles[0]->GetRawInfo(PHONE_HOME_WHOLE_NUMBER));
5108 // The company name from |Homer3| should be kept (no loss of information). 5107 // The company name from |Homer3| should be kept (no loss of information).
5109 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME)); 5108 EXPECT_EQ(UTF8ToUTF16("Fox"), profiles[0]->GetRawInfo(COMPANY_NAME));
5110 // The country from |Homer1| profile should be kept (no loss of information). 5109 // The country from |Homer1| profile should be kept (no loss of information).
5111 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY)); 5110 EXPECT_EQ(UTF8ToUTF16("US"), profiles[0]->GetRawInfo(ADDRESS_HOME_COUNTRY));
5112 // The use count that results from the merge should be the sum of Homer 1, 2 5111 // The use count that results from the merge should be the max of Homer 1, 2
5113 // and 3's respective use counts. 5112 // and 3's respective use counts.
5114 EXPECT_EQ(Homer1.use_count() + Homer2.use_count() + Homer3.use_count(), 5113 EXPECT_EQ(10U, profiles[0]->use_count());
5115 profiles[0]->use_count());
5116 // The use date that results from the merge should be the one from the 5114 // The use date that results from the merge should be the one from the
5117 // |Homer1| since it was the most recently used profile. 5115 // |Homer1| since it was the most recently used profile.
5118 EXPECT_LT(Homer1.use_date() - base::TimeDelta::FromSeconds(5), 5116 EXPECT_LT(Homer1.use_date() - base::TimeDelta::FromSeconds(5),
5119 profiles[0]->use_date()); 5117 profiles[0]->use_date());
5120 EXPECT_GT(Homer1.use_date() + base::TimeDelta::FromSeconds(5), 5118 EXPECT_GT(Homer1.use_date() + base::TimeDelta::FromSeconds(5),
5121 profiles[0]->use_date()); 5119 profiles[0]->use_date());
5122 5120
5123 // The other profiles should not have been modified. 5121 // The other profiles should not have been modified.
5124 EXPECT_TRUE(Marge1 == *profiles[1]); 5122 EXPECT_TRUE(Marge1 == *profiles[1]);
5125 EXPECT_TRUE(Homer4 == *profiles[2]); 5123 EXPECT_TRUE(Homer4 == *profiles[2]);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
5218 EnableAutofillProfileCleanup(); 5216 EnableAutofillProfileCleanup();
5219 5217
5220 // The deduping routine should not be run. 5218 // The deduping routine should not be run.
5221 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine()); 5219 EXPECT_FALSE(personal_data_->ApplyDedupingRoutine());
5222 5220
5223 // The two duplicate profiles should still be present. 5221 // The two duplicate profiles should still be present.
5224 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 5222 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
5225 } 5223 }
5226 5224
5227 } // namespace autofill 5225 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698