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/transport_client_socket_pool.h" | 5 #include "net/socket/transport_client_socket_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
14 #include "net/base/capturing_net_log.h" | |
14 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
16 #include "net/base/load_timing_info.h" | |
15 #include "net/base/mock_host_resolver.h" | 17 #include "net/base/mock_host_resolver.h" |
16 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
17 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
18 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
19 #include "net/socket/client_socket_factory.h" | 21 #include "net/socket/client_socket_factory.h" |
20 #include "net/socket/client_socket_handle.h" | 22 #include "net/socket/client_socket_handle.h" |
21 #include "net/socket/client_socket_pool_histograms.h" | 23 #include "net/socket/client_socket_pool_histograms.h" |
22 #include "net/socket/socket_test_util.h" | 24 #include "net/socket/socket_test_util.h" |
23 #include "net/socket/stream_socket.h" | 25 #include "net/socket/stream_socket.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 | 27 |
26 namespace net { | 28 namespace net { |
27 | 29 |
28 using internal::ClientSocketPoolBaseHelper; | 30 using internal::ClientSocketPoolBaseHelper; |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 const int kMaxSockets = 32; | 34 const int kMaxSockets = 32; |
33 const int kMaxSocketsPerGroup = 6; | 35 const int kMaxSocketsPerGroup = 6; |
34 const net::RequestPriority kDefaultPriority = LOW; | 36 const net::RequestPriority kDefaultPriority = LOW; |
35 | 37 |
38 // Make sure |handle| sets load times are set correctly when it has been | |
eroman
2012/12/14 04:08:35
weird
mmenke
2012/12/14 13:36:12
Done.
| |
39 // assigned a reused socket. | |
40 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { | |
41 LoadTimingInfo load_timing_info; | |
42 // Only pass true in as |is_reused|, as in general, HttpStream types should | |
43 // have stricter concepts of reuse than socket pools. | |
44 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info)); | |
45 | |
46 EXPECT_TRUE(load_timing_info.socket_reused); | |
47 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
48 | |
49 EXPECT_TRUE(load_timing_info.connect_start.is_null()); | |
50 EXPECT_TRUE(load_timing_info.connect_end.is_null()); | |
51 EXPECT_TRUE(load_timing_info.dns_start.is_null()); | |
52 EXPECT_TRUE(load_timing_info.dns_end.is_null()); | |
53 EXPECT_TRUE(load_timing_info.ssl_start.is_null()); | |
54 EXPECT_TRUE(load_timing_info.ssl_end.is_null()); | |
55 EXPECT_TRUE(load_timing_info.proxy_start.is_null()); | |
56 EXPECT_TRUE(load_timing_info.proxy_end.is_null()); | |
57 EXPECT_TRUE(load_timing_info.send_start.is_null()); | |
58 EXPECT_TRUE(load_timing_info.send_end.is_null()); | |
59 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
60 } | |
61 | |
62 // Make sure |handle| sets load times are set correctly when it has been | |
eroman
2012/12/14 04:08:35
weird
mmenke
2012/12/14 13:36:12
Done.
| |
63 // assigned a fresh socket. Also runs TestLoadTimingInfoConnectedReused, since | |
64 // the own of a connection where |is_reused| is false may consider the | |
eroman
2012/12/14 04:08:35
weird
mmenke
2012/12/14 13:36:12
Done.
| |
65 // connection reused. | |
66 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { | |
67 EXPECT_FALSE(handle.is_reused()); | |
68 | |
69 LoadTimingInfo load_timing_info; | |
70 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info)); | |
71 | |
72 EXPECT_FALSE(load_timing_info.socket_reused); | |
73 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
74 | |
75 EXPECT_FALSE(load_timing_info.dns_start.is_null()); | |
76 EXPECT_LE(load_timing_info.dns_start, load_timing_info.dns_end); | |
77 EXPECT_LE(load_timing_info.dns_end, load_timing_info.connect_start); | |
78 EXPECT_LE(load_timing_info.connect_start, load_timing_info.connect_end); | |
79 | |
80 EXPECT_TRUE(load_timing_info.ssl_start.is_null()); | |
81 EXPECT_TRUE(load_timing_info.ssl_end.is_null()); | |
82 EXPECT_TRUE(load_timing_info.proxy_start.is_null()); | |
83 EXPECT_TRUE(load_timing_info.proxy_end.is_null()); | |
84 EXPECT_TRUE(load_timing_info.send_start.is_null()); | |
85 EXPECT_TRUE(load_timing_info.send_end.is_null()); | |
86 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); | |
87 | |
88 TestLoadTimingInfoConnectedReused(handle); | |
89 } | |
90 | |
36 void SetIPv4Address(IPEndPoint* address) { | 91 void SetIPv4Address(IPEndPoint* address) { |
37 IPAddressNumber number; | 92 IPAddressNumber number; |
38 CHECK(ParseIPLiteralToNumber("1.1.1.1", &number)); | 93 CHECK(ParseIPLiteralToNumber("1.1.1.1", &number)); |
39 *address = IPEndPoint(number, 80); | 94 *address = IPEndPoint(number, 80); |
40 } | 95 } |
41 | 96 |
42 void SetIPv6Address(IPEndPoint* address) { | 97 void SetIPv6Address(IPEndPoint* address) { |
43 IPAddressNumber number; | 98 IPAddressNumber number; |
44 CHECK(ParseIPLiteralToNumber("1:abcd::3:4:ff", &number)); | 99 CHECK(ParseIPLiteralToNumber("1:abcd::3:4:ff", &number)); |
45 *address = IPEndPoint(number, 80); | 100 *address = IPEndPoint(number, 80); |
46 } | 101 } |
47 | 102 |
48 class MockClientSocket : public StreamSocket { | 103 class MockClientSocket : public StreamSocket { |
49 public: | 104 public: |
50 MockClientSocket(const AddressList& addrlist) | 105 MockClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
51 : connected_(false), | 106 : connected_(false), |
52 addrlist_(addrlist) {} | 107 addrlist_(addrlist), |
108 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { | |
109 } | |
53 | 110 |
54 // StreamSocket implementation. | 111 // StreamSocket implementation. |
55 virtual int Connect(const CompletionCallback& callback) { | 112 virtual int Connect(const CompletionCallback& callback) { |
56 connected_ = true; | 113 connected_ = true; |
57 return OK; | 114 return OK; |
58 } | 115 } |
59 virtual void Disconnect() { | 116 virtual void Disconnect() { |
60 connected_ = false; | 117 connected_ = false; |
61 } | 118 } |
62 virtual bool IsConnected() const { | 119 virtual bool IsConnected() const { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 virtual bool SetSendBufferSize(int32 size) { return true; } | 169 virtual bool SetSendBufferSize(int32 size) { return true; } |
113 | 170 |
114 private: | 171 private: |
115 bool connected_; | 172 bool connected_; |
116 const AddressList addrlist_; | 173 const AddressList addrlist_; |
117 BoundNetLog net_log_; | 174 BoundNetLog net_log_; |
118 }; | 175 }; |
119 | 176 |
120 class MockFailingClientSocket : public StreamSocket { | 177 class MockFailingClientSocket : public StreamSocket { |
121 public: | 178 public: |
122 MockFailingClientSocket(const AddressList& addrlist) : addrlist_(addrlist) {} | 179 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) |
180 : addrlist_(addrlist), | |
181 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { | |
182 } | |
123 | 183 |
124 // StreamSocket implementation. | 184 // StreamSocket implementation. |
125 virtual int Connect(const CompletionCallback& callback) { | 185 virtual int Connect(const CompletionCallback& callback) { |
126 return ERR_CONNECTION_FAILED; | 186 return ERR_CONNECTION_FAILED; |
127 } | 187 } |
128 | 188 |
129 virtual void Disconnect() {} | 189 virtual void Disconnect() {} |
130 | 190 |
131 virtual bool IsConnected() const { | 191 virtual bool IsConnected() const { |
132 return false; | 192 return false; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 class MockPendingClientSocket : public StreamSocket { | 243 class MockPendingClientSocket : public StreamSocket { |
184 public: | 244 public: |
185 // |should_connect| indicates whether the socket should successfully complete | 245 // |should_connect| indicates whether the socket should successfully complete |
186 // or fail. | 246 // or fail. |
187 // |should_stall| indicates that this socket should never connect. | 247 // |should_stall| indicates that this socket should never connect. |
188 // |delay_ms| is the delay, in milliseconds, before simulating a connect. | 248 // |delay_ms| is the delay, in milliseconds, before simulating a connect. |
189 MockPendingClientSocket( | 249 MockPendingClientSocket( |
190 const AddressList& addrlist, | 250 const AddressList& addrlist, |
191 bool should_connect, | 251 bool should_connect, |
192 bool should_stall, | 252 bool should_stall, |
193 base::TimeDelta delay) | 253 base::TimeDelta delay, |
254 net::NetLog* net_log) | |
194 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 255 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
195 should_connect_(should_connect), | 256 should_connect_(should_connect), |
196 should_stall_(should_stall), | 257 should_stall_(should_stall), |
197 delay_(delay), | 258 delay_(delay), |
198 is_connected_(false), | 259 is_connected_(false), |
199 addrlist_(addrlist) {} | 260 addrlist_(addrlist), |
261 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { | |
262 } | |
200 | 263 |
201 // StreamSocket implementation. | 264 // StreamSocket implementation. |
202 virtual int Connect(const CompletionCallback& callback) { | 265 virtual int Connect(const CompletionCallback& callback) { |
203 MessageLoop::current()->PostDelayedTask( | 266 MessageLoop::current()->PostDelayedTask( |
204 FROM_HERE, | 267 FROM_HERE, |
205 base::Bind(&MockPendingClientSocket::DoCallback, | 268 base::Bind(&MockPendingClientSocket::DoCallback, |
206 weak_factory_.GetWeakPtr(), callback), | 269 weak_factory_.GetWeakPtr(), callback), |
207 delay_); | 270 delay_); |
208 return ERR_IO_PENDING; | 271 return ERR_IO_PENDING; |
209 } | 272 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 MOCK_CLIENT_SOCKET, | 355 MOCK_CLIENT_SOCKET, |
293 MOCK_FAILING_CLIENT_SOCKET, | 356 MOCK_FAILING_CLIENT_SOCKET, |
294 MOCK_PENDING_CLIENT_SOCKET, | 357 MOCK_PENDING_CLIENT_SOCKET, |
295 MOCK_PENDING_FAILING_CLIENT_SOCKET, | 358 MOCK_PENDING_FAILING_CLIENT_SOCKET, |
296 // A delayed socket will pause before connecting through the message loop. | 359 // A delayed socket will pause before connecting through the message loop. |
297 MOCK_DELAYED_CLIENT_SOCKET, | 360 MOCK_DELAYED_CLIENT_SOCKET, |
298 // A stalled socket that never connects at all. | 361 // A stalled socket that never connects at all. |
299 MOCK_STALLED_CLIENT_SOCKET, | 362 MOCK_STALLED_CLIENT_SOCKET, |
300 }; | 363 }; |
301 | 364 |
302 MockClientSocketFactory() | 365 explicit MockClientSocketFactory(NetLog* net_log) |
303 : allocation_count_(0), client_socket_type_(MOCK_CLIENT_SOCKET), | 366 : net_log_(net_log), allocation_count_(0), |
304 client_socket_types_(NULL), client_socket_index_(0), | 367 client_socket_type_(MOCK_CLIENT_SOCKET), client_socket_types_(NULL), |
305 client_socket_index_max_(0), | 368 client_socket_index_(0), client_socket_index_max_(0), |
306 delay_(base::TimeDelta::FromMilliseconds( | 369 delay_(base::TimeDelta::FromMilliseconds( |
307 ClientSocketPool::kMaxConnectRetryIntervalMs)) {} | 370 ClientSocketPool::kMaxConnectRetryIntervalMs)) {} |
308 | 371 |
309 virtual DatagramClientSocket* CreateDatagramClientSocket( | 372 virtual DatagramClientSocket* CreateDatagramClientSocket( |
310 DatagramSocket::BindType bind_type, | 373 DatagramSocket::BindType bind_type, |
311 const RandIntCallback& rand_int_cb, | 374 const RandIntCallback& rand_int_cb, |
312 NetLog* net_log, | 375 NetLog* net_log, |
313 const NetLog::Source& source) { | 376 const NetLog::Source& source) { |
314 NOTREACHED(); | 377 NOTREACHED(); |
315 return NULL; | 378 return NULL; |
316 } | 379 } |
317 | 380 |
318 virtual StreamSocket* CreateTransportClientSocket( | 381 virtual StreamSocket* CreateTransportClientSocket( |
319 const AddressList& addresses, | 382 const AddressList& addresses, |
320 NetLog* /* net_log */, | 383 NetLog* /* net_log */, |
321 const NetLog::Source& /* source */) { | 384 const NetLog::Source& /* source */) { |
322 allocation_count_++; | 385 allocation_count_++; |
323 | 386 |
324 ClientSocketType type = client_socket_type_; | 387 ClientSocketType type = client_socket_type_; |
325 if (client_socket_types_ && | 388 if (client_socket_types_ && |
326 client_socket_index_ < client_socket_index_max_) { | 389 client_socket_index_ < client_socket_index_max_) { |
327 type = client_socket_types_[client_socket_index_++]; | 390 type = client_socket_types_[client_socket_index_++]; |
328 } | 391 } |
329 | 392 |
330 switch (type) { | 393 switch (type) { |
331 case MOCK_CLIENT_SOCKET: | 394 case MOCK_CLIENT_SOCKET: |
332 return new MockClientSocket(addresses); | 395 return new MockClientSocket(addresses, net_log_); |
333 case MOCK_FAILING_CLIENT_SOCKET: | 396 case MOCK_FAILING_CLIENT_SOCKET: |
334 return new MockFailingClientSocket(addresses); | 397 return new MockFailingClientSocket(addresses, net_log_); |
335 case MOCK_PENDING_CLIENT_SOCKET: | 398 case MOCK_PENDING_CLIENT_SOCKET: |
336 return new MockPendingClientSocket( | 399 return new MockPendingClientSocket( |
337 addresses, true, false, base::TimeDelta()); | 400 addresses, true, false, base::TimeDelta(), net_log_); |
338 case MOCK_PENDING_FAILING_CLIENT_SOCKET: | 401 case MOCK_PENDING_FAILING_CLIENT_SOCKET: |
339 return new MockPendingClientSocket( | 402 return new MockPendingClientSocket( |
340 addresses, false, false, base::TimeDelta()); | 403 addresses, false, false, base::TimeDelta(), net_log_); |
341 case MOCK_DELAYED_CLIENT_SOCKET: | 404 case MOCK_DELAYED_CLIENT_SOCKET: |
342 return new MockPendingClientSocket(addresses, true, false, delay_); | 405 return new MockPendingClientSocket( |
406 addresses, true, false, delay_, net_log_); | |
343 case MOCK_STALLED_CLIENT_SOCKET: | 407 case MOCK_STALLED_CLIENT_SOCKET: |
344 return new MockPendingClientSocket( | 408 return new MockPendingClientSocket( |
345 addresses, true, true, base::TimeDelta()); | 409 addresses, true, true, base::TimeDelta(), net_log_); |
346 default: | 410 default: |
347 NOTREACHED(); | 411 NOTREACHED(); |
348 return new MockClientSocket(addresses); | 412 return new MockClientSocket(addresses, net_log_); |
349 } | 413 } |
350 } | 414 } |
351 | 415 |
352 virtual SSLClientSocket* CreateSSLClientSocket( | 416 virtual SSLClientSocket* CreateSSLClientSocket( |
353 ClientSocketHandle* transport_socket, | 417 ClientSocketHandle* transport_socket, |
354 const HostPortPair& host_and_port, | 418 const HostPortPair& host_and_port, |
355 const SSLConfig& ssl_config, | 419 const SSLConfig& ssl_config, |
356 const SSLClientSocketContext& context) { | 420 const SSLClientSocketContext& context) { |
357 NOTIMPLEMENTED(); | 421 NOTIMPLEMENTED(); |
358 return NULL; | 422 return NULL; |
(...skipping 14 matching lines...) Expand all Loading... | |
373 void set_client_socket_types(ClientSocketType* type_list, int num_types) { | 437 void set_client_socket_types(ClientSocketType* type_list, int num_types) { |
374 DCHECK_GT(num_types, 0); | 438 DCHECK_GT(num_types, 0); |
375 client_socket_types_ = type_list; | 439 client_socket_types_ = type_list; |
376 client_socket_index_ = 0; | 440 client_socket_index_ = 0; |
377 client_socket_index_max_ = num_types; | 441 client_socket_index_max_ = num_types; |
378 } | 442 } |
379 | 443 |
380 void set_delay(base::TimeDelta delay) { delay_ = delay; } | 444 void set_delay(base::TimeDelta delay) { delay_ = delay; } |
381 | 445 |
382 private: | 446 private: |
447 NetLog* net_log_; | |
383 int allocation_count_; | 448 int allocation_count_; |
384 ClientSocketType client_socket_type_; | 449 ClientSocketType client_socket_type_; |
385 ClientSocketType* client_socket_types_; | 450 ClientSocketType* client_socket_types_; |
386 int client_socket_index_; | 451 int client_socket_index_; |
387 int client_socket_index_max_; | 452 int client_socket_index_max_; |
388 base::TimeDelta delay_; | 453 base::TimeDelta delay_; |
389 }; | 454 }; |
390 | 455 |
391 class TransportClientSocketPoolTest : public testing::Test { | 456 class TransportClientSocketPoolTest : public testing::Test { |
392 protected: | 457 protected: |
393 TransportClientSocketPoolTest() | 458 TransportClientSocketPoolTest() |
394 : connect_backup_jobs_enabled_( | 459 : connect_backup_jobs_enabled_( |
395 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(true)), | 460 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(true)), |
396 params_( | 461 params_( |
397 new TransportSocketParams(HostPortPair("www.google.com", 80), | 462 new TransportSocketParams(HostPortPair("www.google.com", 80), |
398 kDefaultPriority, false, false, | 463 kDefaultPriority, false, false, |
399 OnHostResolutionCallback())), | 464 OnHostResolutionCallback())), |
400 low_params_( | 465 low_params_( |
401 new TransportSocketParams(HostPortPair("www.google.com", 80), | 466 new TransportSocketParams(HostPortPair("www.google.com", 80), |
402 LOW, false, false, | 467 LOW, false, false, |
403 OnHostResolutionCallback())), | 468 OnHostResolutionCallback())), |
404 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), | 469 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), |
405 host_resolver_(new MockHostResolver), | 470 host_resolver_(new MockHostResolver), |
471 client_socket_factory_(&net_log_), | |
406 pool_(kMaxSockets, | 472 pool_(kMaxSockets, |
407 kMaxSocketsPerGroup, | 473 kMaxSocketsPerGroup, |
408 histograms_.get(), | 474 histograms_.get(), |
409 host_resolver_.get(), | 475 host_resolver_.get(), |
410 &client_socket_factory_, | 476 &client_socket_factory_, |
411 NULL) { | 477 NULL) { |
412 } | 478 } |
413 | 479 |
414 ~TransportClientSocketPoolTest() { | 480 ~TransportClientSocketPoolTest() { |
415 internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( | 481 internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( |
(...skipping 17 matching lines...) Expand all Loading... | |
433 } | 499 } |
434 | 500 |
435 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { | 501 void ReleaseAllConnections(ClientSocketPoolTest::KeepAlive keep_alive) { |
436 test_base_.ReleaseAllConnections(keep_alive); | 502 test_base_.ReleaseAllConnections(keep_alive); |
437 } | 503 } |
438 | 504 |
439 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } | 505 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } |
440 size_t completion_count() const { return test_base_.completion_count(); } | 506 size_t completion_count() const { return test_base_.completion_count(); } |
441 | 507 |
442 bool connect_backup_jobs_enabled_; | 508 bool connect_backup_jobs_enabled_; |
509 CapturingNetLog net_log_; | |
443 scoped_refptr<TransportSocketParams> params_; | 510 scoped_refptr<TransportSocketParams> params_; |
444 scoped_refptr<TransportSocketParams> low_params_; | 511 scoped_refptr<TransportSocketParams> low_params_; |
445 scoped_ptr<ClientSocketPoolHistograms> histograms_; | 512 scoped_ptr<ClientSocketPoolHistograms> histograms_; |
446 scoped_ptr<MockHostResolver> host_resolver_; | 513 scoped_ptr<MockHostResolver> host_resolver_; |
447 MockClientSocketFactory client_socket_factory_; | 514 MockClientSocketFactory client_socket_factory_; |
448 TransportClientSocketPool pool_; | 515 TransportClientSocketPool pool_; |
449 ClientSocketPoolTest test_base_; | 516 ClientSocketPoolTest test_base_; |
450 }; | 517 }; |
451 | 518 |
452 TEST(TransportConnectJobTest, MakeAddrListStartWithIPv4) { | 519 TEST(TransportConnectJobTest, MakeAddrListStartWithIPv4) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 ClientSocketHandle handle; | 592 ClientSocketHandle handle; |
526 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, | 593 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, |
527 BoundNetLog()); | 594 BoundNetLog()); |
528 EXPECT_EQ(ERR_IO_PENDING, rv); | 595 EXPECT_EQ(ERR_IO_PENDING, rv); |
529 EXPECT_FALSE(handle.is_initialized()); | 596 EXPECT_FALSE(handle.is_initialized()); |
530 EXPECT_FALSE(handle.socket()); | 597 EXPECT_FALSE(handle.socket()); |
531 | 598 |
532 EXPECT_EQ(OK, callback.WaitForResult()); | 599 EXPECT_EQ(OK, callback.WaitForResult()); |
533 EXPECT_TRUE(handle.is_initialized()); | 600 EXPECT_TRUE(handle.is_initialized()); |
534 EXPECT_TRUE(handle.socket()); | 601 EXPECT_TRUE(handle.socket()); |
535 | 602 TestLoadTimingInfoConnectedNotReused(handle); |
536 handle.Reset(); | |
537 } | 603 } |
538 | 604 |
539 TEST_F(TransportClientSocketPoolTest, InitHostResolutionFailure) { | 605 TEST_F(TransportClientSocketPoolTest, InitHostResolutionFailure) { |
540 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); | 606 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); |
541 TestCompletionCallback callback; | 607 TestCompletionCallback callback; |
542 ClientSocketHandle handle; | 608 ClientSocketHandle handle; |
543 HostPortPair host_port_pair("unresolvable.host.name", 80); | 609 HostPortPair host_port_pair("unresolvable.host.name", 80); |
544 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( | 610 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( |
545 host_port_pair, kDefaultPriority, false, false, | 611 host_port_pair, kDefaultPriority, false, false, |
546 OnHostResolutionCallback())); | 612 OnHostResolutionCallback())); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
892 ASSERT_LE(kNumRequests, kMaxSockets); // Otherwise the test will hang. | 958 ASSERT_LE(kNumRequests, kMaxSockets); // Otherwise the test will hang. |
893 | 959 |
894 // Queue up all the requests | 960 // Queue up all the requests |
895 for (int i = 0; i < kNumRequests; i++) | 961 for (int i = 0; i < kNumRequests; i++) |
896 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 962 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
897 | 963 |
898 for (int i = 0; i < kNumRequests; i++) | 964 for (int i = 0; i < kNumRequests; i++) |
899 EXPECT_EQ(ERR_CONNECTION_FAILED, (*requests())[i]->WaitForResult()); | 965 EXPECT_EQ(ERR_CONNECTION_FAILED, (*requests())[i]->WaitForResult()); |
900 } | 966 } |
901 | 967 |
968 TEST_F(TransportClientSocketPoolTest, IdleSocketLoadTiming) { | |
969 TestCompletionCallback callback; | |
970 ClientSocketHandle handle; | |
971 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, | |
972 BoundNetLog()); | |
973 EXPECT_EQ(ERR_IO_PENDING, rv); | |
974 EXPECT_FALSE(handle.is_initialized()); | |
975 EXPECT_FALSE(handle.socket()); | |
976 | |
977 EXPECT_EQ(OK, callback.WaitForResult()); | |
978 EXPECT_TRUE(handle.is_initialized()); | |
979 EXPECT_TRUE(handle.socket()); | |
980 TestLoadTimingInfoConnectedNotReused(handle); | |
981 | |
982 handle.Reset(); | |
983 // Need to run all pending to release the socket back to the pool. | |
984 MessageLoop::current()->RunUntilIdle(); | |
985 | |
986 // Now we should have 1 idle socket. | |
987 EXPECT_EQ(1, pool_.IdleSocketCount()); | |
988 | |
989 rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, | |
990 BoundNetLog()); | |
991 EXPECT_EQ(OK, rv); | |
992 EXPECT_EQ(0, pool_.IdleSocketCount()); | |
993 TestLoadTimingInfoConnectedReused(handle); | |
994 } | |
995 | |
902 TEST_F(TransportClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { | 996 TEST_F(TransportClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { |
903 TestCompletionCallback callback; | 997 TestCompletionCallback callback; |
904 ClientSocketHandle handle; | 998 ClientSocketHandle handle; |
905 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, | 999 int rv = handle.Init("a", low_params_, LOW, callback.callback(), &pool_, |
906 BoundNetLog()); | 1000 BoundNetLog()); |
907 EXPECT_EQ(ERR_IO_PENDING, rv); | 1001 EXPECT_EQ(ERR_IO_PENDING, rv); |
908 EXPECT_FALSE(handle.is_initialized()); | 1002 EXPECT_FALSE(handle.is_initialized()); |
909 EXPECT_FALSE(handle.socket()); | 1003 EXPECT_FALSE(handle.socket()); |
910 | 1004 |
911 EXPECT_EQ(OK, callback.WaitForResult()); | 1005 EXPECT_EQ(OK, callback.WaitForResult()); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1274 EXPECT_TRUE(handle.socket()); | 1368 EXPECT_TRUE(handle.socket()); |
1275 IPEndPoint endpoint; | 1369 IPEndPoint endpoint; |
1276 handle.socket()->GetLocalAddress(&endpoint); | 1370 handle.socket()->GetLocalAddress(&endpoint); |
1277 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); | 1371 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); |
1278 EXPECT_EQ(1, client_socket_factory_.allocation_count()); | 1372 EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
1279 } | 1373 } |
1280 | 1374 |
1281 } // namespace | 1375 } // namespace |
1282 | 1376 |
1283 } // namespace net | 1377 } // namespace net |
OLD | NEW |