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

#include <stddef.h>

#include <algorithm>
#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>

#include "base/base64.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/memory/raw_ptr.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/unguessable_token.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_experiments.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/field_types.h"
#include "components/autofill/core/browser/form_parsing/buildflags.h"
#include "components/autofill/core/browser/form_parsing/form_field_parser.h"
#include "components/autofill/core/browser/form_structure_test_api.h"
#include "components/autofill/core/browser/proto/api_v1.pb.h"
#include "components/autofill/core/browser/randomized_encoder.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/form_data.h"
#include "components/autofill/core/common/form_data_test_api.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/html_field_types.h"
#include "components/autofill/core/common/signatures.h"
#include "components/version_info/version_info.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/re2/src/re2/re2.h"
#include "url/gurl.h"

namespace autofill {

namespace {

FormControlType;
CreateTestFormField;
AllOf;
Each;
ElementsAre;
IsEmpty;
Not;
Pointee;
ResultOf;
Truly;
UnorderedElementsAre;

constexpr DenseSet<PatternSource> kAllPatternSources {};

}  // namespace

class FormStructureTestImpl : public test::FormStructureTest {};

class FormStructureTest_ForPatternSource
    : public FormStructureTestImpl,
      public testing::WithParamInterface<PatternSource> {};

INSTANTIATE_TEST_SUITE_P();

TEST_F(FormStructureTestImpl, FieldCount) {}

TEST_F(FormStructureTestImpl, AutofillCount) {}

TEST_F(FormStructureTestImpl, SourceURL) {}

TEST_F(FormStructureTestImpl, FullSourceURLWithHashAndParam) {}

TEST_F(FormStructureTestImpl, IsAutofillable) {}

class FormStructureTestImpl_ShouldBeParsed_Test : public FormStructureTestImpl {};

// Empty forms should not be parsed.
TEST_F(FormStructureTestImpl_ShouldBeParsed_Test, FalseIfNoFields) {}

// Forms with only checkable fields should not be parsed.
TEST_F(FormStructureTestImpl_ShouldBeParsed_Test, IgnoresCheckableFields) {}

// Forms with at least one text field should be parsed.
TEST_F(FormStructureTestImpl_ShouldBeParsed_Test, TrueIfOneTextField) {}

// Forms that have only select fields should not be parsed.
TEST_F(FormStructureTestImpl_ShouldBeParsed_Test, FalseIfOnlySelectField) {}

TEST_F(FormStructureTestImpl_ShouldBeParsed_Test, FalseIfOnlySelectListField) {}

// Form whose action is a search URL should not be parsed.
TEST_F(FormStructureTestImpl_ShouldBeParsed_Test, FalseIfSearchURL) {}

// Forms with two password fields and no other fields should be parsed.
TEST_F(FormStructureTestImpl_ShouldBeParsed_Test, TrueIfOnlyPasswordFields) {}

// Forms with at least one field with an autocomplete attribute should be
// parsed.
TEST_F(FormStructureTestImpl_ShouldBeParsed_Test,
       TrueIfOneFieldHasAutocomplete) {}

TEST_F(FormStructureTestImpl, ShouldBeParsed_BadScheme) {}

// Tests that ShouldBeParsed returns true for a form containing less than three
// fields if at least one has an autocomplete attribute.
TEST_F(FormStructureTestImpl, ShouldBeParsed_TwoFields_HasAutocomplete) {}

// Tests that ShouldBeParsed returns true for a form containing less than three
// fields if at least one has an autocomplete attribute.
TEST_F(FormStructureTestImpl, DetermineHeuristicTypes_AutocompleteFalse) {}

TEST_F(FormStructureTestImpl, HeuristicsContactInfo) {}

// Verify that we can correctly process the |autocomplete| attribute.
TEST_F(FormStructureTestImpl, HeuristicsAutocompleteAttribute) {}

// All fields share a common prefix which could confuse the heuristics. Test
// that the common prefix is stripped out before running heuristics.
TEST_F(FormStructureTestImpl, StripCommonNamePrefix) {}

// All fields share a common prefix which is small enough that it is not
// stripped from the name before running the heuristics.
TEST_F(FormStructureTestImpl, StripCommonNamePrefix_SmallPrefix) {}

TEST_F(FormStructureTestImpl, IsCompleteCreditCardForm_Minimal) {}

TEST_F(FormStructureTestImpl, IsCompleteCreditCardForm_Full) {}

// A form with only the credit card number is not considered sufficient.
TEST_F(FormStructureTestImpl, IsCompleteCreditCardForm_OnlyCCNumber) {}

// A form with only the credit card number is not considered sufficient.
TEST_F(FormStructureTestImpl, IsCompleteCreditCardForm_AddressForm) {}

// Verify that we can correctly process the 'autocomplete' attribute for phone
// number types (especially phone prefixes and suffixes).
TEST_F(FormStructureTestImpl, HeuristicsAutocompleteAttributePhoneTypes) {}

// The heuristics and server predictions should run if there are more than two
// fillable fields.
TEST_F(FormStructureTestImpl,
       HeuristicsAndServerPredictions_BigForm_NoAutocompleteAttribute) {}

// The heuristics and server predictions should run even if a valid autocomplete
// attribute is present in the form (if it has more that two fillable fields).
TEST_F(FormStructureTestImpl,
       HeuristicsAndServerPredictions_ValidAutocompleteAttribute) {}

// The heuristics and server predictions should run even if an unrecognized
// autocomplete attribute is present in the form (if it has more than two
// fillable fields).
TEST_F(FormStructureTestImpl,
       HeuristicsAndServerPredictions_UnrecognizedAutocompleteAttribute) {}

// Tests whether the heuristics and server predictions are run for forms with
// fewer than 3 fields  and no autocomplete attributes.
TEST_F(FormStructureTestImpl,
       HeuristicsAndServerPredictions_SmallForm_NoAutocompleteAttribute) {}

// Tests the heuristics and server predictions are not run for forms with less
// than 3 fields, if the minimum fields required feature is enforced, even if an
// autocomplete attribute is specified.
TEST_F(FormStructureTestImpl,
       HeuristicsAndServerPredictions_SmallForm_ValidAutocompleteAttribute) {}

// Tests that heuristics for single field parseable types are run for forms with
// fewer than 3 fields.
TEST_F(FormStructureTestImpl, PromoCodeHeuristics_SmallForm) {}

// Even with an 'autocomplete' attribute set, ShouldBeQueried() should
// return true if the structure contains a password field, since there are
// no local heuristics to depend upon in this case. Fields will still not be
// considered autofillable though.
TEST_F(FormStructureTestImpl, PasswordFormShouldBeQueried) {}

// Verify that we can correctly process a degenerate section listed in the
// |autocomplete| attribute.
TEST_F(FormStructureTestImpl,
       HeuristicsAutocompleteAttributeWithSectionsDegenerate) {}

// Verify that we can correctly process repeated sections listed in the
// |autocomplete| attribute.
TEST_F(FormStructureTestImpl,
       HeuristicsAutocompleteAttributeWithSectionsRepeated) {}

TEST_F(FormStructureTestImpl, HeuristicsSample8) {}

TEST_F(FormStructureTestImpl, HeuristicsSample6) {}

// Tests a sequence of FormFields where only labels are supplied to heuristics
// for matching.  This works because FormFieldData labels are matched in the
// case that input element ids (or |name| fields) are missing.
TEST_F(FormStructureTestImpl, HeuristicsLabelsOnly) {}

TEST_F(FormStructureTestImpl, HeuristicsCreditCardInfo) {}

TEST_F(FormStructureTestImpl, HeuristicsCreditCardInfoWithUnknownCardField) {}

TEST_F(FormStructureTestImpl, ThreeAddressLines) {}

// Numbered address lines after line two are ignored.
TEST_F(FormStructureTestImpl, SurplusAddressLinesIgnored) {}

// This example comes from expedia.com where they used to use a "Suite" label
// to indicate a suite or apartment number (the form has changed since this
// test was written). We interpret this as address line 2. And the following
// "Street address second line" we interpret as address line 3.
// See http://crbug.com/48197 for details.
TEST_F(FormStructureTestImpl, ThreeAddressLinesExpedia) {}

// This example comes from ebay.com where the word "suite" appears in the label
// and the name "address2" clearly indicates that this is the address line 2.
// See http://crbug.com/48197 for details.
TEST_F(FormStructureTestImpl, TwoAddressLinesEbay) {}

TEST_F(FormStructureTestImpl, HeuristicsStateWithProvince) {}

// This example comes from lego.com's checkout page.
TEST_F(FormStructureTestImpl, HeuristicsWithBilling) {}

TEST_F(FormStructureTestImpl, ThreePartPhoneNumber) {}

TEST_F(FormStructureTestImpl, HeuristicsInfernoCC) {}

// Tests that the heuristics detect split credit card names if they appear in
// the middle of the form.
TEST_F(FormStructureTestImpl, HeuristicsInferCCNames_NamesNotFirst) {}

// Tests that the heuristics detect split credit card names if they appear at
// the beginning of the form. The first name has to contains some credit card
// keyword.
TEST_F(FormStructureTestImpl, HeuristicsInferCCNames_NamesFirst) {}

TEST_F(FormStructureTestImpl, ButtonTitleType_Match) {}

TEST_F(FormStructureTestImpl, CheckFormSignature) {}

TEST_F(FormStructureTestImpl, CheckAlternativeFormSignatureLarge) {}

TEST_F(FormStructureTestImpl, CheckAlternativeFormSignatureSmallPath) {}

TEST_F(FormStructureTestImpl, CheckAlternativeFormSignatureSmallRef) {}

TEST_F(FormStructureTestImpl, CheckAlternativeFormSignatureSmallQuery) {}

TEST_F(FormStructureTestImpl, ToFormData) {}

// Tests that an Autofill upload for password form with 1 field should not be
// uploaded.
TEST_F(FormStructureTestImpl, OneFieldPasswordFormShouldNotBeUpload) {}


// Tests if a new logical form is started with the second appearance of a field
// of type |FieldTypeGroup::kName|.
TEST_F(FormStructureTestImpl, NoAutocompleteSectionNames) {}

// Tests that adjacent name field types are not split into different sections.
TEST_F(FormStructureTestImpl, NoSplitAdjacentNameFieldType) {}

TEST_F(FormStructureTestImpl, FindFieldsEligibleForManualFilling) {}

// Tests that AssignBestFieldTypes() sets (only) the PatternSource.
TEST_P(FormStructureTest_ForPatternSource, ParseFieldTypesWithPatterns) {}

TEST_F(FormStructureTestImpl, DetermineRanks) {}

// Tests that forms that are completely annotated with ac=unrecognized are not
// classified as address forms.
TEST_F(FormStructureTestImpl, GetFormTypes_AutocompleteUnrecognized) {}

// By default, the single field email heuristics are off. Although applying
// heuristics in this case appears to have been intended behavior, the rollout
// must be managed with care. This test is intended to ensure the default
// experience does not change unintentionally.
TEST_F(FormStructureTestImpl, SingleFieldEmailHeuristicsDefaultBehavior) {}

// When the single field email heuristics feature is enabled, a single field
// email form should be parsed accordingly.
TEST_F(FormStructureTestImpl, SingleFieldEmailHeuristicsEnabled) {}

// Verifies that with kAutofillEnableEmailHeuristicAutocompleteEmail enabled,
// only fields with autocomplete=email are parsed as email fields.
TEST_F(FormStructureTestImpl,
       SingleFieldEmailHeuristicsEnabledAutocompleteEmail) {}

// When the single field email heuristics feature is enabled, email fields are
// not parsed if these are outside of form tags.
TEST_F(FormStructureTestImpl,
       SingleFieldEmailHeuristicsNotSupportedOutsideFormTag) {}

// When the single field email heuristics feature is enabled, a single field
// email form should be parsed accordingly. Support for email fields outside of
// form tags is also supported when `kAutofillEnableEmailHeuristicOutsideForms`
// is enabled.
TEST_F(FormStructureTestImpl,
       SingleFieldEmailHeuristicsSupportedOutsideFormTag) {}

}  // namespace autofill