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

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
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/socket/socket.h" 14 #include "net/socket/socket.h"
14 #include "net/socket/stream_socket.h" 15 #include "net/socket/stream_socket.h"
15 #include "remoting/protocol/session.h" 16 #include "remoting/protocol/session.h"
16 17
17 class MessageLoop; 18 class MessageLoop;
18 19
19 namespace remoting { 20 namespace remoting {
20 namespace protocol { 21 namespace protocol {
21 22
22 extern const char kTestJid[]; 23 extern const char kTestJid[];
23 24
24 // FakeSocket implement net::Socket interface for FakeConnection. All data 25 // FakeSocket implement net::Socket interface for FakeConnection. All data
25 // written to FakeSocket is stored in a buffer returned by written_data(). 26 // written to FakeSocket is stored in a buffer returned by written_data().
26 // Read() reads data from another buffer that can be set with AppendInputData(). 27 // Read() reads data from another buffer that can be set with AppendInputData().
27 // Pending reads are supported, so if there is a pending read AppendInputData() 28 // Pending reads are supported, so if there is a pending read AppendInputData()
28 // calls the read callback. 29 // calls the read callback.
29 class FakeSocket : public net::StreamSocket { 30 class FakeSocket : public net::StreamSocket {
Wez 2011/12/09 23:42:33 nit: It strikes me that FakeSocket should probably
Sergey Ulanov 2011/12/12 22:52:00 That would make test code more complicated because
30 public: 31 public:
31 FakeSocket(); 32 FakeSocket();
32 virtual ~FakeSocket(); 33 virtual ~FakeSocket();
33 34
34 const std::string& written_data() const { return written_data_; } 35 const std::string& written_data() const { return written_data_; }
35 36
36 void AppendInputData(const char* data, int data_size); 37 void AppendInputData(const std::vector<char>& data);
38 void Connect(FakeSocket* peer_socket);
Wez 2011/12/09 23:42:33 Isn't Connect() overloading net::StreamSocket::Con
Sergey Ulanov 2011/12/12 22:52:00 Renamed to SetPeer(), though I disagree that overl
Wez 2011/12/13 00:12:38 True, but the semantics of this Connect() method a
37 int input_pos() const { return input_pos_; } 39 int input_pos() const { return input_pos_; }
38 bool read_pending() const { return read_pending_; } 40 bool read_pending() const { return read_pending_; }
39 41
40 // net::Socket interface. 42 // net::Socket interface.
41 virtual int Read(net::IOBuffer* buf, int buf_len, 43 virtual int Read(net::IOBuffer* buf, int buf_len,
42 net::OldCompletionCallback* callback) OVERRIDE; 44 net::OldCompletionCallback* callback) OVERRIDE;
43 virtual int Write(net::IOBuffer* buf, int buf_len, 45 virtual int Write(net::IOBuffer* buf, int buf_len,
44 net::OldCompletionCallback* callback) OVERRIDE; 46 net::OldCompletionCallback* callback) OVERRIDE;
45 47
46 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; 48 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
(...skipping 12 matching lines...) Expand all
59 virtual bool WasEverUsed() const OVERRIDE; 61 virtual bool WasEverUsed() const OVERRIDE;
60 virtual bool UsingTCPFastOpen() const OVERRIDE; 62 virtual bool UsingTCPFastOpen() const OVERRIDE;
61 virtual int64 NumBytesRead() const OVERRIDE; 63 virtual int64 NumBytesRead() const OVERRIDE;
62 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; 64 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
63 65
64 private: 66 private:
65 bool read_pending_; 67 bool read_pending_;
66 scoped_refptr<net::IOBuffer> read_buffer_; 68 scoped_refptr<net::IOBuffer> read_buffer_;
67 int read_buffer_size_; 69 int read_buffer_size_;
68 net::OldCompletionCallback* read_callback_; 70 net::OldCompletionCallback* read_callback_;
71 base::WeakPtr<FakeSocket> peer_socket_;
69 72
70 std::string written_data_; 73 std::string written_data_;
71 std::string input_data_; 74 std::string input_data_;
72 int input_pos_; 75 int input_pos_;
73 76
74 net::BoundNetLog net_log_; 77 net::BoundNetLog net_log_;
75 78
76 MessageLoop* message_loop_; 79 MessageLoop* message_loop_;
80 base::WeakPtrFactory<FakeSocket> weak_factory_;
77 81
78 DISALLOW_COPY_AND_ASSIGN(FakeSocket); 82 DISALLOW_COPY_AND_ASSIGN(FakeSocket);
79 }; 83 };
80 84
81 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written 85 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written
82 // packets are stored separetely in written_packets(). AppendInputPacket() adds 86 // packets are stored separetely in written_packets(). AppendInputPacket() adds
83 // one packet that will be returned by Read(). 87 // one packet that will be returned by Read().
84 class FakeUdpSocket : public net::Socket { 88 class FakeUdpSocket : public net::Socket {
85 public: 89 public:
86 FakeUdpSocket(); 90 FakeUdpSocket();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 Session::Error error_; 176 Session::Error error_;
173 bool closed_; 177 bool closed_;
174 178
175 DISALLOW_COPY_AND_ASSIGN(FakeSession); 179 DISALLOW_COPY_AND_ASSIGN(FakeSession);
176 }; 180 };
177 181
178 } // namespace protocol 182 } // namespace protocol
179 } // namespace remoting 183 } // namespace remoting
180 184
181 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ 185 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698