chromium/components/plus_addresses/plus_address_http_client_impl_unittest.cc

// Copyright 2023 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/plus_addresses/plus_address_http_client_impl.h"

#include <optional>
#include <string>

#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/strings/string_util.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "components/plus_addresses/features.h"
#include "components/plus_addresses/metrics/plus_address_metrics.h"
#include "components/plus_addresses/plus_address_http_client.h"
#include "components/plus_addresses/plus_address_http_client_impl_test_api.h"
#include "components/plus_addresses/plus_address_test_utils.h"
#include "components/plus_addresses/plus_address_types.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/access_token_info.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/signin/public/identity_manager/scope_set.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/http/http_status_code.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.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"

namespace plus_addresses {

namespace {

SizeIs;

constexpr char kServerBaseUrl[] =;
constexpr char kTestScope[] =;
constexpr char kEmailAddress[] =;

constexpr base::TimeDelta kLatency =;

constexpr char kPlusAddressOauthErrorHistogram[] =;

std::string LatencyHistogramFor(PlusAddressNetworkRequestType type) {}

std::string ResponseCodeHistogramFor(PlusAddressNetworkRequestType type) {}

std::string ResponseByteSizeHistogramFor(PlusAddressNetworkRequestType type) {}

}  // namespace

// Tests that use fake out the URL loading and issues requests to the enterprise
// provided server.
class PlusAddressHttpClientRequests : public ::testing::Test {};

// Ensures the request sent by Chrome matches what we intended.
TEST_F(PlusAddressHttpClientRequests, ReservePlusAddress_IssuesCorrectRequest) {}

// Tests that the reserve request contains the expected data when the refresh
// flag is set.
TEST_F(PlusAddressHttpClientRequests,
       ReservePlusAddress_IssuesCorrectRequestWithRefreshFlag) {}

// Ensures the request sent by Chrome matches what we intended.
TEST_F(PlusAddressHttpClientRequests, ConfirmPlusAddress_IssuesCorrectRequest) {}

// Tests the behavior of the PlusAddressCreationRequests (Reserve+Confirm) which
// have identical expectations outside of the method signature.
class PlusAddressCreationRequests
    : public PlusAddressHttpClientRequests,
      public testing::WithParamInterface<PlusAddressNetworkRequestType> {};

// Verifies ability to support making multiple requests at once.
// Note: Create() is not idempotent, but that is ignored for this test.
TEST_P(PlusAddressCreationRequests, HandlesConcurrentRequests) {}

TEST_P(PlusAddressCreationRequests, RequestsOauthToken) {}

TEST_P(PlusAddressCreationRequests, RunCallbackOnSuccess) {}

// Tests that calls to the `Reserve` and `Create` endpoints run the callback
// with an error if the network request experienced an error. Also checks that
// the error includes the HTTP response code.
TEST_P(PlusAddressCreationRequests, RunCallbackOnNetworkError) {}

TEST_P(PlusAddressCreationRequests, RunCallbackOnClientError) {}

TEST_P(PlusAddressCreationRequests, RunCallbackOnOauthError) {}
INSTANTIATE_TEST_SUITE_P();

TEST_F(PlusAddressHttpClientRequests,
       PreallocatePlusAddresses_IssuesCorrectRequest) {}

// Tests that a successful server response from the preallocation endpoint is
// received, parsed, and triggers the callback properly.
TEST_F(PlusAddressHttpClientRequests,
       PreallocatePlusAddresses_SuccessResponse) {}

// Tests that a malformed server response from the preallocation endpoint is
// received, parsed, and passes a parsing error to the callback.
TEST_F(PlusAddressHttpClientRequests, PreallocatePlusAddresses_ParsingError) {}

// Tests that a network error response from the preallocation endpoint is
// received and passed on to the callback.
TEST_F(PlusAddressHttpClientRequests, PreallocatePlusAddresses_NetworkError) {}

// Tests that resetting the http client while a pre-allocate request is ongoing
// results in a `kUserSignedOut` error.
TEST_F(PlusAddressHttpClientRequests, PreallocatePlusAddresses_SignoutError) {}

// Tests that calling reset cancels ongoing network requests and runs pending
// callbacks with a `PlusAddressRequestErrorType::kUserSignedOut`.
TEST_F(PlusAddressHttpClientRequests, ResetWhileWaitingForNetwork) {}

// Tests that calling reset cancels ongoing OAuth requests and runs pending
// callbacks with a `PlusAddressRequestErrorType::kUserSignedOut`.
TEST_F(PlusAddressHttpClientRequests, ResetWhileWaitingForOAuth) {}

TEST(PlusAddressHttpClient, ChecksUrlParamIsValidGurl) {}

TEST(PlusAddressHttpClient, RejectsNonUrlStrings) {}

class PlusAddressAuthToken : public ::testing::Test {};

TEST_F(PlusAddressAuthToken, RequestedBeforeSignin) {}

TEST_F(PlusAddressAuthToken, RequestedUserNeverSignsIn) {}

TEST_F(PlusAddressAuthToken, RequestedAfterExpiration) {}

TEST_F(PlusAddressAuthToken, AuthErrorWithMultipleAccounts) {}

TEST_F(PlusAddressAuthToken, RequestWorks_ManyCallers) {}

TEST_F(PlusAddressAuthToken, RequestFails_ManyCallers) {}

class PlusAddressHttpClientNullServerUrl : public PlusAddressHttpClientRequests {};

TEST_F(PlusAddressHttpClientNullServerUrl, ReservePlusAddress_SendsNoRequest) {}

TEST_F(PlusAddressHttpClientNullServerUrl, ConfirmPlusAddress_SendsNoRequest) {}

}  // namespace plus_addresses