OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 DCHECK_LT(index, tcp_client_sockets_.size()); | 581 DCHECK_LT(index, tcp_client_sockets_.size()); |
582 return tcp_client_sockets_[index]; | 582 return tcp_client_sockets_[index]; |
583 } | 583 } |
584 | 584 |
585 MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket( | 585 MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket( |
586 size_t index) const { | 586 size_t index) const { |
587 DCHECK_LT(index, ssl_client_sockets_.size()); | 587 DCHECK_LT(index, ssl_client_sockets_.size()); |
588 return ssl_client_sockets_[index]; | 588 return ssl_client_sockets_[index]; |
589 } | 589 } |
590 | 590 |
591 ClientSocket* MockClientSocketFactory::CreateTransportClientSocket( | 591 StreamSocket* MockClientSocketFactory::CreateTransportClientSocket( |
592 const AddressList& addresses, | 592 const AddressList& addresses, |
593 net::NetLog* net_log, | 593 net::NetLog* net_log, |
594 const NetLog::Source& source) { | 594 const NetLog::Source& source) { |
595 SocketDataProvider* data_provider = mock_data_.GetNext(); | 595 SocketDataProvider* data_provider = mock_data_.GetNext(); |
596 MockTCPClientSocket* socket = | 596 MockTCPClientSocket* socket = |
597 new MockTCPClientSocket(addresses, net_log, data_provider); | 597 new MockTCPClientSocket(addresses, net_log, data_provider); |
598 data_provider->set_socket(socket); | 598 data_provider->set_socket(socket); |
599 tcp_client_sockets_.push_back(socket); | 599 tcp_client_sockets_.push_back(socket); |
600 return socket; | 600 return socket; |
601 } | 601 } |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 } | 1173 } |
1174 | 1174 |
1175 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { | 1175 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { |
1176 bool released_one; | 1176 bool released_one; |
1177 do { | 1177 do { |
1178 released_one = ReleaseOneConnection(keep_alive); | 1178 released_one = ReleaseOneConnection(keep_alive); |
1179 } while (released_one); | 1179 } while (released_one); |
1180 } | 1180 } |
1181 | 1181 |
1182 MockTransportClientSocketPool::MockConnectJob::MockConnectJob( | 1182 MockTransportClientSocketPool::MockConnectJob::MockConnectJob( |
1183 ClientSocket* socket, | 1183 StreamSocket* socket, |
1184 ClientSocketHandle* handle, | 1184 ClientSocketHandle* handle, |
1185 CompletionCallback* callback) | 1185 CompletionCallback* callback) |
1186 : socket_(socket), | 1186 : socket_(socket), |
1187 handle_(handle), | 1187 handle_(handle), |
1188 user_callback_(callback), | 1188 user_callback_(callback), |
1189 ALLOW_THIS_IN_INITIALIZER_LIST( | 1189 ALLOW_THIS_IN_INITIALIZER_LIST( |
1190 connect_callback_(this, &MockConnectJob::OnConnect)) { | 1190 connect_callback_(this, &MockConnectJob::OnConnect)) { |
1191 } | 1191 } |
1192 | 1192 |
1193 MockTransportClientSocketPool::MockConnectJob::~MockConnectJob() {} | 1193 MockTransportClientSocketPool::MockConnectJob::~MockConnectJob() {} |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 } | 1242 } |
1243 | 1243 |
1244 MockTransportClientSocketPool::~MockTransportClientSocketPool() {} | 1244 MockTransportClientSocketPool::~MockTransportClientSocketPool() {} |
1245 | 1245 |
1246 int MockTransportClientSocketPool::RequestSocket(const std::string& group_name, | 1246 int MockTransportClientSocketPool::RequestSocket(const std::string& group_name, |
1247 const void* socket_params, | 1247 const void* socket_params, |
1248 RequestPriority priority, | 1248 RequestPriority priority, |
1249 ClientSocketHandle* handle, | 1249 ClientSocketHandle* handle, |
1250 CompletionCallback* callback, | 1250 CompletionCallback* callback, |
1251 const BoundNetLog& net_log) { | 1251 const BoundNetLog& net_log) { |
1252 ClientSocket* socket = client_socket_factory_->CreateTransportClientSocket( | 1252 StreamSocket* socket = client_socket_factory_->CreateTransportClientSocket( |
1253 AddressList(), net_log.net_log(), net::NetLog::Source()); | 1253 AddressList(), net_log.net_log(), net::NetLog::Source()); |
1254 MockConnectJob* job = new MockConnectJob(socket, handle, callback); | 1254 MockConnectJob* job = new MockConnectJob(socket, handle, callback); |
1255 job_list_.push_back(job); | 1255 job_list_.push_back(job); |
1256 handle->set_pool_id(1); | 1256 handle->set_pool_id(1); |
1257 return job->Connect(); | 1257 return job->Connect(); |
1258 } | 1258 } |
1259 | 1259 |
1260 void MockTransportClientSocketPool::CancelRequest(const std::string& group_name, | 1260 void MockTransportClientSocketPool::CancelRequest(const std::string& group_name, |
1261 ClientSocketHandle* handle) { | 1261 ClientSocketHandle* handle) { |
1262 std::vector<MockConnectJob*>::iterator i; | 1262 std::vector<MockConnectJob*>::iterator i; |
1263 for (i = job_list_.begin(); i != job_list_.end(); ++i) { | 1263 for (i = job_list_.begin(); i != job_list_.end(); ++i) { |
1264 if ((*i)->CancelHandle(handle)) { | 1264 if ((*i)->CancelHandle(handle)) { |
1265 cancel_count_++; | 1265 cancel_count_++; |
1266 break; | 1266 break; |
1267 } | 1267 } |
1268 } | 1268 } |
1269 } | 1269 } |
1270 | 1270 |
1271 void MockTransportClientSocketPool::ReleaseSocket(const std::string& group_name, | 1271 void MockTransportClientSocketPool::ReleaseSocket(const std::string& group_name, |
1272 ClientSocket* socket, int id) { | 1272 StreamSocket* socket, int id) { |
1273 EXPECT_EQ(1, id); | 1273 EXPECT_EQ(1, id); |
1274 release_count_++; | 1274 release_count_++; |
1275 delete socket; | 1275 delete socket; |
1276 } | 1276 } |
1277 | 1277 |
1278 DeterministicMockClientSocketFactory::DeterministicMockClientSocketFactory() {} | 1278 DeterministicMockClientSocketFactory::DeterministicMockClientSocketFactory() {} |
1279 | 1279 |
1280 DeterministicMockClientSocketFactory::~DeterministicMockClientSocketFactory() {} | 1280 DeterministicMockClientSocketFactory::~DeterministicMockClientSocketFactory() {} |
1281 | 1281 |
1282 void DeterministicMockClientSocketFactory::AddSocketDataProvider( | 1282 void DeterministicMockClientSocketFactory::AddSocketDataProvider( |
(...skipping 10 matching lines...) Expand all Loading... |
1293 mock_data_.ResetNextIndex(); | 1293 mock_data_.ResetNextIndex(); |
1294 mock_ssl_data_.ResetNextIndex(); | 1294 mock_ssl_data_.ResetNextIndex(); |
1295 } | 1295 } |
1296 | 1296 |
1297 MockSSLClientSocket* DeterministicMockClientSocketFactory:: | 1297 MockSSLClientSocket* DeterministicMockClientSocketFactory:: |
1298 GetMockSSLClientSocket(size_t index) const { | 1298 GetMockSSLClientSocket(size_t index) const { |
1299 DCHECK_LT(index, ssl_client_sockets_.size()); | 1299 DCHECK_LT(index, ssl_client_sockets_.size()); |
1300 return ssl_client_sockets_[index]; | 1300 return ssl_client_sockets_[index]; |
1301 } | 1301 } |
1302 | 1302 |
1303 ClientSocket* DeterministicMockClientSocketFactory::CreateTransportClientSocket( | 1303 StreamSocket* DeterministicMockClientSocketFactory::CreateTransportClientSocket( |
1304 const AddressList& addresses, | 1304 const AddressList& addresses, |
1305 net::NetLog* net_log, | 1305 net::NetLog* net_log, |
1306 const net::NetLog::Source& source) { | 1306 const net::NetLog::Source& source) { |
1307 DeterministicSocketData* data_provider = mock_data().GetNext(); | 1307 DeterministicSocketData* data_provider = mock_data().GetNext(); |
1308 DeterministicMockTCPClientSocket* socket = | 1308 DeterministicMockTCPClientSocket* socket = |
1309 new DeterministicMockTCPClientSocket(net_log, data_provider); | 1309 new DeterministicMockTCPClientSocket(net_log, data_provider); |
1310 data_provider->set_socket(socket->AsWeakPtr()); | 1310 data_provider->set_socket(socket->AsWeakPtr()); |
1311 tcp_client_sockets().push_back(socket); | 1311 tcp_client_sockets().push_back(socket); |
1312 return socket; | 1312 return socket; |
1313 } | 1313 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 net_log); | 1355 net_log); |
1356 } | 1356 } |
1357 | 1357 |
1358 void MockSOCKSClientSocketPool::CancelRequest( | 1358 void MockSOCKSClientSocketPool::CancelRequest( |
1359 const std::string& group_name, | 1359 const std::string& group_name, |
1360 ClientSocketHandle* handle) { | 1360 ClientSocketHandle* handle) { |
1361 return transport_pool_->CancelRequest(group_name, handle); | 1361 return transport_pool_->CancelRequest(group_name, handle); |
1362 } | 1362 } |
1363 | 1363 |
1364 void MockSOCKSClientSocketPool::ReleaseSocket(const std::string& group_name, | 1364 void MockSOCKSClientSocketPool::ReleaseSocket(const std::string& group_name, |
1365 ClientSocket* socket, int id) { | 1365 StreamSocket* socket, int id) { |
1366 return transport_pool_->ReleaseSocket(group_name, socket, id); | 1366 return transport_pool_->ReleaseSocket(group_name, socket, id); |
1367 } | 1367 } |
1368 | 1368 |
1369 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; | 1369 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
1370 const int kSOCKS5GreetRequestLength = arraysize(kSOCKS5GreetRequest); | 1370 const int kSOCKS5GreetRequestLength = arraysize(kSOCKS5GreetRequest); |
1371 | 1371 |
1372 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; | 1372 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
1373 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse); | 1373 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse); |
1374 | 1374 |
1375 const char kSOCKS5OkRequest[] = | 1375 const char kSOCKS5OkRequest[] = |
1376 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1376 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
1377 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1377 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
1378 | 1378 |
1379 const char kSOCKS5OkResponse[] = | 1379 const char kSOCKS5OkResponse[] = |
1380 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1380 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
1381 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1381 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
1382 | 1382 |
1383 } // namespace net | 1383 } // namespace net |
OLD | NEW |