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