#include "components/autofill/core/browser/address_suggestion_generator.h"
#include <optional>
#include <string>
#include <vector>
#include "base/memory/raw_ptr.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 "base/uuid.h"
#include "components/autofill/core/browser/address_data_manager.h"
#include "components/autofill/core/browser/autofill_granular_filling_utils.h"
#include "components/autofill/core/browser/autofill_test_utils.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/field_types.h"
#include "components/autofill/core/browser/geo/phone_number_i18n.h"
#include "components/autofill/core/browser/test_address_data_manager.h"
#include "components/autofill/core/browser/test_autofill_client.h"
#include "components/autofill/core/browser/test_personal_data_manager.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/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync/test/test_sync_service.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
namespace autofill {
namespace {
Field;
IsEmpty;
Matcher;
#if !BUILDFLAG(IS_IOS)
constexpr AutofillSuggestionTriggerSource kDefaultTriggerSource = …;
#endif
constexpr char kAddressesSuppressedHistogramName[] = …;
Matcher<Suggestion> EqualLabels(
const std::vector<std::vector<Suggestion::Text>>& suggestion_objects) { … }
Matcher<Suggestion> EqualLabels(
const std::vector<std::vector<std::u16string>>& labels) { … }
Matcher<Suggestion> EqualsFieldByFieldFillingSuggestion(
SuggestionType id,
const std::u16string& main_text,
FieldType field_by_field_filling_type_used,
const Suggestion::Payload& payload,
const std::vector<std::vector<Suggestion::Text>>& labels = { … }
#if !BUILDFLAG(IS_IOS)
Matcher<Suggestion> EqualsUndoAutofillSuggestion() { … }
#endif
Matcher<Suggestion> EqualsManageAddressesSuggestion() { … }
MATCHER(ContainsAddressFooterSuggestions, "") { … }
}
class AddressSuggestionGeneratorTest : public testing::Test { … };
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_UseSpecialCharactersInEmail) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_HideSubsets) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_SuggestionsLimit) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_ProfilesLimit) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_Ranking) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_NumberOfSuggestions) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_PhoneNumberDeduplication) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_SuppressDisusedProfilesOnEmptyField) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_SingleDedupe) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_MultipleDedupe) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_DedupeLimit) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_EmptyMatchingProfiles) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_kAccountPrecedence) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_GetMatchingProfile) { … }
TEST_F(AddressSuggestionGeneratorTest, GetProfilesToSuggest_NoMatchingProfile) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_EmptyProfilesInput) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_RemoveDisusedProfiles_FeatureDisabled) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_RemoveDisusedProfiles_FeatureEnabled) { … }
TEST_F(AddressSuggestionGeneratorTest, CreateSuggestionsFromProfiles) { … }
TEST_F(AddressSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_PhoneSubstring) { … }
TEST_F(AddressSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_PartialNameFieldHasFullNameMainText) { … }
class AutofillLabelSuggestionGeneratorTest
: public AddressSuggestionGeneratorTest,
public testing::WithParamInterface<FieldType> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(
AutofillLabelSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_FullFormFilling_SuggestionsHaveCorrectLabels) { … }
TEST_P(
AutofillLabelSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_FullFormFilling_SuggestionsNeedMoreLabelsForDifferentiation) { … }
TEST_P(
AutofillLabelSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_FullFormFilling_CountryIsChosenAsDifferentiatingLabel) { … }
class AutofillChildrenSuggestionGeneratorTest
: public AddressSuggestionGeneratorTest { … };
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_GroupFillingLabels_AddOnlyFillAddress) { … }
TEST_F(
AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_GroupFillingLabels_AddFillAddressAndDifferentiatingLabel) { … }
TEST_F(
AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_GroupFillingLabels_AddFillAddressAddressLine1AndDifferentiatingLabel) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_GroupFillingLabels_AddOnlyFillName) { … }
TEST_F(
AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_GroupFillingLabels_SingleFieldFillingHasNoLabels) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_FirstLevelChildrenSuggestions) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
IncognitoMode_EditAndDeleteSuggestionsAreNotAdded) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
FillEverythingFromAddressProfile_FullFormFilling_NotAdded) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
FillEverythingFromAddressProfile_FullFormFilling_AddedAtTheTop) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
FillEverythingFromAddressProfile_FieldByFieldFilling_Added) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
FillEverythingFromAddressProfile_FieldByFieldFilling_AddedAtTheTop) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
FillEverythingFromAddressProfile_GroupFilling_Added) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
FillEverythingFromAddressProfile_GroupFilling_AddedAtTheTop) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_SecondLevelChildrenSuggestions) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_FieldByFieldFilling) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_GroupFilling) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_FullFormFilling) { … }
TEST_F(
AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_LastTargetedFieldsContainOnlyEmail_FieldByField) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_LastTargetedFieldsAreNone_FieldByField) { … }
TEST_F(
AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_ChildrenSuggestionsPhoneField_International) { … }
TEST_F(
AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_ChildrenSuggestionsPhoneField_CountryCode) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_ChildrenSuggestionsPhoneField_Local) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_ChildrenSuggestionsEmailField) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_ChildrenSuggestionsAddressField) { … }
TEST_F(AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_ChildrenSuggestionsCompanyField) { … }
TEST_F(
AutofillChildrenSuggestionGeneratorTest,
CreateSuggestionsFromProfiles_ChildrenSuggestions_HouseNumberAndStreetNameCanBeNestedUnderDifferentAddressLines) { … }
class AutofillNonAddressFieldsSuggestionGeneratorTest
: public AutofillChildrenSuggestionGeneratorTest { … };
TEST_F(AutofillNonAddressFieldsSuggestionGeneratorTest,
AllProfilesGenerateSuggestions) { … }
TEST_F(AutofillNonAddressFieldsSuggestionGeneratorTest,
SuggestionsAreCorrectAndExpectedLabelsAndIconsAreCreated) { … }
TEST_F(AutofillNonAddressFieldsSuggestionGeneratorTest,
MainTextAndLabelsAreCorrect_Japanese) { … }
TEST_F(AutofillNonAddressFieldsSuggestionGeneratorTest,
MainTextAndLabelsAreCorrect_Arabic) { … }
TEST_F(AutofillNonAddressFieldsSuggestionGeneratorTest,
MainTextAndLabelsAreCorrect_Thai) { … }
TEST_F(AutofillNonAddressFieldsSuggestionGeneratorTest,
SuggestionHasCorrectChildren) { … }
TEST_F(AddressSuggestionGeneratorTest,
NoProfilesHaveValuesForClassifiedField_AddressManualFallback) { … }
TEST_F(AddressSuggestionGeneratorTest, GetSuggestionsForProfiles_Filtering) { … }
TEST_F(AddressSuggestionGeneratorTest,
GetProfilesToSuggest_TimestampFiltering) { … }
#if !BUILDFLAG(IS_IOS)
TEST_F(AddressSuggestionGeneratorTest, UndoAutofillOnAddressForm) { … }
#endif
TEST_F(AddressSuggestionGeneratorTest,
TestAddressSuggestion_AddressField_ReturnSuggestion) { … }
TEST_F(AddressSuggestionGeneratorTest,
TestAddressSuggestion_NonAddressField_DoNotReturnSuggestion) { … }
}