chromium/components/autofill/core/browser/data_model/autofill_structured_address_component_unittest.cc

// Copyright 2020 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/data_model/autofill_structured_address_component.h"

#include <map>
#include <string>
#include <vector>

#include "base/strings/utf_string_conversions.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/browser/data_model/autofill_i18n_api.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address_component_test_api.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address_name.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address_test_utils.h"
#include "components/autofill/core/browser/data_model/autofill_structured_address_utils.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/common/autofill_features.h"
#include "testing/gtest/include/gtest/gtest.h"

ASCIIToUTF16;
UTF8ToUTF16;

namespace autofill {

AddressComponentTestValues;

// Creates an atomic name component for testing purposes.
class TestAtomicFirstNameAddressComponent : public AddressComponent {};

class TestAtomicMiddleNameAddressComponent : public AddressComponent {};

class TestAtomicLastNameAddressComponent : public AddressComponent {};

// Creates a compound name for testing purposes.
class TestCompoundNameAddressComponent : public AddressComponent {};

// Creates a compound name for testing purposes that uses an expression to
// parse.
class TestCompoundNameRegExParsedAddressComponent : public AddressComponent {};

// Creates a compound name with a custom format for testing purposes.
class TestCompoundNameCustomFormatAddressComponent : public AddressComponent {};

// Creates a compound name with a custom format for testing purposes.
class TestCompoundNameCustomAffixedFormatAddressComponent
    : public AddressComponent {};

// Creates a fictional compound component with sub- and sub subcomponents.
class TestCompoundNameWithTitleAddressComponent : public AddressComponent {};

// Creates a tree that is not proper in the sense that it contains the same type
// multiple times.
class TestNonProperFirstNameAddressComponent : public AddressComponent {};

// Tests the merging of two atomic component with |type|, and values
// |older_values| and |newer_values| respectively, and |merge_modes|.
// If |is_mergeable| it is expected that the two components are mergeable.
// If |newer_was_more_recently_used| the newer component was also more recently
// used which is true by default.
void TestAtomMerging(FieldType type,
                     AddressComponentTestValues older_values,
                     AddressComponentTestValues newer_values,
                     AddressComponentTestValues merge_expectation,
                     bool is_mergeable,
                     int merge_modes,
                     bool newer_was_more_recently_used = true) {}

void TestCompoundNameMerging(AddressComponentTestValues older_values,
                             AddressComponentTestValues newer_values,
                             AddressComponentTestValues merge_expectation,
                             bool is_mergeable,
                             int merge_modes,
                             bool newer_was_more_recently_used = true) {}

class AutofillStructuredAddressAddressComponent : public testing::Test {};

// Tests that the destructor does not crash
TEST_F(AutofillStructuredAddressAddressComponent, ConstructAndDestruct) {}

// Tests that a non-proper AddressComponent tree fails a DCHECK for
// |GetSupportedTypes()|.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestNonProperTreeDcheckFailure) {}

// Tests getting the root node.
TEST_F(AutofillStructuredAddressAddressComponent, TestGetRootNode) {}

// Tests that additional field types are correctly retrieved.
TEST_F(AutofillStructuredAddressAddressComponent, TestGetSupportedFieldType) {}

// Tests setting an additional field type.
TEST_F(AutofillStructuredAddressAddressComponent, TestSetFieldTypeValue) {}

// Tests retrieving an additional field type.
TEST_F(AutofillStructuredAddressAddressComponent, TestGetFieldTypeValue) {}

// Tests retrieving a value for comparison for a field type.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestGetValueForComparisonForType) {}

// Tests adding all supported types to the set.
TEST_F(AutofillStructuredAddressAddressComponent, TestGetSupportedTypes) {}

// Tests adding all storable types to the set.
TEST_F(AutofillStructuredAddressAddressComponent, TestGetStorableTypes) {}

// Tests the comparison of the atoms of the same type.
TEST_F(AutofillStructuredAddressAddressComponent, TestComparison_Atom) {}

// Tests comparison of two different types.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestComparisonOperator_DifferentTypes) {}

// Tests the comparison with itself.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestComparisonOperator_SelfComparison) {}

// Tests the comparison operator.
TEST_F(AutofillStructuredAddressAddressComponent, TestComparison_Compound) {}

// Tests the assignment operator.
TEST_F(AutofillStructuredAddressAddressComponent, TestAssignmentOperator_Atom) {}

// Tests the assignment operator when using the base class type.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestAssignmentOperator_Compound_FromBase) {}

// Tests the assignment operator on a compound node.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestAssignmentOperator_Compound) {}

// Tests that self-assignment does not break things.
TEST_F(AutofillStructuredAddressAddressComponent, SelfAssignment) {}

// Tests that the correct storage types are returned.
TEST_F(AutofillStructuredAddressAddressComponent, GetStorageType) {}

// Tests that the correct storage type names are returned.
TEST_F(AutofillStructuredAddressAddressComponent, GetStorageTypeName) {}

// Tests that the correct atomicity is returned.
TEST_F(AutofillStructuredAddressAddressComponent, GetAtomicity) {}

// Tests directly setting and retrieving values.
TEST_F(AutofillStructuredAddressAddressComponent, DirectlyGetSetAndUnsetValue) {}

// Tests recursively setting and retrieving values.
TEST_F(AutofillStructuredAddressAddressComponent,
       RecursivelySettingAndGettingValues) {}

// Tests retrieving the subcomponents types.
TEST_F(AutofillStructuredAddressAddressComponent, GetSubcomponentTypes) {}

// Tests getting the best format string for an atom.
TEST_F(AutofillStructuredAddressAddressComponent, GetBestFormatString_ForAtom) {}

// Tests getting the best format string using the fallback mechanism.
TEST_F(AutofillStructuredAddressAddressComponent,
       GetBestFormatString_WithFallback) {}

// Tests getting the best format string using the fallback mechanism.
TEST_F(AutofillStructuredAddressAddressComponent,
       GetBestFormatString_WithCustomMethod) {}

// Tests formatting the unstructured value from the subcomponents.
TEST_F(AutofillStructuredAddressAddressComponent,
       FormatValueFromSubcomponents) {}

// Creates a compound name for testing purposes.
class TestCompoundNameAddressComponentCustomFormatSeparator
    : public AddressComponent {};

// Tests formatting the unstructured value from the subcomponents.
TEST_F(AutofillStructuredAddressAddressComponent,
       FormatValueFromSubcomponentsSeparators) {}

// Creates a compound name for testing purposes with a formatting string that
// contains new line characters.
class TestCompoundNameAddressComponentCustomFormatNewLineSeparator
    : public AddressComponent {};

// Tests formatting the unstructured value from the subcomponents.
TEST_F(AutofillStructuredAddressAddressComponent,
       FormatValueFromSubcomponentsNewLineSeparators) {}

// Tests that formatted values are correctly trimmed.
TEST_F(AutofillStructuredAddressAddressComponent,
       FormatAndTrimValueFromSubcomponents) {}

TEST_F(AutofillStructuredAddressAddressComponent,
       TestEquivalenceOfReplacePlaceholderImplementations) {}

// Tests the formatting of the unstructured value from the components with a
// type-specific format string.
TEST_F(AutofillStructuredAddressAddressComponent,
       FormatValueFromSubcomponentsWithTypeSpecificFormat) {}

// Tests the formatting of the unstructured value from the components with a
// type-specific format string containing a prefix and a suffix.
TEST_F(AutofillStructuredAddressAddressComponent,
       FormatValueFromSubcomponentsWithTypeSpecificAffixedFormat) {}

// Tests parsing of an empty value. Because, that's why.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestParseValueAndAssignSubcomponentsByFallbackMethod_EmptyString) {}

// Tests parsing using a defined method.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestParseValueAndAssignSubcomponentsByRegEx) {}

// Go nuclear and parse the value of an atomic component.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestParseValueAndAssignSubcomponentsByFallbackMethod_Atom) {}

// Tests the fallback method to parse a value into its components if there are
// more space-separated tokens than components.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestParseValueAndAssignSubcomponentsByFallbackMethod) {}

// Tests the fallback method to parse a value into its components if there are
// less space-separated tokens than components.
TEST_F(AutofillStructuredAddressAddressComponent,
       ParseValueAndAssignSubcomponentsByFallbackMethod_WithFewTokens) {}

// Tests that a tree is regarded completable if and only if there if the
// maximum number of assigned nodes on a path from the root node to a leaf is
// exactly one.
TEST_F(AutofillStructuredAddressAddressComponent, IsTreeCompletable) {}

// Tests that the tree is completed successfully from the root node down to the
// leafs.
TEST_F(AutofillStructuredAddressAddressComponent, TreeCompletion_TopToBottom) {}

// Tests that the tree is completed successfully from leaf nodes to the root.
TEST_F(AutofillStructuredAddressAddressComponent, TreeCompletion_BottomToTop) {}

// Tests that the tree is completed successfully both upwards and downwards when
// a node with both subcomponents and a parent is set.
TEST_F(AutofillStructuredAddressAddressComponent,
       TreeCompletion_ToTopAndBottom) {}

// Test that values are invalidated correctly.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestSettingsValuesWithInvalidation) {}

// Test unsetting a value and its subcomponents.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestUnsettingAValueAndItsSubcomponents) {}

// Tests that the tree is completed successfully both upwards and downwards when
// a node with both subcomponents and a parent is set.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestUnsettingParsedAndFormattedValues) {}

TEST_F(AutofillStructuredAddressAddressComponent,
       MergeAtomicComponentsWithDifferentValues) {}

TEST_F(AutofillStructuredAddressAddressComponent,
       MergeAtomicComponentsWithSameValue) {}

TEST_F(AutofillStructuredAddressAddressComponent,
       MergeAtomicComponentsSimilarValueThatContainsSameNormalizedValue) {}

TEST_F(AutofillStructuredAddressAddressComponent,
       MergeAtomicComponentsWithPermutedValue) {}

// This test verifies the merging of the verification statuses that is
// applicable for combining variants.
TEST_F(AutofillStructuredAddressAddressComponent, MergeVerificationStatuses) {}

// This tests verifies the formatted and observed values can be reset
// correctly.
TEST_F(AutofillStructuredAddressAddressComponent,
       ClearParsedAndFormattedValues) {}

// This test verifies that if two value-equal components are merged, the higher
// verification statuses are picked.
TEST_F(AutofillStructuredAddressAddressComponent,
       MergeTriviallyMergeableCompoundComponents) {}

// This test verifies that the formatted value is successfully replaced by the
// user-verified value while the substructure is corrected by the observation.
TEST_F(AutofillStructuredAddressAddressComponent, MergePermutedComponent) {}

TEST_F(AutofillStructuredAddressAddressComponent,
       SimpleReplacementBasedMergingStrategies) {}

TEST_F(AutofillStructuredAddressAddressComponent, MergeChildsAndReformatRoot) {}

// Tests the comparison of different Verification statuses.
TEST_F(AutofillStructuredAddressAddressComponent,
       TestIsLessSignificantVerificationStatus) {}

// Tests getting the more significant VerificationStatus.
TEST_F(AutofillStructuredAddressAddressComponent,
       GetMoreSignificantVerificationStatus) {}

// Tests merging using the MergeMode::KUseBetterOrMoreRecentIfDifferent|
TEST_F(AutofillStructuredAddressAddressComponent,
       TestUseBetterOfMoreRecentIfDifferentMergeStrategy) {}

TEST_F(AutofillStructuredAddressAddressComponent, TestFillTreeGaps) {}

TEST_F(AutofillStructuredAddressAddressComponent,
       IsValueCompatibleWithAncestorsCompatible) {}

TEST_F(AutofillStructuredAddressAddressComponent, TestFillTreeGapsParsing) {}

}  // namespace autofill