| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstring> | 8 #include <cstring> |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 309 |
| 310 protected: | 310 protected: |
| 311 StaticSocketDataHelper* helper() { return &helper_; } | 311 StaticSocketDataHelper* helper() { return &helper_; } |
| 312 | 312 |
| 313 private: | 313 private: |
| 314 StaticSocketDataHelper helper_; | 314 StaticSocketDataHelper helper_; |
| 315 | 315 |
| 316 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); | 316 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 // SocketDataProvider which can make decisions about next mock reads based on | |
| 320 // received writes. It can also be used to enforce order of operations, for | |
| 321 // example that tested code must send the "Hello!" message before receiving | |
| 322 // response. This is useful for testing conversation-like protocols like FTP. | |
| 323 class DynamicSocketDataProvider : public SocketDataProvider { | |
| 324 public: | |
| 325 DynamicSocketDataProvider(); | |
| 326 ~DynamicSocketDataProvider() override; | |
| 327 | |
| 328 int short_read_limit() const { return short_read_limit_; } | |
| 329 void set_short_read_limit(int limit) { short_read_limit_ = limit; } | |
| 330 | |
| 331 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; } | |
| 332 | |
| 333 // SocketDataProvider implementation. | |
| 334 MockRead OnRead() override; | |
| 335 MockWriteResult OnWrite(const std::string& data) override = 0; | |
| 336 void Reset() override; | |
| 337 | |
| 338 protected: | |
| 339 // The next time there is a read from this socket, it will return |data|. | |
| 340 // Before calling SimulateRead next time, the previous data must be consumed. | |
| 341 void SimulateRead(const char* data, size_t length); | |
| 342 void SimulateRead(const char* data) { SimulateRead(data, std::strlen(data)); } | |
| 343 | |
| 344 private: | |
| 345 std::deque<MockRead> reads_; | |
| 346 | |
| 347 // Max number of bytes we will read at a time. 0 means no limit. | |
| 348 int short_read_limit_; | |
| 349 | |
| 350 // If true, we'll not require the client to consume all data before we | |
| 351 // mock the next read. | |
| 352 bool allow_unconsumed_reads_; | |
| 353 | |
| 354 DISALLOW_COPY_AND_ASSIGN(DynamicSocketDataProvider); | |
| 355 }; | |
| 356 | |
| 357 // SSLSocketDataProviders only need to keep track of the return code from calls | 319 // SSLSocketDataProviders only need to keep track of the return code from calls |
| 358 // to Connect(). | 320 // to Connect(). |
| 359 struct SSLSocketDataProvider { | 321 struct SSLSocketDataProvider { |
| 360 SSLSocketDataProvider(IoMode mode, int result); | 322 SSLSocketDataProvider(IoMode mode, int result); |
| 361 ~SSLSocketDataProvider(); | 323 ~SSLSocketDataProvider(); |
| 362 | 324 |
| 363 void SetNextProto(NextProto proto); | 325 void SetNextProto(NextProto proto); |
| 364 | 326 |
| 365 MockConnect connect; | 327 MockConnect connect; |
| 366 SSLClientSocket::NextProtoStatus next_proto_status; | 328 SSLClientSocket::NextProtoStatus next_proto_status; |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 | 1303 |
| 1342 extern const char kSOCKS5OkRequest[]; | 1304 extern const char kSOCKS5OkRequest[]; |
| 1343 extern const int kSOCKS5OkRequestLength; | 1305 extern const int kSOCKS5OkRequestLength; |
| 1344 | 1306 |
| 1345 extern const char kSOCKS5OkResponse[]; | 1307 extern const char kSOCKS5OkResponse[]; |
| 1346 extern const int kSOCKS5OkResponseLength; | 1308 extern const int kSOCKS5OkResponseLength; |
| 1347 | 1309 |
| 1348 } // namespace net | 1310 } // namespace net |
| 1349 | 1311 |
| 1350 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1312 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |