| 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> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 enum { | 29 enum { |
| 30 // A private network error code used by the socket test utility classes. | 30 // A private network error code used by the socket test utility classes. |
| 31 // If the |result| member of a MockRead is | 31 // If the |result| member of a MockRead is |
| 32 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a | 32 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a |
| 33 // marker that indicates the peer will close the connection after the next | 33 // marker that indicates the peer will close the connection after the next |
| 34 // MockRead. The other members of that MockRead are ignored. | 34 // MockRead. The other members of that MockRead are ignored. |
| 35 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000, | 35 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 class BoundNetLog; |
| 38 class ClientSocket; | 39 class ClientSocket; |
| 39 class LoadLog; | |
| 40 class MockClientSocket; | 40 class MockClientSocket; |
| 41 class SSLClientSocket; | 41 class SSLClientSocket; |
| 42 | 42 |
| 43 struct MockConnect { | 43 struct MockConnect { |
| 44 // Asynchronous connection success. | 44 // Asynchronous connection success. |
| 45 MockConnect() : async(true), result(OK) { } | 45 MockConnect() : async(true), result(OK) { } |
| 46 MockConnect(bool a, int r) : async(a), result(r) { } | 46 MockConnect(bool a, int r) : async(a), result(r) { } |
| 47 | 47 |
| 48 bool async; | 48 bool async; |
| 49 int result; | 49 int result; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Store pointers to handed out sockets in case the test wants to get them. | 265 // Store pointers to handed out sockets in case the test wants to get them. |
| 266 std::vector<MockTCPClientSocket*> tcp_client_sockets_; | 266 std::vector<MockTCPClientSocket*> tcp_client_sockets_; |
| 267 std::vector<MockSSLClientSocket*> ssl_client_sockets_; | 267 std::vector<MockSSLClientSocket*> ssl_client_sockets_; |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 class MockClientSocket : public net::SSLClientSocket { | 270 class MockClientSocket : public net::SSLClientSocket { |
| 271 public: | 271 public: |
| 272 MockClientSocket(); | 272 MockClientSocket(); |
| 273 | 273 |
| 274 // ClientSocket methods: | 274 // ClientSocket methods: |
| 275 virtual int Connect(net::CompletionCallback* callback, LoadLog* load_log) = 0; | 275 virtual int Connect(net::CompletionCallback* callback, |
| 276 const BoundNetLog& net_log) = 0; |
| 276 virtual void Disconnect(); | 277 virtual void Disconnect(); |
| 277 virtual bool IsConnected() const; | 278 virtual bool IsConnected() const; |
| 278 virtual bool IsConnectedAndIdle() const; | 279 virtual bool IsConnectedAndIdle() const; |
| 279 virtual int GetPeerAddress(AddressList* address) const; | 280 virtual int GetPeerAddress(AddressList* address) const; |
| 280 | 281 |
| 281 // SSLClientSocket methods: | 282 // SSLClientSocket methods: |
| 282 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | 283 virtual void GetSSLInfo(net::SSLInfo* ssl_info); |
| 283 virtual void GetSSLCertRequestInfo( | 284 virtual void GetSSLCertRequestInfo( |
| 284 net::SSLCertRequestInfo* cert_request_info); | 285 net::SSLCertRequestInfo* cert_request_info); |
| 285 virtual NextProtoStatus GetNextProto(std::string* proto); | 286 virtual NextProtoStatus GetNextProto(std::string* proto); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 309 bool connected_; | 310 bool connected_; |
| 310 }; | 311 }; |
| 311 | 312 |
| 312 class MockTCPClientSocket : public MockClientSocket { | 313 class MockTCPClientSocket : public MockClientSocket { |
| 313 public: | 314 public: |
| 314 MockTCPClientSocket(const net::AddressList& addresses, | 315 MockTCPClientSocket(const net::AddressList& addresses, |
| 315 net::SocketDataProvider* socket); | 316 net::SocketDataProvider* socket); |
| 316 | 317 |
| 317 // ClientSocket methods: | 318 // ClientSocket methods: |
| 318 virtual int Connect(net::CompletionCallback* callback, | 319 virtual int Connect(net::CompletionCallback* callback, |
| 319 LoadLog* load_log); | 320 const BoundNetLog& net_log); |
| 320 virtual bool IsConnected() const; | 321 virtual bool IsConnected() const; |
| 321 virtual bool IsConnectedAndIdle() const { return IsConnected(); } | 322 virtual bool IsConnectedAndIdle() const { return IsConnected(); } |
| 322 | 323 |
| 323 // Socket methods: | 324 // Socket methods: |
| 324 virtual int Read(net::IOBuffer* buf, int buf_len, | 325 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 325 net::CompletionCallback* callback); | 326 net::CompletionCallback* callback); |
| 326 virtual int Write(net::IOBuffer* buf, int buf_len, | 327 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 327 net::CompletionCallback* callback); | 328 net::CompletionCallback* callback); |
| 328 | 329 |
| 329 virtual void OnReadComplete(const MockRead& data); | 330 virtual void OnReadComplete(const MockRead& data); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 355 public: | 356 public: |
| 356 MockSSLClientSocket( | 357 MockSSLClientSocket( |
| 357 net::ClientSocket* transport_socket, | 358 net::ClientSocket* transport_socket, |
| 358 const std::string& hostname, | 359 const std::string& hostname, |
| 359 const net::SSLConfig& ssl_config, | 360 const net::SSLConfig& ssl_config, |
| 360 net::SSLSocketDataProvider* socket); | 361 net::SSLSocketDataProvider* socket); |
| 361 ~MockSSLClientSocket(); | 362 ~MockSSLClientSocket(); |
| 362 | 363 |
| 363 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | 364 virtual void GetSSLInfo(net::SSLInfo* ssl_info); |
| 364 | 365 |
| 365 virtual int Connect(net::CompletionCallback* callback, LoadLog* load_log); | 366 virtual int Connect(net::CompletionCallback* callback, |
| 367 const BoundNetLog& net_log); |
| 366 virtual void Disconnect(); | 368 virtual void Disconnect(); |
| 367 | 369 |
| 368 // Socket methods: | 370 // Socket methods: |
| 369 virtual int Read(net::IOBuffer* buf, int buf_len, | 371 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 370 net::CompletionCallback* callback); | 372 net::CompletionCallback* callback); |
| 371 virtual int Write(net::IOBuffer* buf, int buf_len, | 373 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 372 net::CompletionCallback* callback); | 374 net::CompletionCallback* callback); |
| 373 | 375 |
| 374 // This MockSocket does not implement the manual async IO feature. | 376 // This MockSocket does not implement the manual async IO feature. |
| 375 virtual void OnReadComplete(const MockRead& data) { NOTIMPLEMENTED(); } | 377 virtual void OnReadComplete(const MockRead& data) { NOTIMPLEMENTED(); } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 void ReleaseAllConnections(KeepAlive keep_alive); | 452 void ReleaseAllConnections(KeepAlive keep_alive); |
| 451 | 453 |
| 452 ScopedVector<TestSocketRequest> requests_; | 454 ScopedVector<TestSocketRequest> requests_; |
| 453 std::vector<TestSocketRequest*> request_order_; | 455 std::vector<TestSocketRequest*> request_order_; |
| 454 size_t completion_count_; | 456 size_t completion_count_; |
| 455 }; | 457 }; |
| 456 | 458 |
| 457 } // namespace net | 459 } // namespace net |
| 458 | 460 |
| 459 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 461 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |