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/macros.h" | 10 #include "base/macros.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 EXPECT_EQ(ADDRESS_FAMILY_IPV4, addrlist[1].GetFamily()); | 175 EXPECT_EQ(ADDRESS_FAMILY_IPV4, addrlist[1].GetFamily()); |
176 EXPECT_EQ(ADDRESS_FAMILY_IPV6, addrlist[2].GetFamily()); | 176 EXPECT_EQ(ADDRESS_FAMILY_IPV6, addrlist[2].GetFamily()); |
177 EXPECT_EQ(ADDRESS_FAMILY_IPV6, addrlist[3].GetFamily()); | 177 EXPECT_EQ(ADDRESS_FAMILY_IPV6, addrlist[3].GetFamily()); |
178 } | 178 } |
179 | 179 |
180 TEST_F(TransportClientSocketPoolTest, Basic) { | 180 TEST_F(TransportClientSocketPoolTest, Basic) { |
181 TestCompletionCallback callback; | 181 TestCompletionCallback callback; |
182 ClientSocketHandle handle; | 182 ClientSocketHandle handle; |
183 int rv = | 183 int rv = |
184 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 184 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
185 callback.callback(), &pool_, BoundNetLog()); | 185 callback.callback(), &pool_, NetLogWithSource()); |
186 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 186 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
187 EXPECT_FALSE(handle.is_initialized()); | 187 EXPECT_FALSE(handle.is_initialized()); |
188 EXPECT_FALSE(handle.socket()); | 188 EXPECT_FALSE(handle.socket()); |
189 | 189 |
190 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 190 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
191 EXPECT_TRUE(handle.is_initialized()); | 191 EXPECT_TRUE(handle.is_initialized()); |
192 EXPECT_TRUE(handle.socket()); | 192 EXPECT_TRUE(handle.socket()); |
193 TestLoadTimingInfoConnectedNotReused(handle); | 193 TestLoadTimingInfoConnectedNotReused(handle); |
194 EXPECT_EQ(0u, handle.connection_attempts().size()); | 194 EXPECT_EQ(0u, handle.connection_attempts().size()); |
195 } | 195 } |
196 | 196 |
197 // Make sure that TransportConnectJob passes on its priority to its | 197 // Make sure that TransportConnectJob passes on its priority to its |
198 // HostResolver request on Init. | 198 // HostResolver request on Init. |
199 TEST_F(TransportClientSocketPoolTest, SetResolvePriorityOnInit) { | 199 TEST_F(TransportClientSocketPoolTest, SetResolvePriorityOnInit) { |
200 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) { | 200 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) { |
201 RequestPriority priority = static_cast<RequestPriority>(i); | 201 RequestPriority priority = static_cast<RequestPriority>(i); |
202 TestCompletionCallback callback; | 202 TestCompletionCallback callback; |
203 ClientSocketHandle handle; | 203 ClientSocketHandle handle; |
204 EXPECT_EQ(ERR_IO_PENDING, | 204 EXPECT_EQ(ERR_IO_PENDING, |
205 handle.Init("a", params_, priority, | 205 handle.Init("a", params_, priority, |
206 ClientSocketPool::RespectLimits::ENABLED, | 206 ClientSocketPool::RespectLimits::ENABLED, |
207 callback.callback(), &pool_, BoundNetLog())); | 207 callback.callback(), &pool_, NetLogWithSource())); |
208 EXPECT_EQ(priority, host_resolver_->last_request_priority()); | 208 EXPECT_EQ(priority, host_resolver_->last_request_priority()); |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 TEST_F(TransportClientSocketPoolTest, InitHostResolutionFailure) { | 212 TEST_F(TransportClientSocketPoolTest, InitHostResolutionFailure) { |
213 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); | 213 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); |
214 TestCompletionCallback callback; | 214 TestCompletionCallback callback; |
215 ClientSocketHandle handle; | 215 ClientSocketHandle handle; |
216 HostPortPair host_port_pair("unresolvable.host.name", 80); | 216 HostPortPair host_port_pair("unresolvable.host.name", 80); |
217 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( | 217 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( |
218 host_port_pair, false, OnHostResolutionCallback(), | 218 host_port_pair, false, OnHostResolutionCallback(), |
219 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 219 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
220 EXPECT_EQ(ERR_IO_PENDING, | 220 EXPECT_EQ(ERR_IO_PENDING, |
221 handle.Init("a", dest, kDefaultPriority, | 221 handle.Init("a", dest, kDefaultPriority, |
222 ClientSocketPool::RespectLimits::ENABLED, | 222 ClientSocketPool::RespectLimits::ENABLED, |
223 callback.callback(), &pool_, BoundNetLog())); | 223 callback.callback(), &pool_, NetLogWithSource())); |
224 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); | 224 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
225 ASSERT_EQ(1u, handle.connection_attempts().size()); | 225 ASSERT_EQ(1u, handle.connection_attempts().size()); |
226 EXPECT_TRUE(handle.connection_attempts()[0].endpoint.address().empty()); | 226 EXPECT_TRUE(handle.connection_attempts()[0].endpoint.address().empty()); |
227 EXPECT_THAT(handle.connection_attempts()[0].result, | 227 EXPECT_THAT(handle.connection_attempts()[0].result, |
228 IsError(ERR_NAME_NOT_RESOLVED)); | 228 IsError(ERR_NAME_NOT_RESOLVED)); |
229 } | 229 } |
230 | 230 |
231 TEST_F(TransportClientSocketPoolTest, InitConnectionFailure) { | 231 TEST_F(TransportClientSocketPoolTest, InitConnectionFailure) { |
232 client_socket_factory_.set_default_client_socket_type( | 232 client_socket_factory_.set_default_client_socket_type( |
233 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); | 233 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); |
234 TestCompletionCallback callback; | 234 TestCompletionCallback callback; |
235 ClientSocketHandle handle; | 235 ClientSocketHandle handle; |
236 EXPECT_EQ(ERR_IO_PENDING, | 236 EXPECT_EQ(ERR_IO_PENDING, |
237 handle.Init("a", params_, kDefaultPriority, | 237 handle.Init("a", params_, kDefaultPriority, |
238 ClientSocketPool::RespectLimits::ENABLED, | 238 ClientSocketPool::RespectLimits::ENABLED, |
239 callback.callback(), &pool_, BoundNetLog())); | 239 callback.callback(), &pool_, NetLogWithSource())); |
240 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); | 240 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); |
241 ASSERT_EQ(1u, handle.connection_attempts().size()); | 241 ASSERT_EQ(1u, handle.connection_attempts().size()); |
242 EXPECT_EQ("127.0.0.1:80", | 242 EXPECT_EQ("127.0.0.1:80", |
243 handle.connection_attempts()[0].endpoint.ToString()); | 243 handle.connection_attempts()[0].endpoint.ToString()); |
244 EXPECT_THAT(handle.connection_attempts()[0].result, | 244 EXPECT_THAT(handle.connection_attempts()[0].result, |
245 IsError(ERR_CONNECTION_FAILED)); | 245 IsError(ERR_CONNECTION_FAILED)); |
246 | 246 |
247 // Make the host resolutions complete synchronously this time. | 247 // Make the host resolutions complete synchronously this time. |
248 host_resolver_->set_synchronous_mode(true); | 248 host_resolver_->set_synchronous_mode(true); |
249 EXPECT_EQ(ERR_CONNECTION_FAILED, | 249 EXPECT_EQ(ERR_CONNECTION_FAILED, |
250 handle.Init("a", params_, kDefaultPriority, | 250 handle.Init("a", params_, kDefaultPriority, |
251 ClientSocketPool::RespectLimits::ENABLED, | 251 ClientSocketPool::RespectLimits::ENABLED, |
252 callback.callback(), &pool_, BoundNetLog())); | 252 callback.callback(), &pool_, NetLogWithSource())); |
253 ASSERT_EQ(1u, handle.connection_attempts().size()); | 253 ASSERT_EQ(1u, handle.connection_attempts().size()); |
254 EXPECT_EQ("127.0.0.1:80", | 254 EXPECT_EQ("127.0.0.1:80", |
255 handle.connection_attempts()[0].endpoint.ToString()); | 255 handle.connection_attempts()[0].endpoint.ToString()); |
256 EXPECT_THAT(handle.connection_attempts()[0].result, | 256 EXPECT_THAT(handle.connection_attempts()[0].result, |
257 IsError(ERR_CONNECTION_FAILED)); | 257 IsError(ERR_CONNECTION_FAILED)); |
258 } | 258 } |
259 | 259 |
260 TEST_F(TransportClientSocketPoolTest, PendingRequests) { | 260 TEST_F(TransportClientSocketPoolTest, PendingRequests) { |
261 // First request finishes asynchronously. | 261 // First request finishes asynchronously. |
262 EXPECT_THAT(StartRequest("a", kDefaultPriority), IsError(ERR_IO_PENDING)); | 262 EXPECT_THAT(StartRequest("a", kDefaultPriority), IsError(ERR_IO_PENDING)); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 355 |
356 // This test will start up a RequestSocket() and then immediately Cancel() it. | 356 // This test will start up a RequestSocket() and then immediately Cancel() it. |
357 // The pending host resolution will eventually complete, and destroy the | 357 // The pending host resolution will eventually complete, and destroy the |
358 // ClientSocketPool which will crash if the group was not cleared properly. | 358 // ClientSocketPool which will crash if the group was not cleared properly. |
359 TEST_F(TransportClientSocketPoolTest, CancelRequestClearGroup) { | 359 TEST_F(TransportClientSocketPoolTest, CancelRequestClearGroup) { |
360 TestCompletionCallback callback; | 360 TestCompletionCallback callback; |
361 ClientSocketHandle handle; | 361 ClientSocketHandle handle; |
362 EXPECT_EQ(ERR_IO_PENDING, | 362 EXPECT_EQ(ERR_IO_PENDING, |
363 handle.Init("a", params_, kDefaultPriority, | 363 handle.Init("a", params_, kDefaultPriority, |
364 ClientSocketPool::RespectLimits::ENABLED, | 364 ClientSocketPool::RespectLimits::ENABLED, |
365 callback.callback(), &pool_, BoundNetLog())); | 365 callback.callback(), &pool_, NetLogWithSource())); |
366 handle.Reset(); | 366 handle.Reset(); |
367 } | 367 } |
368 | 368 |
369 TEST_F(TransportClientSocketPoolTest, TwoRequestsCancelOne) { | 369 TEST_F(TransportClientSocketPoolTest, TwoRequestsCancelOne) { |
370 ClientSocketHandle handle; | 370 ClientSocketHandle handle; |
371 TestCompletionCallback callback; | 371 TestCompletionCallback callback; |
372 ClientSocketHandle handle2; | 372 ClientSocketHandle handle2; |
373 TestCompletionCallback callback2; | 373 TestCompletionCallback callback2; |
374 | 374 |
375 EXPECT_EQ(ERR_IO_PENDING, | 375 EXPECT_EQ(ERR_IO_PENDING, |
376 handle.Init("a", params_, kDefaultPriority, | 376 handle.Init("a", params_, kDefaultPriority, |
377 ClientSocketPool::RespectLimits::ENABLED, | 377 ClientSocketPool::RespectLimits::ENABLED, |
378 callback.callback(), &pool_, BoundNetLog())); | 378 callback.callback(), &pool_, NetLogWithSource())); |
379 EXPECT_EQ(ERR_IO_PENDING, | 379 EXPECT_EQ(ERR_IO_PENDING, |
380 handle2.Init("a", params_, kDefaultPriority, | 380 handle2.Init("a", params_, kDefaultPriority, |
381 ClientSocketPool::RespectLimits::ENABLED, | 381 ClientSocketPool::RespectLimits::ENABLED, |
382 callback2.callback(), &pool_, BoundNetLog())); | 382 callback2.callback(), &pool_, NetLogWithSource())); |
383 | 383 |
384 handle.Reset(); | 384 handle.Reset(); |
385 | 385 |
386 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 386 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
387 handle2.Reset(); | 387 handle2.Reset(); |
388 } | 388 } |
389 | 389 |
390 TEST_F(TransportClientSocketPoolTest, ConnectCancelConnect) { | 390 TEST_F(TransportClientSocketPoolTest, ConnectCancelConnect) { |
391 client_socket_factory_.set_default_client_socket_type( | 391 client_socket_factory_.set_default_client_socket_type( |
392 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); | 392 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); |
393 ClientSocketHandle handle; | 393 ClientSocketHandle handle; |
394 TestCompletionCallback callback; | 394 TestCompletionCallback callback; |
395 EXPECT_EQ(ERR_IO_PENDING, | 395 EXPECT_EQ(ERR_IO_PENDING, |
396 handle.Init("a", params_, kDefaultPriority, | 396 handle.Init("a", params_, kDefaultPriority, |
397 ClientSocketPool::RespectLimits::ENABLED, | 397 ClientSocketPool::RespectLimits::ENABLED, |
398 callback.callback(), &pool_, BoundNetLog())); | 398 callback.callback(), &pool_, NetLogWithSource())); |
399 | 399 |
400 handle.Reset(); | 400 handle.Reset(); |
401 | 401 |
402 TestCompletionCallback callback2; | 402 TestCompletionCallback callback2; |
403 EXPECT_EQ(ERR_IO_PENDING, | 403 EXPECT_EQ(ERR_IO_PENDING, |
404 handle.Init("a", params_, kDefaultPriority, | 404 handle.Init("a", params_, kDefaultPriority, |
405 ClientSocketPool::RespectLimits::ENABLED, | 405 ClientSocketPool::RespectLimits::ENABLED, |
406 callback2.callback(), &pool_, BoundNetLog())); | 406 callback2.callback(), &pool_, NetLogWithSource())); |
407 | 407 |
408 host_resolver_->set_synchronous_mode(true); | 408 host_resolver_->set_synchronous_mode(true); |
409 // At this point, handle has two ConnectingSockets out for it. Due to the | 409 // At this point, handle has two ConnectingSockets out for it. Due to the |
410 // setting the mock resolver into synchronous mode, the host resolution for | 410 // setting the mock resolver into synchronous mode, the host resolution for |
411 // both will return in the same loop of the MessageLoop. The client socket | 411 // both will return in the same loop of the MessageLoop. The client socket |
412 // is a pending socket, so the Connect() will asynchronously complete on the | 412 // is a pending socket, so the Connect() will asynchronously complete on the |
413 // next loop of the MessageLoop. That means that the first | 413 // next loop of the MessageLoop. That means that the first |
414 // ConnectingSocket will enter OnIOComplete, and then the second one will. | 414 // ConnectingSocket will enter OnIOComplete, and then the second one will. |
415 // If the first one is not cancelled, it will advance the load state, and | 415 // If the first one is not cancelled, it will advance the load state, and |
416 // then the second one will crash. | 416 // then the second one will crash. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 base::MessageLoop::ScopedNestableTaskAllower allow( | 509 base::MessageLoop::ScopedNestableTaskAllower allow( |
510 base::MessageLoop::current()); | 510 base::MessageLoop::current()); |
511 base::RunLoop().RunUntilIdle(); | 511 base::RunLoop().RunUntilIdle(); |
512 } | 512 } |
513 within_callback_ = true; | 513 within_callback_ = true; |
514 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( | 514 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( |
515 HostPortPair("www.google.com", 80), false, OnHostResolutionCallback(), | 515 HostPortPair("www.google.com", 80), false, OnHostResolutionCallback(), |
516 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 516 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
517 int rv = handle_->Init("a", dest, LOWEST, | 517 int rv = handle_->Init("a", dest, LOWEST, |
518 ClientSocketPool::RespectLimits::ENABLED, | 518 ClientSocketPool::RespectLimits::ENABLED, |
519 callback(), pool_, BoundNetLog()); | 519 callback(), pool_, NetLogWithSource()); |
520 EXPECT_THAT(rv, IsOk()); | 520 EXPECT_THAT(rv, IsOk()); |
521 } | 521 } |
522 } | 522 } |
523 | 523 |
524 ClientSocketHandle* const handle_; | 524 ClientSocketHandle* const handle_; |
525 TransportClientSocketPool* const pool_; | 525 TransportClientSocketPool* const pool_; |
526 bool within_callback_; | 526 bool within_callback_; |
527 CompletionCallback callback_; | 527 CompletionCallback callback_; |
528 | 528 |
529 DISALLOW_COPY_AND_ASSIGN(RequestSocketCallback); | 529 DISALLOW_COPY_AND_ASSIGN(RequestSocketCallback); |
530 }; | 530 }; |
531 | 531 |
532 TEST_F(TransportClientSocketPoolTest, RequestTwice) { | 532 TEST_F(TransportClientSocketPoolTest, RequestTwice) { |
533 ClientSocketHandle handle; | 533 ClientSocketHandle handle; |
534 RequestSocketCallback callback(&handle, &pool_); | 534 RequestSocketCallback callback(&handle, &pool_); |
535 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( | 535 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( |
536 HostPortPair("www.google.com", 80), false, OnHostResolutionCallback(), | 536 HostPortPair("www.google.com", 80), false, OnHostResolutionCallback(), |
537 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 537 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
538 int rv = | 538 int rv = |
539 handle.Init("a", dest, LOWEST, ClientSocketPool::RespectLimits::ENABLED, | 539 handle.Init("a", dest, LOWEST, ClientSocketPool::RespectLimits::ENABLED, |
540 callback.callback(), &pool_, BoundNetLog()); | 540 callback.callback(), &pool_, NetLogWithSource()); |
541 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); | 541 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
542 | 542 |
543 // The callback is going to request "www.google.com". We want it to complete | 543 // The callback is going to request "www.google.com". We want it to complete |
544 // synchronously this time. | 544 // synchronously this time. |
545 host_resolver_->set_synchronous_mode(true); | 545 host_resolver_->set_synchronous_mode(true); |
546 | 546 |
547 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 547 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
548 | 548 |
549 handle.Reset(); | 549 handle.Reset(); |
550 } | 550 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 for (int i = 0; i < kNumRequests; i++) | 595 for (int i = 0; i < kNumRequests; i++) |
596 EXPECT_THAT((*requests())[i]->WaitForResult(), | 596 EXPECT_THAT((*requests())[i]->WaitForResult(), |
597 IsError(ERR_CONNECTION_FAILED)); | 597 IsError(ERR_CONNECTION_FAILED)); |
598 } | 598 } |
599 | 599 |
600 TEST_F(TransportClientSocketPoolTest, IdleSocketLoadTiming) { | 600 TEST_F(TransportClientSocketPoolTest, IdleSocketLoadTiming) { |
601 TestCompletionCallback callback; | 601 TestCompletionCallback callback; |
602 ClientSocketHandle handle; | 602 ClientSocketHandle handle; |
603 int rv = | 603 int rv = |
604 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 604 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
605 callback.callback(), &pool_, BoundNetLog()); | 605 callback.callback(), &pool_, NetLogWithSource()); |
606 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 606 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
607 EXPECT_FALSE(handle.is_initialized()); | 607 EXPECT_FALSE(handle.is_initialized()); |
608 EXPECT_FALSE(handle.socket()); | 608 EXPECT_FALSE(handle.socket()); |
609 | 609 |
610 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 610 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
611 EXPECT_TRUE(handle.is_initialized()); | 611 EXPECT_TRUE(handle.is_initialized()); |
612 EXPECT_TRUE(handle.socket()); | 612 EXPECT_TRUE(handle.socket()); |
613 TestLoadTimingInfoConnectedNotReused(handle); | 613 TestLoadTimingInfoConnectedNotReused(handle); |
614 | 614 |
615 handle.Reset(); | 615 handle.Reset(); |
616 // Need to run all pending to release the socket back to the pool. | 616 // Need to run all pending to release the socket back to the pool. |
617 base::RunLoop().RunUntilIdle(); | 617 base::RunLoop().RunUntilIdle(); |
618 | 618 |
619 // Now we should have 1 idle socket. | 619 // Now we should have 1 idle socket. |
620 EXPECT_EQ(1, pool_.IdleSocketCount()); | 620 EXPECT_EQ(1, pool_.IdleSocketCount()); |
621 | 621 |
622 rv = handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 622 rv = handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
623 callback.callback(), &pool_, BoundNetLog()); | 623 callback.callback(), &pool_, NetLogWithSource()); |
624 EXPECT_THAT(rv, IsOk()); | 624 EXPECT_THAT(rv, IsOk()); |
625 EXPECT_EQ(0, pool_.IdleSocketCount()); | 625 EXPECT_EQ(0, pool_.IdleSocketCount()); |
626 TestLoadTimingInfoConnectedReused(handle); | 626 TestLoadTimingInfoConnectedReused(handle); |
627 } | 627 } |
628 | 628 |
629 TEST_F(TransportClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { | 629 TEST_F(TransportClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { |
630 TestCompletionCallback callback; | 630 TestCompletionCallback callback; |
631 ClientSocketHandle handle; | 631 ClientSocketHandle handle; |
632 int rv = | 632 int rv = |
633 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 633 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
634 callback.callback(), &pool_, BoundNetLog()); | 634 callback.callback(), &pool_, NetLogWithSource()); |
635 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 635 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
636 EXPECT_FALSE(handle.is_initialized()); | 636 EXPECT_FALSE(handle.is_initialized()); |
637 EXPECT_FALSE(handle.socket()); | 637 EXPECT_FALSE(handle.socket()); |
638 | 638 |
639 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 639 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
640 EXPECT_TRUE(handle.is_initialized()); | 640 EXPECT_TRUE(handle.is_initialized()); |
641 EXPECT_TRUE(handle.socket()); | 641 EXPECT_TRUE(handle.socket()); |
642 | 642 |
643 handle.Reset(); | 643 handle.Reset(); |
644 | 644 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 681 |
682 for (size_t index = 0; index < arraysize(cases); ++index) { | 682 for (size_t index = 0; index < arraysize(cases); ++index) { |
683 client_socket_factory_.set_client_socket_types(cases[index], 2); | 683 client_socket_factory_.set_client_socket_types(cases[index], 2); |
684 | 684 |
685 EXPECT_EQ(0, pool_.IdleSocketCount()); | 685 EXPECT_EQ(0, pool_.IdleSocketCount()); |
686 | 686 |
687 TestCompletionCallback callback; | 687 TestCompletionCallback callback; |
688 ClientSocketHandle handle; | 688 ClientSocketHandle handle; |
689 int rv = | 689 int rv = |
690 handle.Init("b", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 690 handle.Init("b", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
691 callback.callback(), &pool_, BoundNetLog()); | 691 callback.callback(), &pool_, NetLogWithSource()); |
692 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 692 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
693 EXPECT_FALSE(handle.is_initialized()); | 693 EXPECT_FALSE(handle.is_initialized()); |
694 EXPECT_FALSE(handle.socket()); | 694 EXPECT_FALSE(handle.socket()); |
695 | 695 |
696 // Create the first socket, set the timer. | 696 // Create the first socket, set the timer. |
697 base::RunLoop().RunUntilIdle(); | 697 base::RunLoop().RunUntilIdle(); |
698 | 698 |
699 // Wait for the backup socket timer to fire. | 699 // Wait for the backup socket timer to fire. |
700 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 700 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
701 ClientSocketPool::kMaxConnectRetryIntervalMs + 50)); | 701 ClientSocketPool::kMaxConnectRetryIntervalMs + 50)); |
(...skipping 22 matching lines...) Expand all Loading... |
724 | 724 |
725 enum { CANCEL_BEFORE_WAIT, CANCEL_AFTER_WAIT }; | 725 enum { CANCEL_BEFORE_WAIT, CANCEL_AFTER_WAIT }; |
726 | 726 |
727 for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) { | 727 for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) { |
728 EXPECT_EQ(0, pool_.IdleSocketCount()); | 728 EXPECT_EQ(0, pool_.IdleSocketCount()); |
729 | 729 |
730 TestCompletionCallback callback; | 730 TestCompletionCallback callback; |
731 ClientSocketHandle handle; | 731 ClientSocketHandle handle; |
732 int rv = | 732 int rv = |
733 handle.Init("c", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 733 handle.Init("c", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
734 callback.callback(), &pool_, BoundNetLog()); | 734 callback.callback(), &pool_, NetLogWithSource()); |
735 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 735 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
736 EXPECT_FALSE(handle.is_initialized()); | 736 EXPECT_FALSE(handle.is_initialized()); |
737 EXPECT_FALSE(handle.socket()); | 737 EXPECT_FALSE(handle.socket()); |
738 | 738 |
739 // Create the first socket, set the timer. | 739 // Create the first socket, set the timer. |
740 base::RunLoop().RunUntilIdle(); | 740 base::RunLoop().RunUntilIdle(); |
741 | 741 |
742 if (index == CANCEL_AFTER_WAIT) { | 742 if (index == CANCEL_AFTER_WAIT) { |
743 // Wait for the backup socket timer to fire. | 743 // Wait for the backup socket timer to fire. |
744 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 744 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
(...skipping 26 matching lines...) Expand all Loading... |
771 }; | 771 }; |
772 | 772 |
773 client_socket_factory_.set_client_socket_types(case_types, 2); | 773 client_socket_factory_.set_client_socket_types(case_types, 2); |
774 | 774 |
775 EXPECT_EQ(0, pool_.IdleSocketCount()); | 775 EXPECT_EQ(0, pool_.IdleSocketCount()); |
776 | 776 |
777 TestCompletionCallback callback; | 777 TestCompletionCallback callback; |
778 ClientSocketHandle handle; | 778 ClientSocketHandle handle; |
779 int rv = | 779 int rv = |
780 handle.Init("b", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 780 handle.Init("b", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
781 callback.callback(), &pool_, BoundNetLog()); | 781 callback.callback(), &pool_, NetLogWithSource()); |
782 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 782 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
783 EXPECT_FALSE(handle.is_initialized()); | 783 EXPECT_FALSE(handle.is_initialized()); |
784 EXPECT_FALSE(handle.socket()); | 784 EXPECT_FALSE(handle.socket()); |
785 | 785 |
786 // Create the first socket, set the timer. | 786 // Create the first socket, set the timer. |
787 base::RunLoop().RunUntilIdle(); | 787 base::RunLoop().RunUntilIdle(); |
788 | 788 |
789 // Wait for the backup socket timer to fire. | 789 // Wait for the backup socket timer to fire. |
790 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 790 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
791 ClientSocketPool::kMaxConnectRetryIntervalMs)); | 791 ClientSocketPool::kMaxConnectRetryIntervalMs)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 | 823 |
824 client_socket_factory_.set_client_socket_types(case_types, 2); | 824 client_socket_factory_.set_client_socket_types(case_types, 2); |
825 client_socket_factory_.set_delay(base::TimeDelta::FromSeconds(5)); | 825 client_socket_factory_.set_delay(base::TimeDelta::FromSeconds(5)); |
826 | 826 |
827 EXPECT_EQ(0, pool_.IdleSocketCount()); | 827 EXPECT_EQ(0, pool_.IdleSocketCount()); |
828 | 828 |
829 TestCompletionCallback callback; | 829 TestCompletionCallback callback; |
830 ClientSocketHandle handle; | 830 ClientSocketHandle handle; |
831 int rv = | 831 int rv = |
832 handle.Init("b", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 832 handle.Init("b", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
833 callback.callback(), &pool_, BoundNetLog()); | 833 callback.callback(), &pool_, NetLogWithSource()); |
834 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 834 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
835 EXPECT_FALSE(handle.is_initialized()); | 835 EXPECT_FALSE(handle.is_initialized()); |
836 EXPECT_FALSE(handle.socket()); | 836 EXPECT_FALSE(handle.socket()); |
837 | 837 |
838 // Create the first socket, set the timer. | 838 // Create the first socket, set the timer. |
839 base::RunLoop().RunUntilIdle(); | 839 base::RunLoop().RunUntilIdle(); |
840 | 840 |
841 // Wait for the backup socket timer to fire. | 841 // Wait for the backup socket timer to fire. |
842 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( | 842 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( |
843 ClientSocketPool::kMaxConnectRetryIntervalMs)); | 843 ClientSocketPool::kMaxConnectRetryIntervalMs)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 client_socket_factory_.set_client_socket_types(case_types, 2); | 880 client_socket_factory_.set_client_socket_types(case_types, 2); |
881 | 881 |
882 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. | 882 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. |
883 host_resolver_->rules() | 883 host_resolver_->rules() |
884 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); | 884 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); |
885 | 885 |
886 TestCompletionCallback callback; | 886 TestCompletionCallback callback; |
887 ClientSocketHandle handle; | 887 ClientSocketHandle handle; |
888 int rv = | 888 int rv = |
889 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 889 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
890 callback.callback(), &pool, BoundNetLog()); | 890 callback.callback(), &pool, NetLogWithSource()); |
891 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 891 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
892 EXPECT_FALSE(handle.is_initialized()); | 892 EXPECT_FALSE(handle.is_initialized()); |
893 EXPECT_FALSE(handle.socket()); | 893 EXPECT_FALSE(handle.socket()); |
894 | 894 |
895 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 895 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
896 EXPECT_TRUE(handle.is_initialized()); | 896 EXPECT_TRUE(handle.is_initialized()); |
897 EXPECT_TRUE(handle.socket()); | 897 EXPECT_TRUE(handle.socket()); |
898 IPEndPoint endpoint; | 898 IPEndPoint endpoint; |
899 handle.socket()->GetLocalAddress(&endpoint); | 899 handle.socket()->GetLocalAddress(&endpoint); |
900 EXPECT_TRUE(endpoint.address().IsIPv4()); | 900 EXPECT_TRUE(endpoint.address().IsIPv4()); |
(...skipping 30 matching lines...) Expand all Loading... |
931 TransportConnectJob::kIPv6FallbackTimerInMs + 50)); | 931 TransportConnectJob::kIPv6FallbackTimerInMs + 50)); |
932 | 932 |
933 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. | 933 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. |
934 host_resolver_->rules() | 934 host_resolver_->rules() |
935 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); | 935 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); |
936 | 936 |
937 TestCompletionCallback callback; | 937 TestCompletionCallback callback; |
938 ClientSocketHandle handle; | 938 ClientSocketHandle handle; |
939 int rv = | 939 int rv = |
940 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 940 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
941 callback.callback(), &pool, BoundNetLog()); | 941 callback.callback(), &pool, NetLogWithSource()); |
942 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 942 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
943 EXPECT_FALSE(handle.is_initialized()); | 943 EXPECT_FALSE(handle.is_initialized()); |
944 EXPECT_FALSE(handle.socket()); | 944 EXPECT_FALSE(handle.socket()); |
945 | 945 |
946 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 946 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
947 EXPECT_TRUE(handle.is_initialized()); | 947 EXPECT_TRUE(handle.is_initialized()); |
948 EXPECT_TRUE(handle.socket()); | 948 EXPECT_TRUE(handle.socket()); |
949 IPEndPoint endpoint; | 949 IPEndPoint endpoint; |
950 handle.socket()->GetLocalAddress(&endpoint); | 950 handle.socket()->GetLocalAddress(&endpoint); |
951 EXPECT_TRUE(endpoint.address().IsIPv6()); | 951 EXPECT_TRUE(endpoint.address().IsIPv6()); |
(...skipping 20 matching lines...) Expand all Loading... |
972 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); | 972 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); |
973 | 973 |
974 // Resolve an AddressList with only IPv6 addresses. | 974 // Resolve an AddressList with only IPv6 addresses. |
975 host_resolver_->rules() | 975 host_resolver_->rules() |
976 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string()); | 976 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string()); |
977 | 977 |
978 TestCompletionCallback callback; | 978 TestCompletionCallback callback; |
979 ClientSocketHandle handle; | 979 ClientSocketHandle handle; |
980 int rv = | 980 int rv = |
981 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 981 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
982 callback.callback(), &pool, BoundNetLog()); | 982 callback.callback(), &pool, NetLogWithSource()); |
983 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 983 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
984 EXPECT_FALSE(handle.is_initialized()); | 984 EXPECT_FALSE(handle.is_initialized()); |
985 EXPECT_FALSE(handle.socket()); | 985 EXPECT_FALSE(handle.socket()); |
986 | 986 |
987 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 987 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
988 EXPECT_TRUE(handle.is_initialized()); | 988 EXPECT_TRUE(handle.is_initialized()); |
989 EXPECT_TRUE(handle.socket()); | 989 EXPECT_TRUE(handle.socket()); |
990 IPEndPoint endpoint; | 990 IPEndPoint endpoint; |
991 handle.socket()->GetLocalAddress(&endpoint); | 991 handle.socket()->GetLocalAddress(&endpoint); |
992 EXPECT_TRUE(endpoint.address().IsIPv6()); | 992 EXPECT_TRUE(endpoint.address().IsIPv6()); |
(...skipping 11 matching lines...) Expand all Loading... |
1004 client_socket_factory_.set_default_client_socket_type( | 1004 client_socket_factory_.set_default_client_socket_type( |
1005 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); | 1005 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); |
1006 | 1006 |
1007 // Resolve an AddressList with only IPv4 addresses. | 1007 // Resolve an AddressList with only IPv4 addresses. |
1008 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string()); | 1008 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string()); |
1009 | 1009 |
1010 TestCompletionCallback callback; | 1010 TestCompletionCallback callback; |
1011 ClientSocketHandle handle; | 1011 ClientSocketHandle handle; |
1012 int rv = | 1012 int rv = |
1013 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, | 1013 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, |
1014 callback.callback(), &pool, BoundNetLog()); | 1014 callback.callback(), &pool, NetLogWithSource()); |
1015 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1015 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1016 EXPECT_FALSE(handle.is_initialized()); | 1016 EXPECT_FALSE(handle.is_initialized()); |
1017 EXPECT_FALSE(handle.socket()); | 1017 EXPECT_FALSE(handle.socket()); |
1018 | 1018 |
1019 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 1019 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
1020 EXPECT_TRUE(handle.is_initialized()); | 1020 EXPECT_TRUE(handle.is_initialized()); |
1021 EXPECT_TRUE(handle.socket()); | 1021 EXPECT_TRUE(handle.socket()); |
1022 IPEndPoint endpoint; | 1022 IPEndPoint endpoint; |
1023 handle.socket()->GetLocalAddress(&endpoint); | 1023 handle.socket()->GetLocalAddress(&endpoint); |
1024 EXPECT_TRUE(endpoint.address().IsIPv4()); | 1024 EXPECT_TRUE(endpoint.address().IsIPv4()); |
(...skipping 12 matching lines...) Expand all Loading... |
1037 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, | 1037 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, |
1038 host_resolver_.get(), &factory, NULL, NULL); | 1038 host_resolver_.get(), &factory, NULL, NULL); |
1039 // Resolve an AddressList with only IPv4 addresses. | 1039 // Resolve an AddressList with only IPv4 addresses. |
1040 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string()); | 1040 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string()); |
1041 | 1041 |
1042 TestCompletionCallback callback; | 1042 TestCompletionCallback callback; |
1043 ClientSocketHandle handle; | 1043 ClientSocketHandle handle; |
1044 // Enable TCP FastOpen in TransportSocketParams. | 1044 // Enable TCP FastOpen in TransportSocketParams. |
1045 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); | 1045 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); |
1046 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, | 1046 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, |
1047 callback.callback(), &pool, BoundNetLog()); | 1047 callback.callback(), &pool, NetLogWithSource()); |
1048 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 1048 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
1049 EXPECT_TRUE(socket_data.IsUsingTCPFastOpen()); | 1049 EXPECT_TRUE(socket_data.IsUsingTCPFastOpen()); |
1050 } | 1050 } |
1051 | 1051 |
1052 // Test that if TCP FastOpen is enabled, it is set on the socket | 1052 // Test that if TCP FastOpen is enabled, it is set on the socket |
1053 // when we have only IPv6 addresses. | 1053 // when we have only IPv6 addresses. |
1054 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv6WithNoFallback) { | 1054 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv6WithNoFallback) { |
1055 SequencedSocketData socket_data(nullptr, 0, nullptr, 0); | 1055 SequencedSocketData socket_data(nullptr, 0, nullptr, 0); |
1056 MockClientSocketFactory factory; | 1056 MockClientSocketFactory factory; |
1057 factory.AddSocketDataProvider(&socket_data); | 1057 factory.AddSocketDataProvider(&socket_data); |
1058 // Create a pool without backup jobs. | 1058 // Create a pool without backup jobs. |
1059 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); | 1059 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
1060 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, | 1060 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, |
1061 host_resolver_.get(), &factory, NULL, NULL); | 1061 host_resolver_.get(), &factory, NULL, NULL); |
1062 client_socket_factory_.set_default_client_socket_type( | 1062 client_socket_factory_.set_default_client_socket_type( |
1063 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); | 1063 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); |
1064 // Resolve an AddressList with only IPv6 addresses. | 1064 // Resolve an AddressList with only IPv6 addresses. |
1065 host_resolver_->rules() | 1065 host_resolver_->rules() |
1066 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string()); | 1066 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string()); |
1067 | 1067 |
1068 TestCompletionCallback callback; | 1068 TestCompletionCallback callback; |
1069 ClientSocketHandle handle; | 1069 ClientSocketHandle handle; |
1070 // Enable TCP FastOpen in TransportSocketParams. | 1070 // Enable TCP FastOpen in TransportSocketParams. |
1071 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); | 1071 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); |
1072 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, | 1072 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, |
1073 callback.callback(), &pool, BoundNetLog()); | 1073 callback.callback(), &pool, NetLogWithSource()); |
1074 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 1074 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
1075 EXPECT_TRUE(socket_data.IsUsingTCPFastOpen()); | 1075 EXPECT_TRUE(socket_data.IsUsingTCPFastOpen()); |
1076 } | 1076 } |
1077 | 1077 |
1078 // Test that if TCP FastOpen is enabled, it does not do anything when there | 1078 // Test that if TCP FastOpen is enabled, it does not do anything when there |
1079 // is a IPv6 address with fallback to an IPv4 address. This test tests the case | 1079 // is a IPv6 address with fallback to an IPv4 address. This test tests the case |
1080 // when the IPv6 connect fails and the IPv4 one succeeds. | 1080 // when the IPv6 connect fails and the IPv4 one succeeds. |
1081 TEST_F(TransportClientSocketPoolTest, | 1081 TEST_F(TransportClientSocketPoolTest, |
1082 NoTCPFastOpenOnIPv6FailureWithIPv4Fallback) { | 1082 NoTCPFastOpenOnIPv6FailureWithIPv4Fallback) { |
1083 SequencedSocketData socket_data_1(nullptr, 0, nullptr, 0); | 1083 SequencedSocketData socket_data_1(nullptr, 0, nullptr, 0); |
1084 socket_data_1.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); | 1084 socket_data_1.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
1085 SequencedSocketData socket_data_2(nullptr, 0, nullptr, 0); | 1085 SequencedSocketData socket_data_2(nullptr, 0, nullptr, 0); |
1086 MockClientSocketFactory factory; | 1086 MockClientSocketFactory factory; |
1087 factory.AddSocketDataProvider(&socket_data_1); | 1087 factory.AddSocketDataProvider(&socket_data_1); |
1088 factory.AddSocketDataProvider(&socket_data_2); | 1088 factory.AddSocketDataProvider(&socket_data_2); |
1089 // Create a pool without backup jobs. | 1089 // Create a pool without backup jobs. |
1090 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); | 1090 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); |
1091 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, | 1091 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, |
1092 host_resolver_.get(), &factory, NULL, NULL); | 1092 host_resolver_.get(), &factory, NULL, NULL); |
1093 | 1093 |
1094 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. | 1094 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. |
1095 host_resolver_->rules() | 1095 host_resolver_->rules() |
1096 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); | 1096 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); |
1097 | 1097 |
1098 TestCompletionCallback callback; | 1098 TestCompletionCallback callback; |
1099 ClientSocketHandle handle; | 1099 ClientSocketHandle handle; |
1100 // Enable TCP FastOpen in TransportSocketParams. | 1100 // Enable TCP FastOpen in TransportSocketParams. |
1101 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); | 1101 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); |
1102 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, | 1102 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, |
1103 callback.callback(), &pool, BoundNetLog()); | 1103 callback.callback(), &pool, NetLogWithSource()); |
1104 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 1104 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
1105 // Verify that the socket used is connected to the fallback IPv4 address. | 1105 // Verify that the socket used is connected to the fallback IPv4 address. |
1106 IPEndPoint endpoint; | 1106 IPEndPoint endpoint; |
1107 handle.socket()->GetPeerAddress(&endpoint); | 1107 handle.socket()->GetPeerAddress(&endpoint); |
1108 EXPECT_TRUE(endpoint.address().IsIPv4()); | 1108 EXPECT_TRUE(endpoint.address().IsIPv4()); |
1109 // Verify that TCP FastOpen was not turned on for the socket. | 1109 // Verify that TCP FastOpen was not turned on for the socket. |
1110 EXPECT_FALSE(socket_data_1.IsUsingTCPFastOpen()); | 1110 EXPECT_FALSE(socket_data_1.IsUsingTCPFastOpen()); |
1111 } | 1111 } |
1112 | 1112 |
1113 // Test that if TCP FastOpen is enabled, it does not do anything when there | 1113 // Test that if TCP FastOpen is enabled, it does not do anything when there |
(...skipping 11 matching lines...) Expand all Loading... |
1125 | 1125 |
1126 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. | 1126 // Resolve an AddressList with a IPv6 address first and then a IPv4 address. |
1127 host_resolver_->rules() | 1127 host_resolver_->rules() |
1128 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); | 1128 ->AddIPLiteralRule("*", "2:abcd::3:4:ff,2.2.2.2", std::string()); |
1129 | 1129 |
1130 TestCompletionCallback callback; | 1130 TestCompletionCallback callback; |
1131 ClientSocketHandle handle; | 1131 ClientSocketHandle handle; |
1132 // Enable TCP FastOpen in TransportSocketParams. | 1132 // Enable TCP FastOpen in TransportSocketParams. |
1133 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); | 1133 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); |
1134 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, | 1134 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, |
1135 callback.callback(), &pool, BoundNetLog()); | 1135 callback.callback(), &pool, NetLogWithSource()); |
1136 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 1136 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
1137 IPEndPoint endpoint; | 1137 IPEndPoint endpoint; |
1138 handle.socket()->GetPeerAddress(&endpoint); | 1138 handle.socket()->GetPeerAddress(&endpoint); |
1139 // Verify that the socket used is connected to the IPv6 address. | 1139 // Verify that the socket used is connected to the IPv6 address. |
1140 EXPECT_TRUE(endpoint.address().IsIPv6()); | 1140 EXPECT_TRUE(endpoint.address().IsIPv6()); |
1141 // Verify that TCP FastOpen was not turned on for the socket. | 1141 // Verify that TCP FastOpen was not turned on for the socket. |
1142 EXPECT_FALSE(socket_data.IsUsingTCPFastOpen()); | 1142 EXPECT_FALSE(socket_data.IsUsingTCPFastOpen()); |
1143 } | 1143 } |
1144 | 1144 |
1145 } // namespace | 1145 } // namespace |
1146 | 1146 |
1147 } // namespace net | 1147 } // namespace net |
OLD | NEW |