#include "components/autofill/core/browser/data_model/credit_card.h"
#include <stddef.h>
#include <string>
#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/time/time.h"
#include "base/uuid.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/autofill_type.h"
#include "components/autofill/core/browser/data_model/payments_metadata.h"
#include "components/autofill/core/browser/data_model/test_autofill_data_model.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/credit_card_network_identifiers.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/grit/components_scaled_resources.h"
#include "components/strings/grit/components_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
ASCIIToUTF16;
UTF8ToUTF16;
namespace autofill {
const CreditCard::RecordType LOCAL_CARD = …;
const CreditCard::RecordType MASKED_SERVER_CARD = …;
const CreditCard::RecordType FULL_SERVER_CARD = …;
namespace {
const char* const kValidNumbers[] = …;
const char* const kInvalidNumbers[] = …;
const char* const kValidNicknames[] = …;
const char* const kInvalidNicknames[] = …;
const char* const kEmptyNickname = …;
std::u16string GetYearInTheFuture() { … }
}
TEST(CreditCardTest, GetObfuscatedStringForCardDigits) { … }
TEST(CreditCardTest, LabelSummary) { … }
TEST(CreditCardTest, NetworkAndLastFourDigits) { … }
TEST(CreditCardTest, NicknameAndLastFourDigitsStrings) { … }
TEST(CreditCardTest,
CardIdentifierStringsForAutofillDisplay_NoNicknameNoProductDescription) { … }
TEST(
CreditCardTest,
CardIdentifierStringsForAutofillDisplay_InvalidNicknameNoProductDescription) { … }
TEST(CreditCardTest,
CardIdentifierStringsForAutofillDisplay_NoNicknameWithProductDescription) { … }
TEST(
CreditCardTest,
CardIdentifierStringsForAutofillDisplay_InvalidNicknameWithProductDescription) { … }
TEST(CreditCardTest,
CardIdentifierStringsForAutofillDisplay_WithValidNickname) { … }
TEST(CreditCardTest,
CardIdentifierStringsForAutofillDisplay_WithCustomizedNickname) { … }
TEST(CreditCardTest,
CardIdentifierStringsForAutofillDisplay_WithObfuscationLength) { … }
TEST(CreditCardTest, AssignmentOperator) { … }
TEST(CreditCardTest, GetMetadata) { … }
TEST(CreditCardTest, SetMetadata_MatchingId) { … }
TEST(CreditCardTest, SetMetadata_NotMatchingId) { … }
TEST(CreditCardTest, HasSameNumberAs) { … }
TEST(CreditCardTest, HasSameExpirationDateAs) { … }
struct SetExpirationYearFromStringTestCase { … };
class SetExpirationYearFromStringTest
: public testing::TestWithParam<SetExpirationYearFromStringTestCase> { … };
TEST_P(SetExpirationYearFromStringTest, SetExpirationYearFromString) { … }
INSTANTIATE_TEST_SUITE_P(…);
struct SetExpirationDateFromStringTestCase { … };
class SetExpirationDateFromStringTest
: public testing::TestWithParam<SetExpirationDateFromStringTestCase> { … };
TEST_P(SetExpirationDateFromStringTest, SetExpirationDateFromString) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(CreditCardTest, Copy) { … }
struct IsLocalOrServerDuplicateOfTestCase { … };
class IsLocalOrServerDuplicateOfTest
: public testing::TestWithParam<IsLocalOrServerDuplicateOfTestCase> { … };
TEST_P(IsLocalOrServerDuplicateOfTest, IsLocalOrServerDuplicateOf) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(CreditCardTest, MatchingCardDetails) { … }
TEST(CreditCardTest, IsVerified) { … }
TEST(CreditCardTest, Compare) { … }
TEST(CreditCardTest, IconResourceId) { … }
TEST(CreditCardTest, IconResourceIdFromString) { … }
TEST(CreditCardTest, UpdateFromImportedCard_UpdatedWithNameAndExpirationDate) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_UpdatedWithNameAndInvalidExpirationDateMonth) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_UpdatedWithNameAndInvalidExpirationDateYear) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_UpdatedWithEmptyNameAndValidExpirationDate) { … }
TEST(
CreditCardTest,
UpdateFromImportedCard_VerifiedCardNotUpdatedWithEmptyExpirationDateMonth) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_VerifiedCardNotUpdatedWithEmptyExpirationDateYear) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_VerifiedCardNotUpdatedWithDifferentName) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_ExpiredVerifiedCardNotUpdatedWithDifferentName) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_ExpiredVerifiedCardUpdatedWithSameName) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_ExpiredOriginalCardVerifiedUpdatedWithExpiredCard) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_VerifiedCardUpdatedWithVerifiedCard) { … }
TEST(CreditCardTest,
UpdateFromImportedCard_VerifiedCardNotUpdatedWithDifferentCard) { … }
TEST(CreditCardTest, IsValidCardNumberAndExpiryDate) { … }
TEST(CreditCardTest, HasNonEmptyValidNickname) { … }
TEST(CreditCardTest, IsNicknameValid) { … }
TEST(CreditCardTest, SetRawInfoCreditCardNumber) { … }
TEST(CreditCardTest, SetExpirationMonth) { … }
TEST(CreditCardTest, SetNickname) { … }
TEST(CreditCardTest, CreditCardType) { … }
TEST(CreditCardTest, CreditCardVerificationCode) { … }
TEST(CreditCardTest, IsDeletable) { … }
struct CreditCardMatchingTypesCase { … };
class CreditCardMatchingTypesTest
: public testing::TestWithParam<CreditCardMatchingTypesCase> { … };
TEST_P(CreditCardMatchingTypesTest, Cases) { … }
const CreditCardMatchingTypesCase kCreditCardMatchingTypesTestCases[] = …;
INSTANTIATE_TEST_SUITE_P(…);
TEST(CreditCardTest, LastFourDigits) { … }
TEST(CreditCardTest, FullDigitsForDisplay) { … }
struct ShouldUpdateExpirationTestCase { … };
constexpr base::TimeDelta kCurrent = …;
constexpr base::TimeDelta kOneYear = …;
constexpr base::TimeDelta kOneMonth = …;
void MonthAndYearFromDelta(base::TimeDelta time_delta, int& month, int& year) { … }
class ShouldUpdateExpirationTest
: public testing::TestWithParam<ShouldUpdateExpirationTestCase> { … };
TEST_P(ShouldUpdateExpirationTest, ShouldUpdateExpiration) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(IS_ANDROID)
TEST(CreditCardTestForKeyboardAccessory, GetObfuscatedStringForCardDigits) {
const std::u16string digits = u"1235";
const std::u16string expected =
std::u16string() + base::i18n::kLeftToRightEmbeddingMark +
CreditCard::GetMidlineEllipsisDots(2) + digits +
base::i18n::kPopDirectionalFormatting;
EXPECT_EQ(expected, CreditCard::GetObfuscatedStringForCardDigits(
2, digits));
}
#endif
enum Expectation { … };
struct VirtualCardRankingTestCase { … };
base::Time current_time = …;
class VirtualCardRankingTest
: public testing::TestWithParam<VirtualCardRankingTestCase> { … };
TEST_P(VirtualCardRankingTest, HasGreaterRankingThan) { … }
INSTANTIATE_TEST_SUITE_P(…);
}