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

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>

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

#include "base/containers/flat_map.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/ranges/algorithm.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.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/browser_autofill_manager.h"
#include "components/autofill/core/browser/browser_autofill_manager_test_api.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/filling_product.h"
#include "components/autofill/core/browser/form_structure_test_api.h"
#include "components/autofill/core/browser/geo/alternative_state_name_map_test_utils.h"
#include "components/autofill/core/browser/heuristic_source.h"
#include "components/autofill/core/browser/payments/credit_card_cvc_authenticator.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/test_autofill_client.h"
#include "components/autofill/core/browser/test_autofill_driver.h"
#include "components/autofill/core/browser/test_browser_autofill_manager.h"
#include "components/autofill/core/common/autofill_clock.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/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/mojom/autofill_types.mojom-shared.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/variant.h"

namespace autofill {

namespace  // namespace

class FormFillerTest : public testing::Test {};

// Tests that only fields from `field_types_to_fill` are filled.
TEST_F(FormFillerTest, FillingDetails_FieldTypesToFill_FillOnlySpecificFields) {}

// Test that the correct section is filled.
TEST_F(FormFillerTest, FillTriggeredSection) {}

// Test that if the form cache is outdated because a field has changed, filling
// is aborted after that field.
TEST_F(FormFillerTest, DoNotFillIfFormFieldChanged) {}

// Test that if the form cache is outdated because the form has changed, filling
// is aborted because of that change.
TEST_F(FormFillerTest, DoNotFillIfFormChanged) {}

TEST_F(FormFillerTest, SkipFillIfFieldIsMeaningfullyPreFilled) {}

TEST_F(FormFillerTest, SkipAllPreFilledFieldsExceptIfFieldIsAPlaceholder) {}

TEST_F(FormFillerTest, UndoSavesFormFillingData) {}

TEST_F(FormFillerTest, UndoSavesFieldByFieldFillingData) {}

TEST_F(FormFillerTest, UndoResetsCachedAutofillState) {}

TEST_F(FormFillerTest, FillOrPreviewDataModelFormCallsDidFillOrPreviewForm) {}

// Tests that for autocomplete=unrecognized fields:
// - Are not filled by default.
// - Are filled through manual fallbacks.
TEST_F(FormFillerTest,
       FillAddressForm_AutocompleteUnrecognizedFillingBehavior) {}

// Test that we correctly fill a credit card form.
TEST_F(FormFillerTest, FillCreditCardForm_Simple) {}

// Test that whitespace and separators are stripped from the credit card number.
TEST_F(FormFillerTest, FillCreditCardForm_StripCardNumber) {}

struct PartialCreditCardDateParams {};

class PartialCreditCardDateTest
    : public FormFillerTest,
      public testing::WithParamInterface<PartialCreditCardDateParams> {};

INSTANTIATE_TEST_SUITE_P();

// Test that we correctly fill a credit card form with month input type.
TEST_P(PartialCreditCardDateTest, FillWithPartialDate) {}

// Test that only the first 19 credit card number fields are filled.
TEST_F(FormFillerTest, FillOnlyFirstNineteenCreditCardNumberFields) {}

// Test the credit card number is filled correctly into single-digit fields.
TEST_F(FormFillerTest, FillCreditCardNumberIntoSingleDigitFields) {}

// Test that we correctly fill a credit card form with first and last cardholder
// name.
TEST_F(FormFillerTest, FillCreditCardForm_SplitName) {}

// Test that only filled selection boxes are counted for the type filling limit.
TEST_F(FormFillerTest, OnlyCountFilledSelectionBoxesForTypeFillingLimit) {}

// Test that fields with the autocomplete attribute set to off are filled.
TEST_F(FormFillerTest, FillAddressForm_AutocompleteOffFillingBehavior) {}

// Test that fields with value equal to their placeholder attribute are filled.
TEST_F(FormFillerTest, FillAddressForm_PlaceholderEqualsValue) {}

// Test that credit card fields with unrecognized autocomplete attribute are
// filled.
TEST_F(FormFillerTest,
       FillCreditCardForm_AutocompleteUnrecognizedFillingBehavior) {}

// Test that credit card fields are filled even if they have the autocomplete
// attribute set to off.
TEST_F(FormFillerTest, FillCreditCardForm_AutocompleteOffBehavior) {}

// Test that selecting an expired credit card fills everything except the
// expiration date.
TEST_F(FormFillerTest, FillCreditCardForm_ExpiredCard) {}

TEST_F(FormFillerTest, PreviewCreditCardForm_VirtualCard) {}

// Test that unfocusable fields aren't filled, except for <select> fields (but
// not <selectlist> fields).
TEST_F(FormFillerTest, DoNotFillUnfocusableFieldsExceptForSelect) {}

// Test that we correctly fill a form that has author-specified sections, which
// might not match our expected section breakdown.
TEST_F(FormFillerTest, FillFormWithAuthorSpecifiedSections) {}

// Test that we correctly fill a form that has a single logical section with
// multiple email address fields.
TEST_F(FormFillerTest, FillFormWithMultipleEmails) {}

// Test that we correctly fill a previously autofilled address form.
TEST_F(FormFillerTest, FillAutofilledAddressForm) {}

// Test that we correctly fill a previously autofilled credit card form.
TEST_F(FormFillerTest, FillAutofilledCreditCardForm) {}

// Test that we correctly fill a partly manually filled address form.
TEST_F(FormFillerTest, FillPartlyManuallyFilledAddressForm) {}

// Test that we correctly fill a partly manually filled credit card form.
TEST_F(FormFillerTest, FillPartlyManuallyFilledCreditCardForm) {}

// Test that we correctly fill a phone number split across multiple fields.
TEST_F(FormFillerTest, FillPhoneNumber) {}

TEST_F(FormFillerTest, FillPhoneNumber_ForPhonePrefixOrSuffix) {}

// Tests filling a phone number field with max length limit.
TEST_F(FormFillerTest, FillPhoneNumber_WithMaxLengthLimit) {}

// Tests that only the first complete number is filled when there are multiple
// componentized number fields.
TEST_F(FormFillerTest, FillFirstPhoneNumber_ComponentizedNumbers) {}

TEST_F(FormFillerTest, FillFirstPhoneNumber_WholeNumbers) {}

TEST_F(FormFillerTest, FillFirstPhoneNumber_FillPartsOnceOnly) {}

// Verify when extension is misclassified, and there is a complete
// phone field, we do not fill anything to extension field.
TEST_F(FormFillerTest, FillFirstPhoneNumber_NotFillMisclassifiedExtention) {}

// Verify that phone number fields annotated with the autocomplete attribute
// are filled best-effort. Phone number local heuristics only succeed if a
// PHONE_HOME_NUMBER field is present.
TEST_F(FormFillerTest, FillFirstPhoneNumber_BestEffortFilling) {}

// When the focus is on second phone field explicitly, we will fill the
// entire form, both first phone field and second phone field included.
TEST_F(FormFillerTest, FillFirstPhoneNumber_FocusOnSecondPhoneNumber) {}

TEST_F(FormFillerTest, FillFirstPhoneNumber_HiddenFieldShouldNotCount) {}

// Tests that only hidden/presentational select fields are filled.
TEST_F(FormFillerTest, FormWithHiddenOrPresentationalFields) {}

TEST_F(FormFillerTest, FillFirstPhoneNumber_MultipleSectionFilledCorrectly) {}

// Test that we can still fill a form when a field has been removed from it.
TEST_F(FormFillerTest, FormChangesRemoveField) {}

// Test that we can still fill a form when a field has been added to it.
TEST_F(FormFillerTest, FormChangesAddField) {}

// Test that we can still fill a form when the visibility of some fields
// changes.
TEST_F(FormFillerTest, FormChangesVisibilityOfFields) {}

TEST_F(FormFillerTest, FillInUpdatedExpirationDate) {}

// Test that fields will be assigned with the source profile that was used for
// autofill.
TEST_F(FormFillerTest, TrackFillingOrigin) {}

// Test that filling with multiple autofill profiles will set different source
// profiles for fields.
TEST_F(FormFillerTest, TrackFillingOriginWithUsingMultipleProfiles) {}

// Test that an autofilled and edited field will be assigned with the autofill
// profile.
TEST_F(FormFillerTest, TrackFillingOriginOnEditedField) {}

// Regression test that a field with an unrelated type doesn't cause a crash
// (crbug.com/324811625).
TEST_F(FormFillerTest, PreFilledCCFieldInAddressFormDoesNotCauseCrash) {}

TEST_F(FormFillerTest, FillOrPreviewFormExperimental) {}

// The following Refill Tests ensure that Autofill can handle the situation
// where it fills a credit card form with an expiration date like 04/2999
// and the website tries to reformat the input with whitespaces around the
// slash and then sacrifices the wrong digits in the expiration date. I.e.,
// the website replaces "04/2099" with "04 / 20". The tests ensure that this
// triggers a refill with "04 / 29".
struct RefillTestCase {};

class ExpirationDateRefillTest
    : public FormFillerTest,
      public testing::WithParamInterface<RefillTestCase> {};

TEST_P(ExpirationDateRefillTest, RefillJavascriptModifiedExpirationDates) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace autofill