OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 NET_SOCKET_SOCKET_TEST_UTIL_H_ | 5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ |
6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ | 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/scoped_ptr.h" | |
14 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
15 #include "net/base/io_buffer.h" | |
16 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
17 #include "net/base/ssl_config_service.h" | 15 #include "net/base/ssl_config_service.h" |
18 #include "net/socket/client_socket_factory.h" | 16 #include "net/socket/client_socket_factory.h" |
19 #include "net/socket/ssl_client_socket.h" | |
20 | 17 |
21 namespace net { | 18 namespace net { |
22 | 19 |
23 class ClientSocket; | 20 class ClientSocket; |
24 class SSLClientSocket; | 21 class SSLClientSocket; |
25 | 22 |
26 struct MockConnect { | 23 struct MockConnect { |
27 // Asynchronous connection success. | 24 // Asynchronous connection success. |
28 MockConnect() : async(true), result(OK) { } | 25 MockConnect() : async(true), result(OK) { } |
29 MockConnect(bool a, int r) : async(a), result(r) { } | 26 MockConnect(bool a, int r) : async(a), result(r) { } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 virtual SSLClientSocket* CreateSSLClientSocket( | 193 virtual SSLClientSocket* CreateSSLClientSocket( |
197 ClientSocket* transport_socket, | 194 ClientSocket* transport_socket, |
198 const std::string& hostname, | 195 const std::string& hostname, |
199 const SSLConfig& ssl_config); | 196 const SSLConfig& ssl_config); |
200 | 197 |
201 private: | 198 private: |
202 MockSocketArray<MockSocket> mock_sockets_; | 199 MockSocketArray<MockSocket> mock_sockets_; |
203 MockSocketArray<MockSSLSocket> mock_ssl_sockets_; | 200 MockSocketArray<MockSSLSocket> mock_ssl_sockets_; |
204 }; | 201 }; |
205 | 202 |
206 class MockClientSocket : public net::SSLClientSocket { | |
207 public: | |
208 MockClientSocket(); | |
209 | |
210 // ClientSocket methods: | |
211 virtual int Connect(net::CompletionCallback* callback) = 0; | |
212 | |
213 // SSLClientSocket methods: | |
214 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | |
215 virtual void GetSSLCertRequestInfo( | |
216 net::SSLCertRequestInfo* cert_request_info); | |
217 virtual void Disconnect(); | |
218 virtual bool IsConnected() const; | |
219 virtual bool IsConnectedAndIdle() const; | |
220 | |
221 // Socket methods: | |
222 virtual int Read(net::IOBuffer* buf, int buf_len, | |
223 net::CompletionCallback* callback) = 0; | |
224 virtual int Write(net::IOBuffer* buf, int buf_len, | |
225 net::CompletionCallback* callback) = 0; | |
226 | |
227 #if defined(OS_LINUX) | |
228 virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen); | |
229 #endif | |
230 | |
231 protected: | |
232 void RunCallbackAsync(net::CompletionCallback* callback, int result); | |
233 void RunCallback(int result); | |
234 | |
235 ScopedRunnableMethodFactory<MockClientSocket> method_factory_; | |
236 net::CompletionCallback* callback_; | |
237 bool connected_; | |
238 }; | |
239 | |
240 class MockTCPClientSocket : public MockClientSocket { | |
241 public: | |
242 MockTCPClientSocket(const net::AddressList& addresses, | |
243 net::MockSocket* socket); | |
244 | |
245 // ClientSocket methods: | |
246 virtual int Connect(net::CompletionCallback* callback); | |
247 | |
248 // Socket methods: | |
249 virtual int Read(net::IOBuffer* buf, int buf_len, | |
250 net::CompletionCallback* callback); | |
251 virtual int Write(net::IOBuffer* buf, int buf_len, | |
252 net::CompletionCallback* callback); | |
253 | |
254 private: | |
255 net::MockSocket* data_; | |
256 int read_offset_; | |
257 net::MockRead read_data_; | |
258 bool need_read_data_; | |
259 }; | |
260 | |
261 class MockSSLClientSocket : public MockClientSocket { | |
262 public: | |
263 MockSSLClientSocket( | |
264 net::ClientSocket* transport_socket, | |
265 const std::string& hostname, | |
266 const net::SSLConfig& ssl_config, | |
267 net::MockSSLSocket* socket); | |
268 ~MockSSLClientSocket(); | |
269 | |
270 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | |
271 | |
272 virtual int Connect(net::CompletionCallback* callback); | |
273 virtual void Disconnect(); | |
274 | |
275 // Socket methods: | |
276 virtual int Read(net::IOBuffer* buf, int buf_len, | |
277 net::CompletionCallback* callback); | |
278 virtual int Write(net::IOBuffer* buf, int buf_len, | |
279 net::CompletionCallback* callback); | |
280 | |
281 private: | |
282 class ConnectCallback; | |
283 | |
284 scoped_ptr<ClientSocket> transport_; | |
285 net::MockSSLSocket* data_; | |
286 }; | |
287 | |
288 } // namespace net | 203 } // namespace net |
289 | 204 |
290 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 205 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
OLD | NEW |