chromium/components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager_unittest.cc

// Copyright 2014 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/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) {}

// Sets the `host_form_signature` member of all fields contained in
// `form_structure` to the signature of the `form_structure`.
void SetCorrectFieldHostFormSignatures(FormStructure& form_structure) {}

// Puts all data elements within the response body together in a single
// DataElement and return the buffered content as a string. This ensure all
// the response body data is utilized.
std::string GetStringFromDataElements(
    const std::vector<network::DataElement>* data_elements) {}

// Gets the AutofillUploadRequest proto from the HTTP loader request payload.
// Will return false if failed to get the proto.
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 {};

}  // namespace

// This tests AutofillCrowdsourcingManager. AutofillCrowdsourcingManagerTest
// implements AutofillCrowdsourcingManager::Observer and creates an instance of
// AutofillCrowdsourcingManager. Then it records responses to different
// initiated requests, which are verified later. To mock network requests
// TestURLLoaderFactory is used, which creates SimpleURLLoaders that do not
// go over the wire, but allow calling back HTTP responses directly.
// The responses in test are out of order and verify: successful query request,
// successful upload request, failed upload request.
class AutofillCrowdsourcingManagerTest : public ::testing::Test {};

TEST_F(AutofillCrowdsourcingManagerTest, QueryAndUploadTest) {}

TEST_F(AutofillCrowdsourcingManagerTest, QueryAPITest) {}

TEST_F(AutofillCrowdsourcingManagerTest, QueryAPITestWhenTooLongUrl) {}

// Test whether uploading vote content to the API is done right. We only do some
// spot checks. No thorough testing is done here. Using the API does not add new
// upload logic.
//
// We expect the download manager to do the following things:
//   * Use the right API canonical URL when uploading.
//   * Serialize the upload proto content using the API upload request proto.
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> {};

}  // namespace

TEST_P(AutofillServerCommunicationTest, IsEnabled) {}

TEST_P(AutofillServerCommunicationTest, Query) {}

TEST_P(AutofillServerCommunicationTest, Upload) {}

// Note that we omit DEFAULT_URL from the test params. We don't actually want
// the tests to hit the production server.
INSTANTIATE_TEST_SUITE_P();

AutofillQueryTest;

TEST_P(AutofillQueryTest, CacheableResponse) {}

TEST_P(AutofillQueryTest, SendsExperiment) {}

TEST_P(AutofillQueryTest, ExpiredCacheInResponse) {}

TEST_P(AutofillQueryTest, Metadata) {}

// Note that we omit DEFAULT_URL from the test params. We don't actually want
// the tests to hit the production server. We also excluded DISABLED, since
// these tests exercise "enabled" functionality.
INSTANTIATE_TEST_SUITE_P();

AutofillUploadTest;

TEST_P(AutofillUploadTest, RichMetadata) {}

TEST_P(AutofillUploadTest, Throttling) {}

// Tests that votes are not throttled with
// `features::test::kAutofillUploadThrottling` disabled, but metadata is
// throttled regardless of the feature state.
TEST_P(AutofillUploadTest, SuccessfulSubmissionOnDisabledThrottling) {}

TEST_P(AutofillUploadTest, PeriodicReset) {}

TEST_P(AutofillUploadTest, ResetOnClearUploadHistory) {}

// Tests that password manager uploads will have metadata part of the upload
// throttled, but the vote part of the upload will be sent to the server.
TEST_P(AutofillUploadTest, ThrottleMetadataOnPasswordManagerUploads) {}

// Note that we omit DEFAULT_URL from the test params. We don't actually want
// the tests to hit the production server. We also excluded DISABLED, since
// these tests exercise "enabled" functionality.
INSTANTIATE_TEST_SUITE_P();

}  // namespace autofill