Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: remoting/protocol/fake_session.h

Issue 8743023: Separate Authenticator and Session unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/fake_authenticator.cc ('k') | remoting/protocol/fake_session.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef REMOTING_PROTOCOL_FAKE_SESSION_H_ 5 #ifndef REMOTING_PROTOCOL_FAKE_SESSION_H_
6 #define REMOTING_PROTOCOL_FAKE_SESSION_H_ 6 #define REMOTING_PROTOCOL_FAKE_SESSION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
13 #include "net/base/completion_callback.h" 14 #include "net/base/completion_callback.h"
14 #include "net/socket/socket.h" 15 #include "net/socket/socket.h"
15 #include "net/socket/stream_socket.h" 16 #include "net/socket/stream_socket.h"
16 #include "remoting/protocol/session.h" 17 #include "remoting/protocol/session.h"
17 18
18 class MessageLoop; 19 class MessageLoop;
19 20
20 namespace remoting { 21 namespace remoting {
21 namespace protocol { 22 namespace protocol {
22 23
23 extern const char kTestJid[]; 24 extern const char kTestJid[];
24 25
25 // FakeSocket implement net::Socket interface for FakeConnection. All data 26 // FakeSocket implement net::Socket interface for FakeConnection. All data
26 // written to FakeSocket is stored in a buffer returned by written_data(). 27 // written to FakeSocket is stored in a buffer returned by written_data().
27 // Read() reads data from another buffer that can be set with AppendInputData(). 28 // Read() reads data from another buffer that can be set with AppendInputData().
28 // Pending reads are supported, so if there is a pending read AppendInputData() 29 // Pending reads are supported, so if there is a pending read AppendInputData()
29 // calls the read callback. 30 // calls the read callback.
31 //
32 // Two fake sockets can be connected to each other using the
33 // PairWith() method, e.g.: a->PairWith(b). After this all data
34 // written to |a| can be read from |b| and vica versa. Two connected
35 // sockets |a| and |b| must be created and used on the same thread.
30 class FakeSocket : public net::StreamSocket { 36 class FakeSocket : public net::StreamSocket {
31 public: 37 public:
32 FakeSocket(); 38 FakeSocket();
33 virtual ~FakeSocket(); 39 virtual ~FakeSocket();
34 40
35 const std::string& written_data() const { return written_data_; } 41 const std::string& written_data() const { return written_data_; }
36 42
37 void AppendInputData(const char* data, int data_size); 43 void AppendInputData(const std::vector<char>& data);
44 void PairWith(FakeSocket* peer_socket);
38 int input_pos() const { return input_pos_; } 45 int input_pos() const { return input_pos_; }
39 bool read_pending() const { return read_pending_; } 46 bool read_pending() const { return read_pending_; }
40 47
41 // net::Socket implementation. 48 // net::Socket implementation.
42 virtual int Read(net::IOBuffer* buf, int buf_len, 49 virtual int Read(net::IOBuffer* buf, int buf_len,
43 const net::CompletionCallback& callback) OVERRIDE; 50 const net::CompletionCallback& callback) OVERRIDE;
44 virtual int Write(net::IOBuffer* buf, int buf_len, 51 virtual int Write(net::IOBuffer* buf, int buf_len,
45 const net::CompletionCallback& callback) OVERRIDE; 52 const net::CompletionCallback& callback) OVERRIDE;
46 53
47 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; 54 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
48 virtual bool SetSendBufferSize(int32 size) OVERRIDE; 55 virtual bool SetSendBufferSize(int32 size) OVERRIDE;
49 56
50 // net::StreamSocket implementation. 57 // net::StreamSocket interface.
51 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; 58 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
52 virtual void Disconnect() OVERRIDE; 59 virtual void Disconnect() OVERRIDE;
53 virtual bool IsConnected() const OVERRIDE; 60 virtual bool IsConnected() const OVERRIDE;
54 virtual bool IsConnectedAndIdle() const OVERRIDE; 61 virtual bool IsConnectedAndIdle() const OVERRIDE;
55 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; 62 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE;
56 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; 63 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE;
57 virtual const net::BoundNetLog& NetLog() const OVERRIDE; 64 virtual const net::BoundNetLog& NetLog() const OVERRIDE;
58 virtual void SetSubresourceSpeculation() OVERRIDE; 65 virtual void SetSubresourceSpeculation() OVERRIDE;
59 virtual void SetOmniboxSpeculation() OVERRIDE; 66 virtual void SetOmniboxSpeculation() OVERRIDE;
60 virtual bool WasEverUsed() const OVERRIDE; 67 virtual bool WasEverUsed() const OVERRIDE;
61 virtual bool UsingTCPFastOpen() const OVERRIDE; 68 virtual bool UsingTCPFastOpen() const OVERRIDE;
62 virtual int64 NumBytesRead() const OVERRIDE; 69 virtual int64 NumBytesRead() const OVERRIDE;
63 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; 70 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
64 71
65 private: 72 private:
66 bool read_pending_; 73 bool read_pending_;
67 scoped_refptr<net::IOBuffer> read_buffer_; 74 scoped_refptr<net::IOBuffer> read_buffer_;
68 int read_buffer_size_; 75 int read_buffer_size_;
69 net::CompletionCallback read_callback_; 76 net::CompletionCallback read_callback_;
77 base::WeakPtr<FakeSocket> peer_socket_;
70 78
71 std::string written_data_; 79 std::string written_data_;
72 std::string input_data_; 80 std::string input_data_;
73 int input_pos_; 81 int input_pos_;
74 82
75 net::BoundNetLog net_log_; 83 net::BoundNetLog net_log_;
76 84
77 MessageLoop* message_loop_; 85 MessageLoop* message_loop_;
86 base::WeakPtrFactory<FakeSocket> weak_factory_;
78 87
79 DISALLOW_COPY_AND_ASSIGN(FakeSocket); 88 DISALLOW_COPY_AND_ASSIGN(FakeSocket);
80 }; 89 };
81 90
82 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written 91 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written
83 // packets are stored separetely in written_packets(). AppendInputPacket() adds 92 // packets are stored separetely in written_packets(). AppendInputPacket() adds
84 // one packet that will be returned by Read(). 93 // one packet that will be returned by Read().
85 class FakeUdpSocket : public net::Socket { 94 class FakeUdpSocket : public net::Socket {
86 public: 95 public:
87 FakeUdpSocket(); 96 FakeUdpSocket();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 Session::Error error_; 182 Session::Error error_;
174 bool closed_; 183 bool closed_;
175 184
176 DISALLOW_COPY_AND_ASSIGN(FakeSession); 185 DISALLOW_COPY_AND_ASSIGN(FakeSession);
177 }; 186 };
178 187
179 } // namespace protocol 188 } // namespace protocol
180 } // namespace remoting 189 } // namespace remoting
181 190
182 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ 191 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_
OLDNEW
« no previous file with comments | « remoting/protocol/fake_authenticator.cc ('k') | remoting/protocol/fake_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698