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

#include <stddef.h>

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

#include "base/base64.h"
#include "base/command_line.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/hash/hash.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/metrics_hashes.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_callback_support.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/address_data_manager.h"
#include "components/autofill/core/browser/address_data_manager_test_api.h"
#include "components/autofill/core/browser/address_suggestion_generator.h"
#include "components/autofill/core/browser/autofill_compose_delegate.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/autofill_form_test_utils.h"
#include "components/autofill/core/browser/autofill_plus_address_delegate.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/browser_autofill_manager_test_api.h"
#include "components/autofill/core/browser/crowdsourcing/mock_autofill_crowdsourcing_manager.h"
#include "components/autofill/core/browser/data_model/autofill_profile.h"
#include "components/autofill/core/browser/data_model/autofill_profile_test_api.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/data_model/iban.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/filling_product.h"
#include "components/autofill/core/browser/form_data_importer_test_api.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/metrics/form_events/form_events.h"
#include "components/autofill/core/browser/metrics/log_event.h"
#include "components/autofill/core/browser/mock_autofill_compose_delegate.h"
#include "components/autofill/core/browser/mock_autofill_optimization_guide.h"
#include "components/autofill/core/browser/mock_autofill_plus_address_delegate.h"
#include "components/autofill/core/browser/mock_autofill_prediction_improvements_delegate.h"
#include "components/autofill/core/browser/mock_single_field_form_fill_router.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/payments/test_credit_card_save_manager.h"
#include "components/autofill/core/browser/payments/test_payments_autofill_client.h"
#include "components/autofill/core/browser/payments/test_payments_network_interface.h"
#include "components/autofill/core/browser/payments_data_manager.h"
#include "components/autofill/core/browser/payments_suggestion_generator.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/profile_token_quality.h"
#include "components/autofill/core/browser/profile_token_quality_test_api.h"
#include "components/autofill/core/browser/strike_databases/payments/test_credit_card_save_strike_database.h"
#include "components/autofill/core/browser/test_autofill_client.h"
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/test_autofill_driver.h"
#include "components/autofill/core/browser/test_autofill_external_delegate.h"
#include "components/autofill/core/browser/test_autofill_manager_waiter.h"
#include "components/autofill/core/browser/test_browser_autofill_manager.h"
#include "components/autofill/core/browser/test_form_data_importer.h"
#include "components/autofill/core/browser/test_personal_data_manager.h"
#include "components/autofill/core/browser/test_utils/vote_uploads_test_matchers.h"
#include "components/autofill/core/browser/ui/payments/bubble_show_options.h"
#include "components/autofill/core/browser/ui/suggestion.h"
#include "components/autofill/core/browser/ui/suggestion_test_helpers.h"
#include "components/autofill/core/browser/ui/suggestion_type.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autocomplete_parsing_util.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_prefs.h"
#include "components/autofill/core/common/autofill_switches.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 "components/autofill/core/common/signatures.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/prefs/pref_service.h"
#include "components/security_interstitials/core/pref_names.h"
#include "components/security_state/core/security_state.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync/test/test_sync_service.h"
#include "components/translate/core/common/language_detection_details.h"
#include "components/variations/variations_associated_data.h"
#include "components/version_info/channel.h"
#include "net/base/url_util.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/rect.h"
#include "url/gurl.h"
#include "url/url_canon.h"

namespace autofill {

namespace  // namespace

class BrowserAutofillManagerTest : public testing::Test {};

class SuggestionMatchingTest : public BrowserAutofillManagerTest,
                               public testing::WithParamInterface<bool> {};

#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
void SuggestionMatchingTest::InitializeFeatures() {}
#else
void SuggestionMatchingTest::InitializeFeatures() {}
#endif  // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)

// Credit card suggestion tests related with keyboard accessory.
class CreditCardSuggestionTest : public BrowserAutofillManagerTest {};

// Test that calling OnFormsSeen consecutively with a different set of forms
// will query for each separately.
TEST_F(BrowserAutofillManagerTest, OnFormsSeen_DifferentFormStructures) {}

// Test that when forms are seen, the renderer is updated with the predicted
// field types
TEST_F(BrowserAutofillManagerTest, OnFormsSeen_SendTypePredictionsToRenderer) {}

// Test that no autofill suggestions are returned for a field with an
// unrecognized autocomplete attribute on desktop.
// On mobile, the keyboard accessory is shown unconditionally.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_UnrecognizedAttribute) {}

#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
// Tests the behavior of address suggestion vis a vis the
// AddressSuggestionStrikeDatabase logic.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_BlockSuggestionsAfterStrikeLimit) {}
#endif

// Tests that ac=unrecognized fields only activate suggestions when triggered
// through manual fallbacks (even though the field has a type in both cases) on
// desktop.
// On mobile, suggestions are shown even for ac=unrecognized fields.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_UnrecognizedAttribute_Predictions_Mobile) {
  // Create a form where the first field has ac=unrecognized.
  FormData form = CreateTestAddressFormData();
  test_api(form).field(0).set_parsed_autocomplete(
      AutocompleteParsingResult{.field_type = HtmlFieldType::kUnrecognized});
  FormsSeen({form});

  // Expect that two suggestions + footer are returned for all fields,
  // independently of the autocomplete attribute. Two, because the fixture
  // created three profiles during set up, one of which is empty and cannot be
  // suggested (see `CreateTestAutofillProfiles()`).
  for (const FormFieldData& field : form.fields()) {
    GetAutofillSuggestions(form, field);
    external_delegate()->CheckSuggestionCount(field.global_id(), 4);
  }
}
#else
TEST_F(BrowserAutofillManagerTest,
       AutofillManualFallback_UnclassifiedField_SuggestionsShown) {}

TEST_F(BrowserAutofillManagerTest,
       AutofillManualFallback_AutocompleteUnrecognized_SuggestionsShown) {}

TEST_F(BrowserAutofillManagerTest,
       AutofillManualFallback_ClassifiedField_AddressForm_ShowSuggestions) {}

TEST_F(BrowserAutofillManagerTest,
       AutofillManualFallback_ClassifiedField_PaymentsForm_ShowSuggestions) {}

TEST_F(BrowserAutofillManagerTest,
       AutofillManualFallback_IphIsDisplayedCorrectly) {}

TEST_F(BrowserAutofillManagerTest, AutofillManualFallback_NotifyFeatureUsed) {}

#endif  // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)

// Test that when small forms are disabled (min required fields enforced) no
// suggestions are returned when there are less than three fields and none of
// them have an autocomplete attribute.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_MinFieldsEnforced_NoAutocomplete) {}

// Test that when small forms are disabled (min required fields enforced)
// for a form with two fields with one that has an autocomplete attribute,
// suggestions are only made for the one that has the attribute.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_MinFieldsEnforced_WithOneAutocomplete) {}

// Test that for a form with two fields with autocomplete attributes,
// suggestions are made for both fields. This is true even if a minimum number
// of fields is enforced.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_SmallFormWithTwoAutocomplete) {}

// Tests that BrowserAutofillManager correctly returns virtual cards with usage
// data and VCN last four for a standalone cvc field.
TEST_F(BrowserAutofillManagerTest, GetVirtualCreditCardsForStandaloneCvcField) {}

// Test that we return all address profile suggestions when all form fields
// are empty.
TEST_P(SuggestionMatchingTest, GetProfileSuggestions_EmptyValue) {}

// Test that we return only matching address profile suggestions when the
// selected form field has been partially filled out.
TEST_P(SuggestionMatchingTest, GetProfileSuggestions_MatchCharacter) {}

// Tests that we return address profile suggestions values when the section
// is already autofilled, and that we merge identical values.
TEST_P(SuggestionMatchingTest,
       GetProfileSuggestions_AlreadyAutofilledMergeValues) {}

// Tests that we return address profile suggestions values when the section
// is already autofilled, and that they have no label.
TEST_P(SuggestionMatchingTest,
       GetProfileSuggestions_AlreadyAutofilledNoLabels) {}

// Test that we return no suggestions when the form has no relevant fields.
TEST_F(BrowserAutofillManagerTest, GetProfileSuggestions_UnknownFields) {}

TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_DialogClosedByUser_NoData) {}

// Test that single field suggestions are not queries when autofill is triggered
// manually by the user.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_ManualFallback_NoData) {}

// Test parameter data for asserting that the expected suggestion types are
// returned when triggering Autofill using manual fallback. Note that the tests
// that use this param are only about manual fallback for fields that are not
// classified as the target `FillingProduct` defined by the chosen
// `manual_fallback_option`. Therefore, manual fallbacks for `ac=unrecognized`
// fields are not covered here.
struct ManualFallbackTestParams {};

// Test fixture that covers Autofill being triggered from fields that are not
// classified as the target `FillingProduct`. For example, triggering address
// manual fallback from an unclassified field.
class ManualFallbackTest
    : public BrowserAutofillManagerTest,
      public ::testing::WithParamInterface<ManualFallbackTestParams> {};

TEST_P(ManualFallbackTest, ReturnsExpectedSuggestionTypes) {}

INSTANTIATE_TEST_SUITE_P();

// Test that we call duplicate profile suggestions.
TEST_P(SuggestionMatchingTest, GetProfileSuggestions_WithDuplicates) {}

// Test that we return no suggestions when autofill is disabled.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_AutofillDisabledByUser) {}

TEST_F(BrowserAutofillManagerTest, TestParseFormUntilInteractionMetric) {}

// Tests that `SingleFieldFormFillRouter` returns to the
// `AutofillExternalDelegate`, if it has any.
TEST_F(BrowserAutofillManagerTest,
       OnSuggestionsReturned_CallsExternalDelegate) {}

class BrowserAutofillManagerTestForMetadataCardSuggestions
    : public BrowserAutofillManagerTest,
      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// Test that we return all credit card profile suggestions when all form fields
// are empty.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_EmptyValue) {}

// Test that we return all credit card profile suggestions when the triggering
// field has whitespace in it.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_Whitespace) {}

// Test that we return all credit card profile suggestions when the triggering
// field has stop characters in it, which should be removed.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_StopCharsOnly) {}

// Test that we return all credit card profile suggestions when the triggering
// field has some invisible unicode characters in it.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_InvisibleUnicodeOnly) {}

// Test that we return all credit card profile suggestions when the triggering
// field has stop characters in it and some input.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_StopCharsWithInput) {}

// Test that we return only matching credit card profile suggestions when the
// selected form field has been partially filled out.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_MatchCharacter) {}

// Test that we return credit card profile suggestions when the selected form
// field is the credit card number field.
TEST_F(CreditCardSuggestionTest, GetCreditCardSuggestions_CCNumber) {}

// Test that we return credit card profile suggestions when the selected form
// field is not the credit card number field.
TEST_F(CreditCardSuggestionTest, GetCreditCardSuggestions_NonCCNumber) {}

// Test that we return a warning explaining that credit card profile suggestions
// are unavailable when the page is secure, but the form action URL is valid but
// not secure.
TEST_F(BrowserAutofillManagerTest,
       GetCreditCardSuggestions_SecureContext_FormActionNotHTTPS) {}

// Test that we return credit card suggestions for secure pages that have an
// empty form action target URL.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_SecureContext_EmptyFormAction) {}

// Test that we return credit card suggestions for secure pages that have a
// form action set to "javascript:something".
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_SecureContext_JavascriptFormAction) {}

// Test that we return all credit card suggestions in the case that two cards
// have the same obfuscated number.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_RepeatedObfuscatedNumber) {}

// Test that a masked server card is not suggested if more than six digits
// have been typed in the field.
TEST_F(BrowserAutofillManagerTest,
       GetCreditCardSuggestions_MaskedCardWithMoreThan6Digits) {}

// Test that expired cards are ordered by their ranking score and are always
// suggested after non expired cards even if they have a higher ranking score.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_ExpiredCards) {}

// Test cards that are expired AND disused are suppressed when suppression is
// enabled and the input field is empty.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_SuppressDisusedCreditCardsOnEmptyField) {}

// Test that a card that doesn't have a number is not shown in the
// suggestions when querying credit cards by their number, and is shown when
// querying other fields.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_NumberMissing) {}

// Test that we return profile and credit card suggestions for combined forms.
TEST_P(SuggestionMatchingTest, GetAddressAndCreditCardSuggestions) {}

// Test that for non-https forms with both address and credit card fields, we
// only return address suggestions. Instead of credit card suggestions, we
// should return a warning explaining that credit card profile suggestions are
// unavailable when the form is not https.
TEST_F(BrowserAutofillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {}

TEST_F(BrowserAutofillManagerTest,
       ShouldShowAddressSuggestionsIfCreditCardAutofillDisabled) {}

TEST_F(BrowserAutofillManagerTest,
       ShouldShowCreditCardSuggestionsIfAddressAutofillDisabled) {}

TEST_F(BrowserAutofillManagerTest,
       ShouldNotShowCreditCardsSuggestionsIfCreditCardAutofillDisabled) {}

// Test that credit card suggestions are shown for expiry type field when
// credit card number field is empty.
TEST_F(BrowserAutofillManagerTest,
       ShowCreditCardSuggestions_ForExpirationTypeField_IfEmptyCCNumber) {}

// Test that credit card suggestions are shown for expiry type field when
// credit card number field is not empty and has been autofilled.
TEST_F(
    BrowserAutofillManagerTest,
    ShowCreditCardSuggestions_ForExpirationTypeField_IfNonEmptyAutofilledCCNumber) {}

// Test that credit card suggestions are not shown for expiry type field when
// credit card number field is not empty and has not been autofilled.
TEST_F(
    BrowserAutofillManagerTest,
    DoNotShowCreditCardSuggestions_ForExpirationTypeField_IfNonEmptyNonAutofilledCCNumber) {}

TEST_F(BrowserAutofillManagerTest,
       ShouldNotShowAddressSuggestionsIfAddressAutofillDisabled) {}

// Tests that if the ablation study runs in dry-run mode, suggestions are
// shown even though the ablation study is enabled.
// This is basically a copy of
// ShouldNotShowAddressSuggestionsIfAddressAutofillDisabled, except that the
// dryrun flag ist set.
TEST_F(BrowserAutofillManagerTest,
       ShouldShowAddressSuggestionsIfAblationIsInDryRunMode) {}

struct LogAblationTestParams {};

enum class LogAblationFormType {};

class BrowserAutofillManagerLogAblationTest
    : public BrowserAutofillManagerTest,
      public testing::WithParamInterface<
          std::tuple<LogAblationTestParams, LogAblationFormType>> {};

// Validate that UMA logging works correctly for ablation studies.
INSTANTIATE_TEST_SUITE_P();

TEST_P(BrowserAutofillManagerLogAblationTest, TestLogging) {}

// Test that we properly match typed values to stored state data.
TEST_F(BrowserAutofillManagerTest, DetermineStateFieldTypeForUpload) {}

// Ensures that if autofill is disabled but the password manager is enabled,
// Autofill still performs a lookup to the server.
TEST_F(BrowserAutofillManagerTest,
       OnFormsSeen_AutofillDisabledPasswordManagerEnabled) {}

// Test that we return normal Autofill suggestions when trying to autofill
// already filled forms.
TEST_P(SuggestionMatchingTest, GetFieldSuggestionsWhenFormIsAutofilled) {}

// The method `GetPrefixMatchedProfiles` prevents
// that Android users see values that would override already filled fields
// due to the narrow surface and a missing preview.
#if !BUILDFLAG(IS_ANDROID)
// Test that we do not return duplicate values drawn from multiple profiles when
// filling an already filled field.
TEST_P(SuggestionMatchingTest, GetFieldSuggestionsWithDuplicateValues) {}
#endif

// Tests that we return email profile suggestions values
// when the email field with username autocomplete attribute exist.
TEST_F(BrowserAutofillManagerTest,
       GetProfileSuggestions_ForEmailFieldWithUserNameAutocomplete) {}

// Tests that when focusing on an autofilled field, the user gets field-by-field
// filling suggestions without prefix matching, if AutofillAddressFieldSwapping
// is enabled.
TEST_F(BrowserAutofillManagerTest, GetProfileSuggestions_FieldSwapping) {}

// Tests that fields with unrecognized autocomplete attribute don't contribute
// to key metrics.
TEST_F(BrowserAutofillManagerTest, AutocompleteUnrecognizedFields_KeyMetrics) {}

TEST_F(BrowserAutofillManagerTest,
       OnCreditCardFetchedSuccessfully_LocalCreditCard) {}

TEST_F(BrowserAutofillManagerTest,
       OnCreditCardFetchedSuccessfully_ServerCreditCard) {}

TEST_F(BrowserAutofillManagerTest,
       OnCreditCardFetchedSuccessfully_VirtualCreditCard) {}

// Test that the importing logic is called on form submit.
TEST_F(BrowserAutofillManagerTest, FormSubmitted_FormDataImporter) {}

// Test that the user perception of autofill for address filling survey is
// triggered after a form submission.
TEST_F(BrowserAutofillManagerTest,
       UserPerceptionOfAddressAutofillSurvey_MinFormSizeReached_TriggerSurvey) {}

TEST_F(
    BrowserAutofillManagerTest,
    UserPerceptionOfAutofillSurvey_MinFormSizeNotReached_DoNotTriggerSurvey) {}

// Test that the user perception of autofill for credit card filling survey is
// triggered after a form submission.
TEST_F(BrowserAutofillManagerTest,
       UserPerceptionOfCreditCardAutofillSurvey_TriggerSurvey) {}

// Test the field log events at the form submission.
// TODO(crbug.com/40100455): Move those tests out of this file.
class BrowserAutofillManagerWithLogEventsTest
    : public BrowserAutofillManagerTest {};

// Test that we record TriggerFillFieldLogEvent for the field we click to show
// the autofill suggestion and FillFieldLogEvent for every field in the form.
TEST_F(BrowserAutofillManagerWithLogEventsTest, LogEventsAtFormSubmitted) {}

// Test that we record FillFieldLogEvents correctly after autofill when the
// field has nothing to fill or the field contains a user typed value already.
TEST_F(BrowserAutofillManagerWithLogEventsTest,
       LogEventsFillPartlyManuallyFilledForm) {}

TEST_F(BrowserAutofillManagerWithLogEventsTest,
       FillingMethod_TargetedAllFields_FullForm) {}

TEST_F(BrowserAutofillManagerWithLogEventsTest,
       FillingMethod_TargetedGranularFillingGroup_GroupFilling) {}

TEST_F(BrowserAutofillManagerWithLogEventsTest,
       FillingMethod_TargetedSingleField_FieldByFieldFilling) {}

// Test that we record FillFieldLogEvents after filling a form twice, the first
// time some field values are missing when autofilling.
TEST_F(BrowserAutofillManagerWithLogEventsTest, LogEventsAtRefillForm) {}

// Test that we record user typing log event correctly after autofill.
TEST_F(BrowserAutofillManagerWithLogEventsTest, LogEventsAtUserTypingInField) {}

// Test that we record field log events correctly when the user touches to fill
// and fills the credit card form with a suggestion.
TEST_F(BrowserAutofillManagerWithLogEventsTest,
       LogEventsAutofillSuggestionsOrTouchToFill) {}

// Test that we record AutocompleteAttributeFieldLogEvent for the fields with
// autocomplete attributes in the form.
TEST_F(BrowserAutofillManagerWithLogEventsTest,
       LogEventsOnAutocompleteAttributeField) {}

// Test that we record field log events correctly for autofill crowdsourced
// server prediction.
TEST_F(BrowserAutofillManagerWithLogEventsTest,
       LogEventsParseQueryResponseServerPrediction) {}

// Test that we record field log events correctly for rationalization when
// there are two address fields.
TEST_F(BrowserAutofillManagerWithLogEventsTest,
       LogEventsRationalizationTwoAddresses) {}

// Test that we record field log events correctly for the single field form
// with the IBAN field.
TEST_F(BrowserAutofillManagerWithLogEventsTest, LogIBANField) {}

// Test that when Autocomplete is enabled and Autofill is disabled, form
// submissions are still received by the SingleFieldFormFillRouter.
TEST_F(BrowserAutofillManagerTest, FormSubmittedAutocompleteEnabled) {}

// Test that the value patterns metric is reported.
TEST_F(BrowserAutofillManagerTest, ValuePatternsMetric) {}

// Test that when Autofill is disabled, single field form fill suggestions are
// still queried as a fallback.
TEST_F(BrowserAutofillManagerTest,
       SingleFieldFormFillSuggestions_SomeWhenAutofillDisabled) {}

// Test that we do not query for single field form fill suggestions when there
// are Autofill suggestions available.
TEST_F(BrowserAutofillManagerTest,
       SingleFieldFormFillSuggestions_NoneWhenAutofillPresent) {}

// Test that we query for single field form fill suggestions when there are no
// Autofill suggestions available.
TEST_F(BrowserAutofillManagerTest,
       SingleFieldFormFillSuggestions_SomeWhenAutofillEmpty) {}

// Test that when Autofill is disabled and the field is a credit card name
// field, single field form fill suggestions are queried.
TEST_F(BrowserAutofillManagerTest,
       SingleFieldFormFillSuggestions_CreditCardNameFieldShouldAutocomplete) {}

// Test that when Autofill is disabled and the field is a credit card number
// field, single field form fill suggestions are not queried.
TEST_F(BrowserAutofillManagerTest,
       SingleFieldFormFillSuggestions_CreditCardNumberShouldNotAutocomplete) {}

// Test that the situation where there are no Autofill suggestions available,
// and no single field form fill conditions were met is correctly handled. The
// single field form fill conditions were not met because autocomplete is set to
// off and the field is not recognized as a promo code field.
TEST_F(
    BrowserAutofillManagerTest,
    SingleFieldFormFillSuggestions_NoneWhenAutofillEmptyAndSingleFieldFormFillConditionsNotMet) {}

// Test that the situation where no single field form fill conditions were met
// is handled correctly. The single field form fill conditions were not met
// because autocomplete is set to off and the field is not recognized as a promo
// code field.
TEST_F(
    BrowserAutofillManagerTest,
    SingleFieldFormFillSuggestions_NoneWhenSingleFieldFormFillConditionsNotMet) {}

TEST_F(BrowserAutofillManagerTest,
       DestructorCancelsSingleFieldFormFillQueries) {}

// Test that OnLoadedServerPredictions can obtain the FormStructure with the
// signature of the queried form from the API and apply type predictions.
// What we test here:
//  * The API response parser is used.
//  * The query can be processed with a response from the API.
TEST_F(BrowserAutofillManagerTest, OnLoadedServerPredictionsFromApi) {}

// Test that OnLoadedServerPredictions does not call ParseQueryResponse if the
// BrowserAutofillManager has been reset between the time the query was sent and
// the response received.
TEST_F(BrowserAutofillManagerTest, OnLoadedServerPredictions_ResetManager) {}

// Test that when server predictions disagree with the heuristic ones, the
// overall types and sections would be set based on the server one.
TEST_F(BrowserAutofillManagerTest, DetermineHeuristicsWithOverallPrediction) {}

// Test that the form signature for an uploaded form always matches the form
// signature from the query.
TEST_F(BrowserAutofillManagerTest, FormSubmittedWithDifferentFields) {}

// Test that we do not save form data when submitted fields contain default
// values.
TEST_F(BrowserAutofillManagerTest, FormSubmittedWithDefaultValues) {}

void DoTestFormSubmittedControlWithDefaultValue(
    BrowserAutofillManagerTest* test,
    FormControlType form_control_type) {}

// Test that we save form data when a <select> in the form contains the
// default value.
TEST_F(BrowserAutofillManagerTest, FormSubmittedSelectWithDefaultValue) {}

// Test that we save form data when a <selectlist> in the form contains the
// default value.
TEST_F(BrowserAutofillManagerTest, FormSubmittedSelectListWithDefaultValue) {}

void DoTestFormSubmittedNonAddressControlWithDefaultValue(
    BrowserAutofillManagerTest* test,
    FormControlType form_control_type) {}

// Test that we save form data when a non-country, non-state <select> in the
// form contains the default value.
TEST_F(BrowserAutofillManagerTest,
       FormSubmittedNonAddressSelectWithDefaultValue) {}

// Test that we save form data when a non-country, non-state <selectlist> in the
// form contains the default value.
TEST_F(BrowserAutofillManagerTest,
       FormSubmittedNonAddressSelectListWithDefaultValue) {}

// Tests that DeterminePossibleFieldTypesForUpload is called when a form is
// submitted.
TEST_F(BrowserAutofillManagerTest,
       DeterminePossibleFieldTypesForUpload_IsTriggered) {}

TEST_F(BrowserAutofillManagerTest, RemoveProfile) {}

TEST_F(BrowserAutofillManagerTest, RemoveLocalCreditCard) {}

TEST_F(BrowserAutofillManagerTest, RemoveServerCreditCard) {}

// Test our external delegate is called at the right time.
TEST_F(BrowserAutofillManagerTest, TestExternalDelegate) {}

// Test that unfocusing a filled form sends an upload with types matching the
// fields.
TEST_F(BrowserAutofillManagerTest, OnTextFieldDidChangeAndUnfocus_Upload) {}

// Test that navigating with a filled form sends an upload with types matching
// the fields.
TEST_F(BrowserAutofillManagerTest, OnTextFieldDidChangeAndNavigation_Upload) {}

// Test that unfocusing a filled form sends an upload with types matching the
// fields.
TEST_F(BrowserAutofillManagerTest, OnDidFillAutofillFormDataAndUnfocus_Upload) {}

// Test that suggestions are returned for credit card fields with an
// unrecognized
// autocomplete attribute.
TEST_F(BrowserAutofillManagerTest,
       GetCreditCardSuggestions_UnrecognizedAttribute) {}

// Test to verify suggestions appears for forms having credit card number split
// across fields.
TEST_P(BrowserAutofillManagerTestForMetadataCardSuggestions,
       GetCreditCardSuggestions_ForNumberSplitAcrossFields) {}

// Test that inputs detected to be CVC inputs are forced to
// !should_autocomplete for SingleFieldFormFillRouter::OnWillSubmitForm.
TEST_F(BrowserAutofillManagerTest, DontSaveCvcInAutocompleteHistory) {}

TEST_F(BrowserAutofillManagerTest, DontOfferToSavePaymentsCard) {}

TEST_F(BrowserAutofillManagerTest, ProfileDisabledDoesNotSuggest) {}

TEST_F(BrowserAutofillManagerTest, CreditCardDisabledDoesNotSuggest) {}

TEST_F(BrowserAutofillManagerTest, ShouldUploadForm) {}

// Verify that no suggestions are shown on desktop for non credit card related
// fields if the initiating field has the "autocomplete" attribute set to off.
TEST_F(BrowserAutofillManagerTest,
       DisplaySuggestions_AutocompleteOffNotRespected_AddressField) {}

// Verify that suggestions are shown on desktop for credit card related fields
// even if the initiating field has the "autocomplete" attribute set to off.
TEST_F(BrowserAutofillManagerTest,
       DisplaySuggestions_AutocompleteOff_CreditCardField) {}

// Tests that a form with server only types is still autofillable if the form
// gets updated in cache.
TEST_F(BrowserAutofillManagerTest,
       DisplaySuggestionsForUpdatedServerTypedForm) {}

TEST_F(BrowserAutofillManagerTest, GetCreditCardSuggestions_VirtualCard) {}

TEST_F(BrowserAutofillManagerTest,
       GetCreditCardSuggestions_VirtualCard_MetadataEnabled) {}

TEST_F(BrowserAutofillManagerTest,
       IbanFormProcessed_AutofillOptimizationGuidePresent) {}

TEST_F(BrowserAutofillManagerTest,
       IbanFormProcessed_AutofillOptimizationGuideNotPresent) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogAutocomplete_NoHappinessMetricsEmitted) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogAutofillAddressShownMetric) {}

TEST_F(BrowserAutofillManagerTest, DidShowSuggestions_LogByType_AddressOnly) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_AddressOnlyWithoutName) {}

TEST_F(BrowserAutofillManagerTest, DidShowSuggestions_LogByType_ContactOnly) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_ContactOnlyWithoutName) {}

TEST_F(BrowserAutofillManagerTest, DidShowSuggestions_LogByType_PhoneOnly) {}

TEST_F(BrowserAutofillManagerTest, DidShowSuggestions_LogByType_Other) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_AddressPlusEmail) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_AddressPlusEmailWithoutName) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_AddressPlusPhone) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_AddressPlusPhoneWithoutName) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_AddressPlusEmailPlusPhone) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogByType_AddressPlusEmailPlusPhoneWithoutName) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_LogAutofillCreditCardShownMetric) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_CreditCard_PreflightFetchingCall) {}

TEST_F(BrowserAutofillManagerTest,
       DidShowSuggestions_AddessSuggestion_NoPreflightFetchingCall) {}

TEST_F(BrowserAutofillManagerTest, PageLanguageGetsCorrectlySet) {}

// Test language detection on frames depending on whether the frame is active or
// not.
class BrowserAutofillManagerTestPageLanguageDetection
    : public BrowserAutofillManagerTest,
      public testing::WithParamInterface<bool> {};

TEST_P(BrowserAutofillManagerTestPageLanguageDetection, GetsCorrectlyDetected) {}

INSTANTIATE_TEST_SUITE_P();

// BrowserAutofillManagerTest with different browser profile types.
class BrowserAutofillManagerProfileMetricsTest
    : public BrowserAutofillManagerTest,
      public testing::WithParamInterface<profile_metrics::BrowserProfileType> {};

// Tests if submitting a form in different browser profile types records correct
// |Autofill.FormSubmission.PerProfileType| metric.
TEST_P(BrowserAutofillManagerProfileMetricsTest,
       FormSubmissionPerProfileTypeMetrics) {}

INSTANTIATE_TEST_SUITE_P();

// Tests that autocomplete-related metrics are emitted correctly on form
// submission.
TEST_F(BrowserAutofillManagerTest, AutocompleteMetrics) {}

// Test that if a form is mixed content we show a warning instead of any
// suggestions.
TEST_F(BrowserAutofillManagerTest, GetSuggestions_MixedForm) {}

// Test that if a form is mixed content we do not show a warning if the opt out
// policy is set.
TEST_F(BrowserAutofillManagerTest, GetSuggestions_MixedFormOptOutPolicy) {}

// Test that we dismiss the mixed form warning if user starts typing.
TEST_F(BrowserAutofillManagerTest, GetSuggestions_MixedFormUserTyped) {}

// Test that we don't treat javascript scheme target URLs as mixed forms.
// Regression test for crbug.com/1135173
TEST_F(BrowserAutofillManagerTest, GetSuggestions_JavascriptUrlTarget) {}

// Test that we don't treat about:blank target URLs as mixed forms.
TEST_F(BrowserAutofillManagerTest, GetSuggestions_AboutBlankTarget) {}

// Tests that both Autofill popup and TTF are hidden on renderer event.
TEST_F(BrowserAutofillManagerTest, HideAutofillSuggestionsAndOtherPopups) {}

// Tests that only Autofill popup is hidden on editing end, but not TTF or FC.
TEST_F(BrowserAutofillManagerTest, OnDidEndTextFieldEditing) {}

// Tests that keyboard accessory is not shown if TTF is eligible.
TEST_F(BrowserAutofillManagerTest, TouchToFillSuggestionForIban) {}

// Tests that Autofill suggestions are not shown if TTF is eligible and shown.
TEST_F(BrowserAutofillManagerTest, AutofillSuggestionsOrTouchToFillForCards) {}

// Tests that neither Autofill suggestions nor TTF is triggered if TTF is
// already shown.
TEST_F(BrowserAutofillManagerTest, ShowNothingIfTouchToFillAlreadyShown) {}

// Test that 'Scan New Card' suggestion is shown based on whether autofill
// credit card is enabled or disabled.
TEST_F(BrowserAutofillManagerTest, ScanCreditCardBasedOnAutofillPreference) {}

// Test that 'Scan New Card' suggestion is shown based on whether platform
// supports card scanning.
TEST_F(BrowserAutofillManagerTest, ScanCreditCardBasedOnPlatformSupport) {}

// Test that 'Scan New Card' suggestion is shown based on whether form field
// chosen is a credit card number field.
TEST_F(BrowserAutofillManagerTest, ScanCreditCardBasedOnCreditCardNumberField) {}

// Test that 'Scan New Card' suggestion is shown based on whether the form is
// secure.
TEST_F(BrowserAutofillManagerTest, ScanCreditCardBasedOnIsFormSecure) {}

// Tests that compose suggestions are not queried if Autofill has suggestions
// itself.
TEST_F(BrowserAutofillManagerTest, NoComposeSuggestionsByDefault) {}

// Tests that Compose suggestions are queried if the trigger source indicates
// that the focus change happened without click/tap interaction. It also
// verifies that neither Autofill nor single form fill suggestions are queried.
TEST_F(BrowserAutofillManagerTest, ComposeSuggestionsOnFocusWithoutClick) {}

// Tests that compose suggestions are queried and shown for textareas if
// Autofill does not have suggestions of its own and the OS is not Android, iOS
// or ChromeOS.
TEST_F(BrowserAutofillManagerTest, ComposeSuggestionsAreQueriedForTextareas) {}

// Tests that suggestions requested with
// `AutofillSuggestionTriggerSource::kPredictionImprovements` will be filled
// automatically (via `FormFiller::FillOrPreviewFields()`).
TEST_F(BrowserAutofillManagerTest, FillFormWithPredictionImprovements) {}

// Test param indicates if there is an active screen reader.
class OnFocusOnFormFieldTest : public BrowserAutofillManagerTest,
                               public testing::WithParamInterface<bool> {};

TEST_P(OnFocusOnFormFieldTest, AddressSuggestions) {}

TEST_P(OnFocusOnFormFieldTest, AddressSuggestions_AutocompleteOffNotRespected) {}

TEST_P(OnFocusOnFormFieldTest, AddressSuggestions_Ablation) {}

TEST_P(OnFocusOnFormFieldTest, CreditCardSuggestions_SecureContext) {}

TEST_P(OnFocusOnFormFieldTest, CreditCardSuggestions_NonSecureContext) {}

TEST_P(OnFocusOnFormFieldTest, CreditCardSuggestions_Ablation) {}

// Ensure that focus events are properly reported to the AutofillFields.
TEST_P(OnFocusOnFormFieldTest, FocusReporting) {}

INSTANTIATE_TEST_SUITE_P();

#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
INSTANTIATE_TEST_SUITE_P(, SuggestionMatchingTest, testing::Values(false));
#else
INSTANTIATE_TEST_SUITE_P();
#endif  // BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)

struct ShareNicknameTestParam {};

const ShareNicknameTestParam kShareNicknameTestParam[] =;

class BrowserAutofillManagerTestForSharingNickname
    : public BrowserAutofillManagerTest,
      public testing::WithParamInterface<ShareNicknameTestParam> {};

INSTANTIATE_TEST_SUITE_P();

// Tests that when there is a duplicate local and server card that will be
// combined into a single suggestion, the merged suggestion inherits the correct
// expected nickname.
TEST_P(BrowserAutofillManagerTestForSharingNickname,
       VerifySuggestion_DuplicateCards) {}

// Tests that when there are two unrelated local and server cards, they are
// shown separately and each displays their own nickname.
TEST_P(BrowserAutofillManagerTestForSharingNickname,
       VerifySuggestion_UnrelatedCards) {}

// Tests that analyze metrics logging in case JavaScript clears a field
// immediately after it was filled.
class BrowserAutofillManagerClearFieldTest : public BrowserAutofillManagerTest {};

// Ensure that we log the appropriate Autofill.FormEvents event if an autofilled
// field is cleared by JavaScript immediately after the filling.
TEST_F(BrowserAutofillManagerClearFieldTest, OneClearedField) {}

// Ensure that we log a single Autofill.FormEvents event even if *two*
// autofilled fields are cleared by JavaScript immediately after the filling.
TEST_F(BrowserAutofillManagerClearFieldTest, TwoClearedFields) {}

// Ensure that we do not log an Autofill.FormEvents event for the case that
// JavaScript modifies an autofilled field but does not clear it.
TEST_F(BrowserAutofillManagerClearFieldTest, ModifiedButDidNotClearField) {}

// Ensure that we do not log an appropriate Autofill.FormEvents event if an
// autofilled field is cleared by JavaScript too long after it was filled.
TEST_F(BrowserAutofillManagerClearFieldTest, NoLoggingAfterDelay) {}

class BrowserAutofillManagerVotingTest : public BrowserAutofillManagerTest {};

// Ensure that a vote is submitted after a regular form submission.
TEST_F(BrowserAutofillManagerVotingTest, Submission) {}

// Test that when modifying the form, a blur vote can be sent for the early
// version and a submission vote can be sent for the final version.
TEST_F(BrowserAutofillManagerVotingTest, DynamicFormSubmission) {}

// Ensure that a blur votes is sent after a navigation.
TEST_F(BrowserAutofillManagerVotingTest, BlurVoteOnNavigation) {}

// Ensure that a submission vote blocks sending a blur vote for the same form
// signature.
TEST_F(BrowserAutofillManagerVotingTest, NoBlurVoteOnSubmission) {}

// Test that the call is properly forwarded to its SingleFieldFormFillRouter.
TEST_F(BrowserAutofillManagerTest, OnSingleFieldSuggestionSelected) {}

// Test that we correctly fill an address form and update the used profile.
TEST_F(BrowserAutofillManagerTest, FillAddressForm_UpdateProfile) {}

// Tests that `ProfileTokenQuality` is correctly integrated into
// `AutofillProfile` and that on form submit, observations are collected.
TEST_F(BrowserAutofillManagerTest, FillAddressForm_CollectObservations) {}

class BrowserAutofillManagerPlusAddressTest
    : public BrowserAutofillManagerTest {};

// Ensure that plus address options aren't queried for non-email fields.
TEST_F(BrowserAutofillManagerPlusAddressTest, NoPlusAddressesWithNameFields) {}

// Tests that plus address suggestions are queried and shown for email fields
// when address suggestions are available. In this case, the option to manage
// plus addresses is not offered.
TEST_F(BrowserAutofillManagerPlusAddressTest,
       CreatePlusAddressSuggestionShownWithAddressSuggestions) {}

// Tests that plus address suggestions are queried and shown for email fields
// when no single field form suggestions are available. In this case, a
// ManagePlusAddress suggestion is also offered.
TEST_F(BrowserAutofillManagerPlusAddressTest,
       CreatePlusAddressSuggestionShown) {}

// Tests that single field form suggestions (IBANs in this case) are shown
// normally if plus address suggestions are not available for the field.
TEST_F(BrowserAutofillManagerPlusAddressTest,
       NoPlusAddressOnlyIBANsSuggestions) {}

// Tests that single field form suggestions (Merchant promo code in this case)
// are shown normally if plus address suggestions are not available for the
// field.
TEST_F(BrowserAutofillManagerPlusAddressTest,
       NoPlusAddressOnlyPromoCodesSuggestions) {}

// Tests that plus address suggestions are queried and shown for email fields
// when single field form suggestions are available. Tests also that plus
// address suggestions are prioritized over single field form fill suggestions.
TEST_F(BrowserAutofillManagerPlusAddressTest,
       CreatePlusAddressSuggestionShownWithSingleFieldFormFillSuggestions) {}

// Tests that a manage plus address suggestion is not added if there are no plus
// address suggestions.
TEST_F(BrowserAutofillManagerPlusAddressTest,
       NoStandaloneManagePlusAddressSuggestion) {}

// Tests that only Plus Address suggestions are shown when the trigger source is
// a manual fallback for plus addresses.
TEST_F(BrowserAutofillManagerPlusAddressTest, ManualFallbackPlusAddress) {}

// Test that plus address inputs are forced to !should_autocomplete
// for `SingleFieldFormFillRouter::OnWillSubmitForm()`.
TEST_F(BrowserAutofillManagerPlusAddressTest,
       DontSavePlusAddressInAutocompleteHistory) {}

}  // namespace autofill