#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) { … }
}
class PlusAddressHttpClientRequests : public ::testing::Test { … };
TEST_F(PlusAddressHttpClientRequests, ReservePlusAddress_IssuesCorrectRequest) { … }
TEST_F(PlusAddressHttpClientRequests,
ReservePlusAddress_IssuesCorrectRequestWithRefreshFlag) { … }
TEST_F(PlusAddressHttpClientRequests, ConfirmPlusAddress_IssuesCorrectRequest) { … }
class PlusAddressCreationRequests
: public PlusAddressHttpClientRequests,
public testing::WithParamInterface<PlusAddressNetworkRequestType> { … };
TEST_P(PlusAddressCreationRequests, HandlesConcurrentRequests) { … }
TEST_P(PlusAddressCreationRequests, RequestsOauthToken) { … }
TEST_P(PlusAddressCreationRequests, RunCallbackOnSuccess) { … }
TEST_P(PlusAddressCreationRequests, RunCallbackOnNetworkError) { … }
TEST_P(PlusAddressCreationRequests, RunCallbackOnClientError) { … }
TEST_P(PlusAddressCreationRequests, RunCallbackOnOauthError) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(PlusAddressHttpClientRequests,
PreallocatePlusAddresses_IssuesCorrectRequest) { … }
TEST_F(PlusAddressHttpClientRequests,
PreallocatePlusAddresses_SuccessResponse) { … }
TEST_F(PlusAddressHttpClientRequests, PreallocatePlusAddresses_ParsingError) { … }
TEST_F(PlusAddressHttpClientRequests, PreallocatePlusAddresses_NetworkError) { … }
TEST_F(PlusAddressHttpClientRequests, PreallocatePlusAddresses_SignoutError) { … }
TEST_F(PlusAddressHttpClientRequests, ResetWhileWaitingForNetwork) { … }
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) { … }
}