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

// Copyright 2013 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/field_filling_payments_util.h"

#include <stddef.h>

#include <memory>
#include <string>
#include <vector>

#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/stl_util.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/autofill/core/browser/autofill_field.h"
#include "components/autofill/core/browser/autofill_form_test_utils.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/credit_card.h"
#include "components/autofill/core/browser/data_model/credit_card_test_api.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_parsing/credit_card_field_parser.h"
#include "components/autofill/core/browser/form_structure_test_api.h"
#include "components/autofill/core/browser/heuristic_source.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_test_utils.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/credit_card_network_identifiers.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom-shared.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace autofill {

namespace {

const std::u16string kMidlineEllipsis2Dots =;
const std::u16string kMidlineEllipsis3Dots =;
const std::u16string kMidlineEllipsis4Dots =;

// The following strings do not contain space padding and are more appropriate
// for input fields which have a strict `max_length` set.
const std::u16string kMidlineEllipsis2DotsWithoutPadding =;
const std::u16string kMidlineEllipsis3DotsWithoutPadding =;
const std::u16string kMidlineEllipsis4DotsWithoutPadding =;

constexpr char kAppLocale[] =;

const std::vector<const char*> NotNumericMonthsContentsNoPlaceholder() {}

const std::vector<const char*> NotNumericMonthsContentsWithPlaceholder() {}

AutofillField CreateTestSelectAutofillField(
    const std::vector<const char*>& values,
    FieldType heuristic_type) {}

size_t GetIndexOfValue(const std::vector<SelectOption>& values,
                       const std::u16string& value) {}

// Creates the select field from the specified |values| and |contents| and tests
// filling with 3 different values.
void TestFillingExpirationMonth(const std::vector<const char*>& values,
                                const std::vector<const char*>& contents) {}

struct CreditCardTestCase {};

// Returns the offset to be set within the credit card number field.
size_t GetNumberOffset(size_t index, const CreditCardTestCase& test) {}

class FieldFillingPaymentsUtilTest : public testing::Test {};

// Verify that credit card related fields with the autocomplete attribute
// set to off get filled.
TEST_F(FieldFillingPaymentsUtilTest,
       FillFormField_AutocompleteOff_CreditCardField) {}

// Verify that the correct value is returned if the maximum length of the credit
// card value exceeds the actual length.
TEST_F(FieldFillingPaymentsUtilTest,
       FillFormField_MaxLength_CreditCardField_MaxLengthExceedsLength) {}

// Verify that the full credit card number is returned if the offset exceeds the
// length.
TEST_F(FieldFillingPaymentsUtilTest,
       FillFormField_MaxLength_CreditCardField_OffsetExceedsLength) {}

// Verify that only the truncated and offsetted value of the credit card number
// is set.
TEST_F(FieldFillingPaymentsUtilTest,
       FillFormField_MaxLength_CreditCardField_WithOffset) {}

// Verify that only the truncated value of the credit card number is set.
TEST_F(FieldFillingPaymentsUtilTest, FillFormField_MaxLength_CreditCardField) {}

// Test that in the preview credit card numbers are obfuscated.
TEST_F(FieldFillingPaymentsUtilTest, FillFormField_Preview_CreditCardField) {}

class CreditCardVerificationCodeTest
    : public FieldFillingPaymentsUtilTest,
      public testing::WithParamInterface<mojom::ActionPersistence> {};

// Test that verify CVC should be expected value for Preview and Fill.
TEST_P(CreditCardVerificationCodeTest,
       FillFormField_CreditCardVerificationCode) {}

// Test that verify CVC should be empty for Preview and Fill if CVC is empty.
TEST_P(CreditCardVerificationCodeTest,
       FillFormField_CreditCardVerificationCode_Empty) {}

// Tests that CVC is correctly previewed and filled for a standalone CVC field.
TEST_P(CreditCardVerificationCodeTest, FillFormField_StandaloneCVCField) {}

// Tests that CVC is correctly previewed and filled for a standalone CVC field
// for American Express credit cards, which often use four digit verification
// codes.
TEST_P(CreditCardVerificationCodeTest,
       FillFormField_StandaloneCVCField_AmericanExpress) {}

INSTANTIATE_TEST_SUITE_P();

struct FieldFillingPaymentsUtilTestCase {};

class ExpirationYearTest
    : public FieldFillingPaymentsUtilTest,
      public testing::WithParamInterface<FieldFillingPaymentsUtilTestCase> {};

TEST_P(ExpirationYearTest, FillExpirationYearInput) {}

INSTANTIATE_TEST_SUITE_P();

struct FillUtilExpirationDateTestCase {};

class ExpirationDateTest
    : public FieldFillingPaymentsUtilTest,
      public testing::WithParamInterface<
          std::tuple<FillUtilExpirationDateTestCase,
                     // Whether kAutofillEnableExpirationDateImprovements should
                     // be enabled.
                     bool>> {};

TEST_P(ExpirationDateTest, FillExpirationDateInput) {}

INSTANTIATE_TEST_SUITE_P();

struct FillWithExpirationMonthTestCase {};

class AutofillSelectWithExpirationMonthTest
    : public FieldFillingPaymentsUtilTest,
      public testing::WithParamInterface<FillWithExpirationMonthTestCase> {};

TEST_P(AutofillSelectWithExpirationMonthTest,
       FillSelectControlWithExpirationMonth) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(FieldFillingPaymentsUtilTest,
       FillSelectControlWithAbbreviatedMonthName) {}

TEST_F(FieldFillingPaymentsUtilTest, FillSelectControlWithMonthName) {}

TEST_F(FieldFillingPaymentsUtilTest, FillSelectControlWithMonthNameAndDigits) {}

TEST_F(FieldFillingPaymentsUtilTest,
       FillSelectControlWithMonthNameAndDigits_French) {}

TEST_F(FieldFillingPaymentsUtilTest, FillSelectControlWithMonthName_French) {}

TEST_F(FieldFillingPaymentsUtilTest,
       FillSelectControlWithNumericMonthSansLeadingZero) {}

TEST_F(FieldFillingPaymentsUtilTest,
       FillSelectControlWithTwoDigitCreditCardYear) {}

TEST_F(FieldFillingPaymentsUtilTest, FillSelectControlWithCreditCardType) {}

TEST_F(FieldFillingPaymentsUtilTest, FillMonthControl) {}

TEST_F(FieldFillingPaymentsUtilTest, FillCreditCardNumberWithoutSplits) {}

TEST_F(FieldFillingPaymentsUtilTest, FillCreditCardNumberWithEqualSizeSplits) {}

TEST_F(FieldFillingPaymentsUtilTest,
       PreviewCreditCardNumberWithEqualSizeSplits) {}

TEST_F(FieldFillingPaymentsUtilTest,
       FillCreditCardNumberWithUnequalSizeSplits) {}

TEST_F(FieldFillingPaymentsUtilTest,
       PreviewCreditCardNumberWithUnequalSizeSplits) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualMonth) {}

// Test that month should be empty for Preview if the form control type of the
// field is `kSelectOne`, i.e., is a combobox or listbox.
TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualMonthOneSelectOne_Empty) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualYear) {}

// Test that 4 digit year should be empty for Preview if the form control type
// of the field is `kSelectOne`, i.e., is a combobox or listbox.
TEST_F(FieldFillingPaymentsUtilTest,
       PreviewVirtualFourDigitYearOnSelectOne_Empty) {}

// Test that 2 digit year should be empty for Preview if the form control type
// of the field is `kSelectOne`, i.e., is a combobox or listbox.
TEST_F(FieldFillingPaymentsUtilTest,
       PreviewVirtualTwoDigitYearOnSelectOne_Empty) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualShortenedYear) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualDate) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualShortenedDate) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualCVC) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualCVCAmericanExpress) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualCardNumber) {}

// Verify that the obfuscated virtual card number is returned if the offset is
// greater than 0 and the offset exceeds the length.
TEST_F(FieldFillingPaymentsUtilTest,
       PreviewVirtualCardNumber_OffsetExceedsLength) {}

TEST_F(FieldFillingPaymentsUtilTest, PreviewVirtualCardholderName) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns false on a form with no
// credit card number or CVC fields.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_NoCCNumberField) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns false on a form where
// the credit card number field is present but it is not empty.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_CCNumberFieldNotEmpty) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns false on a form where
// the credit card number field is present but it's autofilled.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_CCNumberFieldIsAutofilled) {}

// Verify that `WillFillCreditCardNumberOrCvc` return true on a form where the
// credit card number field is present and is both empty and not autofilled.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_CCNumberFieldPresent) {}

// Verify that `WillFillCreditCardNumberOrCvc` return true on a form where the
// credit card number field is present and not empty but was not typed by the
// user.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_CCNumberFieldNotEmpty_NotUserTyped) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns true on a form with only
// a credit card credential standalone field if the card has CVC saved.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_StandaloneCvcField_CardHasCvc) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns true on a form with only
// a credit card credential field if the card has CVC saved.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_NormalCvcFormField_CardHasCvc) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns false on a form where
// the credit card verification code field is present but it is not empty and
// the card has CVC saved.
// The CVC field isn't overridden in this case, and we don't need to fetch the
// card as there is no card number field.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_CvcFieldNotEmpty_CardHasCvc) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns true on a form where
// the credit card verification code field is present but it is empty and the
// card has CVC saved. Also the trigger field is the non CVC field.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_FormHasCvcAndName_CardHasCvc) {}

// Verify that `WillFillCreditCardNumberOrCvc` returns false on a form where
// the credit card verification code field is present but it is empty and the
// card has no CVC saved. Also the trigger field is the non CVC field.
TEST_F(FieldFillingPaymentsUtilTest,
       WillFillCreditCardNumberOrCvc_FormHasCvcAndName_CardHasNoCvc) {}

}  // namespace

}  // namespace autofill