#include "components/autofill/core/browser/payments/credit_card_save_manager.h"
#include <stddef.h>
#include <algorithm>
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/metrics/metrics_hashes.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/address_data_manager_test_api.h"
#include "components/autofill/core/browser/autofill_experiments.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/form_data_importer.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/metrics/payments/credit_card_save_metrics.h"
#include "components/autofill/core/browser/payments/client_behavior_constants.h"
#include "components/autofill/core/browser/payments/iban_save_manager.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.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_legal_message_line.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/test_virtual_card_enrollment_manager.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/strike_databases/payments/test_credit_card_save_strike_database.h"
#include "components/autofill/core/browser/strike_databases/payments/test_strike_database.h"
#include "components/autofill/core/browser/test_autofill_client.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_payments_data_manager.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autocomplete_parsing_util.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_test_utils.h"
#include "components/autofill/core/common/credit_card_network_identifiers.h"
#include "components/autofill/core/common/credit_card_number_validation.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 "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source.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 {
namespace {
ASCIIToUTF16;
CreateTestAddressFormData;
CreateTestFormField;
_;
A;
AtLeast;
DoAll;
ElementsAre;
Field;
NiceMock;
Return;
SaveArg;
UnorderedElementsAre;
UkmCardUploadDecisionType;
UkmDeveloperEngagementType;
SaveCreditCardOptions;
SaveCardOfferUserDecision;
#if !BUILDFLAG(IS_IOS)
base::TimeDelta kVeryLargeDelta = …;
#endif
struct CreditCardFormOptions { … };
}
class MockPaymentsDataManager : public TestPaymentsDataManager { … };
class MockPaymentsAutofillClient : public payments::TestPaymentsAutofillClient { … };
class MockAutofillClient : public TestAutofillClient { … };
class MockVirtualCardEnrollmentManager
: public TestVirtualCardEnrollmentManager { … };
class CreditCardSaveManagerTest : public testing::Test { … };
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ImportFormDataCreditCardHTTPS …
#else
#define MAYBE_ImportFormDataCreditCardHTTPS …
#endif
TEST_F(CreditCardSaveManagerTest, MAYBE_ImportFormDataCreditCardHTTPS) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ImportFormDataCreditCardHTTP …
#else
#define MAYBE_ImportFormDataCreditCardHTTP …
#endif
TEST_F(CreditCardSaveManagerTest, MAYBE_ImportFormDataCreditCardHTTP) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_CreditCardSavedWhenAutocompleteOff …
#else
#define MAYBE_CreditCardSavedWhenAutocompleteOff …
#endif
TEST_F(CreditCardSaveManagerTest, MAYBE_CreditCardSavedWhenAutocompleteOff) { … }
TEST_F(CreditCardSaveManagerTest, InvalidCreditCardNumberIsNotSaved) { … }
TEST_F(CreditCardSaveManagerTest, CreditCardDisabledDoesNotSave) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_OnlyCountryInAddresses) { … }
#endif
TEST_F(CreditCardSaveManagerTest, LocalCreditCard_ExpirationDateMissing) { … }
TEST_F(CreditCardSaveManagerTest, LocalCreditCard_WithNonFocusableField) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcLocalSave_ShouldShowSaveCardLocallyWithCvcSaveOnly) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_ShouldShowSaveCardWithCvcSaveOnly) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcLocalSave_ShouldUpdateCreditCardWhenUserAccept) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcLocalSave_ClearStrikesOnAdd) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcLocalSave_NotOfferSaveWithMaxStrikes) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcLocalSave_AddMaxStrikesIfDeclined) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcLocalSave_AddStrikeIfIgnored) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcLocalSave_AddCorrectStrikesForIgnoredAndDeclined) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_ClearStrikesOnAdd) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_NotOfferSaveWithMaxStrikes) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_NotOfferSaveWithoutRequiredDelay) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_AddMaxStrikesIfDeclined) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_AddStrikeIfIgnored) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_AddCorrectStrikesForIgnoredAndDeclined) { … }
TEST_F(
CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_UserAccept_ShouldAddServerCvcWithOldEmptyCvc) { … }
TEST_F(
CreditCardSaveManagerTest,
AttemptToOfferCvcUploadSave_UserAccept_ShouldUpdateServerCvcWithDifferentCvc) { … }
class CvcStorageMetricTest
: public CreditCardSaveManagerTest,
public testing::WithParamInterface<CreditCard::RecordType> { … };
TEST_P(CvcStorageMetricTest, AttemptToOfferCvcSave_NotOfferSaveWithMaxStrikes) { … }
TEST_P(CvcStorageMetricTest,
AttemptToOfferCvcSave_NotOfferSaveWithoutRequiredDelay) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NotSavedLocally) { … }
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_FeatureNotEnabled) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_CvcUnavailable) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_CvcInvalidLength) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_MultipleCvcFields) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NoCvcFieldOnForm) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NoCvcFieldOnForm_InvalidCvcInNonCvcField) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NoCvcFieldOnForm_CvcInNonCvcField) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NoCvcFieldOnForm_CvcInAddressField) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NoProfileAvailable) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NoRecentlyUsedProfile) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_CvcUnavailableAndNoProfileAvailable) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NoNameAvailable) { … }
#endif
#if BUILDFLAG(IS_ANDROID)
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCardUploadSave_AutofillEnableBottomSheetAccountEmail) {
FormData credit_card_form = CreateTestCreditCardFormData();
FormsSeen(std::vector<FormData>(1, credit_card_form));
test_api(credit_card_form).field(0).set_value(u"Jane Doe");
test_api(credit_card_form).field(1).set_value(u"4111111111111111");
test_api(credit_card_form)
.field(2)
.set_value(ASCIIToUTF16(test::NextMonth()));
test_api(credit_card_form).field(3).set_value(ASCIIToUTF16(test::NextYear()));
test_api(credit_card_form).field(4).set_value(u"123");
EXPECT_CALL(payments_client(), ConfirmSaveCreditCardLocally).Times(0);
FormSubmitted(credit_card_form);
EXPECT_TRUE(credit_card_save_manager_->CreditCardWasUploaded());
std::vector<ClientBehaviorConstants> client_behavior_signals_in_request =
payments_network_interface().client_behavior_signals_in_request();
EXPECT_THAT(client_behavior_signals_in_request,
testing::Contains(
ClientBehaviorConstants::kShowAccountEmailInLegalMessage));
}
#endif
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCardUploadSave_SendSaveCvcSignalIfOfferingToSaveCvc) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCardUploadSave_DoNotSendSaveCvcSignalIfCvcEmpty) { … }
TEST_F(
CreditCardSaveManagerTest,
AttemptToOfferCardUploadSave_DoNotSendSaveCvcSignalIfSaveCvvFeatureDisabled) { … }
TEST_F(CreditCardSaveManagerTest,
AttemptToOfferCardUploadSave_DoNotSendSaveCvcSignalIfSaveCvcPrefOff) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NoNameAvailableAndNoProfileAvailable) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_ZipCodesConflict) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_ZipCodesDoNotDiscardWhitespace) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_ZipCodesHavePrefixMatch) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NoZipCodeAvailable) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_CCFormHasMiddleInitial) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NoMiddleInitialInCCForm) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_CCFormHasCardholderMiddleName) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_CCFormHasAddressMiddleName) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NamesCanMismatch) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_IgnoreOldProfiles) { … }
#endif
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_RequestCardholderNameIfNameMissingAndNoPaymentsCustomer) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_RequestCardholderNameIfNameConflictingAndNoPaymentsCustomer) { … }
TEST_F(CreditCardSaveManagerTest,
GoogleHostSite_ShouldNotOfferSaveIfUploadEnabled) { … }
TEST_F(CreditCardSaveManagerTest,
GoogleHostSite_ShouldOfferSaveIfUploadDisabled) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_DoNotRequestCardholderNameIfNameExistsAndNoPaymentsCustomer) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_DoNotRequestCardholderNameIfNameMissingAndPaymentsCustomer) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_DoNotRequestCardholderNameIfNameConflictingAndPaymentsCustomer) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_ShouldRequestCardholderName_ResetBetweenConsecutiveSaves) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_ShouldRequestExpirationDate_ResetBetweenConsecutiveSaves) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_WalletSyncTransportEnabled_ShouldNotRequestExpirationDate) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_WalletSyncTransportNotEnabled_ShouldRequestExpirationDate) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_DoNotRequestExpirationDateIfMissingNameAndExpirationDate) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_AlwaysRequestCardholderNameAndExpirationDateOnIOS) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_RequestExpirationDateViaExpDateFixFlow) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_RequestExpirationDateIfOnlyMonthMissing) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_RequestExpirationDateIfOnlyYearMissing) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_RequestExpirationDateIfExpirationDateInputIsExpired) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_RequestExpirationDateIfExpirationDateInputIsTwoDigitAndExpired) { … }
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_UploadDetailsFails) { … }
#endif
TEST_F(CreditCardSaveManagerTest, DuplicateMaskedCreditCard_NoUpload) { … }
TEST_F(CreditCardSaveManagerTest, NothingIfNothingFound) { … }
TEST_F(CreditCardSaveManagerTest, DetectCvc) { … }
TEST_F(CreditCardSaveManagerTest, DetectCardholderName) { … }
TEST_F(CreditCardSaveManagerTest, DetectAddressName) { … }
TEST_F(CreditCardSaveManagerTest, DetectCardholderAndAddressNameIfMatching) { … }
TEST_F(CreditCardSaveManagerTest, DetectNoUniqueNameIfNamesConflict) { … }
TEST_F(CreditCardSaveManagerTest, DetectPostalCode) { … }
TEST_F(CreditCardSaveManagerTest, DetectNoUniquePostalCodeIfZipsConflict) { … }
TEST_F(CreditCardSaveManagerTest, DetectAddressLine) { … }
TEST_F(CreditCardSaveManagerTest, DetectLocality) { … }
TEST_F(CreditCardSaveManagerTest, DetectAdministrativeArea) { … }
TEST_F(CreditCardSaveManagerTest, DetectCountryCode) { … }
TEST_F(CreditCardSaveManagerTest, DetectHasGooglePaymentAccount) { … }
TEST_F(CreditCardSaveManagerTest, DetectEverythingAtOnce) { … }
TEST_F(CreditCardSaveManagerTest, DetectSubsetOfPossibleFields) { … }
TEST_F(CreditCardSaveManagerTest, DetectAddressComponentsAcrossProfiles) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_LogAdditionalErrorsWithUploadDetailsFailure) { … }
#endif
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_ShouldOfferLocalSaveIfEverythingDetectedAndPaymentsDeclines) { … }
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_ShouldNotOfferLocalSaveIfSomethingNotDetectedAndPaymentsDeclines) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_PaymentsDecidesOfferToSaveIfNoCvc) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_PaymentsDecidesOfferToSaveIfNoName) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_PaymentsDecidesOfferToSaveIfConflictingNames) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_PaymentsDecidesOfferToSaveIfNoZip) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_PaymentsDecidesOfferToSaveIfConflictingZips) { … }
#endif
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_PaymentsDecidesOfferToSaveIfNothingFound) { … }
#endif
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_UploadOfLocalCard) { … }
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_UploadOfNewCard) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_DenyingUploadOfLocalCardShouldNotOfferLocalSave) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(
CreditCardSaveManagerTest,
UploadCreditCard_DoNotAddAnyClientBehaviorSignalsToRequestIfExperimentsOff) { … }
#endif
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_ShouldAddBillableServiceNumberInRequest) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_ShouldAddBillingCustomerNumberInRequest) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_ShouldAddUploadCardSourceInRequest) { … }
TEST_F(CreditCardSaveManagerTest,
LocallySaveCreditCard_NotEnoughStrikesStillShowsOfferToSave) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NotEnoughStrikesStillShowsOfferToSave) { … }
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest,
LocallySaveCreditCard_MaxStrikesDisallowsSave) {
credit_card_save_manager_->SetCreditCardUploadEnabled(false);
TestCreditCardSaveStrikeDatabase credit_card_save_strike_database =
TestCreditCardSaveStrikeDatabase(&strike_database());
credit_card_save_strike_database.AddStrike("1111");
credit_card_save_strike_database.AddStrike("1111");
credit_card_save_strike_database.AddStrike("1111");
EXPECT_EQ(3, credit_card_save_strike_database.GetStrikes("1111"));
FormData credit_card_form = CreateTestCreditCardFormData();
FormsSeen(std::vector<FormData>(1, credit_card_form));
ExpectFillableFormParsedUkm(1 );
test_api(credit_card_form).field(0).set_value(u"Jane Doe");
test_api(credit_card_form).field(1).set_value(u"4111111111111111");
test_api(credit_card_form)
.field(2)
.set_value(ASCIIToUTF16(test::NextMonth()));
test_api(credit_card_form).field(3).set_value(ASCIIToUTF16(test::NextYear()));
test_api(credit_card_form).field(4).set_value(u"123");
base::HistogramTester histogram_tester;
EXPECT_CALL(payments_client(), ConfirmSaveCreditCardLocally).Times(0);
FormSubmitted(credit_card_form);
EXPECT_FALSE(credit_card_save_manager_->CreditCardWasUploaded());
histogram_tester.ExpectBucketCount(
"Autofill.StrikeDatabase.CreditCardSaveNotOfferedDueToMaxStrikes",
AutofillMetrics::SaveTypeMetric::LOCAL, 1);
}
#if !BUILDFLAG(IS_IOS)
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_MaxStrikesDisallowsSave) {
TestCreditCardSaveStrikeDatabase credit_card_save_strike_database =
TestCreditCardSaveStrikeDatabase(&strike_database());
credit_card_save_strike_database.AddStrike("1111");
credit_card_save_strike_database.AddStrike("1111");
credit_card_save_strike_database.AddStrike("1111");
EXPECT_EQ(3, credit_card_save_strike_database.GetStrikes("1111"));
FormData address_form = CreateTestAddressFormData();
FormsSeen(std::vector<FormData>(1, address_form));
ExpectUniqueFillableFormParsedUkm();
ManuallyFillAddressForm("Jane", "Doe", "77401", "US", &address_form);
FormSubmitted(address_form);
FormData credit_card_form = CreateTestCreditCardFormData();
FormsSeen(std::vector<FormData>(1, credit_card_form));
ExpectFillableFormParsedUkm(2 );
test_api(credit_card_form).field(0).set_value(u"Jane Doe");
test_api(credit_card_form).field(1).set_value(u"4111111111111111");
test_api(credit_card_form)
.field(2)
.set_value(ASCIIToUTF16(test::NextMonth()));
test_api(credit_card_form).field(3).set_value(ASCIIToUTF16(test::NextYear()));
test_api(credit_card_form).field(4).set_value(u"123");
base::HistogramTester histogram_tester;
EXPECT_CALL(payments_client(), ConfirmSaveCreditCardLocally).Times(0);
FormSubmitted(credit_card_form);
EXPECT_FALSE(credit_card_save_manager_->CreditCardWasUploaded());
ExpectCardUploadDecision(
histogram_tester,
autofill_metrics::UPLOAD_NOT_OFFERED_MAX_STRIKES_ON_MOBILE);
histogram_tester.ExpectBucketCount(
"Autofill.StrikeDatabase.CreditCardSaveNotOfferedDueToMaxStrikes",
AutofillMetrics::SaveTypeMetric::SERVER, 1);
ExpectCardUploadDecisionUkm(
autofill_metrics::UPLOAD_NOT_OFFERED_MAX_STRIKES_ON_MOBILE);
}
#endif
#else
TEST_F(CreditCardSaveManagerTest,
LocallySaveCreditCard_MaxStrikesStillAllowsSave) { … }
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_MaxStrikesStillAllowsSave) { … }
TEST_F(CreditCardSaveManagerTest,
LocalCreditCard_LocalCardMigrationStrikesRemovedOnLocalSave) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NoLocalSaveMigrationStrikesRemovedOnUpload) { … }
#endif
TEST_F(CreditCardSaveManagerTest, LocallySaveCreditCard_ClearStrikesOnAdd) { … }
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_ClearStrikesOnAdd) { … }
TEST_F(CreditCardSaveManagerTest, LocallySaveCreditCard_NumStrikesLoggedOnAdd) { … }
TEST_F(CreditCardSaveManagerTest, UploadCreditCard_NumStrikesLoggedOnAdd) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NumStrikesLoggedOnUploadNotSuccess) { … }
TEST_F(CreditCardSaveManagerTest,
UploadCreditCard_NumStrikesLoggedOnUploadClientSideTimeout) { … }
TEST_F(CreditCardSaveManagerTest, OnUserDidAcceptUpload_NotifiesPDM) { … }
TEST_F(CreditCardSaveManagerTest, UploadSaveNotOfferedForUnsupportedCard) { … }
TEST_F(CreditCardSaveManagerTest, LocalSaveNotOfferedForSavedUnsupportedCard) { … }
TEST_F(CreditCardSaveManagerTest, UploadSaveOfferedForSupportedCard) { … }
TEST_F(CreditCardSaveManagerTest, InvalidLegalMessageInOnDidGetUploadDetails) { … }
TEST_F(CreditCardSaveManagerTest, LegalMessageInOnDidGetUploadDetails) { … }
TEST_F(CreditCardSaveManagerTest, ExistingServerCard_DifferentExpiration) { … }
class SaveCvcTest
: public CreditCardSaveManagerTest,
public testing::WithParamInterface<
std::
tuple<bool, bool, FormDataImporter::CreditCardImportType, bool>> { … };
TEST_P(SaveCvcTest, OnDidUploadCard_SaveServerCvc) { … }
TEST_P(SaveCvcTest, ShouldNotOfferCvcSaveWithEmptyCvc) { … }
TEST_P(SaveCvcTest, ShouldNotOfferCvcSaveWithoutExistingCard) { … }
TEST_P(SaveCvcTest, ShouldNotOfferCvcSaveWithSameCvc) { … }
TEST_P(SaveCvcTest, ShouldOfferCvcLocalSave) { … }
TEST_P(SaveCvcTest, ShouldOfferCvcUploadSave) { … }
INSTANTIATE_TEST_SUITE_P(…);
class ProceedWithSavingIfApplicableTest
: public CreditCardSaveManagerTest,
public testing::WithParamInterface<
std::
tuple<bool, bool, FormDataImporter::CreditCardImportType, bool>> { … };
TEST_P(ProceedWithSavingIfApplicableTest, CardWithCorrectSaveCardOption) { … }
TEST_P(ProceedWithSavingIfApplicableTest, ProceedWithSavingIfApplicable_Card) { … }
TEST_P(ProceedWithSavingIfApplicableTest, ProceedWithSavingIfApplicable_Cvc) { … }
TEST_P(ProceedWithSavingIfApplicableTest,
ProceedWithSavingIfApplicable_Cvc_Duplicate_Local) { … }
TEST_P(ProceedWithSavingIfApplicableTest,
ProceedWithSavingIfApplicable_Cvc_Duplicate_Server) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(CreditCardSaveManagerTest,
OnDidUploadCard_DoNotAddServerCvcIfCvcIsEmpty) { … }
TEST_F(CreditCardSaveManagerTest,
OnDidUploadCard_DoNotAddServerCvcIfInstrumentIdIsEmpty) { … }
TEST_F(CreditCardSaveManagerTest, InitVirtualCardEnroll) { … }
class CreditCardSaveManagerWithLocalSaveFallbackTest
: public CreditCardSaveManagerTest { … };
TEST_F(CreditCardSaveManagerWithLocalSaveFallbackTest,
OnDidUploadCard_FallbackToLocalSaveOnServerUploadFailure) { … }
TEST_F(CreditCardSaveManagerWithLocalSaveFallbackTest,
OnDidUploadCard_SkipLocalSaveIfMissingExpirationDate) { … }
TEST_F(CreditCardSaveManagerWithLocalSaveFallbackTest,
Metrics_OnDidUploadCard_FallbackToLocalSave_CardAdded) { … }
TEST_F(CreditCardSaveManagerWithLocalSaveFallbackTest,
Metrics_OnDidUploadCard_FallbackToLocalSave_CardExists) { … }
class CreditCardSaveManagerWithLoadingAndConfirmation
: public CreditCardSaveManagerTest,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(CreditCardSaveManagerWithLoadingAndConfirmation,
InitVirtualCardEnroll_LoadingAndConfirmation) { … }
class CreditCardSaveManagerWithVirtualCardEnrollTestParameterized
: public CreditCardSaveManagerTest,
public testing::WithParamInterface<
std::tuple<CreditCard::VirtualCardEnrollmentState, bool>> { … };
TEST_P(CreditCardSaveManagerWithVirtualCardEnrollTestParameterized,
PrepareUploadedCardForVirtualCardEnrollment) { … }
INSTANTIATE_TEST_SUITE_P(…);
}