| 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 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // If true, we'll not require the client to consume all data before we | 222 // If true, we'll not require the client to consume all data before we |
| 223 // mock the next read. | 223 // mock the next read. |
| 224 bool allow_unconsumed_reads_; | 224 bool allow_unconsumed_reads_; |
| 225 | 225 |
| 226 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider); | 226 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider); |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 // SSLSocketDataProviders only need to keep track of the return code from calls | 229 // SSLSocketDataProviders only need to keep track of the return code from calls |
| 230 // to Connect(). | 230 // to Connect(). |
| 231 struct SSLSocketDataProvider { | 231 struct SSLSocketDataProvider { |
| 232 SSLSocketDataProvider(bool async, int result) : connect(async, result) { } | 232 SSLSocketDataProvider(bool async, int result) |
| 233 : connect(async, result), |
| 234 next_proto_status(SSLClientSocket::kNextProtoUnsupported) { } |
| 233 | 235 |
| 234 MockConnect connect; | 236 MockConnect connect; |
| 237 SSLClientSocket::NextProtoStatus next_proto_status; |
| 238 std::string next_proto; |
| 239 }; |
| 240 |
| 241 // A DataProvider where the client must write a request before the reads (e.g. |
| 242 // the response) will complete. |
| 243 class DelayedSocketData : public StaticSocketDataProvider, |
| 244 public base::RefCounted<DelayedSocketData> { |
| 245 public: |
| 246 // |write_delay| the number of MockWrites to complete before allowing |
| 247 // a MockRead to complete. |
| 248 // |reads| the list of MockRead completions. |
| 249 // |writes| the list of MockWrite completions. |
| 250 // Note: All MockReads and MockWrites must be async. |
| 251 // Note: The MockRead and MockWrite lists musts end with a EOF |
| 252 // e.g. a MockRead(true, 0, 0); |
| 253 DelayedSocketData(int write_delay, |
| 254 MockRead* reads, size_t reads_count, |
| 255 MockWrite* writes, size_t writes_count); |
| 256 |
| 257 // |connect| the result for the connect phase. |
| 258 // |reads| the list of MockRead completions. |
| 259 // |write_delay| the number of MockWrites to complete before allowing |
| 260 // a MockRead to complete. |
| 261 // |writes| the list of MockWrite completions. |
| 262 // Note: All MockReads and MockWrites must be async. |
| 263 // Note: The MockRead and MockWrite lists musts end with a EOF |
| 264 // e.g. a MockRead(true, 0, 0); |
| 265 DelayedSocketData(const MockConnect& connect, int write_delay, |
| 266 MockRead* reads, size_t reads_count, |
| 267 MockWrite* writes, size_t writes_count); |
| 268 |
| 269 virtual MockRead GetNextRead(); |
| 270 virtual MockWriteResult OnWrite(const std::string& data); |
| 271 virtual void Reset(); |
| 272 void CompleteRead(); |
| 273 |
| 274 private: |
| 275 int write_delay_; |
| 276 ScopedRunnableMethodFactory<DelayedSocketData> factory_; |
| 235 }; | 277 }; |
| 236 | 278 |
| 237 // Holds an array of SocketDataProvider elements. As Mock{TCP,SSL}ClientSocket | 279 // Holds an array of SocketDataProvider elements. As Mock{TCP,SSL}ClientSocket |
| 238 // objects get instantiated, they take their data from the i'th element of this | 280 // objects get instantiated, they take their data from the i'th element of this |
| 239 // array. | 281 // array. |
| 240 template<typename T> | 282 template<typename T> |
| 241 class SocketDataProviderArray { | 283 class SocketDataProviderArray { |
| 242 public: | 284 public: |
| 243 SocketDataProviderArray() : next_index_(0) { | 285 SocketDataProviderArray() : next_index_(0) { |
| 244 } | 286 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 436 |
| 395 class MockSSLClientSocket : public MockClientSocket { | 437 class MockSSLClientSocket : public MockClientSocket { |
| 396 public: | 438 public: |
| 397 MockSSLClientSocket( | 439 MockSSLClientSocket( |
| 398 net::ClientSocket* transport_socket, | 440 net::ClientSocket* transport_socket, |
| 399 const std::string& hostname, | 441 const std::string& hostname, |
| 400 const net::SSLConfig& ssl_config, | 442 const net::SSLConfig& ssl_config, |
| 401 net::SSLSocketDataProvider* socket); | 443 net::SSLSocketDataProvider* socket); |
| 402 ~MockSSLClientSocket(); | 444 ~MockSSLClientSocket(); |
| 403 | 445 |
| 404 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | 446 // ClientSocket methods: |
| 405 | |
| 406 virtual int Connect(net::CompletionCallback* callback); | 447 virtual int Connect(net::CompletionCallback* callback); |
| 407 virtual void Disconnect(); | 448 virtual void Disconnect(); |
| 408 | 449 |
| 409 // Socket methods: | 450 // Socket methods: |
| 410 virtual int Read(net::IOBuffer* buf, int buf_len, | 451 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 411 net::CompletionCallback* callback); | 452 net::CompletionCallback* callback); |
| 412 virtual int Write(net::IOBuffer* buf, int buf_len, | 453 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 413 net::CompletionCallback* callback); | 454 net::CompletionCallback* callback); |
| 414 | 455 |
| 456 // SSLClientSocket methods: |
| 457 virtual void GetSSLInfo(net::SSLInfo* ssl_info); |
| 458 virtual NextProtoStatus GetNextProto(std::string* proto); |
| 459 |
| 415 // This MockSocket does not implement the manual async IO feature. | 460 // This MockSocket does not implement the manual async IO feature. |
| 416 virtual void OnReadComplete(const MockRead& data) { NOTIMPLEMENTED(); } | 461 virtual void OnReadComplete(const MockRead& data) { NOTIMPLEMENTED(); } |
| 417 | 462 |
| 418 private: | 463 private: |
| 419 class ConnectCallback; | 464 class ConnectCallback; |
| 420 | 465 |
| 421 scoped_ptr<ClientSocket> transport_; | 466 scoped_ptr<ClientSocket> transport_; |
| 422 net::SSLSocketDataProvider* data_; | 467 net::SSLSocketDataProvider* data_; |
| 423 }; | 468 }; |
| 424 | 469 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 549 |
| 505 extern const char kSOCKS5OkRequest[]; | 550 extern const char kSOCKS5OkRequest[]; |
| 506 extern const int kSOCKS5OkRequestLength; | 551 extern const int kSOCKS5OkRequestLength; |
| 507 | 552 |
| 508 extern const char kSOCKS5OkResponse[]; | 553 extern const char kSOCKS5OkResponse[]; |
| 509 extern const int kSOCKS5OkResponseLength; | 554 extern const int kSOCKS5OkResponseLength; |
| 510 | 555 |
| 511 } // namespace net | 556 } // namespace net |
| 512 | 557 |
| 513 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 558 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |