| 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 #include "net/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 DVLOG(1) << pfx | 102 DVLOG(1) << pfx |
| 103 << AsciifyHigh(data[i + 0]) << AsciifyLow(data[i + 0]) | 103 << AsciifyHigh(data[i + 0]) << AsciifyLow(data[i + 0]) |
| 104 << " '" | 104 << " '" |
| 105 << Asciify(data[i + 0]) | 105 << Asciify(data[i + 0]) |
| 106 << " '"; | 106 << " '"; |
| 107 break; | 107 break; |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 void DumpMockRead(const MockRead& r) { | 112 template <MockReadWriteType type> |
| 113 void DumpMockReadWrite(const MockReadWrite<type>& r) { |
| 113 if (logging::LOG_INFO < logging::GetMinLogLevel()) | 114 if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 114 return; | 115 return; |
| 115 DVLOG(1) << "Async: " << (r.mode == ASYNC) | 116 DVLOG(1) << "Async: " << (r.mode == ASYNC) |
| 116 << "\nResult: " << r.result; | 117 << "\nResult: " << r.result; |
| 117 DumpData(r.data, r.data_len); | 118 DumpData(r.data, r.data_len); |
| 118 const char* stop = (r.sequence_number & MockRead::STOPLOOP) ? " (STOP)" : ""; | 119 const char* stop = (r.sequence_number & MockRead::STOPLOOP) ? " (STOP)" : ""; |
| 119 DVLOG(1) << "Stage: " << (r.sequence_number & ~MockRead::STOPLOOP) << stop | 120 DVLOG(1) << "Stage: " << (r.sequence_number & ~MockRead::STOPLOOP) << stop |
| 120 << "\nTime: " << r.time_stamp.ToInternalValue(); | 121 << "\nTime: " << r.time_stamp.ToInternalValue(); |
| 121 } | 122 } |
| 122 | 123 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 MockRead OrderedSocketData::GetNextRead() { | 384 MockRead OrderedSocketData::GetNextRead() { |
| 384 weak_factory_.InvalidateWeakPtrs(); | 385 weak_factory_.InvalidateWeakPtrs(); |
| 385 blocked_ = false; | 386 blocked_ = false; |
| 386 const MockRead& next_read = StaticSocketDataProvider::PeekRead(); | 387 const MockRead& next_read = StaticSocketDataProvider::PeekRead(); |
| 387 if (next_read.sequence_number & MockRead::STOPLOOP) | 388 if (next_read.sequence_number & MockRead::STOPLOOP) |
| 388 EndLoop(); | 389 EndLoop(); |
| 389 if ((next_read.sequence_number & ~MockRead::STOPLOOP) <= | 390 if ((next_read.sequence_number & ~MockRead::STOPLOOP) <= |
| 390 sequence_number_++) { | 391 sequence_number_++) { |
| 391 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 | 392 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 |
| 392 << ": Read " << read_index(); | 393 << ": Read " << read_index(); |
| 393 DumpMockRead(next_read); | 394 DumpMockReadWrite(next_read); |
| 394 blocked_ = (next_read.result == ERR_IO_PENDING); | 395 blocked_ = (next_read.result == ERR_IO_PENDING); |
| 395 return StaticSocketDataProvider::GetNextRead(); | 396 return StaticSocketDataProvider::GetNextRead(); |
| 396 } | 397 } |
| 397 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 | 398 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 |
| 398 << ": I/O Pending"; | 399 << ": I/O Pending"; |
| 399 MockRead result = MockRead(ASYNC, ERR_IO_PENDING); | 400 MockRead result = MockRead(ASYNC, ERR_IO_PENDING); |
| 400 DumpMockRead(result); | 401 DumpMockReadWrite(result); |
| 401 blocked_ = true; | 402 blocked_ = true; |
| 402 return result; | 403 return result; |
| 403 } | 404 } |
| 404 | 405 |
| 405 MockWriteResult OrderedSocketData::OnWrite(const std::string& data) { | 406 MockWriteResult OrderedSocketData::OnWrite(const std::string& data) { |
| 406 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ | 407 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ |
| 407 << ": Write " << write_index(); | 408 << ": Write " << write_index(); |
| 408 DumpMockRead(PeekWrite()); | 409 DumpMockReadWrite(PeekWrite()); |
| 409 ++sequence_number_; | 410 ++sequence_number_; |
| 410 if (blocked_) { | 411 if (blocked_) { |
| 411 // TODO(willchan): This 100ms delay seems to work around some weirdness. We | 412 // TODO(willchan): This 100ms delay seems to work around some weirdness. We |
| 412 // should probably fix the weirdness. One example is in SpdyStream, | 413 // should probably fix the weirdness. One example is in SpdyStream, |
| 413 // DoSendRequest() will return ERR_IO_PENDING, and there's a race. If the | 414 // DoSendRequest() will return ERR_IO_PENDING, and there's a race. If the |
| 414 // SYN_REPLY causes OnResponseReceived() to get called before | 415 // SYN_REPLY causes OnResponseReceived() to get called before |
| 415 // SpdyStream::ReadResponseHeaders() is called, we hit a NOTREACHED(). | 416 // SpdyStream::ReadResponseHeaders() is called, we hit a NOTREACHED(). |
| 416 MessageLoop::current()->PostDelayedTask( | 417 MessageLoop::current()->PostDelayedTask( |
| 417 FROM_HERE, | 418 FROM_HERE, |
| 418 base::Bind(&OrderedSocketData::CompleteRead, | 419 base::Bind(&OrderedSocketData::CompleteRead, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ | 512 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ |
| 512 << ": I/O Pending"; | 513 << ": I/O Pending"; |
| 513 MockRead result = MockRead(SYNCHRONOUS, ERR_IO_PENDING); | 514 MockRead result = MockRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 514 if (current_read_.mode == SYNCHRONOUS) { | 515 if (current_read_.mode == SYNCHRONOUS) { |
| 515 LOG(ERROR) << "Unable to perform synchronous read: " | 516 LOG(ERROR) << "Unable to perform synchronous read: " |
| 516 << current_read_.sequence_number | 517 << current_read_.sequence_number |
| 517 << " at stage: " << sequence_number_; | 518 << " at stage: " << sequence_number_; |
| 518 result = MockRead(SYNCHRONOUS, ERR_UNEXPECTED); | 519 result = MockRead(SYNCHRONOUS, ERR_UNEXPECTED); |
| 519 } | 520 } |
| 520 if (print_debug_) | 521 if (print_debug_) |
| 521 DumpMockRead(result); | 522 DumpMockReadWrite(result); |
| 522 return result; | 523 return result; |
| 523 } | 524 } |
| 524 | 525 |
| 525 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ | 526 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ |
| 526 << ": Read " << read_index(); | 527 << ": Read " << read_index(); |
| 527 if (print_debug_) | 528 if (print_debug_) |
| 528 DumpMockRead(current_read_); | 529 DumpMockReadWrite(current_read_); |
| 529 | 530 |
| 530 // Increment the sequence number if IO is complete | 531 // Increment the sequence number if IO is complete |
| 531 if (current_read_.mode == SYNCHRONOUS) | 532 if (current_read_.mode == SYNCHRONOUS) |
| 532 NextStep(); | 533 NextStep(); |
| 533 | 534 |
| 534 DCHECK_NE(ERR_IO_PENDING, current_read_.result); | 535 DCHECK_NE(ERR_IO_PENDING, current_read_.result); |
| 535 StaticSocketDataProvider::GetNextRead(); | 536 StaticSocketDataProvider::GetNextRead(); |
| 536 | 537 |
| 537 return current_read_; | 538 return current_read_; |
| 538 } | 539 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 555 LOG(ERROR) << "Unable to perform synchronous write: " | 556 LOG(ERROR) << "Unable to perform synchronous write: " |
| 556 << next_write.sequence_number << " at stage: " << sequence_number_; | 557 << next_write.sequence_number << " at stage: " << sequence_number_; |
| 557 return MockWriteResult(SYNCHRONOUS, ERR_UNEXPECTED); | 558 return MockWriteResult(SYNCHRONOUS, ERR_UNEXPECTED); |
| 558 } | 559 } |
| 559 } else { | 560 } else { |
| 560 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ | 561 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ |
| 561 << ": Write " << write_index(); | 562 << ": Write " << write_index(); |
| 562 } | 563 } |
| 563 | 564 |
| 564 if (print_debug_) | 565 if (print_debug_) |
| 565 DumpMockRead(next_write); | 566 DumpMockReadWrite(next_write); |
| 566 | 567 |
| 567 // Move to the next step if I/O is synchronous, since the operation will | 568 // Move to the next step if I/O is synchronous, since the operation will |
| 568 // complete when this method returns. | 569 // complete when this method returns. |
| 569 if (next_write.mode == SYNCHRONOUS) | 570 if (next_write.mode == SYNCHRONOUS) |
| 570 NextStep(); | 571 NextStep(); |
| 571 | 572 |
| 572 // This is either a sync write for this step, or an async write. | 573 // This is either a sync write for this step, or an async write. |
| 573 return StaticSocketDataProvider::OnWrite(data); | 574 return StaticSocketDataProvider::OnWrite(data); |
| 574 } | 575 } |
| 575 | 576 |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 | 1684 |
| 1684 const char kSOCKS5OkRequest[] = | 1685 const char kSOCKS5OkRequest[] = |
| 1685 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1686 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
| 1686 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1687 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
| 1687 | 1688 |
| 1688 const char kSOCKS5OkResponse[] = | 1689 const char kSOCKS5OkResponse[] = |
| 1689 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1690 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 1690 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1691 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
| 1691 | 1692 |
| 1692 } // namespace net | 1693 } // namespace net |
| OLD | NEW |