Chromium Code Reviews| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 if (logging::LOG_INFO < logging::GetMinLogLevel()) | 116 if (logging::LOG_INFO < logging::GetMinLogLevel()) |
| 117 return; | 117 return; |
| 118 DVLOG(1) << "Async: " << (r.mode == ASYNC) | 118 DVLOG(1) << "Async: " << (r.mode == ASYNC) |
| 119 << "\nResult: " << r.result; | 119 << "\nResult: " << r.result; |
| 120 DumpData(r.data, r.data_len); | 120 DumpData(r.data, r.data_len); |
| 121 const char* stop = (r.sequence_number & MockRead::STOPLOOP) ? " (STOP)" : ""; | 121 const char* stop = (r.sequence_number & MockRead::STOPLOOP) ? " (STOP)" : ""; |
| 122 DVLOG(1) << "Stage: " << (r.sequence_number & ~MockRead::STOPLOOP) << stop | 122 DVLOG(1) << "Stage: " << (r.sequence_number & ~MockRead::STOPLOOP) << stop |
| 123 << "\nTime: " << r.time_stamp.ToInternalValue(); | 123 << "\nTime: " << r.time_stamp.ToInternalValue(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ExerciseSocketRandomNumberGenerator(const RandIntCallback& rand_int_cb) { | |
| 127 // Socket connect is supposed to call for some random suggestions for ports. | |
| 128 // We call 3 times so that the quic_stream_factory will know this function | |
| 129 // was consulted (it has a DCHECK), but will not actually DCHECK the | |
| 130 // resulting ephemeral port (which we don't set). | |
| 131 for (int count = 3; count > 0; --count) | |
| 132 rand_int_cb.Run(1000, 2000); | |
| 133 } | |
|
Ryan Hamilton
2013/12/08 23:22:21
Please revert the changes in this file until we're
jar (doing other things)
2013/12/08 23:30:46
Done.
| |
| 134 | |
| 126 } // namespace | 135 } // namespace |
| 127 | 136 |
| 128 MockConnect::MockConnect() : mode(ASYNC), result(OK) { | 137 MockConnect::MockConnect() : mode(ASYNC), result(OK) { |
| 129 IPAddressNumber ip; | 138 IPAddressNumber ip; |
| 130 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); | 139 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
| 131 peer_addr = IPEndPoint(ip, 0); | 140 peer_addr = IPEndPoint(ip, 0); |
| 132 } | 141 } |
| 133 | 142 |
| 134 MockConnect::MockConnect(IoMode io_mode, int r) : mode(io_mode), result(r) { | 143 MockConnect::MockConnect(IoMode io_mode, int r) : mode(io_mode), result(r) { |
| 135 IPAddressNumber ip; | 144 IPAddressNumber ip; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 mock_data_.ResetNextIndex(); | 665 mock_data_.ResetNextIndex(); |
| 657 mock_ssl_data_.ResetNextIndex(); | 666 mock_ssl_data_.ResetNextIndex(); |
| 658 } | 667 } |
| 659 | 668 |
| 660 scoped_ptr<DatagramClientSocket> | 669 scoped_ptr<DatagramClientSocket> |
| 661 MockClientSocketFactory::CreateDatagramClientSocket( | 670 MockClientSocketFactory::CreateDatagramClientSocket( |
| 662 DatagramSocket::BindType bind_type, | 671 DatagramSocket::BindType bind_type, |
| 663 const RandIntCallback& rand_int_cb, | 672 const RandIntCallback& rand_int_cb, |
| 664 net::NetLog* net_log, | 673 net::NetLog* net_log, |
| 665 const net::NetLog::Source& source) { | 674 const net::NetLog::Source& source) { |
| 675 ExerciseSocketRandomNumberGenerator(rand_int_cb); | |
| 666 SocketDataProvider* data_provider = mock_data_.GetNext(); | 676 SocketDataProvider* data_provider = mock_data_.GetNext(); |
| 667 scoped_ptr<MockUDPClientSocket> socket( | 677 scoped_ptr<MockUDPClientSocket> socket( |
| 668 new MockUDPClientSocket(data_provider, net_log)); | 678 new MockUDPClientSocket(data_provider, net_log)); |
| 669 data_provider->set_socket(socket.get()); | 679 data_provider->set_socket(socket.get()); |
| 670 return socket.PassAs<DatagramClientSocket>(); | 680 return socket.PassAs<DatagramClientSocket>(); |
| 671 } | 681 } |
| 672 | 682 |
| 673 scoped_ptr<StreamSocket> MockClientSocketFactory::CreateTransportClientSocket( | 683 scoped_ptr<StreamSocket> MockClientSocketFactory::CreateTransportClientSocket( |
| 674 const AddressList& addresses, | 684 const AddressList& addresses, |
| 675 net::NetLog* net_log, | 685 net::NetLog* net_log, |
| (...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1796 DCHECK_LT(index, ssl_client_sockets_.size()); | 1806 DCHECK_LT(index, ssl_client_sockets_.size()); |
| 1797 return ssl_client_sockets_[index]; | 1807 return ssl_client_sockets_[index]; |
| 1798 } | 1808 } |
| 1799 | 1809 |
| 1800 scoped_ptr<DatagramClientSocket> | 1810 scoped_ptr<DatagramClientSocket> |
| 1801 DeterministicMockClientSocketFactory::CreateDatagramClientSocket( | 1811 DeterministicMockClientSocketFactory::CreateDatagramClientSocket( |
| 1802 DatagramSocket::BindType bind_type, | 1812 DatagramSocket::BindType bind_type, |
| 1803 const RandIntCallback& rand_int_cb, | 1813 const RandIntCallback& rand_int_cb, |
| 1804 net::NetLog* net_log, | 1814 net::NetLog* net_log, |
| 1805 const NetLog::Source& source) { | 1815 const NetLog::Source& source) { |
| 1816 ExerciseSocketRandomNumberGenerator(rand_int_cb); | |
| 1806 DeterministicSocketData* data_provider = mock_data().GetNext(); | 1817 DeterministicSocketData* data_provider = mock_data().GetNext(); |
| 1807 scoped_ptr<DeterministicMockUDPClientSocket> socket( | 1818 scoped_ptr<DeterministicMockUDPClientSocket> socket( |
| 1808 new DeterministicMockUDPClientSocket(net_log, data_provider)); | 1819 new DeterministicMockUDPClientSocket(net_log, data_provider)); |
| 1809 data_provider->set_delegate(socket->AsWeakPtr()); | 1820 data_provider->set_delegate(socket->AsWeakPtr()); |
| 1810 udp_client_sockets().push_back(socket.get()); | 1821 udp_client_sockets().push_back(socket.get()); |
| 1811 return socket.PassAs<DatagramClientSocket>(); | 1822 return socket.PassAs<DatagramClientSocket>(); |
| 1812 } | 1823 } |
| 1813 | 1824 |
| 1814 scoped_ptr<StreamSocket> | 1825 scoped_ptr<StreamSocket> |
| 1815 DeterministicMockClientSocketFactory::CreateTransportClientSocket( | 1826 DeterministicMockClientSocketFactory::CreateTransportClientSocket( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1881 | 1892 |
| 1882 const char kSOCKS5OkRequest[] = | 1893 const char kSOCKS5OkRequest[] = |
| 1883 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1894 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
| 1884 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1895 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
| 1885 | 1896 |
| 1886 const char kSOCKS5OkResponse[] = | 1897 const char kSOCKS5OkResponse[] = |
| 1887 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1898 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 1888 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1899 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
| 1889 | 1900 |
| 1890 } // namespace net | 1901 } // namespace net |
| OLD | NEW |