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

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

Issue 2061303002: [Autofill] Log the number of profiles considered/removed during dedupe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clean Created 4 years, 6 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>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
18 #include "base/guid.h" 18 #include "base/guid.h"
19 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/synchronization/waitable_event.h" 21 #include "base/synchronization/waitable_event.h"
22 #include "base/test/histogram_tester.h"
22 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #include "components/autofill/core/browser/autofill_experiments.h" 26 #include "components/autofill/core/browser/autofill_experiments.h"
26 #include "components/autofill/core/browser/autofill_profile.h" 27 #include "components/autofill/core/browser/autofill_profile.h"
27 #include "components/autofill/core/browser/autofill_test_utils.h" 28 #include "components/autofill/core/browser/autofill_test_utils.h"
28 #include "components/autofill/core/browser/field_types.h" 29 #include "components/autofill/core/browser/field_types.h"
29 #include "components/autofill/core/browser/form_structure.h" 30 #include "components/autofill/core/browser/form_structure.h"
30 #include "components/autofill/core/browser/personal_data_manager_observer.h" 31 #include "components/autofill/core/browser/personal_data_manager_observer.h"
31 #include "components/autofill/core/browser/webdata/autofill_table.h" 32 #include "components/autofill/core/browser/webdata/autofill_table.h"
(...skipping 4401 matching lines...) Expand 10 before | Expand all | Expand 10 after
4433 EXPECT_EQ(4U, personal_data_->GetProfiles().size()); 4434 EXPECT_EQ(4U, personal_data_->GetProfiles().size());
4434 4435
4435 // Create a new imported profile with no company name. It is similar to 4436 // Create a new imported profile with no company name. It is similar to
4436 // profiles 1 and 2 and should be merged with them. 4437 // profiles 1 and 2 and should be merged with them.
4437 AutofillProfile imported_profile(base::GenerateGUID(), 4438 AutofillProfile imported_profile(base::GenerateGUID(),
4438 "https://www.example.com"); 4439 "https://www.example.com");
4439 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson", 4440 test::SetProfileInfo(&imported_profile, "Homer", "Jay", "Simpson",
4440 "homer.simpson@abc.com", "", "742. Evergreen Terrace", 4441 "homer.simpson@abc.com", "", "742. Evergreen Terrace",
4441 "", "Springfield", "IL", "91601", "US", "12345678910"); 4442 "", "Springfield", "IL", "91601", "US", "12345678910");
4442 4443
4444 base::HistogramTester histogram_tester;
4443 // Save the imported profile (use it). 4445 // Save the imported profile (use it).
4444 personal_data_->SaveImportedProfile(imported_profile); 4446 personal_data_->SaveImportedProfile(imported_profile);
4445 4447
4446 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4448 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4447 .WillOnce(QuitMainMessageLoop()); 4449 .WillOnce(QuitMainMessageLoop());
4448 base::MessageLoop::current()->Run(); 4450 base::MessageLoop::current()->Run();
4449 4451
4450 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); 4452 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4451 4453
4452 // The imported profile and saved profiles 1 and 2 should be merged together. 4454 // The imported profile and saved profiles 1 and 2 should be merged together.
4453 // Therefore there should only be 3 saved profiles. 4455 // Therefore there should only be 3 saved profiles.
4454 ASSERT_EQ(3U, profiles.size()); 4456 ASSERT_EQ(3U, profiles.size());
4457 // 4 profiles were considered for dedupe.
4458 histogram_tester.ExpectUniqueSample(
4459 "Autofill.NumberOfProfilesConsideredForDedupe", 4, 1);
4460 // 1 profile was removed.
4461 histogram_tester.ExpectUniqueSample(
4462 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1);
4455 4463
4456 // Sort the profiles by frecency to have a deterministic order. 4464 // Sort the profiles by frecency to have a deterministic order.
4457 base::Time comparison_time = base::Time::Now(); 4465 base::Time comparison_time = base::Time::Now();
4458 std::sort(profiles.begin(), profiles.end(), 4466 std::sort(profiles.begin(), profiles.end(),
4459 [comparison_time](const AutofillDataModel* a, 4467 [comparison_time](const AutofillDataModel* a,
4460 const AutofillDataModel* b) { 4468 const AutofillDataModel* b) {
4461 return a->CompareFrecency(b, comparison_time); 4469 return a->CompareFrecency(b, comparison_time);
4462 }); 4470 });
4463 4471
4464 // Since profiles with higher frecency scores are merged into profiles with 4472 // Since profiles with higher frecency scores are merged into profiles with
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4522 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.", 4530 "homer.simpson@abc.com", "Fox", "742 Evergreen Terrace.",
4523 "", "Springfield", "IL", "91601", "US", "12345678910"); 4531 "", "Springfield", "IL", "91601", "US", "12345678910");
4524 4532
4525 std::vector<AutofillProfile*> existing_profiles; 4533 std::vector<AutofillProfile*> existing_profiles;
4526 existing_profiles.push_back(&profile1); 4534 existing_profiles.push_back(&profile1);
4527 existing_profiles.push_back(&profile2); 4535 existing_profiles.push_back(&profile2);
4528 existing_profiles.push_back(&profile3); 4536 existing_profiles.push_back(&profile3);
4529 existing_profiles.push_back(&profile4); 4537 existing_profiles.push_back(&profile4);
4530 existing_profiles.push_back(&profile5); 4538 existing_profiles.push_back(&profile5);
4531 4539
4540 base::HistogramTester histogram_tester;
4532 std::vector<std::string> guids_to_delete; 4541 std::vector<std::string> guids_to_delete;
4533 personal_data_->FindAndMergeDuplicateProfiles(existing_profiles, &profile1, 4542 personal_data_->FindAndMergeDuplicateProfiles(existing_profiles, &profile1,
4534 &guids_to_delete); 4543 &guids_to_delete);
4544 // 5 profiles were considered for dedupe.
4545 histogram_tester.ExpectUniqueSample(
4546 "Autofill.NumberOfProfilesConsideredForDedupe", 5, 1);
4547 // 2 profiles were removed.
4548 histogram_tester.ExpectUniqueSample(
4549 "Autofill.NumberOfProfilesRemovedDuringDedupe", 2, 1);
4535 4550
4536 // Profile1 should be deleted because it was sent as the profile to merge and 4551 // Profile1 should be deleted because it was sent as the profile to merge and
4537 // thus was merged into profile3 and then into profile5. 4552 // thus was merged into profile3 and then into profile5.
4538 EXPECT_TRUE(std::find(guids_to_delete.begin(), guids_to_delete.end(), 4553 EXPECT_TRUE(std::find(guids_to_delete.begin(), guids_to_delete.end(),
4539 profile1.guid()) != guids_to_delete.end()); 4554 profile1.guid()) != guids_to_delete.end());
4540 4555
4541 // Profile3 should be deleted because profile1 was merged into it and the 4556 // Profile3 should be deleted because profile1 was merged into it and the
4542 // resulting profile was then merged into profile5. 4557 // resulting profile was then merged into profile5.
4543 EXPECT_TRUE(std::find(guids_to_delete.begin(), guids_to_delete.end(), 4558 EXPECT_TRUE(std::find(guids_to_delete.begin(), guids_to_delete.end(),
4544 profile3.guid()) != guids_to_delete.end()); 4559 profile3.guid()) != guids_to_delete.end());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4580 4595
4581 EXPECT_EQ(2U, personal_data_->GetProfiles().size()); 4596 EXPECT_EQ(2U, personal_data_->GetProfiles().size());
4582 4597
4583 // Create a new imported profile to be merged with the saved profiles. 4598 // Create a new imported profile to be merged with the saved profiles.
4584 AutofillProfile imported_profile(base::GenerateGUID(), 4599 AutofillProfile imported_profile(base::GenerateGUID(),
4585 "https://www.example.com"); 4600 "https://www.example.com");
4586 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson", 4601 test::SetProfileInfo(&imported_profile, "Homer", "J", "Simpson",
4587 "homer.simpson@abc.com", "", "742. Evergreen Terrace", 4602 "homer.simpson@abc.com", "", "742. Evergreen Terrace",
4588 "", "Springfield", "IL", "91601", "US", ""); 4603 "", "Springfield", "IL", "91601", "US", "");
4589 4604
4605 base::HistogramTester histogram_tester;
4590 personal_data_->SaveImportedProfile(imported_profile); 4606 personal_data_->SaveImportedProfile(imported_profile);
4591 4607
4592 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged()) 4608 EXPECT_CALL(personal_data_observer_, OnPersonalDataChanged())
4593 .WillOnce(QuitMainMessageLoop()); 4609 .WillOnce(QuitMainMessageLoop());
4594 base::MessageLoop::current()->Run(); 4610 base::MessageLoop::current()->Run();
4595 4611
4596 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles(); 4612 std::vector<AutofillProfile*> profiles = personal_data_->GetProfiles();
4597 4613
4598 // The imported profile and saved profiles 1 and 2 should be merged together. 4614 // The imported profile and saved profiles 1 and 2 should be merged together.
4599 // Therefore there should only be 1 saved profile. 4615 // Therefore there should only be 1 saved profile.
4600 ASSERT_EQ(1U, profiles.size()); 4616 ASSERT_EQ(1U, profiles.size());
4617 // 2 profiles were considered for dedupe.
4618 histogram_tester.ExpectUniqueSample(
4619 "Autofill.NumberOfProfilesConsideredForDedupe", 2, 1);
4620 // 1 profile was removed.
4621 histogram_tester.ExpectUniqueSample(
4622 "Autofill.NumberOfProfilesRemovedDuringDedupe", 1, 1);
4601 4623
4602 // Since profiles with higher frecency scores are merged into profiles with 4624 // Since profiles with higher frecency scores are merged into profiles with
4603 // lower frecency scores, the result of the merge should be contained in 4625 // lower frecency scores, the result of the merge should be contained in
4604 // profile2 since it had a lower frecency score compared to profile1. 4626 // profile2 since it had a lower frecency score compared to profile1.
4605 EXPECT_EQ(profile2.guid(), profiles[0]->guid()); 4627 EXPECT_EQ(profile2.guid(), profiles[0]->guid());
4606 // The address syntax that results from the merge should be the one from the 4628 // The address syntax that results from the merge should be the one from the
4607 // imported profile (highest frecency). 4629 // imported profile (highest frecency).
4608 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"), 4630 EXPECT_EQ(UTF8ToUTF16("742. Evergreen Terrace"),
4609 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1)); 4631 profiles[0]->GetRawInfo(ADDRESS_HOME_LINE1));
4610 // The middle name should be full, even if the profile with the higher 4632 // The middle name should be full, even if the profile with the higher
(...skipping 14 matching lines...) Expand all
4625 EXPECT_EQ(profile1.use_count() + profile2.use_count() + 4647 EXPECT_EQ(profile1.use_count() + profile2.use_count() +
4626 imported_profile.use_count(), 4648 imported_profile.use_count(),
4627 profiles[0]->use_count()); 4649 profiles[0]->use_count());
4628 // The use date that results from the merge should be the one from the 4650 // The use date that results from the merge should be the one from the
4629 // imported profile since it was used just now. 4651 // imported profile since it was used just now.
4630 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10), 4652 EXPECT_LT(base::Time::Now() - base::TimeDelta::FromSeconds(10),
4631 profiles[0]->use_date()); 4653 profiles[0]->use_date());
4632 } 4654 }
4633 4655
4634 } // namespace autofill 4656 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/personal_data_manager.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698