chromium/components/autofill/core/browser/address_profile_save_manager_unittest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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;

// Names of histrogram used for metric collection.
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[] =;

// Test that two AutofillProfiles have the same `record_type() and `Compare()`
// equal.
MATCHER(CompareWithRecordType, "") {}

// This derived version of the AddressProfileSaveManager stores the last import
// for testing purposes and mocks the UI request.
class TestAddressProfileSaveManager : public AddressProfileSaveManager {};

void TestAddressProfileSaveManager::ClearPendingImport(
    std::unique_ptr<ProfileImportProcess> import_process) {}

ProfileImportProcess* TestAddressProfileSaveManager::last_import() {}

// Definition of a test scenario.
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>> {};

// Expects that none of the histograms `names` has any samples.
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 that a profile is correctly imported when no other profile is stored
// yet.
TEST_P(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_P(AddressProfileSaveManagerTest, SaveNewProfile_ProfileAddedWhileWaiting) {}

// Test that a profile is not imported and that the user is not prompted if the
// domain is blocked for importing new profiles.
TEST_P(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_P(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_P(AddressProfileSaveManagerTest, SaveNewProfile_Edited) {}

// Test that a decline to import a new profile is handled correctly.
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_Declined) {}

// Test that a decline to import a new profile in the message UI is handled
// correctly.
TEST_P(AddressProfileSaveManagerTest, SaveNewProfile_MessageDeclined) {}

// Test that the observation of a duplicate profile has no effect.
TEST_P(AddressProfileSaveManagerTest, ImportDuplicateProfile) {}

// Test that the observation of quasi identical profile that has a different
// structure in the name will not result in a silent update when silent updates
// are disabled by a feature flag.
TEST_P(AddressProfileSaveManagerTest,
       SilentlyUpdateProfile_DisabledByFeatureFlag) {}

// Test that the observation of quasi identical profile that has a different
// structure in the name will result in a silent update.
TEST_P(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_P(AddressProfileSaveManagerTest, SilentlyUpdateProfileOnBlockedDomain) {}

// 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_P(AddressProfileSaveManagerTest,
       UserConfirmableMerge_UserNotAskedFallback) {}

// Test the observation of a profile that can only be merged with a
// settings-visible change will not cause an update when the latter is disabled
// by a feature flag.
TEST_P(AddressProfileSaveManagerTest,
       UserConfirmableMerge_DisabledByFeatureFlag) {}

// Test the observation of a profile that can only be merged with a
// settings-visible change.
TEST_P(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_P(AddressProfileSaveManagerTest, UserConfirmableMerge_BlockedProfile) {}

// Test the observation of a profile that can only be merged with a
// settings-visible change.
TEST_P(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_P(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_P(AddressProfileSaveManagerTest, UserConfirmableMergeAndDuplicate) {}

// Test a mixed scenario in which a duplicate profile already exists, but a
// 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_P(AddressProfileSaveManagerTest,
       UserConfirmableMergeAndDuplicateOnBlockedDomain) {}

// 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_P(AddressProfileSaveManagerTest,
       UserConfirmableMergeAndUpdateAndDuplicate) {}

// Same as above, but the merge candidate is blocked for updates.
TEST_P(AddressProfileSaveManagerTest,
       UserConfirmableMergeAndUpdateAndDuplicate_Blocked) {}

// 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_P(AddressProfileSaveManagerTest,
       UserConfirmableMergeAndUpdateAndDuplicate_Declined) {}

// 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_P(AddressProfileSaveManagerTest,
       UserConfirmableMergeAndUpdateAndDuplicate_Edited) {}

// Tests that a new profile is not imported when only silent updates are
// allowed.
TEST_P(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_P(AddressProfileSaveManagerTest,
       SilentlyUpdateProfile_WithIncompleteProfile) {}

// 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_P(AddressProfileSaveManagerTest,
       SilentlyUpdateProfile_UpdateStructuredName) {}

// Tests that the profile's structured name information is silently updated when
// an updated profile with no address data is observed with no settings visible
// difference.
// Silent Update is enabled for the test.
TEST_P(AddressProfileSaveManagerTest,
       SilentlyUpdateProfile_UpdateStructuredNameWithIncompleteProfile) {}

// 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_P(AddressProfileSaveManagerTest, SilentlyUpdateProfile_OnBlockedDomain) {}

// Test a mixed scenario in which a duplicate profile already exists, but
// 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_P(AddressProfileSaveManagerTest,
       SilentlyUpdateProfile_UserConfirmableMergeAndUpdateAndDuplicate) {}

// Tests that the mergeable profiles are not merged when only silent updates
// are allowed.
TEST_P(AddressProfileSaveManagerTest,
       SilentlyUpdateProfile_UserConfirmableMergeNotAllowed) {}

// Tests that for eligible users, migration prompts are offered for
// `kLocalOrSyncable` profiles.
TEST_P(AddressProfileSaveManagerTest, Migration_Accept) {}

// Tests declining a migration. The strike count should be increased.
TEST_P(AddressProfileSaveManagerTest, Migration_Decline) {}

// Tests declining a migration with the "never migrate" option. Tests that the
// strike count is incremented up to the strike limit.
TEST_P(AddressProfileSaveManagerTest, Migration_Never) {}

// Runs the suite as if:
// - the phone number was (not) removed (relevant for UKM metrics).
// - the imported profile contains information from an input with an
//   unrecognized autocomplete attribute. Such fields are considered for import
//   when `kAutofillImportFromAutocompleteUnrecognized` is active.
INSTANTIATE_TEST_SUITE_P();

}  // namespace

}  // namespace autofill