#include "components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager.h"
#include <list>
#include <memory>
#include <string_view>
#include <utility>
#include <vector>
#include "base/base64url.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_command_line.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_timeouts.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/autofill_type.h"
#include "components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_encoding.h"
#include "components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager_test_api.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/proto/server.pb.h"
#include "components/autofill/core/browser/randomized_encoder.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/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_switches.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/mojom/autofill_types.mojom-shared.h"
#include "components/autofill/core/common/signatures.h"
#include "components/prefs/pref_service.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "components/variations/variations_ids_provider.h"
#include "google_apis/common/api_key_request_test_util.h"
#include "net/http/http_status_code.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/network/public/cpp/data_element.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.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/third_party/mozilla/url_parse.h"
namespace autofill {
namespace {
UTF8ToUTF16;
SubmissionSource;
BasicHttpResponse;
EmbeddedTestServer;
HttpRequest;
HttpResponse;
CreateTestFormField;
ElementsAre;
IsEmpty;
SizeIs;
constexpr int METHOD_GET = …;
constexpr int METHOD_POST = …;
constexpr int CACHE_MISS = …;
constexpr int CACHE_HIT = …;
std::vector<raw_ptr<FormStructure, VectorExperimental>> ToRawPointerVector(
const std::vector<std::unique_ptr<FormStructure>>& list) { … }
void SetCorrectFieldHostFormSignatures(FormStructure& form_structure) { … }
std::string GetStringFromDataElements(
const std::vector<network::DataElement>* data_elements) { … }
bool GetUploadRequestProtoFromRequest(
network::TestURLLoaderFactory::PendingRequest* loader_request,
AutofillUploadRequest* upload_request) { … }
bool GetAutofillPageResourceQueryRequestFromRequest(
network::TestURLLoaderFactory::PendingRequest* loader_request,
AutofillPageResourceQueryRequest* query_request) { … }
bool DeserializeAutofillPageQueryRequest(std::string_view serialized_content,
AutofillPageQueryRequest* request) { … }
class AutofillCrowdsourcingManagerWithCustomPayloadSize
: public AutofillCrowdsourcingManager { … };
}
class AutofillCrowdsourcingManagerTest : public ::testing::Test { … };
TEST_F(AutofillCrowdsourcingManagerTest, QueryAndUploadTest) { … }
TEST_F(AutofillCrowdsourcingManagerTest, QueryAPITest) { … }
TEST_F(AutofillCrowdsourcingManagerTest, QueryAPITestWhenTooLongUrl) { … }
TEST_F(AutofillCrowdsourcingManagerTest, UploadToAPITest) { … }
TEST_F(AutofillCrowdsourcingManagerTest, BackoffLogic_Query) { … }
TEST_F(AutofillCrowdsourcingManagerTest, BackoffLogic_Upload) { … }
TEST_F(AutofillCrowdsourcingManagerTest, RetryLimit_Query) { … }
TEST_F(AutofillCrowdsourcingManagerTest, RetryLimit_Upload) { … }
TEST_F(AutofillCrowdsourcingManagerTest, QueryTooManyFieldsTest) { … }
TEST_F(AutofillCrowdsourcingManagerTest, QueryNotTooManyFieldsTest) { … }
TEST_F(AutofillCrowdsourcingManagerTest, CacheQueryTest) { … }
namespace {
enum ServerCommunicationMode { … };
class AutofillServerCommunicationTest
: public testing::TestWithParam<ServerCommunicationMode> { … };
}
TEST_P(AutofillServerCommunicationTest, IsEnabled) { … }
TEST_P(AutofillServerCommunicationTest, Query) { … }
TEST_P(AutofillServerCommunicationTest, Upload) { … }
INSTANTIATE_TEST_SUITE_P(…);
AutofillQueryTest;
TEST_P(AutofillQueryTest, CacheableResponse) { … }
TEST_P(AutofillQueryTest, SendsExperiment) { … }
TEST_P(AutofillQueryTest, ExpiredCacheInResponse) { … }
TEST_P(AutofillQueryTest, Metadata) { … }
INSTANTIATE_TEST_SUITE_P(…);
AutofillUploadTest;
TEST_P(AutofillUploadTest, RichMetadata) { … }
TEST_P(AutofillUploadTest, Throttling) { … }
TEST_P(AutofillUploadTest, SuccessfulSubmissionOnDisabledThrottling) { … }
TEST_P(AutofillUploadTest, PeriodicReset) { … }
TEST_P(AutofillUploadTest, ResetOnClearUploadHistory) { … }
TEST_P(AutofillUploadTest, ThrottleMetadataOnPasswordManagerUploads) { … }
INSTANTIATE_TEST_SUITE_P(…);
}