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 <list> | 10 #include <list> |
| (...skipping 4650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4661 // saved profiles plus 1 (imported profile count). | 4661 // saved profiles plus 1 (imported profile count). |
| 4662 EXPECT_EQ(profile1.use_count() + profile2.use_count() + | 4662 EXPECT_EQ(profile1.use_count() + profile2.use_count() + |
| 4663 imported_profile.use_count(), | 4663 imported_profile.use_count(), |
| 4664 profiles[0]->use_count()); | 4664 profiles[0]->use_count()); |
| 4665 // The use date that results from the merge should be the one from the | 4665 // The use date that results from the merge should be the one from the |
| 4666 // imported profile since it was used just now. | 4666 // imported profile since it was used just now. |
| 4667 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), | 4667 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), |
| 4668 profiles[0]->use_date()); | 4668 profiles[0]->use_date()); |
| 4669 } | 4669 } |
| 4670 | 4670 |
| 4671 // Tests that ApplyProfileUseDatesFix sets the use date of profiles from an | |
| 4672 // incorrect value of 0 to [two weeks from now]. Also tests that SetProfiles | |
| 4673 // does not modify any other profiles. | |
| 4674 TEST_F(PersonalDataManagerTest, ApplyProfileUseDatesFix) { | |
| 4675 // Set the kAutofillProfileUseDatesFixed pref to true so that the fix is not | |
| 4676 // applied just yet. | |
| 4677 personal_data_->pref_service_->SetBoolean( | |
| 4678 prefs::kAutofillProfileUseDatesFixed, true); | |
| 4679 | |
| 4680 // Create a profile. The use date will be set to now automatically. | |
| 4681 AutofillProfile profile1(base::GenerateGUID(), "https://www.example.com"); | |
| 4682 test::SetProfileInfo(&profile1, "Homer", "Jay", "Simpson", | |
| 4683 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | |
| 4684 "", "Springfield", "IL", "91601", "US", "12345678910"); | |
| 4685 | |
| 4686 // Create another profile and set its use date to the default value. | |
| 4687 AutofillProfile profile2(base::GenerateGUID(), "https://www.example.com"); | |
| 4688 test::SetProfileInfo(&profile2, "Marge", "", "Simpson", | |
| 4689 "homer.simpson@abc.com", "SNP", "742 Evergreen Terrace", | |
| 4690 "", "Springfield", "IL", "91601", "US", "12345678910"); | |
| 4691 profile2.set_use_date(base::Time()); | |
| 4692 | |
| 4693 personal_data_->AddProfile(profile1); | |
| 4694 personal_data_->AddProfile(profile2); | |
| 4695 | |
| 4696 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
| 4697 .WillOnce(QuitMainMessageLoop()); | |
| 4698 base::MessageLoop::current()->Run(); | |
| 4699 | |
| 4700 // Get a sorted list of profiles. |profile1| will be first and |profile2| will | |
| 4701 // be second. | |
| 4702 std::vector<AutofillProfile*> saved_profiles = | |
| 4703 personal_data_->GetProfilesToSuggest(); | |
| 4704 | |
| 4705 ASSERT_EQ(2U, saved_profiles.size()); | |
| 4706 // The use dates should not have been modified. | |
| 4707 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), | |
| 4708 saved_profiles[0]->use_date()); | |
| 4709 EXPECT_EQ(base::Time(), saved_profiles[1]->use_date()); | |
| 4710 | |
| 4711 // Set the pref to false to indicate the fix has never been run. | |
| 4712 personal_data_->pref_service_->SetBoolean( | |
| 4713 prefs::kAutofillProfileUseDatesFixed, false); | |
| 4714 personal_data_->ApplyProfileUseDatesFix(); | |
| 4715 | |
| 4716 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) | |
| 4717 .WillOnce(QuitMainMessageLoop()); | |
| 4718 base::MessageLoop::current()->Run(); | |
| 4719 | |
| 4720 // Get a sorted list of profiles. | |
| 4721 saved_profiles = personal_data_->GetProfilesToSuggest(); | |
| 4722 | |
| 4723 ASSERT_EQ(2U, saved_profiles.size()); | |
| 4724 // |profile1|'s use date should not have been modified. | |
| 4725 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(1), | |
| 4726 saved_profiles[0]->use_date()); | |
| 4727 // |profile2|'s use date should have been set to two weeks before now. | |
| 4728 EXPECT_LE(base::Time::Now() - base::TimeDelta::FromDays(15), | |
| 4729 saved_profiles[1]->use_date()); | |
| 4730 EXPECT_GE(base::Time::Now() - base::TimeDelta::FromDays(13), | |
| 4731 saved_profiles[1]->use_date()); | |
|
sebsg
2016/06/17 17:33:05
Could you also test that the fix is not applied a
Mathieu
2016/06/17 17:45:23
Done.
| |
| 4732 } | |
| 4733 | |
| 4671 } // namespace autofill | 4734 } // namespace autofill |
| OLD | NEW |