| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // You can use ResetNextMockIndexes to reset that next entry index for all mock | 238 // You can use ResetNextMockIndexes to reset that next entry index for all mock |
| 239 // socket types. | 239 // socket types. |
| 240 class MockClientSocketFactory : public ClientSocketFactory { | 240 class MockClientSocketFactory : public ClientSocketFactory { |
| 241 public: | 241 public: |
| 242 void AddSocketDataProvider(SocketDataProvider* socket); | 242 void AddSocketDataProvider(SocketDataProvider* socket); |
| 243 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); | 243 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); |
| 244 void ResetNextMockIndexes(); | 244 void ResetNextMockIndexes(); |
| 245 | 245 |
| 246 // Return |index|-th MockTCPClientSocket (starting from 0) that the factory | 246 // Return |index|-th MockTCPClientSocket (starting from 0) that the factory |
| 247 // created. | 247 // created. |
| 248 MockTCPClientSocket* GetMockTCPClientSocket(int index) const; | 248 MockTCPClientSocket* GetMockTCPClientSocket(size_t index) const; |
| 249 | 249 |
| 250 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory | 250 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory |
| 251 // created. | 251 // created. |
| 252 MockSSLClientSocket* GetMockSSLClientSocket(int index) const; | 252 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; |
| 253 | 253 |
| 254 // ClientSocketFactory | 254 // ClientSocketFactory |
| 255 virtual ClientSocket* CreateTCPClientSocket(const AddressList& addresses); | 255 virtual ClientSocket* CreateTCPClientSocket(const AddressList& addresses); |
| 256 virtual SSLClientSocket* CreateSSLClientSocket( | 256 virtual SSLClientSocket* CreateSSLClientSocket( |
| 257 ClientSocket* transport_socket, | 257 ClientSocket* transport_socket, |
| 258 const std::string& hostname, | 258 const std::string& hostname, |
| 259 const SSLConfig& ssl_config); | 259 const SSLConfig& ssl_config); |
| 260 | 260 |
| 261 private: | 261 private: |
| 262 SocketDataProviderArray<SocketDataProvider> mock_data_; | 262 SocketDataProviderArray<SocketDataProvider> mock_data_; |
| 263 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; | 263 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; |
| 264 | 264 |
| 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, LoadLog* load_log) = 0; |
| 276 virtual void Disconnect(); | 276 virtual void Disconnect(); |
| 277 virtual bool IsConnected() const; | 277 virtual bool IsConnected() const; |
| 278 virtual bool IsConnectedAndIdle() const; | 278 virtual bool IsConnectedAndIdle() const; |
| 279 virtual int GetPeerName(struct sockaddr* name, socklen_t* namelen); | 279 virtual int GetPeerAddress(AddressList* address) const; |
| 280 | 280 |
| 281 // SSLClientSocket methods: | 281 // SSLClientSocket methods: |
| 282 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | 282 virtual void GetSSLInfo(net::SSLInfo* ssl_info); |
| 283 virtual void GetSSLCertRequestInfo( | 283 virtual void GetSSLCertRequestInfo( |
| 284 net::SSLCertRequestInfo* cert_request_info); | 284 net::SSLCertRequestInfo* cert_request_info); |
| 285 virtual NextProtoStatus GetNextProto(std::string* proto); | 285 virtual NextProtoStatus GetNextProto(std::string* proto); |
| 286 | 286 |
| 287 // Socket methods: | 287 // Socket methods: |
| 288 virtual int Read(net::IOBuffer* buf, int buf_len, | 288 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 289 net::CompletionCallback* callback) = 0; | 289 net::CompletionCallback* callback) = 0; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 void ReleaseAllConnections(KeepAlive keep_alive); | 450 void ReleaseAllConnections(KeepAlive keep_alive); |
| 451 | 451 |
| 452 ScopedVector<TestSocketRequest> requests_; | 452 ScopedVector<TestSocketRequest> requests_; |
| 453 std::vector<TestSocketRequest*> request_order_; | 453 std::vector<TestSocketRequest*> request_order_; |
| 454 size_t completion_count_; | 454 size_t completion_count_; |
| 455 }; | 455 }; |
| 456 | 456 |
| 457 } // namespace net | 457 } // namespace net |
| 458 | 458 |
| 459 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 459 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |