| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 10 |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 callback->Run(result); | 700 callback->Run(result); |
| 701 } | 701 } |
| 702 | 702 |
| 703 MockTCPClientSocket::MockTCPClientSocket(const net::AddressList& addresses, | 703 MockTCPClientSocket::MockTCPClientSocket(const net::AddressList& addresses, |
| 704 net::NetLog* net_log, | 704 net::NetLog* net_log, |
| 705 net::SocketDataProvider* data) | 705 net::SocketDataProvider* data) |
| 706 : MockClientSocket(net_log), | 706 : MockClientSocket(net_log), |
| 707 addresses_(addresses), | 707 addresses_(addresses), |
| 708 data_(data), | 708 data_(data), |
| 709 read_offset_(0), | 709 read_offset_(0), |
| 710 num_bytes_read_(0), | |
| 711 read_data_(false, net::ERR_UNEXPECTED), | 710 read_data_(false, net::ERR_UNEXPECTED), |
| 712 need_read_data_(true), | 711 need_read_data_(true), |
| 713 peer_closed_connection_(false), | 712 peer_closed_connection_(false), |
| 714 pending_buf_(NULL), | 713 pending_buf_(NULL), |
| 715 pending_buf_len_(0), | 714 pending_buf_len_(0), |
| 716 pending_callback_(NULL), | 715 pending_callback_(NULL), |
| 717 was_used_to_convey_data_(false) { | 716 was_used_to_convey_data_(false) { |
| 718 DCHECK(data_); | 717 DCHECK(data_); |
| 719 data_->Reset(); | 718 data_->Reset(); |
| 720 } | 719 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 } | 804 } |
| 806 | 805 |
| 807 bool MockTCPClientSocket::WasEverUsed() const { | 806 bool MockTCPClientSocket::WasEverUsed() const { |
| 808 return was_used_to_convey_data_; | 807 return was_used_to_convey_data_; |
| 809 } | 808 } |
| 810 | 809 |
| 811 bool MockTCPClientSocket::UsingTCPFastOpen() const { | 810 bool MockTCPClientSocket::UsingTCPFastOpen() const { |
| 812 return false; | 811 return false; |
| 813 } | 812 } |
| 814 | 813 |
| 815 int64 MockTCPClientSocket::NumBytesRead() const { | |
| 816 return num_bytes_read_; | |
| 817 } | |
| 818 | |
| 819 base::TimeDelta MockTCPClientSocket::GetConnectTimeMicros() const { | |
| 820 // Dummy value. | |
| 821 static const base::TimeDelta kTestingConnectTimeMicros = | |
| 822 base::TimeDelta::FromMicroseconds(20); | |
| 823 return kTestingConnectTimeMicros; | |
| 824 } | |
| 825 | |
| 826 void MockTCPClientSocket::OnReadComplete(const MockRead& data) { | 814 void MockTCPClientSocket::OnReadComplete(const MockRead& data) { |
| 827 // There must be a read pending. | 815 // There must be a read pending. |
| 828 DCHECK(pending_buf_); | 816 DCHECK(pending_buf_); |
| 829 // You can't complete a read with another ERR_IO_PENDING status code. | 817 // You can't complete a read with another ERR_IO_PENDING status code. |
| 830 DCHECK_NE(ERR_IO_PENDING, data.result); | 818 DCHECK_NE(ERR_IO_PENDING, data.result); |
| 831 // Since we've been waiting for data, need_read_data_ should be true. | 819 // Since we've been waiting for data, need_read_data_ should be true. |
| 832 DCHECK(need_read_data_); | 820 DCHECK(need_read_data_); |
| 833 | 821 |
| 834 read_data_ = data; | 822 read_data_ = data; |
| 835 need_read_data_ = false; | 823 need_read_data_ = false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 858 pending_callback_ = NULL; | 846 pending_callback_ = NULL; |
| 859 | 847 |
| 860 int result = read_data_.result; | 848 int result = read_data_.result; |
| 861 DCHECK(result != ERR_IO_PENDING); | 849 DCHECK(result != ERR_IO_PENDING); |
| 862 | 850 |
| 863 if (read_data_.data) { | 851 if (read_data_.data) { |
| 864 if (read_data_.data_len - read_offset_ > 0) { | 852 if (read_data_.data_len - read_offset_ > 0) { |
| 865 result = std::min(buf_len, read_data_.data_len - read_offset_); | 853 result = std::min(buf_len, read_data_.data_len - read_offset_); |
| 866 memcpy(buf->data(), read_data_.data + read_offset_, result); | 854 memcpy(buf->data(), read_data_.data + read_offset_, result); |
| 867 read_offset_ += result; | 855 read_offset_ += result; |
| 868 num_bytes_read_ += result; | |
| 869 if (read_offset_ == read_data_.data_len) { | 856 if (read_offset_ == read_data_.data_len) { |
| 870 need_read_data_ = true; | 857 need_read_data_ = true; |
| 871 read_offset_ = 0; | 858 read_offset_ = 0; |
| 872 } | 859 } |
| 873 } else { | 860 } else { |
| 874 result = 0; // EOF | 861 result = 0; // EOF |
| 875 } | 862 } |
| 876 } | 863 } |
| 877 | 864 |
| 878 if (read_data_.async) { | 865 if (read_data_.async) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 } | 994 } |
| 1008 | 995 |
| 1009 bool DeterministicMockTCPClientSocket::WasEverUsed() const { | 996 bool DeterministicMockTCPClientSocket::WasEverUsed() const { |
| 1010 return was_used_to_convey_data_; | 997 return was_used_to_convey_data_; |
| 1011 } | 998 } |
| 1012 | 999 |
| 1013 bool DeterministicMockTCPClientSocket::UsingTCPFastOpen() const { | 1000 bool DeterministicMockTCPClientSocket::UsingTCPFastOpen() const { |
| 1014 return false; | 1001 return false; |
| 1015 } | 1002 } |
| 1016 | 1003 |
| 1017 int64 DeterministicMockTCPClientSocket::NumBytesRead() const { | |
| 1018 return -1; | |
| 1019 } | |
| 1020 | |
| 1021 base::TimeDelta DeterministicMockTCPClientSocket::GetConnectTimeMicros() const { | |
| 1022 return base::TimeDelta::FromMicroseconds(-1); | |
| 1023 } | |
| 1024 | |
| 1025 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {} | 1004 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {} |
| 1026 | 1005 |
| 1027 class MockSSLClientSocket::ConnectCallback | 1006 class MockSSLClientSocket::ConnectCallback |
| 1028 : public net::CompletionCallbackImpl<MockSSLClientSocket::ConnectCallback> { | 1007 : public net::CompletionCallbackImpl<MockSSLClientSocket::ConnectCallback> { |
| 1029 public: | 1008 public: |
| 1030 ConnectCallback(MockSSLClientSocket *ssl_client_socket, | 1009 ConnectCallback(MockSSLClientSocket *ssl_client_socket, |
| 1031 net::CompletionCallback* user_callback, | 1010 net::CompletionCallback* user_callback, |
| 1032 int rv) | 1011 int rv) |
| 1033 : ALLOW_THIS_IN_INITIALIZER_LIST( | 1012 : ALLOW_THIS_IN_INITIALIZER_LIST( |
| 1034 net::CompletionCallbackImpl<MockSSLClientSocket::ConnectCallback>( | 1013 net::CompletionCallbackImpl<MockSSLClientSocket::ConnectCallback>( |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 } | 1087 } |
| 1109 | 1088 |
| 1110 bool MockSSLClientSocket::WasEverUsed() const { | 1089 bool MockSSLClientSocket::WasEverUsed() const { |
| 1111 return transport_->socket()->WasEverUsed(); | 1090 return transport_->socket()->WasEverUsed(); |
| 1112 } | 1091 } |
| 1113 | 1092 |
| 1114 bool MockSSLClientSocket::UsingTCPFastOpen() const { | 1093 bool MockSSLClientSocket::UsingTCPFastOpen() const { |
| 1115 return transport_->socket()->UsingTCPFastOpen(); | 1094 return transport_->socket()->UsingTCPFastOpen(); |
| 1116 } | 1095 } |
| 1117 | 1096 |
| 1118 int64 MockSSLClientSocket::NumBytesRead() const { | |
| 1119 return -1; | |
| 1120 } | |
| 1121 | |
| 1122 base::TimeDelta MockSSLClientSocket::GetConnectTimeMicros() const { | |
| 1123 return base::TimeDelta::FromMicroseconds(-1); | |
| 1124 } | |
| 1125 | |
| 1126 void MockSSLClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) { | 1097 void MockSSLClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) { |
| 1127 ssl_info->Reset(); | 1098 ssl_info->Reset(); |
| 1128 ssl_info->cert = data_->cert_; | 1099 ssl_info->cert = data_->cert_; |
| 1129 } | 1100 } |
| 1130 | 1101 |
| 1131 void MockSSLClientSocket::GetSSLCertRequestInfo( | 1102 void MockSSLClientSocket::GetSSLCertRequestInfo( |
| 1132 net::SSLCertRequestInfo* cert_request_info) { | 1103 net::SSLCertRequestInfo* cert_request_info) { |
| 1133 DCHECK(cert_request_info); | 1104 DCHECK(cert_request_info); |
| 1134 if (data_->cert_request_info) { | 1105 if (data_->cert_request_info) { |
| 1135 cert_request_info->host_and_port = | 1106 cert_request_info->host_and_port = |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1520 | 1491 |
| 1521 const char kSOCKS5OkRequest[] = | 1492 const char kSOCKS5OkRequest[] = |
| 1522 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1493 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
| 1523 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1494 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
| 1524 | 1495 |
| 1525 const char kSOCKS5OkResponse[] = | 1496 const char kSOCKS5OkResponse[] = |
| 1526 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1497 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 1527 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1498 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
| 1528 | 1499 |
| 1529 } // namespace net | 1500 } // namespace net |
| OLD | NEW |