| 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 <deque> | 8 #include <deque> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 15 #include "base/scoped_vector.h" | 15 #include "base/scoped_vector.h" |
| 16 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
| 17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 #include "net/base/ssl_config_service.h" | 19 #include "net/base/ssl_config_service.h" |
| 20 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 21 #include "net/socket/client_socket_factory.h" | 21 #include "net/socket/client_socket_factory.h" |
| 22 #include "net/socket/client_socket_handle.h" | 22 #include "net/socket/client_socket_handle.h" |
| 23 #include "net/socket/ssl_client_socket.h" | 23 #include "net/socket/ssl_client_socket.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 class ClientSocket; | 28 class ClientSocket; |
| 29 class LoadLog; |
| 29 class SSLClientSocket; | 30 class SSLClientSocket; |
| 30 | 31 |
| 31 struct MockConnect { | 32 struct MockConnect { |
| 32 // Asynchronous connection success. | 33 // Asynchronous connection success. |
| 33 MockConnect() : async(true), result(OK) { } | 34 MockConnect() : async(true), result(OK) { } |
| 34 MockConnect(bool a, int r) : async(a), result(r) { } | 35 MockConnect(bool a, int r) : async(a), result(r) { } |
| 35 | 36 |
| 36 bool async; | 37 bool async; |
| 37 int result; | 38 int result; |
| 38 }; | 39 }; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // Store pointers to handed out sockets in case the test wants to get them. | 226 // Store pointers to handed out sockets in case the test wants to get them. |
| 226 std::vector<MockTCPClientSocket*> tcp_client_sockets_; | 227 std::vector<MockTCPClientSocket*> tcp_client_sockets_; |
| 227 std::vector<MockSSLClientSocket*> ssl_client_sockets_; | 228 std::vector<MockSSLClientSocket*> ssl_client_sockets_; |
| 228 }; | 229 }; |
| 229 | 230 |
| 230 class MockClientSocket : public net::SSLClientSocket { | 231 class MockClientSocket : public net::SSLClientSocket { |
| 231 public: | 232 public: |
| 232 MockClientSocket(); | 233 MockClientSocket(); |
| 233 | 234 |
| 234 // ClientSocket methods: | 235 // ClientSocket methods: |
| 235 virtual int Connect(net::CompletionCallback* callback) = 0; | 236 virtual int Connect(net::CompletionCallback* callback, LoadLog* load_log) = 0; |
| 236 | 237 |
| 237 // SSLClientSocket methods: | 238 // SSLClientSocket methods: |
| 238 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | 239 virtual void GetSSLInfo(net::SSLInfo* ssl_info); |
| 239 virtual void GetSSLCertRequestInfo( | 240 virtual void GetSSLCertRequestInfo( |
| 240 net::SSLCertRequestInfo* cert_request_info); | 241 net::SSLCertRequestInfo* cert_request_info); |
| 241 virtual void Disconnect(); | 242 virtual void Disconnect(); |
| 242 virtual bool IsConnected() const; | 243 virtual bool IsConnected() const; |
| 243 virtual bool IsConnectedAndIdle() const; | 244 virtual bool IsConnectedAndIdle() const; |
| 244 | 245 |
| 245 // Socket methods: | 246 // Socket methods: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 261 ScopedRunnableMethodFactory<MockClientSocket> method_factory_; | 262 ScopedRunnableMethodFactory<MockClientSocket> method_factory_; |
| 262 bool connected_; | 263 bool connected_; |
| 263 }; | 264 }; |
| 264 | 265 |
| 265 class MockTCPClientSocket : public MockClientSocket { | 266 class MockTCPClientSocket : public MockClientSocket { |
| 266 public: | 267 public: |
| 267 MockTCPClientSocket(const net::AddressList& addresses, | 268 MockTCPClientSocket(const net::AddressList& addresses, |
| 268 net::MockSocket* socket); | 269 net::MockSocket* socket); |
| 269 | 270 |
| 270 // ClientSocket methods: | 271 // ClientSocket methods: |
| 271 virtual int Connect(net::CompletionCallback* callback); | 272 virtual int Connect(net::CompletionCallback* callback, |
| 273 LoadLog* load_log); |
| 272 | 274 |
| 273 // Socket methods: | 275 // Socket methods: |
| 274 virtual int Read(net::IOBuffer* buf, int buf_len, | 276 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 275 net::CompletionCallback* callback); | 277 net::CompletionCallback* callback); |
| 276 virtual int Write(net::IOBuffer* buf, int buf_len, | 278 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 277 net::CompletionCallback* callback); | 279 net::CompletionCallback* callback); |
| 278 | 280 |
| 279 net::AddressList addresses() const { return addresses_; } | 281 net::AddressList addresses() const { return addresses_; } |
| 280 | 282 |
| 281 private: | 283 private: |
| 282 net::AddressList addresses_; | 284 net::AddressList addresses_; |
| 283 | 285 |
| 284 net::MockSocket* data_; | 286 net::MockSocket* data_; |
| 285 int read_offset_; | 287 int read_offset_; |
| 286 net::MockRead read_data_; | 288 net::MockRead read_data_; |
| 287 bool need_read_data_; | 289 bool need_read_data_; |
| 288 }; | 290 }; |
| 289 | 291 |
| 290 class MockSSLClientSocket : public MockClientSocket { | 292 class MockSSLClientSocket : public MockClientSocket { |
| 291 public: | 293 public: |
| 292 MockSSLClientSocket( | 294 MockSSLClientSocket( |
| 293 net::ClientSocket* transport_socket, | 295 net::ClientSocket* transport_socket, |
| 294 const std::string& hostname, | 296 const std::string& hostname, |
| 295 const net::SSLConfig& ssl_config, | 297 const net::SSLConfig& ssl_config, |
| 296 net::MockSSLSocket* socket); | 298 net::MockSSLSocket* socket); |
| 297 ~MockSSLClientSocket(); | 299 ~MockSSLClientSocket(); |
| 298 | 300 |
| 299 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | 301 virtual void GetSSLInfo(net::SSLInfo* ssl_info); |
| 300 | 302 |
| 301 virtual int Connect(net::CompletionCallback* callback); | 303 virtual int Connect(net::CompletionCallback* callback, LoadLog* load_log); |
| 302 virtual void Disconnect(); | 304 virtual void Disconnect(); |
| 303 | 305 |
| 304 // Socket methods: | 306 // Socket methods: |
| 305 virtual int Read(net::IOBuffer* buf, int buf_len, | 307 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 306 net::CompletionCallback* callback); | 308 net::CompletionCallback* callback); |
| 307 virtual int Write(net::IOBuffer* buf, int buf_len, | 309 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 308 net::CompletionCallback* callback); | 310 net::CompletionCallback* callback); |
| 309 | 311 |
| 310 private: | 312 private: |
| 311 class ConnectCallback; | 313 class ConnectCallback; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 void ReleaseAllConnections(KeepAlive keep_alive); | 385 void ReleaseAllConnections(KeepAlive keep_alive); |
| 384 | 386 |
| 385 ScopedVector<TestSocketRequest> requests_; | 387 ScopedVector<TestSocketRequest> requests_; |
| 386 std::vector<TestSocketRequest*> request_order_; | 388 std::vector<TestSocketRequest*> request_order_; |
| 387 size_t completion_count_; | 389 size_t completion_count_; |
| 388 }; | 390 }; |
| 389 | 391 |
| 390 } // namespace net | 392 } // namespace net |
| 391 | 393 |
| 392 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 394 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |