| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // complete in this step, but is marked asynchronous. Write() returns | 426 // complete in this step, but is marked asynchronous. Write() returns |
| 427 // ERR_IO_PENDING. The current step is still 1. At this point RunFor(1) is | 427 // ERR_IO_PENDING. The current step is still 1. At this point RunFor(1) is |
| 428 // called which will cause the write callback to be invoked, and will then | 428 // called which will cause the write callback to be invoked, and will then |
| 429 // stop. The current state is now 2. RunFor(1) is called again, which | 429 // stop. The current state is now 2. RunFor(1) is called again, which |
| 430 // causes the read callback to be invoked, and will then stop. Then current | 430 // causes the read callback to be invoked, and will then stop. Then current |
| 431 // step is 2. Write() is called again. Then next available write is | 431 // step is 2. Write() is called again. Then next available write is |
| 432 // synchronous so the call to Write() returns length. | 432 // synchronous so the call to Write() returns length. |
| 433 // | 433 // |
| 434 // For examples of how to use this class, see: | 434 // For examples of how to use this class, see: |
| 435 // deterministic_socket_data_unittests.cc | 435 // deterministic_socket_data_unittests.cc |
| 436 class DeterministicSocketData : public StaticSocketDataProvider, | 436 class DeterministicSocketData |
| 437 public base::RefCounted<DeterministicSocketData> { | 437 : public StaticSocketDataProvider, |
| 438 public base::RefCounted<DeterministicSocketData> { |
| 438 public: | 439 public: |
| 439 // |reads| the list of MockRead completions. | 440 // |reads| the list of MockRead completions. |
| 440 // |writes| the list of MockWrite completions. | 441 // |writes| the list of MockWrite completions. |
| 441 DeterministicSocketData(MockRead* reads, size_t reads_count, | 442 DeterministicSocketData(MockRead* reads, size_t reads_count, |
| 442 MockWrite* writes, size_t writes_count); | 443 MockWrite* writes, size_t writes_count); |
| 443 virtual ~DeterministicSocketData(); | |
| 444 | 444 |
| 445 // Consume all the data up to the give stop point (via SetStop()). | 445 // Consume all the data up to the give stop point (via SetStop()). |
| 446 void Run(); | 446 void Run(); |
| 447 | 447 |
| 448 // Set the stop point to be |steps| from now, and then invoke Run(). | 448 // Set the stop point to be |steps| from now, and then invoke Run(). |
| 449 void RunFor(int steps); | 449 void RunFor(int steps); |
| 450 | 450 |
| 451 // Stop at step |seq|, which must be in the future. | 451 // Stop at step |seq|, which must be in the future. |
| 452 virtual void SetStop(int seq); | 452 virtual void SetStop(int seq); |
| 453 | 453 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 469 virtual MockRead GetNextRead() OVERRIDE; | 469 virtual MockRead GetNextRead() OVERRIDE; |
| 470 | 470 |
| 471 // When the socket calls Write(), it always completes synchronously. OnWrite() | 471 // When the socket calls Write(), it always completes synchronously. OnWrite() |
| 472 // checks to make sure the written data matches the expected data. The | 472 // checks to make sure the written data matches the expected data. The |
| 473 // callback will not be invoked until its sequence number is reached. | 473 // callback will not be invoked until its sequence number is reached. |
| 474 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; | 474 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; |
| 475 virtual void Reset() OVERRIDE; | 475 virtual void Reset() OVERRIDE; |
| 476 virtual void CompleteRead() OVERRIDE {} | 476 virtual void CompleteRead() OVERRIDE {} |
| 477 | 477 |
| 478 private: | 478 private: |
| 479 friend class base::RefCounted<DeterministicSocketData>; |
| 480 virtual ~DeterministicSocketData(); |
| 481 |
| 479 // Invoke the read and write callbacks, if the timing is appropriate. | 482 // Invoke the read and write callbacks, if the timing is appropriate. |
| 480 void InvokeCallbacks(); | 483 void InvokeCallbacks(); |
| 481 | 484 |
| 482 void NextStep(); | 485 void NextStep(); |
| 483 | 486 |
| 484 int sequence_number_; | 487 int sequence_number_; |
| 485 MockRead current_read_; | 488 MockRead current_read_; |
| 486 MockWrite current_write_; | 489 MockWrite current_write_; |
| 487 int stopping_sequence_number_; | 490 int stopping_sequence_number_; |
| 488 bool stopped_; | 491 bool stopped_; |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 | 1046 |
| 1044 extern const char kSOCKS5OkRequest[]; | 1047 extern const char kSOCKS5OkRequest[]; |
| 1045 extern const int kSOCKS5OkRequestLength; | 1048 extern const int kSOCKS5OkRequestLength; |
| 1046 | 1049 |
| 1047 extern const char kSOCKS5OkResponse[]; | 1050 extern const char kSOCKS5OkResponse[]; |
| 1048 extern const int kSOCKS5OkResponseLength; | 1051 extern const int kSOCKS5OkResponseLength; |
| 1049 | 1052 |
| 1050 } // namespace net | 1053 } // namespace net |
| 1051 | 1054 |
| 1052 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1055 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |