| 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" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 13 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 14 #include "net/base/capturing_net_log.h" | 12 #include "net/base/capturing_net_log.h" |
| 15 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
| 16 #include "net/base/load_timing_info.h" | 14 #include "net/base/load_timing_info.h" |
| 17 #include "net/base/load_timing_info_test_util.h" | 15 #include "net/base/load_timing_info_test_util.h" |
| 18 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 19 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 20 #include "net/base/test_completion_callback.h" | 18 #include "net/base/test_completion_callback.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/socket/client_socket_factory.h" | |
| 23 #include "net/socket/client_socket_handle.h" | 20 #include "net/socket/client_socket_handle.h" |
| 24 #include "net/socket/client_socket_pool_histograms.h" | 21 #include "net/socket/client_socket_pool_histograms.h" |
| 25 #include "net/socket/socket_test_util.h" | 22 #include "net/socket/socket_test_util.h" |
| 26 #include "net/socket/ssl_client_socket.h" | |
| 27 #include "net/socket/stream_socket.h" | 23 #include "net/socket/stream_socket.h" |
| 24 #include "net/socket/transport_client_socket_pool_test_util.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 26 |
| 30 namespace net { | 27 namespace net { |
| 31 | 28 |
| 32 using internal::ClientSocketPoolBaseHelper; | 29 using internal::ClientSocketPoolBaseHelper; |
| 33 | 30 |
| 34 namespace { | 31 namespace { |
| 35 | 32 |
| 36 const int kMaxSockets = 32; | 33 const int kMaxSockets = 32; |
| 37 const int kMaxSocketsPerGroup = 6; | 34 const int kMaxSocketsPerGroup = 6; |
| 38 const net::RequestPriority kDefaultPriority = LOW; | 35 const net::RequestPriority kDefaultPriority = LOW; |
| 39 | 36 |
| 40 // Make sure |handle| sets load times correctly when it has been assigned a | |
| 41 // reused socket. | |
| 42 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { | |
| 43 LoadTimingInfo load_timing_info; | |
| 44 // Only pass true in as |is_reused|, as in general, HttpStream types should | |
| 45 // have stricter concepts of reuse than socket pools. | |
| 46 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info)); | |
| 47 | |
| 48 EXPECT_TRUE(load_timing_info.socket_reused); | |
| 49 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
| 50 | |
| 51 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | |
| 52 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | |
| 53 } | |
| 54 | |
| 55 // Make sure |handle| sets load times correctly when it has been assigned a | |
| 56 // fresh socket. Also runs TestLoadTimingInfoConnectedReused, since the owner | |
| 57 // of a connection where |is_reused| is false may consider the connection | |
| 58 // reused. | |
| 59 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { | |
| 60 EXPECT_FALSE(handle.is_reused()); | |
| 61 | |
| 62 LoadTimingInfo load_timing_info; | |
| 63 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info)); | |
| 64 | |
| 65 EXPECT_FALSE(load_timing_info.socket_reused); | |
| 66 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | |
| 67 | |
| 68 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | |
| 69 CONNECT_TIMING_HAS_DNS_TIMES); | |
| 70 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | |
| 71 | |
| 72 TestLoadTimingInfoConnectedReused(handle); | |
| 73 } | |
| 74 | |
| 75 void SetIPv4Address(IPEndPoint* address) { | |
| 76 IPAddressNumber number; | |
| 77 CHECK(ParseIPLiteralToNumber("1.1.1.1", &number)); | |
| 78 *address = IPEndPoint(number, 80); | |
| 79 } | |
| 80 | |
| 81 void SetIPv6Address(IPEndPoint* address) { | |
| 82 IPAddressNumber number; | |
| 83 CHECK(ParseIPLiteralToNumber("1:abcd::3:4:ff", &number)); | |
| 84 *address = IPEndPoint(number, 80); | |
| 85 } | |
| 86 | |
| 87 class MockClientSocket : public StreamSocket { | |
| 88 public: | |
| 89 MockClientSocket(const AddressList& addrlist, net::NetLog* net_log) | |
| 90 : connected_(false), | |
| 91 addrlist_(addrlist), | |
| 92 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { | |
| 93 } | |
| 94 | |
| 95 // StreamSocket implementation. | |
| 96 virtual int Connect(const CompletionCallback& callback) OVERRIDE { | |
| 97 connected_ = true; | |
| 98 return OK; | |
| 99 } | |
| 100 virtual void Disconnect() OVERRIDE { | |
| 101 connected_ = false; | |
| 102 } | |
| 103 virtual bool IsConnected() const OVERRIDE { | |
| 104 return connected_; | |
| 105 } | |
| 106 virtual bool IsConnectedAndIdle() const OVERRIDE { | |
| 107 return connected_; | |
| 108 } | |
| 109 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { | |
| 110 return ERR_UNEXPECTED; | |
| 111 } | |
| 112 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { | |
| 113 if (!connected_) | |
| 114 return ERR_SOCKET_NOT_CONNECTED; | |
| 115 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) | |
| 116 SetIPv4Address(address); | |
| 117 else | |
| 118 SetIPv6Address(address); | |
| 119 return OK; | |
| 120 } | |
| 121 virtual const BoundNetLog& NetLog() const OVERRIDE { | |
| 122 return net_log_; | |
| 123 } | |
| 124 | |
| 125 virtual void SetSubresourceSpeculation() OVERRIDE {} | |
| 126 virtual void SetOmniboxSpeculation() OVERRIDE {} | |
| 127 virtual bool WasEverUsed() const OVERRIDE { return false; } | |
| 128 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } | |
| 129 virtual bool WasNpnNegotiated() const OVERRIDE { | |
| 130 return false; | |
| 131 } | |
| 132 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { | |
| 133 return kProtoUnknown; | |
| 134 } | |
| 135 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { | |
| 136 return false; | |
| 137 } | |
| 138 | |
| 139 // Socket implementation. | |
| 140 virtual int Read(IOBuffer* buf, int buf_len, | |
| 141 const CompletionCallback& callback) OVERRIDE { | |
| 142 return ERR_FAILED; | |
| 143 } | |
| 144 virtual int Write(IOBuffer* buf, int buf_len, | |
| 145 const CompletionCallback& callback) OVERRIDE { | |
| 146 return ERR_FAILED; | |
| 147 } | |
| 148 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } | |
| 149 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } | |
| 150 | |
| 151 private: | |
| 152 bool connected_; | |
| 153 const AddressList addrlist_; | |
| 154 BoundNetLog net_log_; | |
| 155 | |
| 156 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); | |
| 157 }; | |
| 158 | |
| 159 class MockFailingClientSocket : public StreamSocket { | |
| 160 public: | |
| 161 MockFailingClientSocket(const AddressList& addrlist, net::NetLog* net_log) | |
| 162 : addrlist_(addrlist), | |
| 163 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)) { | |
| 164 } | |
| 165 | |
| 166 // StreamSocket implementation. | |
| 167 virtual int Connect(const CompletionCallback& callback) OVERRIDE { | |
| 168 return ERR_CONNECTION_FAILED; | |
| 169 } | |
| 170 | |
| 171 virtual void Disconnect() OVERRIDE {} | |
| 172 | |
| 173 virtual bool IsConnected() const OVERRIDE { | |
| 174 return false; | |
| 175 } | |
| 176 virtual bool IsConnectedAndIdle() const OVERRIDE { | |
| 177 return false; | |
| 178 } | |
| 179 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { | |
| 180 return ERR_UNEXPECTED; | |
| 181 } | |
| 182 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { | |
| 183 return ERR_UNEXPECTED; | |
| 184 } | |
| 185 virtual const BoundNetLog& NetLog() const OVERRIDE { | |
| 186 return net_log_; | |
| 187 } | |
| 188 | |
| 189 virtual void SetSubresourceSpeculation() OVERRIDE {} | |
| 190 virtual void SetOmniboxSpeculation() OVERRIDE {} | |
| 191 virtual bool WasEverUsed() const OVERRIDE { return false; } | |
| 192 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } | |
| 193 virtual bool WasNpnNegotiated() const OVERRIDE { | |
| 194 return false; | |
| 195 } | |
| 196 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { | |
| 197 return kProtoUnknown; | |
| 198 } | |
| 199 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { | |
| 200 return false; | |
| 201 } | |
| 202 | |
| 203 // Socket implementation. | |
| 204 virtual int Read(IOBuffer* buf, int buf_len, | |
| 205 const CompletionCallback& callback) OVERRIDE { | |
| 206 return ERR_FAILED; | |
| 207 } | |
| 208 | |
| 209 virtual int Write(IOBuffer* buf, int buf_len, | |
| 210 const CompletionCallback& callback) OVERRIDE { | |
| 211 return ERR_FAILED; | |
| 212 } | |
| 213 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } | |
| 214 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } | |
| 215 | |
| 216 private: | |
| 217 const AddressList addrlist_; | |
| 218 BoundNetLog net_log_; | |
| 219 | |
| 220 DISALLOW_COPY_AND_ASSIGN(MockFailingClientSocket); | |
| 221 }; | |
| 222 | |
| 223 class MockPendingClientSocket : public StreamSocket { | |
| 224 public: | |
| 225 // |should_connect| indicates whether the socket should successfully complete | |
| 226 // or fail. | |
| 227 // |should_stall| indicates that this socket should never connect. | |
| 228 // |delay_ms| is the delay, in milliseconds, before simulating a connect. | |
| 229 MockPendingClientSocket( | |
| 230 const AddressList& addrlist, | |
| 231 bool should_connect, | |
| 232 bool should_stall, | |
| 233 base::TimeDelta delay, | |
| 234 net::NetLog* net_log) | |
| 235 : should_connect_(should_connect), | |
| 236 should_stall_(should_stall), | |
| 237 delay_(delay), | |
| 238 is_connected_(false), | |
| 239 addrlist_(addrlist), | |
| 240 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_SOCKET)), | |
| 241 weak_factory_(this) { | |
| 242 } | |
| 243 | |
| 244 // StreamSocket implementation. | |
| 245 virtual int Connect(const CompletionCallback& callback) OVERRIDE { | |
| 246 base::MessageLoop::current()->PostDelayedTask( | |
| 247 FROM_HERE, | |
| 248 base::Bind(&MockPendingClientSocket::DoCallback, | |
| 249 weak_factory_.GetWeakPtr(), callback), | |
| 250 delay_); | |
| 251 return ERR_IO_PENDING; | |
| 252 } | |
| 253 | |
| 254 virtual void Disconnect() OVERRIDE {} | |
| 255 | |
| 256 virtual bool IsConnected() const OVERRIDE { | |
| 257 return is_connected_; | |
| 258 } | |
| 259 virtual bool IsConnectedAndIdle() const OVERRIDE { | |
| 260 return is_connected_; | |
| 261 } | |
| 262 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE { | |
| 263 return ERR_UNEXPECTED; | |
| 264 } | |
| 265 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE { | |
| 266 if (!is_connected_) | |
| 267 return ERR_SOCKET_NOT_CONNECTED; | |
| 268 if (addrlist_.front().GetFamily() == ADDRESS_FAMILY_IPV4) | |
| 269 SetIPv4Address(address); | |
| 270 else | |
| 271 SetIPv6Address(address); | |
| 272 return OK; | |
| 273 } | |
| 274 virtual const BoundNetLog& NetLog() const OVERRIDE { | |
| 275 return net_log_; | |
| 276 } | |
| 277 | |
| 278 virtual void SetSubresourceSpeculation() OVERRIDE {} | |
| 279 virtual void SetOmniboxSpeculation() OVERRIDE {} | |
| 280 virtual bool WasEverUsed() const OVERRIDE { return false; } | |
| 281 virtual bool UsingTCPFastOpen() const OVERRIDE { return false; } | |
| 282 virtual bool WasNpnNegotiated() const OVERRIDE { | |
| 283 return false; | |
| 284 } | |
| 285 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { | |
| 286 return kProtoUnknown; | |
| 287 } | |
| 288 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE { | |
| 289 return false; | |
| 290 } | |
| 291 | |
| 292 // Socket implementation. | |
| 293 virtual int Read(IOBuffer* buf, int buf_len, | |
| 294 const CompletionCallback& callback) OVERRIDE { | |
| 295 return ERR_FAILED; | |
| 296 } | |
| 297 | |
| 298 virtual int Write(IOBuffer* buf, int buf_len, | |
| 299 const CompletionCallback& callback) OVERRIDE { | |
| 300 return ERR_FAILED; | |
| 301 } | |
| 302 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { return OK; } | |
| 303 virtual int SetSendBufferSize(int32 size) OVERRIDE { return OK; } | |
| 304 | |
| 305 private: | |
| 306 void DoCallback(const CompletionCallback& callback) { | |
| 307 if (should_stall_) | |
| 308 return; | |
| 309 | |
| 310 if (should_connect_) { | |
| 311 is_connected_ = true; | |
| 312 callback.Run(OK); | |
| 313 } else { | |
| 314 is_connected_ = false; | |
| 315 callback.Run(ERR_CONNECTION_FAILED); | |
| 316 } | |
| 317 } | |
| 318 | |
| 319 bool should_connect_; | |
| 320 bool should_stall_; | |
| 321 base::TimeDelta delay_; | |
| 322 bool is_connected_; | |
| 323 const AddressList addrlist_; | |
| 324 BoundNetLog net_log_; | |
| 325 | |
| 326 base::WeakPtrFactory<MockPendingClientSocket> weak_factory_; | |
| 327 | |
| 328 DISALLOW_COPY_AND_ASSIGN(MockPendingClientSocket); | |
| 329 }; | |
| 330 | |
| 331 class MockClientSocketFactory : public ClientSocketFactory { | |
| 332 public: | |
| 333 enum ClientSocketType { | |
| 334 MOCK_CLIENT_SOCKET, | |
| 335 MOCK_FAILING_CLIENT_SOCKET, | |
| 336 MOCK_PENDING_CLIENT_SOCKET, | |
| 337 MOCK_PENDING_FAILING_CLIENT_SOCKET, | |
| 338 // A delayed socket will pause before connecting through the message loop. | |
| 339 MOCK_DELAYED_CLIENT_SOCKET, | |
| 340 // A stalled socket that never connects at all. | |
| 341 MOCK_STALLED_CLIENT_SOCKET, | |
| 342 }; | |
| 343 | |
| 344 explicit MockClientSocketFactory(NetLog* net_log) | |
| 345 : net_log_(net_log), allocation_count_(0), | |
| 346 client_socket_type_(MOCK_CLIENT_SOCKET), client_socket_types_(NULL), | |
| 347 client_socket_index_(0), client_socket_index_max_(0), | |
| 348 delay_(base::TimeDelta::FromMilliseconds( | |
| 349 ClientSocketPool::kMaxConnectRetryIntervalMs)) {} | |
| 350 | |
| 351 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | |
| 352 DatagramSocket::BindType bind_type, | |
| 353 const RandIntCallback& rand_int_cb, | |
| 354 NetLog* net_log, | |
| 355 const NetLog::Source& source) OVERRIDE { | |
| 356 NOTREACHED(); | |
| 357 return scoped_ptr<DatagramClientSocket>(); | |
| 358 } | |
| 359 | |
| 360 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( | |
| 361 const AddressList& addresses, | |
| 362 NetLog* /* net_log */, | |
| 363 const NetLog::Source& /* source */) OVERRIDE { | |
| 364 allocation_count_++; | |
| 365 | |
| 366 ClientSocketType type = client_socket_type_; | |
| 367 if (client_socket_types_ && | |
| 368 client_socket_index_ < client_socket_index_max_) { | |
| 369 type = client_socket_types_[client_socket_index_++]; | |
| 370 } | |
| 371 | |
| 372 switch (type) { | |
| 373 case MOCK_CLIENT_SOCKET: | |
| 374 return scoped_ptr<StreamSocket>( | |
| 375 new MockClientSocket(addresses, net_log_)); | |
| 376 case MOCK_FAILING_CLIENT_SOCKET: | |
| 377 return scoped_ptr<StreamSocket>( | |
| 378 new MockFailingClientSocket(addresses, net_log_)); | |
| 379 case MOCK_PENDING_CLIENT_SOCKET: | |
| 380 return scoped_ptr<StreamSocket>( | |
| 381 new MockPendingClientSocket( | |
| 382 addresses, true, false, base::TimeDelta(), net_log_)); | |
| 383 case MOCK_PENDING_FAILING_CLIENT_SOCKET: | |
| 384 return scoped_ptr<StreamSocket>( | |
| 385 new MockPendingClientSocket( | |
| 386 addresses, false, false, base::TimeDelta(), net_log_)); | |
| 387 case MOCK_DELAYED_CLIENT_SOCKET: | |
| 388 return scoped_ptr<StreamSocket>( | |
| 389 new MockPendingClientSocket( | |
| 390 addresses, true, false, delay_, net_log_)); | |
| 391 case MOCK_STALLED_CLIENT_SOCKET: | |
| 392 return scoped_ptr<StreamSocket>( | |
| 393 new MockPendingClientSocket( | |
| 394 addresses, true, true, base::TimeDelta(), net_log_)); | |
| 395 default: | |
| 396 NOTREACHED(); | |
| 397 return scoped_ptr<StreamSocket>( | |
| 398 new MockClientSocket(addresses, net_log_)); | |
| 399 } | |
| 400 } | |
| 401 | |
| 402 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | |
| 403 scoped_ptr<ClientSocketHandle> transport_socket, | |
| 404 const HostPortPair& host_and_port, | |
| 405 const SSLConfig& ssl_config, | |
| 406 const SSLClientSocketContext& context) OVERRIDE { | |
| 407 NOTIMPLEMENTED(); | |
| 408 return scoped_ptr<SSLClientSocket>(); | |
| 409 } | |
| 410 | |
| 411 virtual void ClearSSLSessionCache() OVERRIDE { | |
| 412 NOTIMPLEMENTED(); | |
| 413 } | |
| 414 | |
| 415 int allocation_count() const { return allocation_count_; } | |
| 416 | |
| 417 // Set the default ClientSocketType. | |
| 418 void set_client_socket_type(ClientSocketType type) { | |
| 419 client_socket_type_ = type; | |
| 420 } | |
| 421 | |
| 422 // Set a list of ClientSocketTypes to be used. | |
| 423 void set_client_socket_types(ClientSocketType* type_list, int num_types) { | |
| 424 DCHECK_GT(num_types, 0); | |
| 425 client_socket_types_ = type_list; | |
| 426 client_socket_index_ = 0; | |
| 427 client_socket_index_max_ = num_types; | |
| 428 } | |
| 429 | |
| 430 void set_delay(base::TimeDelta delay) { delay_ = delay; } | |
| 431 | |
| 432 private: | |
| 433 NetLog* net_log_; | |
| 434 int allocation_count_; | |
| 435 ClientSocketType client_socket_type_; | |
| 436 ClientSocketType* client_socket_types_; | |
| 437 int client_socket_index_; | |
| 438 int client_socket_index_max_; | |
| 439 base::TimeDelta delay_; | |
| 440 | |
| 441 DISALLOW_COPY_AND_ASSIGN(MockClientSocketFactory); | |
| 442 }; | |
| 443 | |
| 444 class TransportClientSocketPoolTest : public testing::Test { | 37 class TransportClientSocketPoolTest : public testing::Test { |
| 445 protected: | 38 protected: |
| 446 TransportClientSocketPoolTest() | 39 TransportClientSocketPoolTest() |
| 447 : connect_backup_jobs_enabled_( | 40 : connect_backup_jobs_enabled_( |
| 448 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(true)), | 41 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(true)), |
| 449 params_( | 42 params_( |
| 450 new TransportSocketParams(HostPortPair("www.google.com", 80), | 43 new TransportSocketParams(HostPortPair("www.google.com", 80), |
| 451 false, false, | 44 false, false, |
| 452 OnHostResolutionCallback())), | 45 OnHostResolutionCallback())), |
| 453 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), | 46 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } | 80 } |
| 488 | 81 |
| 489 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } | 82 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } |
| 490 size_t completion_count() const { return test_base_.completion_count(); } | 83 size_t completion_count() const { return test_base_.completion_count(); } |
| 491 | 84 |
| 492 bool connect_backup_jobs_enabled_; | 85 bool connect_backup_jobs_enabled_; |
| 493 CapturingNetLog net_log_; | 86 CapturingNetLog net_log_; |
| 494 scoped_refptr<TransportSocketParams> params_; | 87 scoped_refptr<TransportSocketParams> params_; |
| 495 scoped_ptr<ClientSocketPoolHistograms> histograms_; | 88 scoped_ptr<ClientSocketPoolHistograms> histograms_; |
| 496 scoped_ptr<MockHostResolver> host_resolver_; | 89 scoped_ptr<MockHostResolver> host_resolver_; |
| 497 MockClientSocketFactory client_socket_factory_; | 90 MockTransportClientSocketFactory client_socket_factory_; |
| 498 TransportClientSocketPool pool_; | 91 TransportClientSocketPool pool_; |
| 499 ClientSocketPoolTest test_base_; | 92 ClientSocketPoolTest test_base_; |
| 500 | 93 |
| 94 private: |
| 501 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPoolTest); | 95 DISALLOW_COPY_AND_ASSIGN(TransportClientSocketPoolTest); |
| 502 }; | 96 }; |
| 503 | 97 |
| 504 TEST(TransportConnectJobTest, MakeAddrListStartWithIPv4) { | 98 TEST(TransportConnectJobTest, MakeAddrListStartWithIPv4) { |
| 505 IPAddressNumber ip_number; | 99 IPAddressNumber ip_number; |
| 506 ASSERT_TRUE(ParseIPLiteralToNumber("192.168.1.1", &ip_number)); | 100 ASSERT_TRUE(ParseIPLiteralToNumber("192.168.1.1", &ip_number)); |
| 507 IPEndPoint addrlist_v4_1(ip_number, 80); | 101 IPEndPoint addrlist_v4_1(ip_number, 80); |
| 508 ASSERT_TRUE(ParseIPLiteralToNumber("192.168.1.2", &ip_number)); | 102 ASSERT_TRUE(ParseIPLiteralToNumber("192.168.1.2", &ip_number)); |
| 509 IPEndPoint addrlist_v4_2(ip_number, 80); | 103 IPEndPoint addrlist_v4_2(ip_number, 80); |
| 510 ASSERT_TRUE(ParseIPLiteralToNumber("2001:4860:b006::64", &ip_number)); | 104 ASSERT_TRUE(ParseIPLiteralToNumber("2001:4860:b006::64", &ip_number)); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 host_port_pair, false, false, | 204 host_port_pair, false, false, |
| 611 OnHostResolutionCallback())); | 205 OnHostResolutionCallback())); |
| 612 EXPECT_EQ(ERR_IO_PENDING, | 206 EXPECT_EQ(ERR_IO_PENDING, |
| 613 handle.Init("a", dest, kDefaultPriority, callback.callback(), | 207 handle.Init("a", dest, kDefaultPriority, callback.callback(), |
| 614 &pool_, BoundNetLog())); | 208 &pool_, BoundNetLog())); |
| 615 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult()); | 209 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult()); |
| 616 } | 210 } |
| 617 | 211 |
| 618 TEST_F(TransportClientSocketPoolTest, InitConnectionFailure) { | 212 TEST_F(TransportClientSocketPoolTest, InitConnectionFailure) { |
| 619 client_socket_factory_.set_client_socket_type( | 213 client_socket_factory_.set_client_socket_type( |
| 620 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); | 214 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); |
| 621 TestCompletionCallback callback; | 215 TestCompletionCallback callback; |
| 622 ClientSocketHandle handle; | 216 ClientSocketHandle handle; |
| 623 EXPECT_EQ(ERR_IO_PENDING, | 217 EXPECT_EQ(ERR_IO_PENDING, |
| 624 handle.Init("a", params_, kDefaultPriority, callback.callback(), | 218 handle.Init("a", params_, kDefaultPriority, callback.callback(), |
| 625 &pool_, BoundNetLog())); | 219 &pool_, BoundNetLog())); |
| 626 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); | 220 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); |
| 627 | 221 |
| 628 // Make the host resolutions complete synchronously this time. | 222 // Make the host resolutions complete synchronously this time. |
| 629 host_resolver_->set_synchronous_mode(true); | 223 host_resolver_->set_synchronous_mode(true); |
| 630 EXPECT_EQ(ERR_CONNECTION_FAILED, | 224 EXPECT_EQ(ERR_CONNECTION_FAILED, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 &pool_, BoundNetLog())); | 348 &pool_, BoundNetLog())); |
| 755 | 349 |
| 756 handle.Reset(); | 350 handle.Reset(); |
| 757 | 351 |
| 758 EXPECT_EQ(OK, callback2.WaitForResult()); | 352 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 759 handle2.Reset(); | 353 handle2.Reset(); |
| 760 } | 354 } |
| 761 | 355 |
| 762 TEST_F(TransportClientSocketPoolTest, ConnectCancelConnect) { | 356 TEST_F(TransportClientSocketPoolTest, ConnectCancelConnect) { |
| 763 client_socket_factory_.set_client_socket_type( | 357 client_socket_factory_.set_client_socket_type( |
| 764 MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); | 358 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); |
| 765 ClientSocketHandle handle; | 359 ClientSocketHandle handle; |
| 766 TestCompletionCallback callback; | 360 TestCompletionCallback callback; |
| 767 EXPECT_EQ(ERR_IO_PENDING, | 361 EXPECT_EQ(ERR_IO_PENDING, |
| 768 handle.Init("a", params_, kDefaultPriority, callback.callback(), | 362 handle.Init("a", params_, kDefaultPriority, callback.callback(), |
| 769 &pool_, BoundNetLog())); | 363 &pool_, BoundNetLog())); |
| 770 | 364 |
| 771 handle.Reset(); | 365 handle.Reset(); |
| 772 | 366 |
| 773 TestCompletionCallback callback2; | 367 TestCompletionCallback callback2; |
| 774 EXPECT_EQ(ERR_IO_PENDING, | 368 EXPECT_EQ(ERR_IO_PENDING, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 | 508 |
| 915 EXPECT_EQ(OK, callback.WaitForResult()); | 509 EXPECT_EQ(OK, callback.WaitForResult()); |
| 916 | 510 |
| 917 handle.Reset(); | 511 handle.Reset(); |
| 918 } | 512 } |
| 919 | 513 |
| 920 // Make sure that pending requests get serviced after active requests get | 514 // Make sure that pending requests get serviced after active requests get |
| 921 // cancelled. | 515 // cancelled. |
| 922 TEST_F(TransportClientSocketPoolTest, CancelActiveRequestWithPendingRequests) { | 516 TEST_F(TransportClientSocketPoolTest, CancelActiveRequestWithPendingRequests) { |
| 923 client_socket_factory_.set_client_socket_type( | 517 client_socket_factory_.set_client_socket_type( |
| 924 MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); | 518 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); |
| 925 | 519 |
| 926 // Queue up all the requests | 520 // Queue up all the requests |
| 927 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 521 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 928 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 522 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 929 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 523 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 930 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 524 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 931 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 525 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 932 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 526 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 933 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 527 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 934 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 528 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 935 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 529 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 936 | 530 |
| 937 // Now, kMaxSocketsPerGroup requests should be active. Let's cancel them. | 531 // Now, kMaxSocketsPerGroup requests should be active. Let's cancel them. |
| 938 ASSERT_LE(kMaxSocketsPerGroup, static_cast<int>(requests()->size())); | 532 ASSERT_LE(kMaxSocketsPerGroup, static_cast<int>(requests()->size())); |
| 939 for (int i = 0; i < kMaxSocketsPerGroup; i++) | 533 for (int i = 0; i < kMaxSocketsPerGroup; i++) |
| 940 (*requests())[i]->handle()->Reset(); | 534 (*requests())[i]->handle()->Reset(); |
| 941 | 535 |
| 942 // Let's wait for the rest to complete now. | 536 // Let's wait for the rest to complete now. |
| 943 for (size_t i = kMaxSocketsPerGroup; i < requests()->size(); ++i) { | 537 for (size_t i = kMaxSocketsPerGroup; i < requests()->size(); ++i) { |
| 944 EXPECT_EQ(OK, (*requests())[i]->WaitForResult()); | 538 EXPECT_EQ(OK, (*requests())[i]->WaitForResult()); |
| 945 (*requests())[i]->handle()->Reset(); | 539 (*requests())[i]->handle()->Reset(); |
| 946 } | 540 } |
| 947 | 541 |
| 948 EXPECT_EQ(requests()->size() - kMaxSocketsPerGroup, completion_count()); | 542 EXPECT_EQ(requests()->size() - kMaxSocketsPerGroup, completion_count()); |
| 949 } | 543 } |
| 950 | 544 |
| 951 // Make sure that pending requests get serviced after active requests fail. | 545 // Make sure that pending requests get serviced after active requests fail. |
| 952 TEST_F(TransportClientSocketPoolTest, FailingActiveRequestWithPendingRequests) { | 546 TEST_F(TransportClientSocketPoolTest, FailingActiveRequestWithPendingRequests) { |
| 953 client_socket_factory_.set_client_socket_type( | 547 client_socket_factory_.set_client_socket_type( |
| 954 MockClientSocketFactory::MOCK_PENDING_FAILING_CLIENT_SOCKET); | 548 MockTransportClientSocketFactory::MOCK_PENDING_FAILING_CLIENT_SOCKET); |
| 955 | 549 |
| 956 const int kNumRequests = 2 * kMaxSocketsPerGroup + 1; | 550 const int kNumRequests = 2 * kMaxSocketsPerGroup + 1; |
| 957 ASSERT_LE(kNumRequests, kMaxSockets); // Otherwise the test will hang. | 551 ASSERT_LE(kNumRequests, kMaxSockets); // Otherwise the test will hang. |
| 958 | 552 |
| 959 // Queue up all the requests | 553 // Queue up all the requests |
| 960 for (int i = 0; i < kNumRequests; i++) | 554 for (int i = 0; i < kNumRequests; i++) |
| 961 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 555 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
| 962 | 556 |
| 963 for (int i = 0; i < kNumRequests; i++) | 557 for (int i = 0; i < kNumRequests; i++) |
| 964 EXPECT_EQ(ERR_CONNECTION_FAILED, (*requests())[i]->WaitForResult()); | 558 EXPECT_EQ(ERR_CONNECTION_FAILED, (*requests())[i]->WaitForResult()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 | 609 |
| 1016 // After an IP address change, we should have 0 idle sockets. | 610 // After an IP address change, we should have 0 idle sockets. |
| 1017 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 611 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 1018 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 612 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
| 1019 | 613 |
| 1020 EXPECT_EQ(0, pool_.IdleSocketCount()); | 614 EXPECT_EQ(0, pool_.IdleSocketCount()); |
| 1021 } | 615 } |
| 1022 | 616 |
| 1023 TEST_F(TransportClientSocketPoolTest, BackupSocketConnect) { | 617 TEST_F(TransportClientSocketPoolTest, BackupSocketConnect) { |
| 1024 // Case 1 tests the first socket stalling, and the backup connecting. | 618 // Case 1 tests the first socket stalling, and the backup connecting. |
| 1025 MockClientSocketFactory::ClientSocketType case1_types[] = { | 619 MockTransportClientSocketFactory::ClientSocketType case1_types[] = { |
| 1026 // The first socket will not connect. | 620 // The first socket will not connect. |
| 1027 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, | 621 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, |
| 1028 // The second socket will connect more quickly. | 622 // The second socket will connect more quickly. |
| 1029 MockClientSocketFactory::MOCK_CLIENT_SOCKET | 623 MockTransportClientSocketFactory::MOCK_CLIENT_SOCKET |
| 1030 }; | 624 }; |
| 1031 | 625 |
| 1032 // Case 2 tests the first socket being slow, so that we start the | 626 // Case 2 tests the first socket being slow, so that we start the |
| 1033 // second connect, but the second connect stalls, and we still | 627 // second connect, but the second connect stalls, and we still |
| 1034 // complete the first. | 628 // complete the first. |
| 1035 MockClientSocketFactory::ClientSocketType case2_types[] = { | 629 MockTransportClientSocketFactory::ClientSocketType case2_types[] = { |
| 1036 // The first socket will connect, although delayed. | 630 // The first socket will connect, although delayed. |
| 1037 MockClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET, | 631 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET, |
| 1038 // The second socket will not connect. | 632 // The second socket will not connect. |
| 1039 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET | 633 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET |
| 1040 }; | 634 }; |
| 1041 | 635 |
| 1042 MockClientSocketFactory::ClientSocketType* cases[2] = { | 636 MockTransportClientSocketFactory::ClientSocketType* cases[2] = { |
| 1043 case1_types, | 637 case1_types, |
| 1044 case2_types | 638 case2_types |
| 1045 }; | 639 }; |
| 1046 | 640 |
| 1047 for (size_t index = 0; index < arraysize(cases); ++index) { | 641 for (size_t index = 0; index < arraysize(cases); ++index) { |
| 1048 client_socket_factory_.set_client_socket_types(cases[index], 2); | 642 client_socket_factory_.set_client_socket_types(cases[index], 2); |
| 1049 | 643 |
| 1050 EXPECT_EQ(0, pool_.IdleSocketCount()); | 644 EXPECT_EQ(0, pool_.IdleSocketCount()); |
| 1051 | 645 |
| 1052 TestCompletionCallback callback; | 646 TestCompletionCallback callback; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1077 | 671 |
| 1078 // Close all pending connect jobs and existing sockets. | 672 // Close all pending connect jobs and existing sockets. |
| 1079 pool_.FlushWithError(ERR_NETWORK_CHANGED); | 673 pool_.FlushWithError(ERR_NETWORK_CHANGED); |
| 1080 } | 674 } |
| 1081 } | 675 } |
| 1082 | 676 |
| 1083 // Test the case where a socket took long enough to start the creation | 677 // Test the case where a socket took long enough to start the creation |
| 1084 // of the backup socket, but then we cancelled the request after that. | 678 // of the backup socket, but then we cancelled the request after that. |
| 1085 TEST_F(TransportClientSocketPoolTest, BackupSocketCancel) { | 679 TEST_F(TransportClientSocketPoolTest, BackupSocketCancel) { |
| 1086 client_socket_factory_.set_client_socket_type( | 680 client_socket_factory_.set_client_socket_type( |
| 1087 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET); | 681 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET); |
| 1088 | 682 |
| 1089 enum { CANCEL_BEFORE_WAIT, CANCEL_AFTER_WAIT }; | 683 enum { CANCEL_BEFORE_WAIT, CANCEL_AFTER_WAIT }; |
| 1090 | 684 |
| 1091 for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) { | 685 for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) { |
| 1092 EXPECT_EQ(0, pool_.IdleSocketCount()); | 686 EXPECT_EQ(0, pool_.IdleSocketCount()); |
| 1093 | 687 |
| 1094 TestCompletionCallback callback; | 688 TestCompletionCallback callback; |
| 1095 ClientSocketHandle handle; | 689 ClientSocketHandle handle; |
| 1096 int rv = handle.Init("c", params_, LOW, callback.callback(), &pool_, | 690 int rv = handle.Init("c", params_, LOW, callback.callback(), &pool_, |
| 1097 BoundNetLog()); | 691 BoundNetLog()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1119 | 713 |
| 1120 // One socket is stalled, the other is active. | 714 // One socket is stalled, the other is active. |
| 1121 EXPECT_EQ(0, pool_.IdleSocketCount()); | 715 EXPECT_EQ(0, pool_.IdleSocketCount()); |
| 1122 } | 716 } |
| 1123 } | 717 } |
| 1124 | 718 |
| 1125 // Test the case where a socket took long enough to start the creation | 719 // Test the case where a socket took long enough to start the creation |
| 1126 // of the backup socket and never completes, and then the backup | 720 // of the backup socket and never completes, and then the backup |
| 1127 // connection fails. | 721 // connection fails. |
| 1128 TEST_F(TransportClientSocketPoolTest, BackupSocketFailAfterStall) { | 722 TEST_F(TransportClientSocketPoolTest, BackupSocketFailAfterStall) { |
| 1129 MockClientSocketFactory::ClientSocketType case_types[] = { | 723 MockTransportClientSocketFactory::ClientSocketType case_types[] = { |
| 1130 // The first socket will not connect. | 724 // The first socket will not connect. |
| 1131 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, | 725 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, |
| 1132 // The second socket will fail immediately. | 726 // The second socket will fail immediately. |
| 1133 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET | 727 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET |
| 1134 }; | 728 }; |
| 1135 | 729 |
| 1136 client_socket_factory_.set_client_socket_types(case_types, 2); | 730 client_socket_factory_.set_client_socket_types(case_types, 2); |
| 1137 | 731 |
| 1138 EXPECT_EQ(0, pool_.IdleSocketCount()); | 732 EXPECT_EQ(0, pool_.IdleSocketCount()); |
| 1139 | 733 |
| 1140 TestCompletionCallback callback; | 734 TestCompletionCallback callback; |
| 1141 ClientSocketHandle handle; | 735 ClientSocketHandle handle; |
| 1142 int rv = handle.Init("b", params_, LOW, callback.callback(), &pool_, | 736 int rv = handle.Init("b", params_, LOW, callback.callback(), &pool_, |
| 1143 BoundNetLog()); | 737 BoundNetLog()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1166 handle.Reset(); | 760 handle.Reset(); |
| 1167 | 761 |
| 1168 // Reset for the next case. | 762 // Reset for the next case. |
| 1169 host_resolver_->set_synchronous_mode(false); | 763 host_resolver_->set_synchronous_mode(false); |
| 1170 } | 764 } |
| 1171 | 765 |
| 1172 // Test the case where a socket took long enough to start the creation | 766 // Test the case where a socket took long enough to start the creation |
| 1173 // of the backup socket and eventually completes, but the backup socket | 767 // of the backup socket and eventually completes, but the backup socket |
| 1174 // fails. | 768 // fails. |
| 1175 TEST_F(TransportClientSocketPoolTest, BackupSocketFailAfterDelay) { | 769 TEST_F(TransportClientSocketPoolTest, BackupSocketFailAfterDelay) { |
| 1176 MockClientSocketFactory::ClientSocketType case_types[] = { | 770 MockTransportClientSocketFactory::ClientSocketType case_types[] = { |
| 1177 // The first socket will connect, although delayed. | 771 // The first socket will connect, although delayed. |
| 1178 MockClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET, | 772 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET, |
| 1179 // The second socket will not connect. | 773 // The second socket will not connect. |
| 1180 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET | 774 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET |
| 1181 }; | 775 }; |
| 1182 | 776 |
| 1183 client_socket_factory_.set_client_socket_types(case_types, 2); | 777 client_socket_factory_.set_client_socket_types(case_types, 2); |
| 1184 client_socket_factory_.set_delay(base::TimeDelta::FromSeconds(5)); | 778 client_socket_factory_.set_delay(base::TimeDelta::FromSeconds(5)); |
| 1185 | 779 |
| 1186 EXPECT_EQ(0, pool_.IdleSocketCount()); | 780 EXPECT_EQ(0, pool_.IdleSocketCount()); |
| 1187 | 781 |
| 1188 TestCompletionCallback callback; | 782 TestCompletionCallback callback; |
| 1189 ClientSocketHandle handle; | 783 ClientSocketHandle handle; |
| 1190 int rv = handle.Init("b", params_, LOW, callback.callback(), &pool_, | 784 int rv = handle.Init("b", params_, LOW, callback.callback(), &pool_, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1221 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv4FinishesFirst) { | 815 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv4FinishesFirst) { |
| 1222 // Create a pool without backup jobs. | 816 // Create a pool without backup jobs. |
| 1223 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); | 817 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
| 1224 TransportClientSocketPool pool(kMaxSockets, | 818 TransportClientSocketPool pool(kMaxSockets, |
| 1225 kMaxSocketsPerGroup, | 819 kMaxSocketsPerGroup, |
| 1226 histograms_.get(), | 820 histograms_.get(), |
| 1227 host_resolver_.get(), | 821 host_resolver_.get(), |
| 1228 &client_socket_factory_, | 822 &client_socket_factory_, |
| 1229 NULL); | 823 NULL); |
| 1230 | 824 |
| 1231 MockClientSocketFactory::ClientSocketType case_types[] = { | 825 MockTransportClientSocketFactory::ClientSocketType case_types[] = { |
| 1232 // This is the IPv6 socket. | 826 // This is the IPv6 socket. |
| 1233 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, | 827 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET, |
| 1234 // This is the IPv4 socket. | 828 // This is the IPv4 socket. |
| 1235 MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET | 829 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET |
| 1236 }; | 830 }; |
| 1237 | 831 |
| 1238 client_socket_factory_.set_client_socket_types(case_types, 2); | 832 client_socket_factory_.set_client_socket_types(case_types, 2); |
| 1239 | 833 |
| 1240 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. | 834 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. |
| 1241 host_resolver_->rules() | 835 host_resolver_->rules() |
| 1242 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); | 836 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); |
| 1243 | 837 |
| 1244 TestCompletionCallback callback; | 838 TestCompletionCallback callback; |
| 1245 ClientSocketHandle handle; | 839 ClientSocketHandle handle; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1264 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) { | 858 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) { |
| 1265 // Create a pool without backup jobs. | 859 // Create a pool without backup jobs. |
| 1266 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); | 860 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
| 1267 TransportClientSocketPool pool(kMaxSockets, | 861 TransportClientSocketPool pool(kMaxSockets, |
| 1268 kMaxSocketsPerGroup, | 862 kMaxSocketsPerGroup, |
| 1269 histograms_.get(), | 863 histograms_.get(), |
| 1270 host_resolver_.get(), | 864 host_resolver_.get(), |
| 1271 &client_socket_factory_, | 865 &client_socket_factory_, |
| 1272 NULL); | 866 NULL); |
| 1273 | 867 |
| 1274 MockClientSocketFactory::ClientSocketType case_types[] = { | 868 MockTransportClientSocketFactory::ClientSocketType case_types[] = { |
| 1275 // This is the IPv6 socket. | 869 // This is the IPv6 socket. |
| 1276 MockClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET, | 870 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET, |
| 1277 // This is the IPv4 socket. | 871 // This is the IPv4 socket. |
| 1278 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET | 872 MockTransportClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET |
| 1279 }; | 873 }; |
| 1280 | 874 |
| 1281 client_socket_factory_.set_client_socket_types(case_types, 2); | 875 client_socket_factory_.set_client_socket_types(case_types, 2); |
| 1282 client_socket_factory_.set_delay(base::TimeDelta::FromMilliseconds( | 876 client_socket_factory_.set_delay(base::TimeDelta::FromMilliseconds( |
| 1283 TransportConnectJob::kIPv6FallbackTimerInMs + 50)); | 877 TransportConnectJobHelper::kIPv6FallbackTimerInMs + 50)); |
| 1284 | 878 |
| 1285 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. | 879 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. |
| 1286 host_resolver_->rules() | 880 host_resolver_->rules() |
| 1287 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); | 881 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); |
| 1288 | 882 |
| 1289 TestCompletionCallback callback; | 883 TestCompletionCallback callback; |
| 1290 ClientSocketHandle handle; | 884 ClientSocketHandle handle; |
| 1291 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, | 885 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, |
| 1292 BoundNetLog()); | 886 BoundNetLog()); |
| 1293 EXPECT_EQ(ERR_IO_PENDING, rv); | 887 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1307 // Create a pool without backup jobs. | 901 // Create a pool without backup jobs. |
| 1308 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); | 902 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
| 1309 TransportClientSocketPool pool(kMaxSockets, | 903 TransportClientSocketPool pool(kMaxSockets, |
| 1310 kMaxSocketsPerGroup, | 904 kMaxSocketsPerGroup, |
| 1311 histograms_.get(), | 905 histograms_.get(), |
| 1312 host_resolver_.get(), | 906 host_resolver_.get(), |
| 1313 &client_socket_factory_, | 907 &client_socket_factory_, |
| 1314 NULL); | 908 NULL); |
| 1315 | 909 |
| 1316 client_socket_factory_.set_client_socket_type( | 910 client_socket_factory_.set_client_socket_type( |
| 1317 MockClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); | 911 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); |
| 1318 | 912 |
| 1319 // Resolve an AddressList with only IPv6 addresses. | 913 // Resolve an AddressList with only IPv6 addresses. |
| 1320 host_resolver_->rules() | 914 host_resolver_->rules() |
| 1321 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string()); | 915 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string()); |
| 1322 | 916 |
| 1323 TestCompletionCallback callback; | 917 TestCompletionCallback callback; |
| 1324 ClientSocketHandle handle; | 918 ClientSocketHandle handle; |
| 1325 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, | 919 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, |
| 1326 BoundNetLog()); | 920 BoundNetLog()); |
| 1327 EXPECT_EQ(ERR_IO_PENDING, rv); | 921 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1341 // Create a pool without backup jobs. | 935 // Create a pool without backup jobs. |
| 1342 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); | 936 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
| 1343 TransportClientSocketPool pool(kMaxSockets, | 937 TransportClientSocketPool pool(kMaxSockets, |
| 1344 kMaxSocketsPerGroup, | 938 kMaxSocketsPerGroup, |
| 1345 histograms_.get(), | 939 histograms_.get(), |
| 1346 host_resolver_.get(), | 940 host_resolver_.get(), |
| 1347 &client_socket_factory_, | 941 &client_socket_factory_, |
| 1348 NULL); | 942 NULL); |
| 1349 | 943 |
| 1350 client_socket_factory_.set_client_socket_type( | 944 client_socket_factory_.set_client_socket_type( |
| 1351 MockClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); | 945 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); |
| 1352 | 946 |
| 1353 // Resolve an AddressList with only IPv4 addresses. | 947 // Resolve an AddressList with only IPv4 addresses. |
| 1354 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string()); | 948 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string()); |
| 1355 | 949 |
| 1356 TestCompletionCallback callback; | 950 TestCompletionCallback callback; |
| 1357 ClientSocketHandle handle; | 951 ClientSocketHandle handle; |
| 1358 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, | 952 int rv = handle.Init("a", params_, LOW, callback.callback(), &pool, |
| 1359 BoundNetLog()); | 953 BoundNetLog()); |
| 1360 EXPECT_EQ(ERR_IO_PENDING, rv); | 954 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1361 EXPECT_FALSE(handle.is_initialized()); | 955 EXPECT_FALSE(handle.is_initialized()); |
| 1362 EXPECT_FALSE(handle.socket()); | 956 EXPECT_FALSE(handle.socket()); |
| 1363 | 957 |
| 1364 EXPECT_EQ(OK, callback.WaitForResult()); | 958 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1365 EXPECT_TRUE(handle.is_initialized()); | 959 EXPECT_TRUE(handle.is_initialized()); |
| 1366 EXPECT_TRUE(handle.socket()); | 960 EXPECT_TRUE(handle.socket()); |
| 1367 IPEndPoint endpoint; | 961 IPEndPoint endpoint; |
| 1368 handle.socket()->GetLocalAddress(&endpoint); | 962 handle.socket()->GetLocalAddress(&endpoint); |
| 1369 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); | 963 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); |
| 1370 EXPECT_EQ(1, client_socket_factory_.allocation_count()); | 964 EXPECT_EQ(1, client_socket_factory_.allocation_count()); |
| 1371 } | 965 } |
| 1372 | 966 |
| 1373 } // namespace | 967 } // namespace |
| 1374 | 968 |
| 1375 } // namespace net | 969 } // namespace net |
| OLD | NEW |