blob: 6499b57a396afb58961554b50a9e325cbe3d6308 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMECAST_NET_MOCK_STREAM_SOCKET_H_
#define CHROMECAST_NET_MOCK_STREAM_SOCKET_H_
#include <stdint.h>
#include "base/callback_helpers.h"
#include "base/macros.h"
#include "net/base/completion_callback.h"
#include "net/log/net_log_with_source.h"
#include "net/socket/stream_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace chromecast {
// Google Mock implementation of StreamSocket.
class MockStreamSocket : public net::StreamSocket {
public:
MockStreamSocket();
~MockStreamSocket() override;
int Read(net::IOBuffer* buffer,
int bytes,
net::CompletionOnceCallback callback) override {
return Read(buffer, bytes,
base::AdaptCallbackForRepeating(std::move(callback)));
}
int Write(net::IOBuffer* buffer,
int bytes,
net::CompletionOnceCallback callback,
const net::NetworkTrafficAnnotationTag& tag) override {
return Write(buffer, bytes,
base::AdaptCallbackForRepeating(std::move(callback)), tag);
}
int Connect(net::CompletionOnceCallback callback) override {
return Connect(base::AdaptCallbackForRepeating(std::move(callback)));
}
MOCK_METHOD3(Read, int(net::IOBuffer*, int, const net::CompletionCallback&));
MOCK_METHOD4(Write,
int(net::IOBuffer*,
int,
const net::CompletionCallback&,
const net::NetworkTrafficAnnotationTag&));
MOCK_METHOD1(SetReceiveBufferSize, int(int32_t));
MOCK_METHOD1(SetSendBufferSize, int(int32_t));
MOCK_METHOD1(Connect, int(const net::CompletionCallback&));
MOCK_METHOD0(Disconnect, void());
MOCK_CONST_METHOD0(IsConnected, bool());
MOCK_CONST_METHOD0(IsConnectedAndIdle, bool());
MOCK_CONST_METHOD1(GetPeerAddress, int(net::IPEndPoint*));
MOCK_CONST_METHOD1(GetLocalAddress, int(net::IPEndPoint*));
MOCK_CONST_METHOD0(NetLog, const net::NetLogWithSource&());
MOCK_CONST_METHOD0(WasEverUsed, bool());
MOCK_CONST_METHOD0(UsingTCPFastOpen, bool());
MOCK_CONST_METHOD0(WasAlpnNegotiated, bool());
MOCK_CONST_METHOD0(GetNegotiatedProtocol, net::NextProto());
MOCK_METHOD1(GetSSLInfo, bool(net::SSLInfo*));
MOCK_CONST_METHOD1(GetConnectionAttempts, void(net::ConnectionAttempts*));
MOCK_METHOD0(ClearConnectionAttempts, void());
MOCK_METHOD1(AddConnectionAttempts, void(const net::ConnectionAttempts&));
MOCK_CONST_METHOD0(GetTotalReceivedBytes, int64_t());
MOCK_METHOD1(ApplySocketTag, void(const net::SocketTag&));
private:
net::NetLogWithSource net_log_;
DISALLOW_COPY_AND_ASSIGN(MockStreamSocket);
};
} // namespace chromecast
#endif // CHROMECAST_NET_MOCK_STREAM_SOCKET_H_