#include "components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_encoding.h"
#include <algorithm>
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include "base/base64.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 "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/form_field_parser.h"
#include "components/autofill/core/browser/proto/api_v1.pb.h"
#include "components/autofill/core/browser/randomized_encoder.h"
#include "components/autofill/core/common/autofill_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/autofill/core/common/unique_ids.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "components/version_info/version_info.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/re2/src/re2/re2.h"
#include "url/gurl.h"
namespace autofill {
namespace {
SubmissionIndicatorEvent;
SubmissionSource;
AddFieldPredictionsToForm;
AddFieldPredictionToForm;
CreateFieldPrediction;
CreateTestFormField;
ASCIIToUTF16;
AllOf;
AnyOf;
Each;
ElementsAre;
IsEmpty;
Matcher;
Not;
Pointee;
Property;
Truly;
GetProductNameAndVersionForUserAgent;
FieldPrediction;
struct ManualOverride { … };
template <typename T>
auto SerializesSameAs(const T& expected) { … }
template <typename... Matchers>
auto ElementsSerializeSameAs(Matchers... element_matchers) { … }
template <typename... Matchers>
auto UnorderedElementsSerializeSameAs(Matchers... element_matchers) { … }
Matcher<FieldPrediction> EqualsPrediction(const FieldPrediction& prediction) { … }
Matcher<FieldPrediction> EqualsPrediction(FieldType type) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
Matcher<FieldPrediction> EqualsPrediction(FieldType type,
FieldPrediction::Source source) { … }
#endif
std::string SerializeAndEncode(const AutofillQueryResponse& response) { … }
void AddFieldOverrideToForm(
autofill::FormFieldData field_data,
FieldType field_type,
::autofill::AutofillQueryResponse_FormSuggestion* form_suggestion) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
std::string CreateManualOverridePrediction(
const std::vector<ManualOverride>& overrides) { … }
#endif
}
class AutofillCrowdsourcingEncoding : public testing::Test { … };
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequest_SubmissionIndicatorEvents_Match) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequest) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequestWithAdditionalPasswordFormSignature) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequestWithPropertiesMask) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequest_ObservedSubmissionFalse) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequest_WithLabels) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequest_EmailFieldContentMatched) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequest_WithSubForms) { … }
TEST_F(AutofillCrowdsourcingEncoding, CheckDataPresence) { … }
TEST_F(AutofillCrowdsourcingEncoding, CheckMultipleTypes) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequest_PasswordsRevealed) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequest_IsFormTag) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequest_RichMetadata) { … }
TEST_F(AutofillCrowdsourcingEncoding, Metadata_OnlySendFullUrlWithUserConsent) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequest_WithSingleUsernameVoteType) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequest_WithSingleUsernameData) { … }
TEST_F(AutofillCrowdsourcingEncoding, CreateForPasswordManagerUpload) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeUploadRequest_MilestoneSet) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequest_SetsInitialValueChanged) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeUploadRequest_SkipFieldsFilledWithFallback) { … }
TEST_F(AutofillCrowdsourcingEncoding, EncodeAutofillPageQueryRequest) { … }
TEST_F(AutofillCrowdsourcingEncoding, SkipFieldTest) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeAutofillPageQueryRequest_WithLabels) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeAutofillPageQueryRequest_WithLongLabels) { … }
TEST_F(AutofillCrowdsourcingEncoding,
EncodeAutofillPageQueryRequest_MissingNames) { … }
TEST_F(AutofillCrowdsourcingEncoding, AllowBigForms) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseQueryResponse_ServerPredictionIsOverride) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseQueryResponse_HeuristicsOverrideSpanishLastNameTypes) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseQueryResponse_HeuristicsOverrideStreetNameAndHouseNumberTypes) { … }
TEST_F(AutofillCrowdsourcingEncoding, ParseQueryResponse_TooManyTypes) { … }
TEST_F(AutofillCrowdsourcingEncoding, ParseQueryResponse_UnknownType) { … }
TEST_F(
AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponse_PrecedenceRulesBetweenMainFrameAndIframe) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseQueryResponse_MergeAutofillAndPasswordsPredictions) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponse_FallbackToHostFormSignature) { … }
TEST_F(AutofillCrowdsourcingEncoding, ParseServerPredictionsQueryResponse) { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
TEST_F(AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseWithManualOverrides) { … }
TEST_F(
AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseWithManualOverridesAndNoServerPredictions) { … }
TEST_F(
AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseWithManualOverridesAndPassthroughInLastPosition) { … }
TEST_F(
AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseWithManualOverridesAndPassthroughInMiddlePosition) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseOverridesAlternativeFormSignature) { … }
TEST_F(
AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseServerOverridesAlternativeFormSignature) { … }
TEST_F(
AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseReplaceServerOverrideWithManualOverride) { … }
#endif
TEST_F(AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseWhenCannotParseProtoFromString) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseServerPredictionsQueryResponseWhenPayloadNotBase64) { … }
TEST_F(AutofillCrowdsourcingEncoding, ParseQueryResponse_AuthorDefinedTypes) { … }
TEST_F(AutofillCrowdsourcingEncoding,
NoServerData_AutocompleteOff_FlagDisabled_NoOverwrite) { … }
TEST_F(AutofillCrowdsourcingEncoding, NoServerDataCCFields_CVC_NoOverwrite) { … }
TEST_F(AutofillCrowdsourcingEncoding, WithServerDataCCFields_CVC_NoOverwrite) { … }
TEST_F(AutofillCrowdsourcingEncoding, ParseQueryResponse_RankEqualSignatures) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ParseQueryResponse_EqualSignaturesFewerPredictions) { … }
TEST_F(AutofillCrowdsourcingEncoding,
ExperimentalServerPredictionsAreSeparate) { … }
}