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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 result(0), | 159 result(0), |
160 data(data), | 160 data(data), |
161 data_len(data_len), | 161 data_len(data_len), |
162 sequence_number(seq) {} | 162 sequence_number(seq) {} |
163 | 163 |
164 IoMode mode; | 164 IoMode mode; |
165 int result; | 165 int result; |
166 const char* data; | 166 const char* data; |
167 int data_len; | 167 int data_len; |
168 | 168 |
169 // For OrderedSocketData, which only allows reads to occur in a particular | 169 // For data providers that only allows reads to occur in a particular |
170 // sequence. If a read occurs before the given |sequence_number| is reached, | 170 // sequence. If a read occurs before the given |sequence_number| is reached, |
171 // an ERR_IO_PENDING is returned. | 171 // an ERR_IO_PENDING is returned. |
172 int sequence_number; // The sequence number at which a read is allowed | 172 int sequence_number; // The sequence number at which a read is allowed |
173 // to occur. | 173 // to occur. |
174 }; | 174 }; |
175 | 175 |
176 typedef MockReadWrite<MOCK_READ> MockRead; | 176 typedef MockReadWrite<MOCK_READ> MockRead; |
177 typedef MockReadWrite<MOCK_WRITE> MockWrite; | 177 typedef MockReadWrite<MOCK_WRITE> MockWrite; |
178 | 178 |
179 struct MockWriteResult { | 179 struct MockWriteResult { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 415 |
416 private: | 416 private: |
417 int write_delay_; | 417 int write_delay_; |
418 bool read_in_progress_; | 418 bool read_in_progress_; |
419 | 419 |
420 base::WeakPtrFactory<DelayedSocketData> weak_factory_; | 420 base::WeakPtrFactory<DelayedSocketData> weak_factory_; |
421 | 421 |
422 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData); | 422 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData); |
423 }; | 423 }; |
424 | 424 |
425 // A DataProvider where the reads are ordered. | |
426 // If a read is requested before its sequence number is reached, we return an | |
427 // ERR_IO_PENDING (that way we don't have to explicitly add a MockRead just to | |
428 // wait). | |
429 // The sequence number is incremented on every read and write operation. | |
430 // The message loop may be interrupted by setting the high bit of the sequence | |
431 // number in the MockRead's sequence number. When that MockRead is reached, | |
432 // we post a Quit message to the loop. This allows us to interrupt the reading | |
433 // of data before a complete message has arrived, and provides support for | |
434 // testing server push when the request is issued while the response is in the | |
435 // middle of being received. | |
436 class OrderedSocketData : public StaticSocketDataProvider { | |
437 public: | |
438 // |reads| the list of MockRead completions. | |
439 // |writes| the list of MockWrite completions. | |
440 // Note: All MockReads and MockWrites must be async. | |
441 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a | |
442 // MockRead(true, 0, 0); | |
443 OrderedSocketData(MockRead* reads, | |
444 size_t reads_count, | |
445 MockWrite* writes, | |
446 size_t writes_count); | |
447 ~OrderedSocketData() override; | |
448 | |
449 // |connect| the result for the connect phase. | |
450 // |reads| the list of MockRead completions. | |
451 // |writes| the list of MockWrite completions. | |
452 // Note: All MockReads and MockWrites must be async. | |
453 // Note: For stream sockets, the MockRead list must end with a EOF, e.g., a | |
454 // MockRead(true, 0, 0); | |
455 OrderedSocketData(const MockConnect& connect, | |
456 MockRead* reads, | |
457 size_t reads_count, | |
458 MockWrite* writes, | |
459 size_t writes_count); | |
460 | |
461 // Posts a quit message to the current message loop, if one is running. | |
462 void EndLoop(); | |
463 | |
464 // StaticSocketDataProvider: | |
465 MockRead OnRead() override; | |
466 MockWriteResult OnWrite(const std::string& data) override; | |
467 void Reset() override; | |
468 void CompleteRead() override; | |
469 | |
470 private: | |
471 int sequence_number_; | |
472 int loop_stop_stage_; | |
473 bool blocked_; | |
474 | |
475 base::WeakPtrFactory<OrderedSocketData> weak_factory_; | |
476 | |
477 DISALLOW_COPY_AND_ASSIGN(OrderedSocketData); | |
478 }; | |
479 | |
480 // Uses the sequence_number field in the mock reads and writes to | 425 // Uses the sequence_number field in the mock reads and writes to |
481 // complete the operations in a specified order. | 426 // complete the operations in a specified order. |
482 class SequencedSocketData : public SocketDataProvider { | 427 class SequencedSocketData : public SocketDataProvider { |
483 public: | 428 public: |
484 // |reads| is the list of MockRead completions. | 429 // |reads| is the list of MockRead completions. |
485 // |writes| is the list of MockWrite completions. | 430 // |writes| is the list of MockWrite completions. |
486 SequencedSocketData(MockRead* reads, | 431 SequencedSocketData(MockRead* reads, |
487 size_t reads_count, | 432 size_t reads_count, |
488 MockWrite* writes, | 433 MockWrite* writes, |
489 size_t writes_count); | 434 size_t writes_count); |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1328 |
1384 extern const char kSOCKS5OkRequest[]; | 1329 extern const char kSOCKS5OkRequest[]; |
1385 extern const int kSOCKS5OkRequestLength; | 1330 extern const int kSOCKS5OkRequestLength; |
1386 | 1331 |
1387 extern const char kSOCKS5OkResponse[]; | 1332 extern const char kSOCKS5OkResponse[]; |
1388 extern const int kSOCKS5OkResponseLength; | 1333 extern const int kSOCKS5OkResponseLength; |
1389 | 1334 |
1390 } // namespace net | 1335 } // namespace net |
1391 | 1336 |
1392 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1337 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
OLD | NEW |