OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "net/socket/socket.h" | 12 #include "net/socket/socket.h" |
13 #include "remoting/protocol/session.h" | 13 #include "remoting/protocol/session.h" |
14 | 14 |
15 namespace remoting { | 15 namespace remoting { |
16 namespace protocol { | 16 namespace protocol { |
17 | 17 |
18 extern const char kTestJid[]; | 18 extern const char kTestJid[]; |
19 | 19 |
20 // FakeSocket implement net::Socket interface for FakeConnection. All data | 20 // FakeSocket implement net::Socket interface for FakeConnection. All data |
21 // written to FakeSocket is stored in a buffer returned by written_data(). | 21 // written to FakeSocket is stored in a buffer returned by written_data(). |
22 // Read() reads data from another buffer that can be set with AppendInputData(). | 22 // Read() reads data from another buffer that can be set with AppendInputData(). |
23 // Pending reads are supported, so if there is a pending read AppendInputData() | 23 // Pending reads are supported, so if there is a pending read AppendInputData() |
24 // calls the read callback. | 24 // calls the read callback. |
25 class FakeSocket : public net::Socket { | 25 class FakeSocket : public net::Socket { |
26 public: | 26 public: |
27 FakeSocket(); | 27 FakeSocket(); |
28 virtual ~FakeSocket(); | 28 virtual ~FakeSocket(); |
29 | 29 |
30 const std::string& written_data() { return written_data_; } | 30 const std::string& written_data() const { return written_data_; } |
31 | 31 |
32 void AppendInputData(char* data, int data_size); | 32 void AppendInputData(const char* data, int data_size); |
33 int input_pos() { return input_pos_; } | 33 int input_pos() const { return input_pos_; } |
| 34 bool read_pending() const { return read_pending_; } |
34 | 35 |
35 // net::Socket interface. | 36 // net::Socket interface. |
36 virtual int Read(net::IOBuffer* buf, int buf_len, | 37 virtual int Read(net::IOBuffer* buf, int buf_len, |
37 net::CompletionCallback* callback); | 38 net::CompletionCallback* callback); |
38 virtual int Write(net::IOBuffer* buf, int buf_len, | 39 virtual int Write(net::IOBuffer* buf, int buf_len, |
39 net::CompletionCallback* callback); | 40 net::CompletionCallback* callback); |
40 | 41 |
41 virtual bool SetReceiveBufferSize(int32 size); | 42 virtual bool SetReceiveBufferSize(int32 size); |
42 virtual bool SetSendBufferSize(int32 size); | 43 virtual bool SetSendBufferSize(int32 size); |
43 | 44 |
44 private: | 45 private: |
45 bool read_pending_; | 46 bool read_pending_; |
46 scoped_refptr<net::IOBuffer> read_buffer_; | 47 scoped_refptr<net::IOBuffer> read_buffer_; |
47 int read_buffer_size_; | 48 int read_buffer_size_; |
48 net::CompletionCallback* read_callback_; | 49 net::CompletionCallback* read_callback_; |
49 | 50 |
50 std::string written_data_; | 51 std::string written_data_; |
51 std::string input_data_; | 52 std::string input_data_; |
52 int input_pos_; | 53 int input_pos_; |
53 }; | 54 }; |
54 | 55 |
55 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written | 56 // FakeUdpSocket is similar to FakeSocket but behaves as UDP socket. All written |
56 // packets are stored separetely in written_packets(). AppendInputPacket() adds | 57 // packets are stored separetely in written_packets(). AppendInputPacket() adds |
57 // one packet that will be returned by Read(). | 58 // one packet that will be returned by Read(). |
58 class FakeUdpSocket : public net::Socket { | 59 class FakeUdpSocket : public net::Socket { |
59 public: | 60 public: |
60 FakeUdpSocket(); | 61 FakeUdpSocket(); |
61 virtual ~FakeUdpSocket(); | 62 virtual ~FakeUdpSocket(); |
62 | 63 |
63 const std::vector<std::string>& written_packets() { | 64 const std::vector<std::string>& written_packets() const { |
64 return written_packets_; | 65 return written_packets_; |
65 } | 66 } |
66 | 67 |
67 void AppendInputPacket(char* data, int data_size); | 68 void AppendInputPacket(const char* data, int data_size); |
68 int input_pos() { return input_pos_; } | 69 int input_pos() const { return input_pos_; } |
69 | 70 |
70 // net::Socket interface. | 71 // net::Socket interface. |
71 virtual int Read(net::IOBuffer* buf, int buf_len, | 72 virtual int Read(net::IOBuffer* buf, int buf_len, |
72 net::CompletionCallback* callback); | 73 net::CompletionCallback* callback); |
73 virtual int Write(net::IOBuffer* buf, int buf_len, | 74 virtual int Write(net::IOBuffer* buf, int buf_len, |
74 net::CompletionCallback* callback); | 75 net::CompletionCallback* callback); |
75 | 76 |
76 virtual bool SetReceiveBufferSize(int32 size); | 77 virtual bool SetReceiveBufferSize(int32 size); |
77 virtual bool SetSendBufferSize(int32 size); | 78 virtual bool SetSendBufferSize(int32 size); |
78 | 79 |
(...skipping 14 matching lines...) Expand all Loading... |
93 public: | 94 public: |
94 FakeSession(); | 95 FakeSession(); |
95 virtual ~FakeSession(); | 96 virtual ~FakeSession(); |
96 | 97 |
97 StateChangeCallback* state_change_callback() { return callback_.get(); } | 98 StateChangeCallback* state_change_callback() { return callback_.get(); } |
98 | 99 |
99 void set_message_loop(MessageLoop* message_loop) { | 100 void set_message_loop(MessageLoop* message_loop) { |
100 message_loop_ = message_loop; | 101 message_loop_ = message_loop; |
101 } | 102 } |
102 | 103 |
103 bool is_closed() { return closed_; } | 104 bool is_closed() const { return closed_; } |
104 | 105 |
105 virtual void SetStateChangeCallback(StateChangeCallback* callback); | 106 virtual void SetStateChangeCallback(StateChangeCallback* callback); |
106 | 107 |
107 virtual FakeSocket* control_channel(); | 108 virtual FakeSocket* control_channel(); |
108 virtual FakeSocket* event_channel(); | 109 virtual FakeSocket* event_channel(); |
109 virtual FakeSocket* video_channel(); | 110 virtual FakeSocket* video_channel(); |
110 | 111 |
111 virtual FakeUdpSocket* video_rtp_channel(); | 112 virtual FakeUdpSocket* video_rtp_channel(); |
112 virtual FakeUdpSocket* video_rtcp_channel(); | 113 virtual FakeUdpSocket* video_rtcp_channel(); |
113 | 114 |
(...skipping 26 matching lines...) Expand all Loading... |
140 std::string receiver_token_; | 141 std::string receiver_token_; |
141 | 142 |
142 std::string jid_; | 143 std::string jid_; |
143 bool closed_; | 144 bool closed_; |
144 }; | 145 }; |
145 | 146 |
146 } // namespace protocol | 147 } // namespace protocol |
147 } // namespace remoting | 148 } // namespace remoting |
148 | 149 |
149 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ | 150 #endif // REMOTING_PROTOCOL_FAKE_SESSION_H_ |
OLD | NEW |