chromium/components/autofill/core/browser/field_filling_address_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_address_util.h"

#include <memory>
#include <vector>

#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/test/task_environment.h"
#include "components/autofill/core/browser/address_normalizer.h"
#include "components/autofill/core/browser/address_normalizer_impl.h"
#include "components/autofill/core/browser/autofill_field.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/autofill_profile.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_parsing/regex_patterns.h"
#include "components/autofill/core/browser/geo/alternative_state_name_map_test_utils.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_test_utils.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/prefs/pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/null_storage.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h"
#include "third_party/libaddressinput/src/cpp/test/testdata_source.h"

namespace autofill {

namespace {

NullStorage;
Source;
Storage;
TestdataSource;

constexpr char kAppLocale[] =;

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

std::u16string GetValueForProfile(const AutofillProfile& profile,
                                  const std::string& app_locale,
                                  const AutofillType& field_type,
                                  const FormFieldData& field_data,
                                  AddressNormalizer* address_normalizer) {}

class FieldFillingAddressUtilTest : public testing::Test {};

// Verify that profile fields with autocomplete attribute 'off' are filled.
TEST_F(FieldFillingAddressUtilTest,
       FillFormField_AutocompleteOffNotRespected_AddressField) {}

struct FieldFillingAddressUtilTestCase {};

struct AutofillPhoneFieldFillerTestCase
    : public FieldFillingAddressUtilTestCase {};

class PhoneNumberTest
    : public FieldFillingAddressUtilTest,
      public testing::WithParamInterface<AutofillPhoneFieldFillerTestCase> {};

TEST_P(PhoneNumberTest, FillPhoneNumber) {}

INSTANTIATE_TEST_SUITE_P();

struct FillSelectTestCase {};

class AutofillSelectWithStatesTest
    : public FieldFillingAddressUtilTest,
      public testing::WithParamInterface<FillSelectTestCase> {};

TEST_P(AutofillSelectWithStatesTest, FillSelectWithStates) {}

INSTANTIATE_TEST_SUITE_P();

// Tests that a select element is properly filled if it contains country names.
TEST_F(FieldFillingAddressUtilTest, FillSelectWithCountryName) {}

// Tests that a select element is properly filled if it contains country codes.
TEST_F(FieldFillingAddressUtilTest, FillSelectWithCountryCode) {}

// Tests that a text input field is properly filled with a country name or code,
// depending on HTML and heuristic type.
TEST_F(FieldFillingAddressUtilTest, FillInputWithCountry) {}

TEST_F(FieldFillingAddressUtilTest, FillStreetAddressTextArea) {}

TEST_F(FieldFillingAddressUtilTest, FillStreetAddressTextField) {}

// Tests that text state fields are filled correctly depending on their
// maxlength attribute value.
struct FillStateTextTestCase {};

class AutofillStateTextTest
    : public FieldFillingAddressUtilTest,
      public testing::WithParamInterface<FillStateTextTestCase> {};

TEST_P(AutofillStateTextTest, FillStateText) {}

INSTANTIATE_TEST_SUITE_P();

// Tests that augment phone country code fields are filled correctly.
struct FillAugmentedPhoneCountryCodeTestCase {};

// The first parameter indicates whether
// kAutofillEnableFillingPhoneCountryCodesByAddressCountryCodes is enabled.
class AutofillFillAugmentedPhoneCountryCodeTest
    : public FieldFillingAddressUtilTest,
      public testing::WithParamInterface<
          std::tuple<bool, FillAugmentedPhoneCountryCodeTestCase>> {};

void DoTestFillAugmentedPhoneCountryCodeField(
    bool enable_filling_phone_country_codes_by_address_country_codes,
    const FillAugmentedPhoneCountryCodeTestCase& test_case,
    FormControlType field_type) {}

TEST_P(AutofillFillAugmentedPhoneCountryCodeTest,
       FillAugmentedPhoneCountryCodeField) {}

TEST_P(AutofillFillAugmentedPhoneCountryCodeTest,
       FillAugmentedPhoneCountryCodeSelectListField) {}

INSTANTIATE_TEST_SUITE_P();

// Tests that the abbreviated state names are selected correctly.
TEST_F(FieldFillingAddressUtilTest, FillSelectAbbreviatedState) {}

// Tests that the localized state names are selected correctly.
TEST_F(FieldFillingAddressUtilTest, FillSelectLocalizedState) {}

// Tests that the state names are selected correctly when the state name exists
// as a substring in the selection options.
TEST_F(FieldFillingAddressUtilTest, FillSelectLocalizedStateSubstring) {}

// Tests that the state abbreviations are filled in the text field when the
// field length is limited.
TEST_F(FieldFillingAddressUtilTest, FillStateAbbreviationInTextField) {}

// Tests that the state names are selected correctly even though the state
// value saved in the address is not recognized by the AlternativeStateNameMap.
TEST_F(FieldFillingAddressUtilTest, FillStateFieldWithSavedValueInProfile) {}

// Tests that Autofill does not wrongly fill the state when the appropriate
// state is not in the list of selection options given that the abbreviation is
// saved in the profile.
TEST_F(FieldFillingAddressUtilTest, FillStateFieldWhenStateIsNotInOptions) {}

// Tests that Autofill uses the static states data of US as a fallback mechanism
// for filling when |AlternativeStateNameMap| is not populated.
TEST_F(FieldFillingAddressUtilTest,
       FillStateFieldWhenAlternativeStateNameMapIsNotPopulated) {}

// Tests that Autofill fills upper case abbreviation in the input field when
// field length is limited.
TEST_F(FieldFillingAddressUtilTest, FillUpperCaseAbbreviationInStateTextField) {}

// Tests that Autofill does not fill the state when abbreviated data is stored
// in the profile and none of the options match with the abbreviated state.
TEST_F(FieldFillingAddressUtilTest,
       DoNotFillStateFieldWhenAbbrStoredInProfileAndNotInOptionsList) {}

}  // namespace

}  // namespace autofill