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

// Copyright 2023 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/payments_network_interface.h"

#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/payments/autofill_error_dialog_context.h"
#include "components/autofill/core/browser/payments/card_unmask_challenge_option.h"
#include "components/autofill/core/browser/payments/client_behavior_constants.h"
#include "components/autofill/core/browser/payments/local_card_migration_manager.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/payments/payments_network_interface_test_base.h"
#include "components/autofill/core/browser/payments/test/autofill_payments_test_utils.h"
#include "components/autofill/core/browser/payments/virtual_card_enrollment_flow.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_switches.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/variations/net/variations_http_headers.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "components/variations/variations_associated_data.h"
#include "components/variations/variations_ids_provider.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

HasSubstr;

namespace autofill::payments {
namespace {

PaymentsRpcResult;

struct CardUnmaskOptions {};

}  // namespace

class PaymentsNetworkInterfaceTest : public PaymentsNetworkInterfaceTestBase,
                                     public testing::Test {};

TEST_F(PaymentsNetworkInterfaceTest, GetUnmaskDetailsSuccess) {}

TEST_F(PaymentsNetworkInterfaceTest, GetUnmaskDetailsIncludesChromeUserContext) {}

TEST_F(PaymentsNetworkInterfaceTest, OAuthError) {}

TEST_F(PaymentsNetworkInterfaceTest,
       UnmaskRequestIncludesBillingCustomerNumberInRequest) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskSuccessViaCVC) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskSuccessViaFIDO) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskSuccessViaCVCWithCreationOptions) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskSuccessAccountFromSyncTest) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskSuccessWithVirtualCardCvcAuth) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskSuccessWithVirtualCardFidoAuth) {}

TEST_F(PaymentsNetworkInterfaceTest, VirtualCardRiskBasedGreenPathResponse) {}

TEST_F(PaymentsNetworkInterfaceTest, VirtualCardRiskBasedRedPathResponse_Error) {}

TEST_F(PaymentsNetworkInterfaceTest,
       VirtualCardRiskBasedRedPathResponse_NoOptionProvided) {}

TEST_F(PaymentsNetworkInterfaceTest, VirtualCardRiskBasedYellowPathResponse) {}

TEST_F(PaymentsNetworkInterfaceTest, VirtualCardCvcRetrieval_FlowStatusPresent) {}

TEST_F(PaymentsNetworkInterfaceTest,
       VirtualCardRiskBasedYellowPathResponseWithUnknownType) {}

TEST_F(PaymentsNetworkInterfaceTest, VirtualCardRiskBasedThenFido) {}

TEST_F(PaymentsNetworkInterfaceTest, VirtualCardRiskBasedThenOtpSuccess) {}

TEST_F(PaymentsNetworkInterfaceTest, ExpiredOtp) {}

TEST_F(PaymentsNetworkInterfaceTest, IncorrectOtp) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskIncludesLegacyAndNonLegacyId) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskIncludesOnlyLegacyId) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskIncludesOnlyNonLegacyId) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskIncludesChromeUserContext) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskIncludesMerchantDomain) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskResponseIncludesDeclineDetails) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskResponseIncludesEmptyDeclineDetails) {}

TEST_F(PaymentsNetworkInterfaceTest, OptInSuccess) {}

TEST_F(PaymentsNetworkInterfaceTest, OptInServerUnresponsive) {}

TEST_F(PaymentsNetworkInterfaceTest, OptOutSuccess) {}

TEST_F(PaymentsNetworkInterfaceTest, EnrollAttemptReturnsCreationOptions) {}

TEST_F(PaymentsNetworkInterfaceTest, GetDetailsSuccess) {}

TEST_F(PaymentsNetworkInterfaceTest, GetDetailsSuccessRequestLatencyMetric) {}

TEST_F(PaymentsNetworkInterfaceTest, GetDetailsFailureRequestLatencyMetric) {}

TEST_F(PaymentsNetworkInterfaceTest, GetUploadDetailsVariationsTest) {}

TEST_F(PaymentsNetworkInterfaceTest, GetDetailsFollowedByUploadSuccess) {}

TEST_F(PaymentsNetworkInterfaceTest, GetDetailsMissingContextToken) {}

TEST_F(PaymentsNetworkInterfaceTest, GetDetailsMissingLegalMessage) {}

TEST_F(PaymentsNetworkInterfaceTest, SupportedCardBinRangesParsesCorrectly) {}

TEST_F(PaymentsNetworkInterfaceTest, GetUploadAccountFromSyncTest) {}

TEST_F(PaymentsNetworkInterfaceTest, UploadCardVariationsTest) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskCardVariationsTest) {}

TEST_F(PaymentsNetworkInterfaceTest, UploadSuccessEmptyResponse) {}

TEST_F(PaymentsNetworkInterfaceTest, UploadSuccessInstrumentIdPresent) {}

TEST_F(PaymentsNetworkInterfaceTest, UploadSuccessVirtualCardEnrollmentStatePresent) {}

TEST_F(PaymentsNetworkInterfaceTest,
       UploadSuccessGetDetailsForEnrollmentResponseDetailsPresent) {}

TEST_F(PaymentsNetworkInterfaceTest, UploadSuccessCardArtUrlPresent) {}

TEST_F(PaymentsNetworkInterfaceTest, UploadSuccessMeasureTimeoutHistogram) {}

TEST_F(PaymentsNetworkInterfaceTest, UploadFailureDueToClientSideTimeout) {}

TEST_F(PaymentsNetworkInterfaceTest,
       UploadClientTimeoutNotRecordedForOtherFailure) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskMissingPan) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskRetryFailure) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskPermanentFailure) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskMalformedResponse) {}

TEST_F(PaymentsNetworkInterfaceTest, ReauthNeeded) {}

TEST_F(PaymentsNetworkInterfaceTest, NetworkError) {}

TEST_F(PaymentsNetworkInterfaceTest, OtherError) {}

TEST_F(PaymentsNetworkInterfaceTest, VcnRetrievalTryAgainFailure) {}

TEST_F(PaymentsNetworkInterfaceTest, VcnRetrievalPermanentFailure) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskPermanentFailureWhenVcnMissingExpiration) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskPermanentFailureWhenVcnMissingCvv) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskSuccessMeasureTimeoutHistogram) {}

TEST_F(PaymentsNetworkInterfaceTest, UnmaskFailureDueToClientSideTimeout) {}

TEST_F(PaymentsNetworkInterfaceTest,
       UnmaskClientTimeoutNotRecordedForOtherFailure) {}

// Tests for the local card migration flow. Desktop only.
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
TEST_F(PaymentsNetworkInterfaceTest, GetDetailsFollowedByMigrationSuccess) {}
#endif

// Tests for the local card migration flow. Desktop only.
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
TEST_F(PaymentsNetworkInterfaceTest, MigrateCardsVariationsTest) {}

TEST_F(PaymentsNetworkInterfaceTest, MigrationSuccessWithSaveResult) {}

TEST_F(PaymentsNetworkInterfaceTest, MigrationMissingSaveResult) {}

TEST_F(PaymentsNetworkInterfaceTest, MigrationSuccessWithDisplayText) {}
#endif

TEST_F(PaymentsNetworkInterfaceTest, SelectChallengeOptionWithSmsOtpMethod) {}

TEST_F(PaymentsNetworkInterfaceTest, SelectChallengeOptionSuccess) {}

TEST_F(PaymentsNetworkInterfaceTest, SelectChallengeOptionTemporaryFailure) {}

TEST_F(PaymentsNetworkInterfaceTest, SelectChallengeOptionVcnFlowPermanentFailure) {}

TEST_F(PaymentsNetworkInterfaceTest, SelectChallengeOptionResponseMissingContextToken) {}

UpdateVirtualCardEnrollmentTestData;

class UpdateVirtualCardEnrollmentTest
    : public PaymentsNetworkInterfaceTest,
      public ::testing::WithParamInterface<
          UpdateVirtualCardEnrollmentTestData> {};

// Initializes the parameterized test suite with all possible values of
// VirtualCardEnrollmentSource, VirtualCardEnrollmentRequestType, and
// PaymentsRpcResult.
INSTANTIATE_TEST_SUITE_P();

// Parameterized test that tests all combinations of
// VirtualCardEnrollmentSource and VirtualCardEnrollmentRequestType against all
// possible server responses in the UpdateVirtualCardEnrollmentFlow. This test
// will be run once for each combination.
TEST_P(UpdateVirtualCardEnrollmentTest,
       UpdateVirtualCardEnrollmentTest_TestAllFlows) {}

class GetVirtualCardEnrollmentDetailsTest
    : public PaymentsNetworkInterfaceTest,
      public ::testing::WithParamInterface<
          std::tuple<VirtualCardEnrollmentSource, PaymentsRpcResult>> {};

// Initializes the parameterized test suite with all possible combinations of
// VirtualCardEnrollmentSource and PaymentsRpcResult.
INSTANTIATE_TEST_SUITE_P();

// Parameterized test that tests all combinations of
// VirtualCardEnrollmentSource and server PaymentsRpcResult. This test
// will be run once for each combination.
TEST_P(GetVirtualCardEnrollmentDetailsTest,
       GetVirtualCardEnrollmentDetailsTest_TestAllFlows) {}

}  // namespace autofill::payments