chromium/components/autofill/core/browser/payments/local_card_migration_manager_unittest.cc

// Copyright 2018 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/payments/local_card_migration_manager.h"

#include <stddef.h>

#include <algorithm>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/metrics/metrics_hashes.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/metrics/payments/local_card_migration_metrics.h"
#include "components/autofill/core/browser/payments/iban_save_manager.h"
#include "components/autofill/core/browser/payments/payments_customer_data.h"
#include "components/autofill/core/browser/payments/payments_util.h"
#include "components/autofill/core/browser/payments/test_credit_card_save_manager.h"
#include "components/autofill/core/browser/payments/test_local_card_migration_manager.h"
#include "components/autofill/core/browser/payments/test_payments_autofill_client.h"
#include "components/autofill/core/browser/payments/test_payments_network_interface.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/test_autofill_client.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/test_autofill_driver.h"
#include "components/autofill/core/browser/test_browser_autofill_manager.h"
#include "components/autofill/core/browser/test_form_data_importer.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/credit_card_network_identifiers.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/form_data_test_api.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/prefs/pref_service.h"
#include "components/sync/test/test_sync_service.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace autofill {

ASCIIToUTF16;
CreateTestCreditCardFormData;
_;
NiceMock;

class LocalCardMigrationManagerTest : public testing::Test {};

// Having one local card on file and using it will not trigger migration.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_UseLocalCardWithOneLocal) {}

// Having any number of local cards on file and using a new card will not
// trigger migration.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_UseNewCardWithAnyLocal) {}

// Use one local card with more valid local cards available, will trigger
// migration.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_UseLocalCardWithMoreLocal) {}

// Using a local card will not trigger migration even if there are other local
// cards as long as the other local cards are not eligible for migration.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_UseLocalCardWithInvalidLocal) {}

// Using a server card when any number of local cards are eligible for migration
// will trigger migration.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_UseServerCardWithOneValidLocal) {}

// Using a server card will not trigger migration even if there are other local
// cards as long as the other local cards are not eligible for migration.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_UseServerCardWithNoneValidLocal) {}

// Trigger migration if user only signs in.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_SignInOnly) {}

// Use one local card with more valid local cards available but billing customer
// number is blank, will not trigger migration.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_NoPaymentsAccount) {}

// Tests that local cards that match masked server cards do not count as
// migratable.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_LocalCardMatchMaskedServerCard) {}

// GetDetectedValues() should includes cardholder name if all cards have it.
TEST_F(LocalCardMigrationManagerTest, GetDetectedValues_AllWithCardHolderName) {}

// GetDetectedValues() should not include cardholder name if not all cards have
// a cardholder name.
TEST_F(LocalCardMigrationManagerTest,
       GetDetectedValues_OneCardWithoutCardHolderName) {}

// GetDetectedValues() should include the existence of a Google Payments
// account.
TEST_F(LocalCardMigrationManagerTest,
       GetDetectedValues_IncludeGooglePaymentsAccount) {}

TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_ShouldAddMigrateCardsBillableServiceNumberInRequest) {}

TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_ShouldAddMigrateCardsBillingCustomerNumberInRequest) {}

TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_ShouldAddUploadCardSourceInRequest_CheckoutFlow) {}

TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_ShouldAddUploadCardSourceInRequest_SettingsPage) {}

// Verify that when triggering from settings page, intermediate prompt will not
// be triggered.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_TriggerFromSettingsPage) {}

// Verify that when triggering from submitted form, intermediate prompt and main
// prompt are both triggered.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_TriggerFromSubmittedForm) {}

// Verify that given the parsed response from the PaymentsNetworkInterface, the
// migration status is correctly set.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_MigrationSuccess) {}

// Verify that given the parsed response from the PaymentsNetworkInterface, the
// migration status is correctly set.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_MigrationTemporaryFailure) {}

// Verify that given the parsed response from the PaymentsNetworkInterface, the
// migration status is correctly set.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_MigrationPermanentFailure) {}

// Verify selected cards are correctly passed to manager.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_ToggleIsChosen) {}

TEST_F(LocalCardMigrationManagerTest, DeleteLocalCardViaMigrationDialog) {}

// Use one local card with more valid local cards available, don't show prompt
// if max strikes reached.
TEST_F(LocalCardMigrationManagerTest,
       MigrateLocalCreditCard_MaxStrikesReached) {}

// Use one server card with more valid local cards available, don't show prompt
// if max strikes reached.
TEST_F(LocalCardMigrationManagerTest,
       MigrateServerCreditCard_MaxStrikesReached) {}

// When local card migration is accepted, UMA metrics for LocalCardMigration
// strike count is logged.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_StrikeCountUMALogged) {}

// Use one unsupported local card with more supported local cards will not
// show intermediate prompt.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_MigrationAbortWhenUseUnsupportedLocalCard) {}

// Use one supported local card with more unsupported local cards available
// will show intermediate prompt with the only supported local card.
TEST_F(LocalCardMigrationManagerTest,
       MigrateCreditCard_MigrateWhenHasSupportedLocalCard) {}

// Use one unsupported server card with more supported local cards available
// will still show intermediate prompt.
TEST_F(
    LocalCardMigrationManagerTest,
    MigrateCreditCard_MigrateWhenUseUnsupportedServerCardWithSupportedLocalCard) {}

// Use one supported server card with more unsupported local cards will not show
// intermediate prompt.
TEST_F(
    LocalCardMigrationManagerTest,
    MigrateCreditCard_MigrateAbortWhenUseSupportedServerCardWithUnsupportedLocalCard) {}

// All migration requirements are met but GetUploadDetails rpc fails. Verified
// that the intermediate prompt was not shown.
TEST_F(LocalCardMigrationManagerTest, MigrateCreditCard_GetUploadDetailsFails) {}

// Use one local card with more valid local cards available, will log to
// UseOfLocalCard sub-histogram.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationOrigin_UseLocalCardWithMoreLocal) {}

// Using a server card when any number of local cards are eligible for migration
// will log to UseOfServerCard sub-histogram.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationOrigin_UseServerCardWithOneValidLocal) {}

// Using a server card will not trigger migration even if there are other local
// cards as long as the other local cards are not eligible for migration. Verify
// that it will not log to UseOfServerCard sub-histogram.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationOrigin_UseServerCardWithNoneValidLocal) {}

// Verify that triggering from settings page will log to SettingsPage
// sub-histogram.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationOrigin_TriggerFromSettingsPage) {}

// Use new card when submit so migration was not offered. Verify the migration
// decision metric is logged as new card used.
TEST_F(LocalCardMigrationManagerTest, LogMigrationDecisionMetric_UseNewCard) {}

// Use one local card with more valid local cards available but billing customer
// number is blank, will not trigger migration. Verify the migration decision
// metric is logged as failed enablement prerequisites.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_FailedEnablementPrerequisites) {}

// All migration requirements are met but max strikes reached. Verify the
// migration decision metric is logged as max strikes reached.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_MaxStrikesReached) {}

// Use one local card with invalid local card so migration was not offered.
// Verify the migration decision metric is logged as not offered single local
// card.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_NotOfferedSingleLocalCard) {}

// Use one server card with invalid local card so migration was not offered.
// Verify the migration decision metric is logged as no migratable cards.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_NoMigratableCards) {}

// All migration requirements are met but GetUploadDetails rpc fails. Verify the
// migration decision metric is logged as get upload details failed.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_GetUploadDetailsFails) {}

// Use one unsupported local card with more supported local cards will not
// show intermediate prompt. Verify the migration decision metric is logged as
// use unsupported local card.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_UseUnsupportedLocalCard) {}

// Use one supported server card with more unsupported local cards will not show
// intermediate prompt. Verify the migration decision metric is logged as no
// supported cards.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_NoSupportedCardsForSupportedServerCard) {}

// Use one unsupported server card with more unsupported local cards will not
// show intermediate prompt. Verify the migration decision metric is logged as
// no supported cards.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_NoSupportedCardsForUnsupportedServerCard) {}

// All migration requirements are met and migration was offered. Verify the
// migration decision metric is logged as migration offered.
TEST_F(LocalCardMigrationManagerTest,
       LogMigrationDecisionMetric_MigrationOffered) {}

// Tests that if the PaymentsNetworkInterface returns an invalid legal message,
// migration should not be offered.
TEST_F(LocalCardMigrationManagerTest,
       InvalidLegalMessageInOnDidGetUploadDetails) {}

}  // namespace autofill