blob: b934d4dbea85343d8045e8541b1a94a816ba9ba7 [file] [log] [blame]
jameswestafe2f80f2016-11-12 00:25:451// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROMECAST_NET_FAKE_STREAM_SOCKET_H_
6#define CHROMECAST_NET_FAKE_STREAM_SOCKET_H_
7
8#include <stdint.h>
9
10#include <memory>
11
12#include "base/macros.h"
13#include "net/base/ip_endpoint.h"
14#include "net/log/net_log_with_source.h"
15#include "net/socket/stream_socket.h"
16
17namespace chromecast {
18class SocketBuffer;
19
20// Fake StreamSocket that communicates with another instance in memory.
21class FakeStreamSocket : public net::StreamSocket {
22 public:
23 explicit FakeStreamSocket(const net::IPEndPoint& local_address);
24 ~FakeStreamSocket() override;
25
26 // Sets the peer for this socket.
27 void SetPeer(FakeStreamSocket* peer);
28
29 // net::StreamSocket implementation:
30 int Read(net::IOBuffer* buf,
31 int buf_len,
32 const net::CompletionCallback& callback) override;
33 int Write(net::IOBuffer* buf,
34 int buf_len,
35 const net::CompletionCallback& callback) override;
36 int SetReceiveBufferSize(int32_t size) override;
37 int SetSendBufferSize(int32_t size) override;
38 int Connect(const net::CompletionCallback& callback) override;
39 void Disconnect() override;
40 bool IsConnected() const override;
41 bool IsConnectedAndIdle() const override;
42 int GetPeerAddress(net::IPEndPoint* address) const override;
43 int GetLocalAddress(net::IPEndPoint* address) const override;
44 const net::NetLogWithSource& NetLog() const override;
45 void SetSubresourceSpeculation() override;
46 void SetOmniboxSpeculation() override;
47 bool WasEverUsed() const override;
tfarina2846404c2016-12-25 14:31:3748 bool WasAlpnNegotiated() const override;
jameswestafe2f80f2016-11-12 00:25:4549 net::NextProto GetNegotiatedProtocol() const override;
50 bool GetSSLInfo(net::SSLInfo* ssl_info) override;
51 void GetConnectionAttempts(net::ConnectionAttempts* out) const override;
52 void ClearConnectionAttempts() override;
53 void AddConnectionAttempts(const net::ConnectionAttempts& attempts) override;
54 int64_t GetTotalReceivedBytes() const override;
55
56 private:
57 const net::IPEndPoint local_address_;
58 const std::unique_ptr<SocketBuffer> buffer_;
59 FakeStreamSocket* peer_;
60 net::NetLogWithSource net_log_;
61
62 DISALLOW_COPY_AND_ASSIGN(FakeStreamSocket);
63};
64
65} // namespace chromecast
66
67#endif // CHROMECAST_NET_FAKE_STREAM_SOCKET_H_