chromium/remoting/base/protobuf_http_client_unittest.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/base/protobuf_http_client.h"

#include <memory>

#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "remoting/base/protobuf_http_client_messages.pb.h"
#include "remoting/base/protobuf_http_client_test_messages.pb.h"
#include "remoting/base/protobuf_http_request.h"
#include "remoting/base/protobuf_http_request_config.h"
#include "remoting/base/protobuf_http_status.h"
#include "remoting/base/protobuf_http_stream_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_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace remoting {

namespace {

Status;
StreamBody;
using protobufhttpclienttest::EchoRequest;
using protobufhttpclienttest::EchoResponse;

RunOnceCallback;
_;
InSequence;

using EchoResponseCallback =
    ProtobufHttpRequest::ResponseCallback<EchoResponse>;
using MockEchoResponseCallback = base::MockCallback<EchoResponseCallback>;
using MockEchoMessageCallback = base::MockCallback<
    ProtobufHttpStreamRequest::MessageCallback<EchoResponse>>;
MockStreamClosedCallback;

constexpr char kTestServerEndpoint[] =;
constexpr char kTestRpcPath[] =;
constexpr char kTestFullUrl[] =;
constexpr char kRequestText[] =;
constexpr char kResponseText[] =;
constexpr char kAuthorizationHeaderKey[] =;
constexpr char kFakeAccessToken[] =;
constexpr char kFakeAccessTokenHeaderValue[] =;

MATCHER_P(HasErrorCode, error_code, "") {}

MATCHER_P(EqualsToStatus, expected_status, "") {}

MATCHER(IsDefaultResponseText, "") {}

MATCHER_P(IsResponseText, response_text, "") {}

MATCHER(IsNullResponse, "") {}

class MockOAuthTokenGetter : public OAuthTokenGetter {};

EchoResponseCallback DoNothingResponse() {}

std::unique_ptr<ProtobufHttpRequestConfig> CreateDefaultRequestConfig() {}

std::unique_ptr<ProtobufHttpRequest> CreateDefaultTestRequest() {}

std::unique_ptr<ProtobufHttpStreamRequest> CreateDefaultTestStreamRequest() {}

std::string CreateSerializedEchoResponse(
    const std::string& text = kResponseText) {}

std::string CreateSerializedStreamBodyWithText(
    const std::string& text = kResponseText) {}

std::string CreateSerializedStreamBodyWithStatusCode(
    ProtobufHttpStatus::Code status_code) {}

}  // namespace

class ProtobufHttpClientTest : public testing::Test {};

void ProtobufHttpClientTest::ExpectCallWithTokenSuccess() {}

void ProtobufHttpClientTest::ExpectCallWithTokenAuthError() {}

void ProtobufHttpClientTest::ExpectCallWithTokenNetworkError() {}

// Unary request tests.

TEST_F(ProtobufHttpClientTest, SendRequestAndDecodeResponse) {}

TEST_F(ProtobufHttpClientTest,
       SendUnauthenticatedRequest_TokenGetterNotCalled) {}

TEST_F(ProtobufHttpClientTest,
       FailedToFetchAuthToken_RejectsWithUnauthorizedError) {}

TEST_F(ProtobufHttpClientTest,
       FailedToFetchAuthToken_RejectsWithUnavailableError) {}

TEST_F(ProtobufHttpClientTest, FailedToParseResponse_GetsInvalidResponseError) {}

TEST_F(ProtobufHttpClientTest, ServerRespondsWithErrorStatusMessage) {}

TEST_F(ProtobufHttpClientTest, ServerRespondsWithHttpErrorCode) {}

TEST_F(ProtobufHttpClientTest,
       CancelPendingRequestsBeforeTokenCallback_CallbackNotCalled) {}

TEST_F(ProtobufHttpClientTest,
       CancelPendingRequestsAfterTokenCallback_CallbackNotCalled) {}

TEST_F(ProtobufHttpClientTest, RequestTimeout_ReturnsDeadlineExceeded) {}

TEST_F(ProtobufHttpClientTest, DeletesRequestHolderWhenRequestIsCanceled) {}

TEST_F(ProtobufHttpClientTest, DeletesRequestHolderAfterResponseIsReceived) {}

// Stream request tests.

TEST_F(ProtobufHttpClientTest,
       StreamRequestFailedToFetchAuthToken_RejectsWithUnauthorizedError) {}

TEST_F(ProtobufHttpClientTest,
       StreamRequestFailedToFetchAuthToken_RejectsWithUnavailableError) {}

TEST_F(ProtobufHttpClientTest, StartStreamRequestAndDecodeMessages) {}

TEST_F(ProtobufHttpClientTest, InvalidStreamData_Ignored) {}

TEST_F(ProtobufHttpClientTest, SendHttpStatusOnly_StreamClosesWithHttpStatus) {}

TEST_F(ProtobufHttpClientTest, SendStreamStatusAndHttpStatus_StreamStatusWins) {}

TEST_F(ProtobufHttpClientTest, StreamReadyTimeout) {}

}  // namespace remoting