diff options
Diffstat (limited to 'chromium/components/autofill/core/browser/address_profile_save_manager_unittest.cc')
-rw-r--r-- | chromium/components/autofill/core/browser/address_profile_save_manager_unittest.cc | 159 |
1 files changed, 125 insertions, 34 deletions
diff --git a/chromium/components/autofill/core/browser/address_profile_save_manager_unittest.cc b/chromium/components/autofill/core/browser/address_profile_save_manager_unittest.cc index 4a32d003e19..945d5c3c570 100644 --- a/chromium/components/autofill/core/browser/address_profile_save_manager_unittest.cc +++ b/chromium/components/autofill/core/browser/address_profile_save_manager_unittest.cc @@ -48,6 +48,16 @@ constexpr char kProfileUpdateNumberOfEditsHistogram[] = "Autofill.ProfileImport.UpdateProfileNumberOfEditedFields"; constexpr char kProfileUpdateNumberOfAffectedTypesHistogram[] = "Autofill.ProfileImport.UpdateProfileNumberOfAffectedFields"; +// Histograms related to kAutofillComplementCountryCodeOnImport +// TODO(crbug.com/1297032): Cleanup when launched. +constexpr char kNewProfileWithComplementedCountryDecisionHistogram[] = + "Autofill.ProfileImport.NewProfileWithComplementedCountryDecision"; +constexpr char kProfileUpdateWithComplementedCountryDecisionHistogram[] = + "Autofill.ProfileImport.UpdateProfileWithComplementedCountryDecision"; +constexpr char kNewProfileEditComplementedCountryHistogram[] = + "Autofill.ProfileImport.NewProfileEditedComplementedCountry"; +constexpr char kProfileUpdateEditComplementedCountryHistogram[] = + "Autofill.ProfileImport.UpdateProfileEditedComplementedCountry"; class MockPersonalDataManager : public TestPersonalDataManager { public: @@ -146,9 +156,12 @@ struct ImportScenarioTestCase { bool allow_only_silent_updates = false; }; -class AddressProfileSaveManagerTest : public testing::Test { +class AddressProfileSaveManagerTest + : public testing::Test, + public testing::WithParamInterface<std::tuple<bool>> { public: void SetUp() override { + complement_country_ = std::get<0>(GetParam()); // Enable both explicit save prompts and structured names. // The latter is needed to test the concept of silent updates. scoped_feature_list_.InitWithFeatures( @@ -171,6 +184,7 @@ class AddressProfileSaveManagerTest : public testing::Test { TestAutofillClient autofill_client_; MockPersonalDataManager mock_personal_data_manager_; base::test::ScopedFeatureList scoped_feature_list_; + bool complement_country_; }; void AddressProfileSaveManagerTest::TestImportScenario( @@ -231,7 +245,8 @@ void AddressProfileSaveManagerTest::TestImportScenario( // Initiate the profile import. save_manager.ImportProfileFromForm( test_scenario.observed_profile, "en-US", url, - /*allow_only_silent_updates=*/test_scenario.allow_only_silent_updates); + /*allow_only_silent_updates=*/test_scenario.allow_only_silent_updates, + /*did_complement_country=*/complement_country_); // Assert that there is a finished import process on record. ASSERT_NE(save_manager.last_import(), nullptr); @@ -273,8 +288,12 @@ void AddressProfileSaveManagerTest::TestImportScenario( if (!is_new_profile && !is_confirmable_merge) { histogram_tester.ExpectTotalCount(kNewProfileEditsHistogram, 0); histogram_tester.ExpectTotalCount(kNewProfileDecisionHistogram, 0); + histogram_tester.ExpectTotalCount( + kNewProfileWithComplementedCountryDecisionHistogram, 0); histogram_tester.ExpectTotalCount(kProfileUpdateEditsHistogram, 0); histogram_tester.ExpectTotalCount(kProfileUpdateDecisionHistogram, 0); + histogram_tester.ExpectTotalCount( + kProfileUpdateWithComplementedCountryDecisionHistogram, 0); } else { DCHECK(!is_new_profile || !is_confirmable_merge); @@ -308,6 +327,48 @@ void AddressProfileSaveManagerTest::TestImportScenario( affected_edits_histo, test_scenario.expected_edited_types_for_metrics.size()); + // Metrics related to country complemention. + if (complement_country_) { + histogram_tester.ExpectTotalCount( + !is_new_profile + ? kNewProfileWithComplementedCountryDecisionHistogram + : kProfileUpdateWithComplementedCountryDecisionHistogram, + 0); + histogram_tester.ExpectUniqueSample( + is_new_profile + ? kNewProfileWithComplementedCountryDecisionHistogram + : kProfileUpdateWithComplementedCountryDecisionHistogram, + test_scenario.user_decision, 1); + + // In case the country was edited, expect increased metrics. + if (base::Contains( + test_scenario.expected_edited_types_for_metrics, + AutofillMetrics::SettingsVisibleFieldTypeForMetrics::kCountry)) { + histogram_tester.ExpectTotalCount( + !is_new_profile ? kNewProfileEditComplementedCountryHistogram + : kProfileUpdateEditComplementedCountryHistogram, + 0); + histogram_tester.ExpectTotalCount( + is_new_profile ? kNewProfileEditComplementedCountryHistogram + : kProfileUpdateEditComplementedCountryHistogram, + 1); + } else { + histogram_tester.ExpectTotalCount( + kNewProfileEditComplementedCountryHistogram, 0); + histogram_tester.ExpectTotalCount( + kProfileUpdateEditComplementedCountryHistogram, 0); + } + } else { + histogram_tester.ExpectTotalCount( + kNewProfileWithComplementedCountryDecisionHistogram, 0); + histogram_tester.ExpectTotalCount( + kProfileUpdateWithComplementedCountryDecisionHistogram, 0); + histogram_tester.ExpectTotalCount( + kNewProfileEditComplementedCountryHistogram, 0); + histogram_tester.ExpectTotalCount( + kProfileUpdateEditComplementedCountryHistogram, 0); + } + for (auto edited_type : test_scenario.expected_edited_types_for_metrics) { histogram_tester.ExpectBucketCount(affected_edits_histo, edited_type, 1); } @@ -395,7 +456,7 @@ void AddressProfileSaveManagerTest::TestImportScenario( // Test that a profile is correctly imported when no other profile is stored // yet. -TEST_F(AddressProfileSaveManagerTest, SaveNewProfile) { +TEST_P(AddressProfileSaveManagerTest, SaveNewProfile) { AutofillProfile observed_profile = test::StandardProfile(); ImportScenarioTestCase test_scenario{ @@ -414,7 +475,7 @@ TEST_F(AddressProfileSaveManagerTest, SaveNewProfile) { // Test that a profile is correctly imported when no other profile is stored // yet but another profile is added while waiting for the user response. -TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_ProfileAddedWhileWaiting) { +TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_ProfileAddedWhileWaiting) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile profile_added_while_waiting = test::DifferentFromStandardProfile(); @@ -436,8 +497,8 @@ TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_ProfileAddedWhileWaiting) { } // Test that a profile is not imported and that the user is not prompted if the -// domain is blocked for imorting new profiles. -TEST_F(AddressProfileSaveManagerTest, SaveNewProfileOnBlockedDomain) { +// domain is blocked for importing new profiles. +TEST_P(AddressProfileSaveManagerTest, SaveNewProfileOnBlockedDomain) { AutofillProfile observed_profile = test::StandardProfile(); ImportScenarioTestCase test_scenario{ @@ -458,7 +519,7 @@ TEST_F(AddressProfileSaveManagerTest, SaveNewProfileOnBlockedDomain) { // Test that a profile is correctly imported when no other profile is stored // yet. Here, `kUserNotAsked` is supplied which is done as a fallback in case // the UI is unavailable for technical reasons. -TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_UserNotAskedFallback) { +TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_UserNotAskedFallback) { AutofillProfile observed_profile = test::StandardProfile(); ImportScenarioTestCase test_scenario{ @@ -477,7 +538,7 @@ TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_UserNotAskedFallback) { // Test that a profile is correctly imported when no other profile is stored // yet. Here, the profile is edited by the user. -TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_Edited) { +TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_Edited) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile edited_profile = test::DifferentFromStandardProfile(); // The edited profile must have the same GUID then the observed one. @@ -503,8 +564,32 @@ TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_Edited) { TestImportScenario(test_scenario); } +// Test that the country complemention metric is correctly increased. +TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_EditedCountry) { + AutofillProfile observed_profile = test::StandardProfile(); + AutofillProfile edited_profile = observed_profile; + edited_profile.SetRawInfoWithVerificationStatus( + ADDRESS_HOME_COUNTRY, u"DE", VerificationStatus::kObserved); + + ImportScenarioTestCase test_scenario{ + .existing_profiles = {}, + .observed_profile = observed_profile, + .is_prompt_expected = true, + .user_decision = UserDecision::kEditAccepted, + .edited_profile = edited_profile, + .expected_import_type = AutofillProfileImportType::kNewProfile, + .is_profile_change_expected = true, + .merge_candidate = absl::nullopt, + .import_candidate = observed_profile, + .expected_final_profiles = {edited_profile}, + .expected_edited_types_for_metrics = { + AutofillMetrics::SettingsVisibleFieldTypeForMetrics::kCountry}}; + + TestImportScenario(test_scenario); +} + // Test that a decline to import a new profile is handled correctly. -TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_Declined) { +TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_Declined) { AutofillProfile observed_profile = test::StandardProfile(); ImportScenarioTestCase test_scenario{ @@ -523,7 +608,7 @@ TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_Declined) { // Test that a decline to import a new profile in the message UI is handled // correctly. -TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_MessageDeclined) { +TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_MessageDeclined) { AutofillProfile observed_profile = test::StandardProfile(); ImportScenarioTestCase test_scenario{ @@ -541,7 +626,7 @@ TEST_F(AddressProfileSaveManagerTest, SaveNewProfile_MessageDeclined) { } // Test that the observation of a duplicate profile has no effect. -TEST_F(AddressProfileSaveManagerTest, ImportDuplicateProfile) { +TEST_P(AddressProfileSaveManagerTest, ImportDuplicateProfile) { // Note that the profile is created twice to enforce different GUIDs. AutofillProfile existing_profile = test::StandardProfile(); AutofillProfile observed_profile = test::StandardProfile(); @@ -562,7 +647,7 @@ TEST_F(AddressProfileSaveManagerTest, ImportDuplicateProfile) { // Test that the observation of quasi identical profile that has a different // structure in the name will result in a silent update. -TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfile) { +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile updateable_profile = test::UpdateableStandardProfile(); AutofillProfile final_profile = observed_profile; @@ -583,7 +668,7 @@ TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfile) { // Test that the observation of quasi identical profile that has a different // structure in the name will result in a silent update even though the domain // is blocked for new profile imports. -TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfileOnBlockedDomain) { +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfileOnBlockedDomain) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile updateable_profile = test::UpdateableStandardProfile(); AutofillProfile final_profile = observed_profile; @@ -605,7 +690,7 @@ TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfileOnBlockedDomain) { // Test that the observation of quasi identical profile that has a different // structure in the name will result in a silent update even when the profile // has the legacy property of being verified. -TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateVerifiedProfile) { +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateVerifiedProfile) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile updateable_profile = test::UpdateableStandardProfile(); @@ -630,7 +715,7 @@ TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateVerifiedProfile) { // Test the observation of a profile that can only be merged with a // settings-visible change. Here, `kUserNotAsked` is returned as the fallback // mechanism when the UI is not available for technical reasons. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_UserNotAskedFallback) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); @@ -653,7 +738,7 @@ TEST_F(AddressProfileSaveManagerTest, // Test the observation of a profile that can only be merged with a // settings-visible change. -TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge) { +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); AutofillProfile final_profile = observed_profile; @@ -678,7 +763,7 @@ TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge) { // Test the observation of a profile that can only be merged with a // settings-visible change but the mergeable profile is blocked for updates. -TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_BlockedProfile) { +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_BlockedProfile) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); AutofillProfile final_profile = observed_profile; @@ -701,7 +786,7 @@ TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_BlockedProfile) { // Test the observation of a profile that can only be merged with a // settings-visible change. The existing profile has the legacy property of // being verified. -TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_VerifiedProfile) { +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_VerifiedProfile) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); @@ -730,7 +815,7 @@ TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_VerifiedProfile) { // Test the observation of a profile that can only be merged with a // settings-visible change. -TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_Edited) { +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_Edited) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); AutofillProfile edited_profile = test::DifferentFromStandardProfile(); @@ -761,7 +846,7 @@ TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_Edited) { // Test the observation of a profile that can only be merged with a // settings-visible change but the import is declined by the user. -TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_Declined) { +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_Declined) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); AutofillProfile final_profile = observed_profile; @@ -783,7 +868,7 @@ TEST_F(AddressProfileSaveManagerTest, UserConfirmableMerge_Declined) { // Test a mixed scenario in which a duplicate profile already exists, but a // another profile is mergeable with the observed profile. -TEST_F(AddressProfileSaveManagerTest, UserConfirmableMergeAndDuplicate) { +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndDuplicate) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile existing_duplicate = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); @@ -812,7 +897,7 @@ TEST_F(AddressProfileSaveManagerTest, UserConfirmableMergeAndDuplicate) { // another profile is mergeable with the observed profile. The result should not // be affected by the fact that the domain is blocked for the import of new // profiles. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndDuplicateOnBlockedDomain) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile existing_duplicate = test::StandardProfile(); @@ -842,7 +927,7 @@ TEST_F(AddressProfileSaveManagerTest, // Test a mixed scenario in which a duplicate profile already exists, but a // another profile is mergeable with the observed profile and yet another // profile can be silently updated. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndUpdateAndDuplicate) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile existing_duplicate = test::StandardProfile(); @@ -878,7 +963,7 @@ TEST_F(AddressProfileSaveManagerTest, } // Same as above, but the merge candidate is blocked for updates. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndUpdateAndDuplicate_Blocked) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile existing_duplicate = test::StandardProfile(); @@ -912,7 +997,7 @@ TEST_F(AddressProfileSaveManagerTest, // Test a mixed scenario in which a duplicate profile already exists, but a // another profile is mergeable with the observed profile and yet another // profile can be silently updated. Here, the merge is declined. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndUpdateAndDuplicate_Declined) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile existing_duplicate = test::StandardProfile(); @@ -947,7 +1032,7 @@ TEST_F(AddressProfileSaveManagerTest, // Test a mixed scenario in which a duplicate profile already exists, but a // another profile is mergeable with the observed profile and yet another // profile can be silently updated. Here, the merge is accepted with edits. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndUpdateAndDuplicate_Edited) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile existing_duplicate = test::StandardProfile(); @@ -987,7 +1072,7 @@ TEST_F(AddressProfileSaveManagerTest, TestImportScenario(test_scenario); } -TEST_F(AddressProfileSaveManagerTest, SaveProfileWhenNoSavePrompt) { +TEST_P(AddressProfileSaveManagerTest, SaveProfileWhenNoSavePrompt) { base::test::ScopedFeatureList scoped_feature_list; scoped_feature_list.InitAndDisableFeature( features::kAutofillAddressProfileSavePrompt); @@ -1003,7 +1088,7 @@ TEST_F(AddressProfileSaveManagerTest, SaveProfileWhenNoSavePrompt) { // Tests that a new profile is not imported when only silent updates are // allowed. -TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfile_SaveNewProfile) { +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_SaveNewProfile) { AutofillProfile observed_profile = test::StandardProfile(); ImportScenarioTestCase test_scenario{ @@ -1023,7 +1108,7 @@ TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfile_SaveNewProfile) { // Test that the observation of quasi identical profile that has a different // structure in the name will result in a silent update when only silent updates // are allowed. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_WithIncompleteProfile) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile updateable_profile = test::UpdateableStandardProfile(); @@ -1045,7 +1130,7 @@ TEST_F(AddressProfileSaveManagerTest, // Tests that the profile's structured name information is silently updated when // an updated profile is observed with no settings visible difference. // Silent Update is enabled for the test. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_UpdateStructuredName) { AutofillProfile updateable_profile; test::SetProfileTestValues( @@ -1094,7 +1179,7 @@ TEST_F(AddressProfileSaveManagerTest, // an updated profile with no address data is observed with no settings visible // difference. // Silent Update is enabled for the test. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_UpdateStructuredNameWithIncompleteProfile) { AutofillProfile updateable_profile; test::SetProfileTestValues( @@ -1148,7 +1233,7 @@ TEST_F(AddressProfileSaveManagerTest, // Test that the observation of quasi identical profile that has a different // structure in the name will result in a silent update even though the domain // is blocked for new profile imports when silent updates are enforced. -TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfile_OnBlockedDomain) { +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_OnBlockedDomain) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile updateable_profile = test::UpdateableStandardProfile(); AutofillProfile final_profile = observed_profile; @@ -1171,7 +1256,7 @@ TEST_F(AddressProfileSaveManagerTest, SilentlyUpdateProfile_OnBlockedDomain) { // another profile is mergeable with the observed profile and yet another // profile can be silently updated. Only silent updates are allowed for this // test. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_UserConfirmableMergeAndUpdateAndDuplicate) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile existing_duplicate = test::StandardProfile(); @@ -1200,7 +1285,7 @@ TEST_F(AddressProfileSaveManagerTest, // Tests that the mergeable profiles are not merged when only silent updates // are allowed. -TEST_F(AddressProfileSaveManagerTest, +TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_UserConfirmableMergeNotAllowed) { AutofillProfile observed_profile = test::StandardProfile(); AutofillProfile mergeable_profile = test::SubsetOfStandardProfile(); @@ -1219,6 +1304,12 @@ TEST_F(AddressProfileSaveManagerTest, TestImportScenario(test_scenario); } +// Runs the suite as if the the country was (not) complemented using +// |kAutofillComplementCountryCodeOnImport|. +INSTANTIATE_TEST_SUITE_P(, + AddressProfileSaveManagerTest, + testing::Combine(testing::Bool())); + } // namespace } // namespace autofill |