| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 connected_(false), | 120 connected_(false), |
| 121 net_log_(NetLog::Source(), net_log) { | 121 net_log_(NetLog::Source(), net_log) { |
| 122 } | 122 } |
| 123 | 123 |
| 124 void MockClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) { | 124 void MockClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) { |
| 125 NOTREACHED(); | 125 NOTREACHED(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void MockClientSocket::GetSSLCertRequestInfo( | 128 void MockClientSocket::GetSSLCertRequestInfo( |
| 129 net::SSLCertRequestInfo* cert_request_info) { | 129 net::SSLCertRequestInfo* cert_request_info) { |
| 130 NOTREACHED(); | |
| 131 } | 130 } |
| 132 | 131 |
| 133 SSLClientSocket::NextProtoStatus | 132 SSLClientSocket::NextProtoStatus |
| 134 MockClientSocket::GetNextProto(std::string* proto) { | 133 MockClientSocket::GetNextProto(std::string* proto) { |
| 135 proto->clear(); | 134 proto->clear(); |
| 136 return SSLClientSocket::kNextProtoUnsupported; | 135 return SSLClientSocket::kNextProtoUnsupported; |
| 137 } | 136 } |
| 138 | 137 |
| 139 void MockClientSocket::Disconnect() { | 138 void MockClientSocket::Disconnect() { |
| 140 connected_ = false; | 139 connected_ = false; |
| (...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse); | 1227 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse); |
| 1229 | 1228 |
| 1230 const char kSOCKS5OkRequest[] = | 1229 const char kSOCKS5OkRequest[] = |
| 1231 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1230 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
| 1232 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1231 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
| 1233 | 1232 |
| 1234 const char kSOCKS5OkResponse[] = | 1233 const char kSOCKS5OkResponse[] = |
| 1235 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1234 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 1236 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1235 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
| 1237 | 1236 |
| 1238 MockSSLClientSocketPool::MockSSLClientSocketPool( | |
| 1239 int max_sockets, | |
| 1240 int max_sockets_per_group, | |
| 1241 ClientSocketPoolHistograms* histograms, | |
| 1242 ClientSocketFactory* socket_factory, | |
| 1243 TCPClientSocketPool* tcp_pool) | |
| 1244 : SSLClientSocketPool(max_sockets, max_sockets_per_group, histograms, | |
| 1245 NULL, NULL, socket_factory, | |
| 1246 tcp_pool, | |
| 1247 NULL, NULL, NULL, NULL), | |
| 1248 client_socket_factory_(socket_factory), | |
| 1249 release_count_(0), | |
| 1250 cancel_count_(0) { | |
| 1251 } | |
| 1252 | |
| 1253 int MockSSLClientSocketPool::RequestSocket(const std::string& group_name, | |
| 1254 const void* socket_params, | |
| 1255 RequestPriority priority, | |
| 1256 ClientSocketHandle* handle, | |
| 1257 CompletionCallback* callback, | |
| 1258 const BoundNetLog& net_log) { | |
| 1259 ClientSocket* socket = client_socket_factory_->CreateTCPClientSocket( | |
| 1260 AddressList(), net_log.net_log(), net::NetLog::Source()); | |
| 1261 MockConnectJob* job = new MockConnectJob(socket, handle, callback); | |
| 1262 job_list_.push_back(job); | |
| 1263 handle->set_pool_id(1); | |
| 1264 return job->Connect(); | |
| 1265 } | |
| 1266 | |
| 1267 void MockSSLClientSocketPool::CancelRequest(const std::string& group_name, | |
| 1268 ClientSocketHandle* handle) { | |
| 1269 std::vector<MockConnectJob*>::iterator i; | |
| 1270 for (i = job_list_.begin(); i != job_list_.end(); ++i) { | |
| 1271 if ((*i)->CancelHandle(handle)) { | |
| 1272 cancel_count_++; | |
| 1273 break; | |
| 1274 } | |
| 1275 } | |
| 1276 } | |
| 1277 | |
| 1278 void MockSSLClientSocketPool::ReleaseSocket(const std::string& group_name, | |
| 1279 ClientSocket* socket, int id) { | |
| 1280 EXPECT_EQ(1, id); | |
| 1281 release_count_++; | |
| 1282 delete socket; | |
| 1283 } | |
| 1284 | |
| 1285 MockSSLClientSocketPool::~MockSSLClientSocketPool() {} | |
| 1286 | |
| 1287 MockSSLClientSocketPool::MockConnectJob::MockConnectJob( | |
| 1288 ClientSocket* socket, | |
| 1289 ClientSocketHandle* handle, | |
| 1290 CompletionCallback* callback) | |
| 1291 : socket_(socket), | |
| 1292 handle_(handle), | |
| 1293 user_callback_(callback), | |
| 1294 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 1295 connect_callback_(this, &MockConnectJob::OnConnect)) { | |
| 1296 } | |
| 1297 | |
| 1298 int MockSSLClientSocketPool::MockConnectJob::Connect() { | |
| 1299 int rv = socket_->Connect(&connect_callback_); | |
| 1300 if (rv == OK) { | |
| 1301 user_callback_ = NULL; | |
| 1302 OnConnect(OK); | |
| 1303 } | |
| 1304 return rv; | |
| 1305 } | |
| 1306 | |
| 1307 bool MockSSLClientSocketPool::MockConnectJob::CancelHandle( | |
| 1308 const ClientSocketHandle* handle) { | |
| 1309 if (handle != handle_) | |
| 1310 return false; | |
| 1311 socket_.reset(); | |
| 1312 handle_ = NULL; | |
| 1313 user_callback_ = NULL; | |
| 1314 return true; | |
| 1315 } | |
| 1316 | |
| 1317 void MockSSLClientSocketPool::MockConnectJob::OnConnect(int rv) { | |
| 1318 if (!socket_.get()) | |
| 1319 return; | |
| 1320 if (rv == OK) { | |
| 1321 handle_->set_socket(socket_.release()); | |
| 1322 } else { | |
| 1323 socket_.reset(); | |
| 1324 } | |
| 1325 | |
| 1326 handle_ = NULL; | |
| 1327 | |
| 1328 if (user_callback_) { | |
| 1329 CompletionCallback* callback = user_callback_; | |
| 1330 user_callback_ = NULL; | |
| 1331 callback->Run(rv); | |
| 1332 } | |
| 1333 } | |
| 1334 } // namespace net | 1237 } // namespace net |
| OLD | NEW |