| 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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 url::SchemeHostPort server(request_info.url); | 835 url::SchemeHostPort server(request_info.url); |
| 836 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 836 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 837 SetAlternativeService(request_info, alternative_service); | 837 SetAlternativeService(request_info, alternative_service); |
| 838 | 838 |
| 839 request_.reset( | 839 request_.reset( |
| 840 job_controller_->Start(request_info, &request_delegate_, nullptr, | 840 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 841 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 841 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 842 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 842 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 843 EXPECT_TRUE(job_controller_->main_job()); | 843 EXPECT_TRUE(job_controller_->main_job()); |
| 844 EXPECT_TRUE(job_controller_->alternative_job()); | 844 EXPECT_TRUE(job_controller_->alternative_job()); |
| 845 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 845 | 846 |
| 846 // The alternative job stalls as host resolution hangs when creating the QUIC | 847 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 847 // request and controller should resume the main job after delay. | 848 // request and controller should resume the main job after delay. |
| 848 // Verify the waiting time for delayed main job. | 849 base::RunLoop run_loop; |
| 849 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 850 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 851 .Times(1) |
| 852 .WillOnce(testing::DoAll( |
| 853 testing::Invoke(testing::CreateFunctor( |
| 854 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 855 base::TimeDelta::FromMicroseconds(15))), |
| 856 testing::Invoke([&run_loop]() { run_loop.Quit(); }))); |
| 857 |
| 858 // Wait for the main job to be resumed. |
| 859 run_loop.Run(); |
| 860 |
| 861 EXPECT_TRUE(job_controller_->main_job()); |
| 862 EXPECT_TRUE(job_controller_->alternative_job()); |
| 863 |
| 864 // |alternative_job| fails but should not report status to Request. |
| 865 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 866 |
| 867 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 868 // OnStreamFailed will not resume the main job again since it's been resumed |
| 869 // already. |
| 870 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 871 |
| 872 job_controller_->OnStreamFailed(job_factory_.alternative_job(), |
| 873 ERR_NETWORK_CHANGED, SSLConfig()); |
| 874 } |
| 875 |
| 876 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 877 ResumeMainJobImmediatelyOnStreamFailed) { |
| 878 HangingResolver* resolver = new HangingResolver(); |
| 879 session_deps_.host_resolver.reset(resolver); |
| 880 |
| 881 HttpRequestInfo request_info; |
| 882 request_info.method = "GET"; |
| 883 request_info.url = GURL("https://www.google.com"); |
| 884 |
| 885 Initialize(request_info, false, false); |
| 886 |
| 887 // Enable delayed TCP and set time delay for waiting job. |
| 888 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 889 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 890 quic_stream_factory->set_require_confirmation(false); |
| 891 ServerNetworkStats stats1; |
| 892 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 893 session_->http_server_properties()->SetServerNetworkStats( |
| 894 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
| 895 |
| 896 // Set a SPDY alternative service for the server. |
| 897 url::SchemeHostPort server(request_info.url); |
| 898 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 899 SetAlternativeService(request_info, alternative_service); |
| 900 |
| 901 request_.reset( |
| 902 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 903 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 904 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 905 EXPECT_TRUE(job_controller_->main_job()); |
| 906 EXPECT_TRUE(job_controller_->alternative_job()); |
| 907 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 908 |
| 909 // |alternative_job| fails but should not report status to Request. |
| 910 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 911 |
| 912 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 913 // request and controller should resume the main job with delay. |
| 914 // OnStreamFailed should resume the main job immediately. |
| 915 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 916 .Times(1) |
| 850 .WillOnce(Invoke(testing::CreateFunctor( | 917 .WillOnce(Invoke(testing::CreateFunctor( |
| 851 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 918 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 852 base::TimeDelta::FromMicroseconds(15)))); | 919 base::TimeDelta::FromMicroseconds(0)))); |
| 920 |
| 921 job_controller_->OnStreamFailed(job_factory_.alternative_job(), |
| 922 ERR_NETWORK_CHANGED, SSLConfig()); |
| 853 | 923 |
| 854 base::RunLoop().RunUntilIdle(); | 924 base::RunLoop().RunUntilIdle(); |
| 855 } | 925 } |
| 856 | |
| 857 // Verifies that the alternative proxy server job is not created if the URL | 926 // Verifies that the alternative proxy server job is not created if the URL |
| 858 // scheme is HTTPS. | 927 // scheme is HTTPS. |
| 859 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { | 928 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { |
| 860 // Using hanging resolver will cause the alternative job to hang indefinitely. | 929 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 861 HangingResolver* resolver = new HangingResolver(); | 930 HangingResolver* resolver = new HangingResolver(); |
| 862 session_deps_.host_resolver.reset(resolver); | 931 session_deps_.host_resolver.reset(resolver); |
| 863 | 932 |
| 864 Initialize(true); | 933 Initialize(true); |
| 865 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 934 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 866 | 935 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 // Reset the request as it's been successfully served. | 1126 // Reset the request as it's been successfully served. |
| 1058 request_.reset(); | 1127 request_.reset(); |
| 1059 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1128 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1060 | 1129 |
| 1061 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", | 1130 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", |
| 1062 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, | 1131 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, |
| 1063 1); | 1132 1); |
| 1064 } | 1133 } |
| 1065 | 1134 |
| 1066 } // namespace net | 1135 } // namespace net |
| OLD | NEW |