#include "components/autofill/core/browser/address_profile_save_manager.h"
#include <string_view>
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/autofill_profile_import_process.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address_test_utils.h"
#include "components/autofill/core/browser/metrics/autofill_metrics_utils.h"
#include "components/autofill/core/browser/test_autofill_client.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/browser/test_utils/test_profiles.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace autofill {
namespace {
UkmAddressProfileImportType;
UserDecision;
SettingsVisibleFieldTypeForMetrics;
constexpr char kProfileImportTypeHistogram[] = …;
constexpr char kSilentUpdatesProfileImportTypeHistogram[] = …;
constexpr char kNewProfileStorageHistogram[] = …;
constexpr char kNewProfileEditsHistogram[] = …;
constexpr char kProfileUpdateEditsHistogram[] = …;
constexpr char kProfileMigrationEditsHistogram[] = …;
constexpr char kProfileUpdateAffectedTypesHistogram[] = …;
constexpr char kNewProfileDecisionHistogram[] = …;
constexpr char kProfileUpdateDecisionHistogram[] = …;
constexpr char kProfileMigrationDecisionHistogram[] = …;
constexpr char kProfileUpdateNumberOfAffectedTypesHistogram[] = …;
MATCHER(CompareWithRecordType, "") { … }
class TestAddressProfileSaveManager : public AddressProfileSaveManager { … };
void TestAddressProfileSaveManager::ClearPendingImport(
std::unique_ptr<ProfileImportProcess> import_process) { … }
ProfileImportProcess* TestAddressProfileSaveManager::last_import() { … }
struct ImportScenarioTestCase { … };
bool IsNewProfile(const ImportScenarioTestCase& test_scenario) { … }
bool IsConfirmableMerge(const ImportScenarioTestCase& test_scenario) { … }
bool IsMigration(const ImportScenarioTestCase& test_scenario) { … }
class AddressProfileSaveManagerTest
: public testing::Test,
public testing::WithParamInterface<std::tuple<bool, bool>> { … };
void ExpectEmptyHistograms(const base::HistogramTester& histogram_tester,
const std::vector<std::string_view>& names) { … }
void AddressProfileSaveManagerTest::TestImportScenario(
ImportScenarioTestCase& test_scenario) { … }
void AddressProfileSaveManagerTest::VerifyFinalProfiles(
const ImportScenarioTestCase& test_scenario) { … }
void AddressProfileSaveManagerTest::VerifyUMAMetricsCollection(
const ImportScenarioTestCase& test_scenario,
const base::HistogramTester& histogram_tester) const { … }
void AddressProfileSaveManagerTest::VerifyUpdateAffectedTypesHistogram(
const ImportScenarioTestCase& test_scenario,
const base::HistogramTester& histogram_tester) const { … }
void AddressProfileSaveManagerTest::VerifyStrikeCounts(
const ImportScenarioTestCase& test_scenario,
const ProfileImportProcess& last_import,
int initial_strikes_for_domain) { … }
void AddressProfileSaveManagerTest::VerifyUkmForAddressImport(
const ukm::TestUkmRecorder* ukm_recorder,
const ImportScenarioTestCase& test_scenario) const { … }
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile) { … }
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_ProfileAddedWhileWaiting) { … }
TEST_P(AddressProfileSaveManagerTest, SaveNewProfileOnBlockedDomain) { … }
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_UserNotAskedFallback) { … }
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_Edited) { … }
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_Declined) { … }
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_MessageDeclined) { … }
TEST_P(AddressProfileSaveManagerTest, ImportDuplicateProfile) { … }
TEST_P(AddressProfileSaveManagerTest,
SilentlyUpdateProfile_DisabledByFeatureFlag) { … }
TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile) { … }
TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfileOnBlockedDomain) { … }
TEST_P(AddressProfileSaveManagerTest,
UserConfirmableMerge_UserNotAskedFallback) { … }
TEST_P(AddressProfileSaveManagerTest,
UserConfirmableMerge_DisabledByFeatureFlag) { … }
TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge) { … }
TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_BlockedProfile) { … }
TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_Edited) { … }
TEST_P(AddressProfileSaveManagerTest, UserConfirmableMerge_Declined) { … }
TEST_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndDuplicate) { … }
TEST_P(AddressProfileSaveManagerTest,
UserConfirmableMergeAndDuplicateOnBlockedDomain) { … }
TEST_P(AddressProfileSaveManagerTest,
UserConfirmableMergeAndUpdateAndDuplicate) { … }
TEST_P(AddressProfileSaveManagerTest,
UserConfirmableMergeAndUpdateAndDuplicate_Blocked) { … }
TEST_P(AddressProfileSaveManagerTest,
UserConfirmableMergeAndUpdateAndDuplicate_Declined) { … }
TEST_P(AddressProfileSaveManagerTest,
UserConfirmableMergeAndUpdateAndDuplicate_Edited) { … }
TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_SaveNewProfile) { … }
TEST_P(AddressProfileSaveManagerTest,
SilentlyUpdateProfile_WithIncompleteProfile) { … }
TEST_P(AddressProfileSaveManagerTest,
SilentlyUpdateProfile_UpdateStructuredName) { … }
TEST_P(AddressProfileSaveManagerTest,
SilentlyUpdateProfile_UpdateStructuredNameWithIncompleteProfile) { … }
TEST_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_OnBlockedDomain) { … }
TEST_P(AddressProfileSaveManagerTest,
SilentlyUpdateProfile_UserConfirmableMergeAndUpdateAndDuplicate) { … }
TEST_P(AddressProfileSaveManagerTest,
SilentlyUpdateProfile_UserConfirmableMergeNotAllowed) { … }
TEST_P(AddressProfileSaveManagerTest, Migration_Accept) { … }
TEST_P(AddressProfileSaveManagerTest, Migration_Decline) { … }
TEST_P(AddressProfileSaveManagerTest, Migration_Never) { … }
INSTANTIATE_TEST_SUITE_P(…);
}
}