OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/client_socket_pool_base.h" | 5 #include "net/socket/client_socket_pool_base.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/platform_thread.h" | 9 #include "base/platform_thread.h" |
10 #include "base/scoped_vector.h" | 10 #include "base/scoped_vector.h" |
(...skipping 230 matching lines...) Loading... |
241 class TestClientSocketPool : public ClientSocketPool { | 241 class TestClientSocketPool : public ClientSocketPool { |
242 public: | 242 public: |
243 TestClientSocketPool( | 243 TestClientSocketPool( |
244 int max_sockets, | 244 int max_sockets, |
245 int max_sockets_per_group, | 245 int max_sockets_per_group, |
246 ClientSocketPoolBase::ConnectJobFactory* connect_job_factory) | 246 ClientSocketPoolBase::ConnectJobFactory* connect_job_factory) |
247 : base_(new ClientSocketPoolBase( | 247 : base_(new ClientSocketPoolBase( |
248 max_sockets, max_sockets_per_group, connect_job_factory)) {} | 248 max_sockets, max_sockets_per_group, connect_job_factory)) {} |
249 | 249 |
250 virtual int RequestSocket( | 250 virtual int RequestSocket( |
| 251 LoadLog* load_log, |
251 const std::string& group_name, | 252 const std::string& group_name, |
252 const HostResolver::RequestInfo& resolve_info, | 253 const HostResolver::RequestInfo& resolve_info, |
253 int priority, | 254 int priority, |
254 ClientSocketHandle* handle, | 255 ClientSocketHandle* handle, |
255 CompletionCallback* callback) { | 256 CompletionCallback* callback) { |
256 return base_->RequestSocket( | 257 return base_->RequestSocket( |
257 group_name, resolve_info, priority, handle, callback); | 258 NULL, group_name, resolve_info, priority, handle, callback); |
258 } | 259 } |
259 | 260 |
260 virtual void CancelRequest( | 261 virtual void CancelRequest( |
261 const std::string& group_name, | 262 const std::string& group_name, |
262 const ClientSocketHandle* handle) { | 263 const ClientSocketHandle* handle) { |
263 base_->CancelRequest(group_name, handle); | 264 base_->CancelRequest(group_name, handle); |
264 } | 265 } |
265 | 266 |
266 virtual void ReleaseSocket( | 267 virtual void ReleaseSocket( |
267 const std::string& group_name, | 268 const std::string& group_name, |
(...skipping 109 matching lines...) Loading... |
377 | 378 |
378 // Even though a timeout is specified, it doesn't time out on a synchronous | 379 // Even though a timeout is specified, it doesn't time out on a synchronous |
379 // completion. | 380 // completion. |
380 TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) { | 381 TEST_F(ClientSocketPoolBaseTest, ConnectJob_NoTimeoutOnSynchronousCompletion) { |
381 TestConnectJobDelegate delegate; | 382 TestConnectJobDelegate delegate; |
382 ClientSocketPoolBase::Request request; | 383 ClientSocketPoolBase::Request request; |
383 ClientSocketHandle ignored(pool_.get()); | 384 ClientSocketHandle ignored(pool_.get()); |
384 request.handle = &ignored; | 385 request.handle = &ignored; |
385 scoped_ptr<TestConnectJob> job( | 386 scoped_ptr<TestConnectJob> job( |
386 new TestConnectJob(TestConnectJob::kMockJob, | 387 new TestConnectJob(TestConnectJob::kMockJob, |
387 "a", | 388 "a", |
388 request, | 389 request, |
389 base::TimeDelta::FromMicroseconds(1), | 390 base::TimeDelta::FromMicroseconds(1), |
390 &delegate, | 391 &delegate, |
391 &client_socket_factory_)); | 392 &client_socket_factory_)); |
392 EXPECT_EQ(OK, job->Connect()); | 393 EXPECT_EQ(OK, job->Connect()); |
393 } | 394 } |
394 | 395 |
395 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { | 396 TEST_F(ClientSocketPoolBaseTest, ConnectJob_TimedOut) { |
396 TestConnectJobDelegate delegate; | 397 TestConnectJobDelegate delegate; |
397 ClientSocketPoolBase::Request request; | 398 ClientSocketPoolBase::Request request; |
398 ClientSocketHandle ignored(pool_.get()); | 399 ClientSocketHandle ignored(pool_.get()); |
399 request.handle = &ignored; | 400 request.handle = &ignored; |
400 // Deleted by TestConnectJobDelegate. | 401 // Deleted by TestConnectJobDelegate. |
401 TestConnectJob* job = | 402 TestConnectJob* job = |
402 new TestConnectJob(TestConnectJob::kMockPendingJob, | 403 new TestConnectJob(TestConnectJob::kMockPendingJob, |
403 "a", | 404 "a", |
404 request, | 405 request, |
405 base::TimeDelta::FromMicroseconds(1), | 406 base::TimeDelta::FromMicroseconds(1), |
406 &delegate, | 407 &delegate, |
407 &client_socket_factory_); | 408 &client_socket_factory_); |
408 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); | 409 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); |
409 PlatformThread::Sleep(1); | 410 PlatformThread::Sleep(1); |
410 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); | 411 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); |
411 } | 412 } |
412 | 413 |
413 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { | 414 TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { |
414 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 415 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
415 | 416 |
416 TestCompletionCallback callback; | 417 TestCompletionCallback callback; |
417 ClientSocketHandle handle(pool_.get()); | 418 ClientSocketHandle handle(pool_.get()); |
418 EXPECT_EQ(OK, handle.Init("a", ignored_request_info_, kDefaultPriority, | 419 EXPECT_EQ(OK, handle.Init(NULL, "a", ignored_request_info_, |
419 &callback)); | 420 kDefaultPriority, &callback)); |
420 EXPECT_TRUE(handle.is_initialized()); | 421 EXPECT_TRUE(handle.is_initialized()); |
421 EXPECT_TRUE(handle.socket()); | 422 EXPECT_TRUE(handle.socket()); |
422 handle.Reset(); | 423 handle.Reset(); |
423 } | 424 } |
424 | 425 |
425 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { | 426 TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { |
426 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 427 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
427 | 428 |
428 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 429 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
429 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 430 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
430 int rv = req.handle()->Init("a", ignored_request_info_, 0, &req); | 431 int rv = req.handle()->Init(NULL, "a", ignored_request_info_, 0, &req); |
431 EXPECT_EQ(ERR_IO_PENDING, rv); | 432 EXPECT_EQ(ERR_IO_PENDING, rv); |
432 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); | 433 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); |
433 EXPECT_EQ(OK, req.WaitForResult()); | 434 EXPECT_EQ(OK, req.WaitForResult()); |
434 EXPECT_TRUE(req.handle()->is_initialized()); | 435 EXPECT_TRUE(req.handle()->is_initialized()); |
435 EXPECT_TRUE(req.handle()->socket()); | 436 EXPECT_TRUE(req.handle()->socket()); |
436 req.handle()->Reset(); | 437 req.handle()->Reset(); |
437 } | 438 } |
438 | 439 |
439 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { | 440 TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { |
440 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 441 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
441 | 442 |
442 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); | 443 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
443 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 444 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
444 EXPECT_EQ(ERR_CONNECTION_FAILED, | 445 EXPECT_EQ(ERR_CONNECTION_FAILED, |
445 req.handle()->Init("a", ignored_request_info_, | 446 req.handle()->Init(NULL, "a", ignored_request_info_, |
446 kDefaultPriority, &req)); | 447 kDefaultPriority, &req)); |
447 } | 448 } |
448 | 449 |
449 TEST_F(ClientSocketPoolBaseTest, InitConnectionAsynchronousFailure) { | 450 TEST_F(ClientSocketPoolBaseTest, InitConnectionAsynchronousFailure) { |
450 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 451 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
451 | 452 |
452 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); | 453 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
453 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 454 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
454 EXPECT_EQ(ERR_IO_PENDING, | 455 EXPECT_EQ(ERR_IO_PENDING, |
455 req.handle()->Init("a", ignored_request_info_, kDefaultPriority, | 456 req.handle()->Init(NULL, "a", ignored_request_info_, |
456 &req)); | 457 kDefaultPriority, &req)); |
457 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); | 458 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); |
458 EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); | 459 EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); |
459 } | 460 } |
460 | 461 |
461 TEST_F(ClientSocketPoolBaseTest, TotalLimit) { | 462 TEST_F(ClientSocketPoolBaseTest, TotalLimit) { |
462 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 463 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
463 | 464 |
464 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); | 465 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
465 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); | 466 EXPECT_EQ(OK, StartRequest("b", kDefaultPriority)); |
466 EXPECT_EQ(OK, StartRequest("c", kDefaultPriority)); | 467 EXPECT_EQ(OK, StartRequest("c", kDefaultPriority)); |
(...skipping 270 matching lines...) Loading... |
737 | 738 |
738 // This test will start up a RequestSocket() and then immediately Cancel() it. | 739 // This test will start up a RequestSocket() and then immediately Cancel() it. |
739 // The pending connect job will be cancelled and should not call back into | 740 // The pending connect job will be cancelled and should not call back into |
740 // ClientSocketPoolBase. | 741 // ClientSocketPoolBase. |
741 TEST_F(ClientSocketPoolBaseTest, CancelRequestClearGroup) { | 742 TEST_F(ClientSocketPoolBaseTest, CancelRequestClearGroup) { |
742 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 743 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
743 | 744 |
744 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 745 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
745 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 746 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
746 EXPECT_EQ(ERR_IO_PENDING, | 747 EXPECT_EQ(ERR_IO_PENDING, |
747 req.handle()->Init("a", ignored_request_info_, | 748 req.handle()->Init(NULL, "a", ignored_request_info_, |
748 kDefaultPriority, &req)); | 749 kDefaultPriority, &req)); |
749 req.handle()->Reset(); | 750 req.handle()->Reset(); |
750 } | 751 } |
751 | 752 |
752 TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { | 753 TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { |
753 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 754 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
754 | 755 |
755 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 756 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
756 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 757 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
757 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 758 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
758 | 759 |
759 EXPECT_EQ(ERR_IO_PENDING, | 760 EXPECT_EQ(ERR_IO_PENDING, |
760 req.handle()->Init("a", ignored_request_info_, | 761 req.handle()->Init(NULL, "a", ignored_request_info_, |
761 kDefaultPriority, &req)); | 762 kDefaultPriority, &req)); |
762 EXPECT_EQ(ERR_IO_PENDING, | 763 EXPECT_EQ(ERR_IO_PENDING, |
763 req2.handle()->Init("a", ignored_request_info_, | 764 req2.handle()->Init(NULL, "a", ignored_request_info_, |
764 kDefaultPriority, &req2)); | 765 kDefaultPriority, &req2)); |
765 | 766 |
766 req.handle()->Reset(); | 767 req.handle()->Reset(); |
767 | 768 |
768 EXPECT_EQ(OK, req2.WaitForResult()); | 769 EXPECT_EQ(OK, req2.WaitForResult()); |
769 req2.handle()->Reset(); | 770 req2.handle()->Reset(); |
770 } | 771 } |
771 | 772 |
772 TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { | 773 TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { |
773 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 774 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
774 | 775 |
775 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 776 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
776 ClientSocketHandle handle(pool_.get()); | 777 ClientSocketHandle handle(pool_.get()); |
777 TestCompletionCallback callback; | 778 TestCompletionCallback callback; |
778 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 779 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
779 | 780 |
780 EXPECT_EQ(ERR_IO_PENDING, | 781 EXPECT_EQ(ERR_IO_PENDING, |
781 handle.Init("a", ignored_request_info_, | 782 handle.Init(NULL, "a", ignored_request_info_, |
782 kDefaultPriority, &callback)); | 783 kDefaultPriority, &callback)); |
783 | 784 |
784 handle.Reset(); | 785 handle.Reset(); |
785 | 786 |
786 TestCompletionCallback callback2; | 787 TestCompletionCallback callback2; |
787 EXPECT_EQ(ERR_IO_PENDING, | 788 EXPECT_EQ(ERR_IO_PENDING, |
788 handle.Init("a", ignored_request_info_, | 789 handle.Init(NULL, "a", ignored_request_info_, |
789 kDefaultPriority, &callback2)); | 790 kDefaultPriority, &callback2)); |
790 | 791 |
791 EXPECT_EQ(OK, callback2.WaitForResult()); | 792 EXPECT_EQ(OK, callback2.WaitForResult()); |
792 EXPECT_FALSE(callback.have_result()); | 793 EXPECT_FALSE(callback.have_result()); |
793 | 794 |
794 handle.Reset(); | 795 handle.Reset(); |
795 } | 796 } |
796 | 797 |
797 TEST_F(ClientSocketPoolBaseTest, CancelRequest) { | 798 TEST_F(ClientSocketPoolBaseTest, CancelRequest) { |
798 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 799 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
(...skipping 42 matching lines...) Loading... |
841 | 842 |
842 virtual void RunWithParams(const Tuple1<int>& params) { | 843 virtual void RunWithParams(const Tuple1<int>& params) { |
843 callback_.RunWithParams(params); | 844 callback_.RunWithParams(params); |
844 ASSERT_EQ(OK, params.a); | 845 ASSERT_EQ(OK, params.a); |
845 | 846 |
846 if (!within_callback_) { | 847 if (!within_callback_) { |
847 test_connect_job_factory_->set_job_type(next_job_type_); | 848 test_connect_job_factory_->set_job_type(next_job_type_); |
848 handle_->Reset(); | 849 handle_->Reset(); |
849 within_callback_ = true; | 850 within_callback_ = true; |
850 int rv = handle_->Init( | 851 int rv = handle_->Init( |
851 "a", HostResolver::RequestInfo("www.google.com", 80), | 852 NULL, "a", HostResolver::RequestInfo("www.google.com", 80), |
852 kDefaultPriority, this); | 853 kDefaultPriority, this); |
853 switch (next_job_type_) { | 854 switch (next_job_type_) { |
854 case TestConnectJob::kMockJob: | 855 case TestConnectJob::kMockJob: |
855 EXPECT_EQ(OK, rv); | 856 EXPECT_EQ(OK, rv); |
856 break; | 857 break; |
857 case TestConnectJob::kMockPendingJob: | 858 case TestConnectJob::kMockPendingJob: |
858 EXPECT_EQ(ERR_IO_PENDING, rv); | 859 EXPECT_EQ(ERR_IO_PENDING, rv); |
859 break; | 860 break; |
860 default: | 861 default: |
861 FAIL() << "Unexpected job type: " << next_job_type_; | 862 FAIL() << "Unexpected job type: " << next_job_type_; |
(...skipping 15 matching lines...) Loading... |
877 }; | 878 }; |
878 | 879 |
879 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { | 880 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { |
880 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 881 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
881 | 882 |
882 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 883 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
883 ClientSocketHandle handle(pool_.get()); | 884 ClientSocketHandle handle(pool_.get()); |
884 RequestSocketCallback callback( | 885 RequestSocketCallback callback( |
885 &handle, connect_job_factory_, TestConnectJob::kMockPendingJob); | 886 &handle, connect_job_factory_, TestConnectJob::kMockPendingJob); |
886 int rv = handle.Init( | 887 int rv = handle.Init( |
887 "a", ignored_request_info_, kDefaultPriority, &callback); | 888 NULL, "a", ignored_request_info_, kDefaultPriority, &callback); |
888 ASSERT_EQ(ERR_IO_PENDING, rv); | 889 ASSERT_EQ(ERR_IO_PENDING, rv); |
889 | 890 |
890 EXPECT_EQ(OK, callback.WaitForResult()); | 891 EXPECT_EQ(OK, callback.WaitForResult()); |
891 handle.Reset(); | 892 handle.Reset(); |
892 } | 893 } |
893 | 894 |
894 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { | 895 TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { |
895 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 896 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
896 | 897 |
897 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 898 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
898 ClientSocketHandle handle(pool_.get()); | 899 ClientSocketHandle handle(pool_.get()); |
899 RequestSocketCallback callback( | 900 RequestSocketCallback callback( |
900 &handle, connect_job_factory_, TestConnectJob::kMockJob); | 901 &handle, connect_job_factory_, TestConnectJob::kMockJob); |
901 int rv = handle.Init( | 902 int rv = handle.Init( |
902 "a", ignored_request_info_, kDefaultPriority, &callback); | 903 NULL, "a", ignored_request_info_, kDefaultPriority, &callback); |
903 ASSERT_EQ(ERR_IO_PENDING, rv); | 904 ASSERT_EQ(ERR_IO_PENDING, rv); |
904 | 905 |
905 EXPECT_EQ(OK, callback.WaitForResult()); | 906 EXPECT_EQ(OK, callback.WaitForResult()); |
906 handle.Reset(); | 907 handle.Reset(); |
907 } | 908 } |
908 | 909 |
909 // Make sure that pending requests get serviced after active requests get | 910 // Make sure that pending requests get serviced after active requests get |
910 // cancelled. | 911 // cancelled. |
911 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) { | 912 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) { |
912 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 913 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
(...skipping 42 matching lines...) Loading... |
955 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); | 956 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); |
956 } | 957 } |
957 | 958 |
958 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { | 959 TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { |
959 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 960 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
960 | 961 |
961 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 962 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
962 | 963 |
963 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 964 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
964 int rv = req.handle()->Init( | 965 int rv = req.handle()->Init( |
965 "a", ignored_request_info_, kDefaultPriority, &req); | 966 NULL, "a", ignored_request_info_, kDefaultPriority, &req); |
966 EXPECT_EQ(ERR_IO_PENDING, rv); | 967 EXPECT_EQ(ERR_IO_PENDING, rv); |
967 | 968 |
968 // Cancel the active request. | 969 // Cancel the active request. |
969 req.handle()->Reset(); | 970 req.handle()->Reset(); |
970 | 971 |
971 rv = req.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req); | 972 rv = req.handle()->Init( |
| 973 NULL, "a", ignored_request_info_, kDefaultPriority, &req); |
972 EXPECT_EQ(ERR_IO_PENDING, rv); | 974 EXPECT_EQ(ERR_IO_PENDING, rv); |
973 EXPECT_EQ(OK, req.WaitForResult()); | 975 EXPECT_EQ(OK, req.WaitForResult()); |
974 | 976 |
975 EXPECT_FALSE(req.handle()->is_reused()); | 977 EXPECT_FALSE(req.handle()->is_reused()); |
976 EXPECT_EQ(1U, completion_count_); | 978 EXPECT_EQ(1U, completion_count_); |
977 EXPECT_EQ(2, client_socket_factory_.allocation_count()); | 979 EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
978 } | 980 } |
979 | 981 |
980 // A pending asynchronous job completes, which will free up a socket slot. The | 982 // A pending asynchronous job completes, which will free up a socket slot. The |
981 // next job finishes synchronously. The callback for the asynchronous job | 983 // next job finishes synchronously. The callback for the asynchronous job |
982 // should be first though. | 984 // should be first though. |
983 TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { | 985 TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { |
984 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 986 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
985 | 987 |
986 // First two jobs are async. | 988 // First two jobs are async. |
987 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); | 989 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
988 | 990 |
989 // Start job 1 (async error). | 991 // Start job 1 (async error). |
990 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); | 992 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); |
991 int rv = req1.handle()->Init("a", ignored_request_info_, | 993 int rv = req1.handle()->Init(NULL, "a", ignored_request_info_, |
992 kDefaultPriority, &req1); | 994 kDefaultPriority, &req1); |
993 EXPECT_EQ(ERR_IO_PENDING, rv); | 995 EXPECT_EQ(ERR_IO_PENDING, rv); |
994 | 996 |
995 // Start job 2 (async error). | 997 // Start job 2 (async error). |
996 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 998 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
997 rv = req2.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req2); | 999 rv = req2.handle()->Init( |
| 1000 NULL, "a", ignored_request_info_, kDefaultPriority, &req2); |
998 EXPECT_EQ(ERR_IO_PENDING, rv); | 1001 EXPECT_EQ(ERR_IO_PENDING, rv); |
999 | 1002 |
1000 // The pending job is sync. | 1003 // The pending job is sync. |
1001 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | 1004 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
1002 | 1005 |
1003 // Request 3 does not have a ConnectJob yet. It's just pending. | 1006 // Request 3 does not have a ConnectJob yet. It's just pending. |
1004 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); | 1007 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); |
1005 rv = req3.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req3); | 1008 rv = req3.handle()->Init( |
| 1009 NULL, "a", ignored_request_info_, kDefaultPriority, &req3); |
1006 EXPECT_EQ(ERR_IO_PENDING, rv); | 1010 EXPECT_EQ(ERR_IO_PENDING, rv); |
1007 | 1011 |
1008 EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult()); | 1012 EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult()); |
1009 EXPECT_EQ(ERR_CONNECTION_FAILED, req2.WaitForResult()); | 1013 EXPECT_EQ(ERR_CONNECTION_FAILED, req2.WaitForResult()); |
1010 EXPECT_EQ(OK, req3.WaitForResult()); | 1014 EXPECT_EQ(OK, req3.WaitForResult()); |
1011 | 1015 |
1012 ASSERT_EQ(3U, request_order_.size()); | 1016 ASSERT_EQ(3U, request_order_.size()); |
1013 | 1017 |
1014 // After job 1 finishes unsuccessfully, it will try to process the pending | 1018 // After job 1 finishes unsuccessfully, it will try to process the pending |
1015 // requests queue, so it starts up job 3 for request 3. This job | 1019 // requests queue, so it starts up job 3 for request 3. This job |
1016 // synchronously succeeds, so the request order is 1, 3, 2. | 1020 // synchronously succeeds, so the request order is 1, 3, 2. |
1017 EXPECT_EQ(&req1, request_order_[0]); | 1021 EXPECT_EQ(&req1, request_order_[0]); |
1018 EXPECT_EQ(&req2, request_order_[2]); | 1022 EXPECT_EQ(&req2, request_order_[2]); |
1019 EXPECT_EQ(&req3, request_order_[1]); | 1023 EXPECT_EQ(&req3, request_order_[1]); |
1020 } | 1024 } |
1021 | 1025 |
1022 // When a ConnectJob is coupled to a request, even if a free socket becomes | 1026 // When a ConnectJob is coupled to a request, even if a free socket becomes |
1023 // available, the request will be serviced by the ConnectJob. | 1027 // available, the request will be serviced by the ConnectJob. |
1024 TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { | 1028 TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { |
1025 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1029 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1026 ClientSocketPoolBase::EnableLateBindingOfSockets(false); | 1030 ClientSocketPoolBase::EnableLateBindingOfSockets(false); |
1027 | 1031 |
1028 // Start job 1 (async OK) | 1032 // Start job 1 (async OK) |
1029 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1033 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1030 | 1034 |
1031 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); | 1035 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); |
1032 int rv = req1.handle()->Init("a", ignored_request_info_, kDefaultPriority, | 1036 int rv = req1.handle()->Init(NULL, "a", ignored_request_info_, |
1033 &req1); | 1037 kDefaultPriority, &req1); |
1034 EXPECT_EQ(ERR_IO_PENDING, rv); | 1038 EXPECT_EQ(ERR_IO_PENDING, rv); |
1035 EXPECT_EQ(OK, req1.WaitForResult()); | 1039 EXPECT_EQ(OK, req1.WaitForResult()); |
1036 | 1040 |
1037 // Job 1 finished OK. Start job 2 (also async OK). Release socket 1. | 1041 // Job 1 finished OK. Start job 2 (also async OK). Release socket 1. |
1038 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); | 1042 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
1039 | 1043 |
1040 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 1044 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
1041 rv = req2.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req2); | 1045 rv = req2.handle()->Init( |
| 1046 NULL, "a", ignored_request_info_, kDefaultPriority, &req2); |
1042 EXPECT_EQ(ERR_IO_PENDING, rv); | 1047 EXPECT_EQ(ERR_IO_PENDING, rv); |
1043 req1.handle()->Reset(); | 1048 req1.handle()->Reset(); |
1044 MessageLoop::current()->RunAllPending(); // Run the DoReleaseSocket() | 1049 MessageLoop::current()->RunAllPending(); // Run the DoReleaseSocket() |
1045 | 1050 |
1046 // Job 2 is pending. Start request 3 (which has no associated job since it | 1051 // Job 2 is pending. Start request 3 (which has no associated job since it |
1047 // will use the idle socket). | 1052 // will use the idle socket). |
1048 | 1053 |
1049 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); | 1054 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); |
1050 rv = req3.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req3); | 1055 rv = req3.handle()->Init( |
| 1056 NULL, "a", ignored_request_info_, kDefaultPriority, &req3); |
1051 EXPECT_EQ(OK, rv); | 1057 EXPECT_EQ(OK, rv); |
1052 | 1058 |
1053 EXPECT_FALSE(req2.handle()->socket()); | 1059 EXPECT_FALSE(req2.handle()->socket()); |
1054 client_socket_factory_.SignalJobs(); | 1060 client_socket_factory_.SignalJobs(); |
1055 EXPECT_EQ(OK, req2.WaitForResult()); | 1061 EXPECT_EQ(OK, req2.WaitForResult()); |
1056 | 1062 |
1057 ASSERT_EQ(2U, request_order_.size()); | 1063 ASSERT_EQ(2U, request_order_.size()); |
1058 EXPECT_EQ(&req1, request_order_[0]); | 1064 EXPECT_EQ(&req1, request_order_[0]); |
1059 EXPECT_EQ(&req2, request_order_[1]); | 1065 EXPECT_EQ(&req2, request_order_[1]); |
1060 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 1066 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
(...skipping 45 matching lines...) Loading... |
1106 // Even though a timeout is specified, it doesn't time out on a synchronous | 1112 // Even though a timeout is specified, it doesn't time out on a synchronous |
1107 // completion. | 1113 // completion. |
1108 TEST_F(ClientSocketPoolBaseTest_LateBinding, | 1114 TEST_F(ClientSocketPoolBaseTest_LateBinding, |
1109 ConnectJob_NoTimeoutOnSynchronousCompletion) { | 1115 ConnectJob_NoTimeoutOnSynchronousCompletion) { |
1110 TestConnectJobDelegate delegate; | 1116 TestConnectJobDelegate delegate; |
1111 ClientSocketPoolBase::Request request; | 1117 ClientSocketPoolBase::Request request; |
1112 ClientSocketHandle ignored(pool_.get()); | 1118 ClientSocketHandle ignored(pool_.get()); |
1113 request.handle = &ignored; | 1119 request.handle = &ignored; |
1114 scoped_ptr<TestConnectJob> job( | 1120 scoped_ptr<TestConnectJob> job( |
1115 new TestConnectJob(TestConnectJob::kMockJob, | 1121 new TestConnectJob(TestConnectJob::kMockJob, |
1116 "a", | 1122 "a", |
1117 request, | 1123 request, |
1118 base::TimeDelta::FromMicroseconds(1), | 1124 base::TimeDelta::FromMicroseconds(1), |
1119 &delegate, | 1125 &delegate, |
1120 &client_socket_factory_)); | 1126 &client_socket_factory_)); |
1121 EXPECT_EQ(OK, job->Connect()); | 1127 EXPECT_EQ(OK, job->Connect()); |
1122 } | 1128 } |
1123 | 1129 |
1124 TEST_F(ClientSocketPoolBaseTest_LateBinding, ConnectJob_TimedOut) { | 1130 TEST_F(ClientSocketPoolBaseTest_LateBinding, ConnectJob_TimedOut) { |
1125 TestConnectJobDelegate delegate; | 1131 TestConnectJobDelegate delegate; |
1126 ClientSocketPoolBase::Request request; | 1132 ClientSocketPoolBase::Request request; |
1127 ClientSocketHandle ignored(pool_.get()); | 1133 ClientSocketHandle ignored(pool_.get()); |
1128 request.handle = &ignored; | 1134 request.handle = &ignored; |
1129 // Deleted by TestConnectJobDelegate. | 1135 // Deleted by TestConnectJobDelegate. |
1130 TestConnectJob* job = | 1136 TestConnectJob* job = |
1131 new TestConnectJob(TestConnectJob::kMockPendingJob, | 1137 new TestConnectJob(TestConnectJob::kMockPendingJob, |
1132 "a", | 1138 "a", |
1133 request, | 1139 request, |
1134 base::TimeDelta::FromMicroseconds(1), | 1140 base::TimeDelta::FromMicroseconds(1), |
1135 &delegate, | 1141 &delegate, |
1136 &client_socket_factory_); | 1142 &client_socket_factory_); |
1137 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); | 1143 ASSERT_EQ(ERR_IO_PENDING, job->Connect()); |
1138 PlatformThread::Sleep(1); | 1144 PlatformThread::Sleep(1); |
1139 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); | 1145 EXPECT_EQ(ERR_TIMED_OUT, delegate.WaitForResult()); |
1140 } | 1146 } |
1141 | 1147 |
1142 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { | 1148 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicSynchronous) { |
1143 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1149 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1144 | 1150 |
1145 TestCompletionCallback callback; | 1151 TestCompletionCallback callback; |
1146 ClientSocketHandle handle(pool_.get()); | 1152 ClientSocketHandle handle(pool_.get()); |
1147 EXPECT_EQ(OK, handle.Init("a", ignored_request_info_, kDefaultPriority, | 1153 EXPECT_EQ(OK, handle.Init(NULL, "a", ignored_request_info_, kDefaultPriority, |
1148 &callback)); | 1154 &callback)); |
1149 EXPECT_TRUE(handle.is_initialized()); | 1155 EXPECT_TRUE(handle.is_initialized()); |
1150 EXPECT_TRUE(handle.socket()); | 1156 EXPECT_TRUE(handle.socket()); |
1151 handle.Reset(); | 1157 handle.Reset(); |
1152 } | 1158 } |
1153 | 1159 |
1154 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicAsynchronous) { | 1160 TEST_F(ClientSocketPoolBaseTest_LateBinding, BasicAsynchronous) { |
1155 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1161 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1156 | 1162 |
1157 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1163 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1158 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 1164 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
1159 int rv = req.handle()->Init("a", ignored_request_info_, 0, &req); | 1165 int rv = req.handle()->Init(NULL, "a", ignored_request_info_, 0, &req); |
1160 EXPECT_EQ(ERR_IO_PENDING, rv); | 1166 EXPECT_EQ(ERR_IO_PENDING, rv); |
1161 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); | 1167 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); |
1162 EXPECT_EQ(OK, req.WaitForResult()); | 1168 EXPECT_EQ(OK, req.WaitForResult()); |
1163 EXPECT_TRUE(req.handle()->is_initialized()); | 1169 EXPECT_TRUE(req.handle()->is_initialized()); |
1164 EXPECT_TRUE(req.handle()->socket()); | 1170 EXPECT_TRUE(req.handle()->socket()); |
1165 req.handle()->Reset(); | 1171 req.handle()->Reset(); |
1166 } | 1172 } |
1167 | 1173 |
1168 TEST_F(ClientSocketPoolBaseTest_LateBinding, InitConnectionFailure) { | 1174 TEST_F(ClientSocketPoolBaseTest_LateBinding, InitConnectionFailure) { |
1169 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1175 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1170 | 1176 |
1171 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); | 1177 connect_job_factory_->set_job_type(TestConnectJob::kMockFailingJob); |
1172 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 1178 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
1173 EXPECT_EQ(ERR_CONNECTION_FAILED, | 1179 EXPECT_EQ(ERR_CONNECTION_FAILED, |
1174 req.handle()->Init("a", ignored_request_info_, | 1180 req.handle()->Init(NULL, "a", ignored_request_info_, |
1175 kDefaultPriority, &req)); | 1181 kDefaultPriority, &req)); |
1176 } | 1182 } |
1177 | 1183 |
1178 TEST_F(ClientSocketPoolBaseTest_LateBinding, | 1184 TEST_F(ClientSocketPoolBaseTest_LateBinding, |
1179 InitConnectionAsynchronousFailure) { | 1185 InitConnectionAsynchronousFailure) { |
1180 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1186 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1181 | 1187 |
1182 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); | 1188 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
1183 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 1189 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
1184 EXPECT_EQ(ERR_IO_PENDING, | 1190 EXPECT_EQ(ERR_IO_PENDING, |
1185 req.handle()->Init("a", ignored_request_info_, kDefaultPriority, | 1191 req.handle()->Init(NULL, "a", ignored_request_info_, |
1186 &req)); | 1192 kDefaultPriority, &req)); |
1187 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); | 1193 EXPECT_EQ(LOAD_STATE_CONNECTING, pool_->GetLoadState("a", req.handle())); |
1188 EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); | 1194 EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); |
1189 } | 1195 } |
1190 | 1196 |
1191 TEST_F(ClientSocketPoolBaseTest_LateBinding, PendingRequests) { | 1197 TEST_F(ClientSocketPoolBaseTest_LateBinding, PendingRequests) { |
1192 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1198 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1193 | 1199 |
1194 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); | 1200 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
1195 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); | 1201 EXPECT_EQ(OK, StartRequest("a", kDefaultPriority)); |
1196 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); | 1202 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", 1)); |
(...skipping 43 matching lines...) Loading... |
1240 | 1246 |
1241 // This test will start up a RequestSocket() and then immediately Cancel() it. | 1247 // This test will start up a RequestSocket() and then immediately Cancel() it. |
1242 // The pending connect job will be cancelled and should not call back into | 1248 // The pending connect job will be cancelled and should not call back into |
1243 // ClientSocketPoolBase. | 1249 // ClientSocketPoolBase. |
1244 TEST_F(ClientSocketPoolBaseTest_LateBinding, CancelRequestClearGroup) { | 1250 TEST_F(ClientSocketPoolBaseTest_LateBinding, CancelRequestClearGroup) { |
1245 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1251 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1246 | 1252 |
1247 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1253 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1248 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 1254 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
1249 EXPECT_EQ(ERR_IO_PENDING, | 1255 EXPECT_EQ(ERR_IO_PENDING, |
1250 req.handle()->Init("a", ignored_request_info_, | 1256 req.handle()->Init(NULL, "a", ignored_request_info_, |
1251 kDefaultPriority, &req)); | 1257 kDefaultPriority, &req)); |
1252 req.handle()->Reset(); | 1258 req.handle()->Reset(); |
1253 } | 1259 } |
1254 | 1260 |
1255 TEST_F(ClientSocketPoolBaseTest_LateBinding, TwoRequestsCancelOne) { | 1261 TEST_F(ClientSocketPoolBaseTest_LateBinding, TwoRequestsCancelOne) { |
1256 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1262 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1257 | 1263 |
1258 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1264 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1259 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 1265 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
1260 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 1266 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
1261 | 1267 |
1262 EXPECT_EQ(ERR_IO_PENDING, | 1268 EXPECT_EQ(ERR_IO_PENDING, |
1263 req.handle()->Init("a", ignored_request_info_, | 1269 req.handle()->Init(NULL, "a", ignored_request_info_, |
1264 kDefaultPriority, &req)); | 1270 kDefaultPriority, &req)); |
1265 EXPECT_EQ(ERR_IO_PENDING, | 1271 EXPECT_EQ(ERR_IO_PENDING, |
1266 req2.handle()->Init("a", ignored_request_info_, | 1272 req2.handle()->Init(NULL, "a", ignored_request_info_, |
1267 kDefaultPriority, &req2)); | 1273 kDefaultPriority, &req2)); |
1268 | 1274 |
1269 req.handle()->Reset(); | 1275 req.handle()->Reset(); |
1270 | 1276 |
1271 EXPECT_EQ(OK, req2.WaitForResult()); | 1277 EXPECT_EQ(OK, req2.WaitForResult()); |
1272 req2.handle()->Reset(); | 1278 req2.handle()->Reset(); |
1273 } | 1279 } |
1274 | 1280 |
1275 TEST_F(ClientSocketPoolBaseTest_LateBinding, ConnectCancelConnect) { | 1281 TEST_F(ClientSocketPoolBaseTest_LateBinding, ConnectCancelConnect) { |
1276 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1282 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1277 | 1283 |
1278 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1284 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1279 ClientSocketHandle handle(pool_.get()); | 1285 ClientSocketHandle handle(pool_.get()); |
1280 TestCompletionCallback callback; | 1286 TestCompletionCallback callback; |
1281 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 1287 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
1282 | 1288 |
1283 EXPECT_EQ(ERR_IO_PENDING, | 1289 EXPECT_EQ(ERR_IO_PENDING, |
1284 handle.Init("a", ignored_request_info_, | 1290 handle.Init(NULL, "a", ignored_request_info_, |
1285 kDefaultPriority, &callback)); | 1291 kDefaultPriority, &callback)); |
1286 | 1292 |
1287 handle.Reset(); | 1293 handle.Reset(); |
1288 | 1294 |
1289 TestCompletionCallback callback2; | 1295 TestCompletionCallback callback2; |
1290 EXPECT_EQ(ERR_IO_PENDING, | 1296 EXPECT_EQ(ERR_IO_PENDING, |
1291 handle.Init("a", ignored_request_info_, | 1297 handle.Init(NULL, "a", ignored_request_info_, |
1292 kDefaultPriority, &callback2)); | 1298 kDefaultPriority, &callback2)); |
1293 | 1299 |
1294 EXPECT_EQ(OK, callback2.WaitForResult()); | 1300 EXPECT_EQ(OK, callback2.WaitForResult()); |
1295 EXPECT_FALSE(callback.have_result()); | 1301 EXPECT_FALSE(callback.have_result()); |
1296 | 1302 |
1297 handle.Reset(); | 1303 handle.Reset(); |
1298 } | 1304 } |
1299 | 1305 |
1300 TEST_F(ClientSocketPoolBaseTest_LateBinding, CancelRequest) { | 1306 TEST_F(ClientSocketPoolBaseTest_LateBinding, CancelRequest) { |
1301 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1307 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
(...skipping 53 matching lines...) Loading... |
1355 } | 1361 } |
1356 | 1362 |
1357 TEST_F(ClientSocketPoolBaseTest_LateBinding, RequestPendingJobTwice) { | 1363 TEST_F(ClientSocketPoolBaseTest_LateBinding, RequestPendingJobTwice) { |
1358 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1364 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1359 | 1365 |
1360 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1366 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1361 ClientSocketHandle handle(pool_.get()); | 1367 ClientSocketHandle handle(pool_.get()); |
1362 RequestSocketCallback callback( | 1368 RequestSocketCallback callback( |
1363 &handle, connect_job_factory_, TestConnectJob::kMockPendingJob); | 1369 &handle, connect_job_factory_, TestConnectJob::kMockPendingJob); |
1364 int rv = handle.Init( | 1370 int rv = handle.Init( |
1365 "a", ignored_request_info_, kDefaultPriority, &callback); | 1371 NULL, "a", ignored_request_info_, kDefaultPriority, &callback); |
1366 ASSERT_EQ(ERR_IO_PENDING, rv); | 1372 ASSERT_EQ(ERR_IO_PENDING, rv); |
1367 | 1373 |
1368 EXPECT_EQ(OK, callback.WaitForResult()); | 1374 EXPECT_EQ(OK, callback.WaitForResult()); |
1369 handle.Reset(); | 1375 handle.Reset(); |
1370 } | 1376 } |
1371 | 1377 |
1372 TEST_F(ClientSocketPoolBaseTest_LateBinding, RequestPendingJobThenSynchronous) { | 1378 TEST_F(ClientSocketPoolBaseTest_LateBinding, RequestPendingJobThenSynchronous) { |
1373 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1379 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1374 | 1380 |
1375 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1381 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1376 ClientSocketHandle handle(pool_.get()); | 1382 ClientSocketHandle handle(pool_.get()); |
1377 RequestSocketCallback callback( | 1383 RequestSocketCallback callback( |
1378 &handle, connect_job_factory_, TestConnectJob::kMockJob); | 1384 &handle, connect_job_factory_, TestConnectJob::kMockJob); |
1379 int rv = handle.Init( | 1385 int rv = handle.Init( |
1380 "a", ignored_request_info_, kDefaultPriority, &callback); | 1386 NULL, "a", ignored_request_info_, kDefaultPriority, &callback); |
1381 ASSERT_EQ(ERR_IO_PENDING, rv); | 1387 ASSERT_EQ(ERR_IO_PENDING, rv); |
1382 | 1388 |
1383 EXPECT_EQ(OK, callback.WaitForResult()); | 1389 EXPECT_EQ(OK, callback.WaitForResult()); |
1384 handle.Reset(); | 1390 handle.Reset(); |
1385 } | 1391 } |
1386 | 1392 |
1387 // Make sure that pending requests get serviced after active requests get | 1393 // Make sure that pending requests get serviced after active requests get |
1388 // cancelled. | 1394 // cancelled. |
1389 TEST_F(ClientSocketPoolBaseTest_LateBinding, | 1395 TEST_F(ClientSocketPoolBaseTest_LateBinding, |
1390 CancelActiveRequestWithPendingRequests) { | 1396 CancelActiveRequestWithPendingRequests) { |
(...skipping 45 matching lines...) Loading... |
1436 } | 1442 } |
1437 | 1443 |
1438 TEST_F(ClientSocketPoolBaseTest_LateBinding, | 1444 TEST_F(ClientSocketPoolBaseTest_LateBinding, |
1439 CancelActiveRequestThenRequestSocket) { | 1445 CancelActiveRequestThenRequestSocket) { |
1440 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1446 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1441 | 1447 |
1442 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1448 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1443 | 1449 |
1444 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); | 1450 TestSocketRequest req(pool_.get(), &request_order_, &completion_count_); |
1445 int rv = req.handle()->Init( | 1451 int rv = req.handle()->Init( |
1446 "a", ignored_request_info_, kDefaultPriority, &req); | 1452 NULL, "a", ignored_request_info_, kDefaultPriority, &req); |
1447 EXPECT_EQ(ERR_IO_PENDING, rv); | 1453 EXPECT_EQ(ERR_IO_PENDING, rv); |
1448 | 1454 |
1449 // Cancel the active request. | 1455 // Cancel the active request. |
1450 req.handle()->Reset(); | 1456 req.handle()->Reset(); |
1451 | 1457 |
1452 rv = req.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req); | 1458 rv = req.handle()->Init( |
| 1459 NULL, "a", ignored_request_info_, kDefaultPriority, &req); |
1453 EXPECT_EQ(ERR_IO_PENDING, rv); | 1460 EXPECT_EQ(ERR_IO_PENDING, rv); |
1454 EXPECT_EQ(OK, req.WaitForResult()); | 1461 EXPECT_EQ(OK, req.WaitForResult()); |
1455 | 1462 |
1456 EXPECT_FALSE(req.handle()->is_reused()); | 1463 EXPECT_FALSE(req.handle()->is_reused()); |
1457 EXPECT_EQ(1U, completion_count_); | 1464 EXPECT_EQ(1U, completion_count_); |
1458 EXPECT_EQ(2, client_socket_factory_.allocation_count()); | 1465 EXPECT_EQ(2, client_socket_factory_.allocation_count()); |
1459 } | 1466 } |
1460 | 1467 |
1461 // When requests and ConnectJobs are not coupled, the request will get serviced | 1468 // When requests and ConnectJobs are not coupled, the request will get serviced |
1462 // by whatever comes first. | 1469 // by whatever comes first. |
1463 TEST_F(ClientSocketPoolBaseTest_LateBinding, ReleaseSockets) { | 1470 TEST_F(ClientSocketPoolBaseTest_LateBinding, ReleaseSockets) { |
1464 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1471 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1465 | 1472 |
1466 // Start job 1 (async OK) | 1473 // Start job 1 (async OK) |
1467 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); | 1474 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingJob); |
1468 | 1475 |
1469 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); | 1476 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); |
1470 int rv = req1.handle()->Init("a", ignored_request_info_, kDefaultPriority, | 1477 int rv = req1.handle()->Init(NULL, "a", ignored_request_info_, |
1471 &req1); | 1478 kDefaultPriority, &req1); |
1472 EXPECT_EQ(ERR_IO_PENDING, rv); | 1479 EXPECT_EQ(ERR_IO_PENDING, rv); |
1473 EXPECT_EQ(OK, req1.WaitForResult()); | 1480 EXPECT_EQ(OK, req1.WaitForResult()); |
1474 | 1481 |
1475 // Job 1 finished OK. Start job 2 (also async OK). Request 3 is pending | 1482 // Job 1 finished OK. Start job 2 (also async OK). Request 3 is pending |
1476 // without a job. | 1483 // without a job. |
1477 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); | 1484 connect_job_factory_->set_job_type(TestConnectJob::kMockWaitingJob); |
1478 | 1485 |
1479 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 1486 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
1480 rv = req2.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req2); | 1487 rv = req2.handle()->Init( |
| 1488 NULL, "a", ignored_request_info_, kDefaultPriority, &req2); |
1481 EXPECT_EQ(ERR_IO_PENDING, rv); | 1489 EXPECT_EQ(ERR_IO_PENDING, rv); |
1482 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); | 1490 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); |
1483 rv = req3.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req3); | 1491 rv = req3.handle()->Init( |
| 1492 NULL, "a", ignored_request_info_, kDefaultPriority, &req3); |
1484 EXPECT_EQ(ERR_IO_PENDING, rv); | 1493 EXPECT_EQ(ERR_IO_PENDING, rv); |
1485 | 1494 |
1486 // Both Requests 2 and 3 are pending. We release socket 1 which should | 1495 // Both Requests 2 and 3 are pending. We release socket 1 which should |
1487 // service request 2. Request 3 should still be waiting. | 1496 // service request 2. Request 3 should still be waiting. |
1488 req1.handle()->Reset(); | 1497 req1.handle()->Reset(); |
1489 MessageLoop::current()->RunAllPending(); // Run the DoReleaseSocket() | 1498 MessageLoop::current()->RunAllPending(); // Run the DoReleaseSocket() |
1490 ASSERT_TRUE(req2.handle()->socket()); | 1499 ASSERT_TRUE(req2.handle()->socket()); |
1491 EXPECT_EQ(OK, req2.WaitForResult()); | 1500 EXPECT_EQ(OK, req2.WaitForResult()); |
1492 EXPECT_FALSE(req3.handle()->socket()); | 1501 EXPECT_FALSE(req3.handle()->socket()); |
1493 | 1502 |
(...skipping 10 matching lines...) Loading... |
1504 } | 1513 } |
1505 | 1514 |
1506 // The requests are not coupled to the jobs. So, the requests should finish in | 1515 // The requests are not coupled to the jobs. So, the requests should finish in |
1507 // their priority / insertion order. | 1516 // their priority / insertion order. |
1508 TEST_F(ClientSocketPoolBaseTest_LateBinding, PendingJobCompletionOrder) { | 1517 TEST_F(ClientSocketPoolBaseTest_LateBinding, PendingJobCompletionOrder) { |
1509 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1518 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1510 // First two jobs are async. | 1519 // First two jobs are async. |
1511 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); | 1520 connect_job_factory_->set_job_type(TestConnectJob::kMockPendingFailingJob); |
1512 | 1521 |
1513 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); | 1522 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); |
1514 int rv = req1.handle()->Init("a", ignored_request_info_, kDefaultPriority, &re
q1); | 1523 int rv = req1.handle()->Init( |
| 1524 NULL, "a", ignored_request_info_, kDefaultPriority, &req1); |
1515 EXPECT_EQ(ERR_IO_PENDING, rv); | 1525 EXPECT_EQ(ERR_IO_PENDING, rv); |
1516 | 1526 |
1517 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 1527 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
1518 rv = req2.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req2); | 1528 rv = req2.handle()->Init( |
| 1529 NULL, "a", ignored_request_info_, kDefaultPriority, &req2); |
1519 EXPECT_EQ(ERR_IO_PENDING, rv); | 1530 EXPECT_EQ(ERR_IO_PENDING, rv); |
1520 | 1531 |
1521 // The pending job is sync. | 1532 // The pending job is sync. |
1522 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); | 1533 connect_job_factory_->set_job_type(TestConnectJob::kMockJob); |
1523 | 1534 |
1524 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); | 1535 TestSocketRequest req3(pool_.get(), &request_order_, &completion_count_); |
1525 rv = req3.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req3); | 1536 rv = req3.handle()->Init( |
| 1537 NULL, "a", ignored_request_info_, kDefaultPriority, &req3); |
1526 EXPECT_EQ(ERR_IO_PENDING, rv); | 1538 EXPECT_EQ(ERR_IO_PENDING, rv); |
1527 | 1539 |
1528 EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult()); | 1540 EXPECT_EQ(ERR_CONNECTION_FAILED, req1.WaitForResult()); |
1529 EXPECT_EQ(OK, req2.WaitForResult()); | 1541 EXPECT_EQ(OK, req2.WaitForResult()); |
1530 EXPECT_EQ(ERR_CONNECTION_FAILED, req3.WaitForResult()); | 1542 EXPECT_EQ(ERR_CONNECTION_FAILED, req3.WaitForResult()); |
1531 | 1543 |
1532 ASSERT_EQ(3U, request_order_.size()); | 1544 ASSERT_EQ(3U, request_order_.size()); |
1533 EXPECT_EQ(&req1, request_order_[0]); | 1545 EXPECT_EQ(&req1, request_order_[0]); |
1534 EXPECT_EQ(&req2, request_order_[1]); | 1546 EXPECT_EQ(&req2, request_order_[1]); |
1535 EXPECT_EQ(&req3, request_order_[2]); | 1547 EXPECT_EQ(&req3, request_order_[2]); |
1536 } | 1548 } |
1537 | 1549 |
1538 TEST_F(ClientSocketPoolBaseTest_LateBinding, DISABLED_LoadState) { | 1550 TEST_F(ClientSocketPoolBaseTest_LateBinding, DISABLED_LoadState) { |
1539 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); | 1551 CreatePool(kDefaultMaxSockets, kDefaultMaxSocketsPerGroup); |
1540 connect_job_factory_->set_job_type( | 1552 connect_job_factory_->set_job_type( |
1541 TestConnectJob::kMockAdvancingLoadStateJob); | 1553 TestConnectJob::kMockAdvancingLoadStateJob); |
1542 | 1554 |
1543 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); | 1555 TestSocketRequest req1(pool_.get(), &request_order_, &completion_count_); |
1544 int rv = req1.handle()->Init("a", ignored_request_info_, kDefaultPriority, | 1556 int rv = req1.handle()->Init( |
1545 &req1); | 1557 NULL, "a", ignored_request_info_, kDefaultPriority, &req1); |
1546 EXPECT_EQ(ERR_IO_PENDING, rv); | 1558 EXPECT_EQ(ERR_IO_PENDING, rv); |
1547 EXPECT_EQ(LOAD_STATE_IDLE, req1.handle()->GetLoadState()); | 1559 EXPECT_EQ(LOAD_STATE_IDLE, req1.handle()->GetLoadState()); |
1548 | 1560 |
1549 MessageLoop::current()->RunAllPending(); | 1561 MessageLoop::current()->RunAllPending(); |
1550 | 1562 |
1551 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); | 1563 TestSocketRequest req2(pool_.get(), &request_order_, &completion_count_); |
1552 rv = req2.handle()->Init("a", ignored_request_info_, kDefaultPriority, &req2); | 1564 rv = req2.handle()->Init( |
| 1565 NULL, "a", ignored_request_info_, kDefaultPriority, &req2); |
1553 EXPECT_EQ(ERR_IO_PENDING, rv); | 1566 EXPECT_EQ(ERR_IO_PENDING, rv); |
1554 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle()->GetLoadState()); | 1567 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req1.handle()->GetLoadState()); |
1555 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle()->GetLoadState()); | 1568 EXPECT_EQ(LOAD_STATE_WAITING_FOR_CACHE, req2.handle()->GetLoadState()); |
1556 } | 1569 } |
1557 | 1570 |
1558 // Regression test for http://crbug.com/17985. | 1571 // Regression test for http://crbug.com/17985. |
1559 TEST_F(ClientSocketPoolBaseTest_LateBinding, | 1572 TEST_F(ClientSocketPoolBaseTest_LateBinding, |
1560 GroupWithPendingRequestsIsNotEmpty) { | 1573 GroupWithPendingRequestsIsNotEmpty) { |
1561 const int kMaxSockets = 3; | 1574 const int kMaxSockets = 3; |
1562 const int kMaxSocketsPerGroup = 2; | 1575 const int kMaxSocketsPerGroup = 2; |
(...skipping 24 matching lines...) Loading... |
1587 // Closing idle sockets should not get us into trouble, but in the bug | 1600 // Closing idle sockets should not get us into trouble, but in the bug |
1588 // we were hitting a CHECK here. | 1601 // we were hitting a CHECK here. |
1589 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a")); | 1602 EXPECT_EQ(2, pool_->IdleSocketCountInGroup("a")); |
1590 pool_->CloseIdleSockets(); | 1603 pool_->CloseIdleSockets(); |
1591 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); | 1604 EXPECT_EQ(0, pool_->IdleSocketCountInGroup("a")); |
1592 } | 1605 } |
1593 | 1606 |
1594 } // namespace | 1607 } // namespace |
1595 | 1608 |
1596 } // namespace net | 1609 } // namespace net |
OLD | NEW |