OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/http/http_stream_factory_impl_job_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 EXPECT_TRUE(job_controller_->main_job()); | 612 EXPECT_TRUE(job_controller_->main_job()); |
613 EXPECT_TRUE(job_controller_->alternative_job()); | 613 EXPECT_TRUE(job_controller_->alternative_job()); |
614 | 614 |
615 MockAsyncProxyResolver resolver; | 615 MockAsyncProxyResolver resolver; |
616 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | 616 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
617 net::OK, &resolver); | 617 net::OK, &resolver); |
618 | 618 |
619 // Resolve proxy for the main job which then proceed to wait for the | 619 // Resolve proxy for the main job which then proceed to wait for the |
620 // alternative job which is IO_PENDING. | 620 // alternative job which is IO_PENDING. |
621 int main_job_request_id = | 621 int main_job_request_id = |
622 resolver.pending_requests()[0]->url().SchemeIs("http") ? 0 : 1; | 622 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; |
623 | 623 |
624 resolver.pending_requests()[main_job_request_id]->results()->UseNamedProxy( | 624 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( |
625 "result1:80"); | 625 "result1:80"); |
626 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK); | 626 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); |
627 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 627 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
628 | 628 |
629 // Resolve proxy for the alternative job to proceed to create a connection. | 629 // Resolve proxy for the alternative job to proceed to create a connection. |
630 // Use hanging HostResolver to fail creation of a SPDY session for the | 630 // Use hanging HostResolver to fail creation of a SPDY session for the |
631 // alternative job. The alternative job will be IO_PENDING thus should resume | 631 // alternative job. The alternative job will be IO_PENDING thus should resume |
632 // the main job. | 632 // the main job. |
633 resolver.pending_requests()[0]->CompleteNow(net::OK); | 633 resolver.pending_jobs()[0]->CompleteNow(net::OK); |
634 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 634 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
635 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 635 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
636 | 636 |
637 base::RunLoop().RunUntilIdle(); | 637 base::RunLoop().RunUntilIdle(); |
638 } | 638 } |
639 | 639 |
640 TEST_F(HttpStreamFactoryImplJobControllerTest, | 640 TEST_F(HttpStreamFactoryImplJobControllerTest, |
641 NoAvailableQuicSessionToResumeMainJob) { | 641 NoAvailableQuicSessionToResumeMainJob) { |
642 // Use failing HostResolver which is unable to resolve the host name for QUIC. | 642 // Use failing HostResolver which is unable to resolve the host name for QUIC. |
643 // No QUIC session is created and thus should resume the main job. | 643 // No QUIC session is created and thus should resume the main job. |
(...skipping 29 matching lines...) Expand all Loading... |
673 EXPECT_TRUE(job_controller_->main_job()); | 673 EXPECT_TRUE(job_controller_->main_job()); |
674 EXPECT_TRUE(job_controller_->alternative_job()); | 674 EXPECT_TRUE(job_controller_->alternative_job()); |
675 | 675 |
676 MockAsyncProxyResolver resolver; | 676 MockAsyncProxyResolver resolver; |
677 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | 677 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
678 net::OK, &resolver); | 678 net::OK, &resolver); |
679 | 679 |
680 // Resolve proxy for the main job which then proceed to wait for the | 680 // Resolve proxy for the main job which then proceed to wait for the |
681 // alternative job which is IO_PENDING. | 681 // alternative job which is IO_PENDING. |
682 int main_job_request_id = | 682 int main_job_request_id = |
683 resolver.pending_requests()[0]->url().SchemeIs("http") ? 0 : 1; | 683 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; |
684 | 684 |
685 resolver.pending_requests()[main_job_request_id]->results()->UseNamedProxy( | 685 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( |
686 "result1:80"); | 686 "result1:80"); |
687 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK); | 687 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); |
688 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 688 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
689 | 689 |
690 // Resolve proxy for the alternative job to proceed to create a connection. | 690 // Resolve proxy for the alternative job to proceed to create a connection. |
691 // Use failing HostResolver to fail creation of a QUIC session for the | 691 // Use failing HostResolver to fail creation of a QUIC session for the |
692 // alternative job. The alternative job will thus resume the main job. | 692 // alternative job. The alternative job will thus resume the main job. |
693 resolver.pending_requests()[0]->results()->UseNamedProxy("result1:80"); | 693 resolver.pending_jobs()[0]->results()->UseNamedProxy("result1:80"); |
694 resolver.pending_requests()[0]->CompleteNow(net::OK); | 694 resolver.pending_jobs()[0]->CompleteNow(net::OK); |
695 | 695 |
696 // Wait until OnStreamFailedCallback is executed on the alternative job. | 696 // Wait until OnStreamFailedCallback is executed on the alternative job. |
697 // Request shouldn't be notified as the main job is still pending status. | 697 // Request shouldn't be notified as the main job is still pending status. |
698 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 698 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
699 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 699 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
700 | 700 |
701 base::RunLoop().RunUntilIdle(); | 701 base::RunLoop().RunUntilIdle(); |
702 } | 702 } |
703 | 703 |
704 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 704 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 // Reset the request as it's been successfully served. | 947 // Reset the request as it's been successfully served. |
948 request_.reset(); | 948 request_.reset(); |
949 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 949 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
950 | 950 |
951 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", | 951 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", |
952 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, | 952 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, |
953 1); | 953 1); |
954 } | 954 } |
955 | 955 |
956 } // namespace net | 956 } // namespace net |
OLD | NEW |