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

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: merge 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
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 SetPeer()
33 // method, e.g.:
34 // a->SetPeer(b);
35 // b->SetPeer(a);
Wez 2011/12/13 00:12:38 nit: You could actually have SetPeer() set the pee
Sergey Ulanov 2011/12/13 02:31:55 Done.
36 // After this all data written to |a| can be read from |b| and vica
37 // versa. Two connected sockets |a| and |b| must be created and used on the
38 // same thread.
39 //
30 class FakeSocket : public net::StreamSocket { 40 class FakeSocket : public net::StreamSocket {
31 public: 41 public:
32 FakeSocket(); 42 FakeSocket();
33 virtual ~FakeSocket(); 43 virtual ~FakeSocket();
34 44
35 const std::string& written_data() const { return written_data_; } 45 const std::string& written_data() const { return written_data_; }
36 46
37 void AppendInputData(const char* data, int data_size); 47 void AppendInputData(const std::vector<char>& data);
48 void SetPeer(FakeSocket* peer_socket);
38 int input_pos() const { return input_pos_; } 49 int input_pos() const { return input_pos_; }
39 bool read_pending() const { return read_pending_; } 50 bool read_pending() const { return read_pending_; }
40 51
41 // net::Socket implementation. 52 // net::Socket implementation.
Wez 2011/12/13 00:12:38 nit: I prefer "interface" to "implementation"; the
Sergey Ulanov 2011/12/13 02:31:55 Done.
42 virtual int Read(net::IOBuffer* buf, int buf_len, 53 virtual int Read(net::IOBuffer* buf, int buf_len,
43 const net::CompletionCallback& callback) OVERRIDE; 54 const net::CompletionCallback& callback) OVERRIDE;
44 virtual int Write(net::IOBuffer* buf, int buf_len, 55 virtual int Write(net::IOBuffer* buf, int buf_len,
45 const net::CompletionCallback& callback) OVERRIDE; 56 const net::CompletionCallback& callback) OVERRIDE;
46 57
47 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; 58 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
48 virtual bool SetSendBufferSize(int32 size) OVERRIDE; 59 virtual bool SetSendBufferSize(int32 size) OVERRIDE;
49 60
50 // net::StreamSocket implementation. 61 // net::StreamSocket implementation.
51 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; 62 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE;
52 virtual void Disconnect() OVERRIDE; 63 virtual void Disconnect() OVERRIDE;
53 virtual bool IsConnected() const OVERRIDE; 64 virtual bool IsConnected() const OVERRIDE;
54 virtual bool IsConnectedAndIdle() const OVERRIDE; 65 virtual bool IsConnectedAndIdle() const OVERRIDE;
55 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE; 66 virtual int GetPeerAddress(net::AddressList* address) const OVERRIDE;
56 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE; 67 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE;
57 virtual const net::BoundNetLog& NetLog() const OVERRIDE; 68 virtual const net::BoundNetLog& NetLog() const OVERRIDE;
58 virtual void SetSubresourceSpeculation() OVERRIDE; 69 virtual void SetSubresourceSpeculation() OVERRIDE;
59 virtual void SetOmniboxSpeculation() OVERRIDE; 70 virtual void SetOmniboxSpeculation() OVERRIDE;
60 virtual bool WasEverUsed() const OVERRIDE; 71 virtual bool WasEverUsed() const OVERRIDE;
61 virtual bool UsingTCPFastOpen() const OVERRIDE; 72 virtual bool UsingTCPFastOpen() const OVERRIDE;
62 virtual int64 NumBytesRead() const OVERRIDE; 73 virtual int64 NumBytesRead() const OVERRIDE;
63 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; 74 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
64 75
65 private: 76 private:
66 bool read_pending_; 77 bool read_pending_;
67 scoped_refptr<net::IOBuffer> read_buffer_; 78 scoped_refptr<net::IOBuffer> read_buffer_;
68 int read_buffer_size_; 79 int read_buffer_size_;
69 net::CompletionCallback read_callback_; 80 net::CompletionCallback read_callback_;
81 base::WeakPtr<FakeSocket> peer_socket_;
70 82
71 std::string written_data_; 83 std::string written_data_;
72 std::string input_data_; 84 std::string input_data_;
73 int input_pos_; 85 int input_pos_;
74 86
75 net::BoundNetLog net_log_; 87 net::BoundNetLog net_log_;
76 88
77 MessageLoop* message_loop_; 89 MessageLoop* message_loop_;
90 base::WeakPtrFactory<FakeSocket> weak_factory_;
78 91
79 DISALLOW_COPY_AND_ASSIGN(FakeSocket); 92 DISALLOW_COPY_AND_ASSIGN(FakeSocket);
80 }; 93 };
81 94
82 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written 95 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written
83 // packets are stored separetely in written_packets(). AppendInputPacket() adds 96 // packets are stored separetely in written_packets(). AppendInputPacket() adds
84 // one packet that will be returned by Read(). 97 // one packet that will be returned by Read().
85 class FakeUdpSocket : public net::Socket { 98 class FakeUdpSocket : public net::Socket {
86 public: 99 public:
87 FakeUdpSocket(); 100 FakeUdpSocket();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 Session::Error error_; 186 Session::Error error_;
174 bool closed_; 187 bool closed_;
175 188
176 DISALLOW_COPY_AND_ASSIGN(FakeSession); 189 DISALLOW_COPY_AND_ASSIGN(FakeSession);
177 }; 190 };
178 191
179 } // namespace protocol 192 } // namespace protocol
180 } // namespace remoting 193 } // namespace remoting
181 194
182 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ 195 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698