Chromium Code Reviews| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 911 | 911 |
| 912 request_.reset( | 912 request_.reset( |
| 913 job_controller_->Start(request_info, &request_delegate_, nullptr, | 913 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 914 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 914 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 915 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 915 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 916 EXPECT_TRUE(job_controller_->main_job()); | 916 EXPECT_TRUE(job_controller_->main_job()); |
| 917 EXPECT_TRUE(job_controller_->alternative_job()); | 917 EXPECT_TRUE(job_controller_->alternative_job()); |
| 918 | 918 |
| 919 // The alternative job stalls as host resolution hangs when creating the QUIC | 919 // The alternative job stalls as host resolution hangs when creating the QUIC |
| 920 // request and controller should resume the main job after delay. | 920 // request and controller should resume the main job after delay. |
| 921 // Verify the waiting time for delayed main job. | 921 base::RunLoop run_loop; |
| 922 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 922 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 923 .Times(1) | |
| 924 .WillOnce(testing::DoAll( | |
| 925 testing::Invoke(testing::CreateFunctor( | |
| 926 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | |
| 927 base::TimeDelta::FromMicroseconds(15))), | |
| 928 testing::Invoke([&run_loop]() { run_loop.Quit(); }))); | |
| 929 | |
| 930 // Wait for the main job to be resumed. | |
| 931 run_loop.Run(); | |
| 932 | |
| 933 EXPECT_TRUE(job_controller_->main_job()); | |
| 934 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 935 | |
| 936 // |alternative_job| fails but should not report status to Request. | |
| 937 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
| 938 | |
| 939 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); | |
| 940 // OnStreamFailed will not resume the main job again since it's been resumed | |
| 941 // already. | |
| 942 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | |
| 943 | |
| 944 job_controller_->OnStreamFailed(job_factory_.alternative_job(), | |
| 945 ERR_NETWORK_CHANGED, SSLConfig()); | |
| 946 } | |
|
Ryan Hamilton
2017/02/15 00:52:08
Does this old test fail with the new code (And so
Zhongyi Shi
2017/02/15 01:39:08
The old test won't fail with the new code. I just
| |
| 947 | |
| 948 TEST_F(HttpStreamFactoryImplJobControllerTest, | |
| 949 ResumeMainJobImmediatelyOnStreamFailed) { | |
|
Ryan Hamilton
2017/02/15 00:52:08
I assume this fails with the old code?
Zhongyi Shi
2017/02/15 01:39:09
It'll, this one now expects the main job to be res
| |
| 950 HangingResolver* resolver = new HangingResolver(); | |
| 951 session_deps_.host_resolver.reset(resolver); | |
| 952 | |
| 953 HttpRequestInfo request_info; | |
| 954 request_info.method = "GET"; | |
| 955 request_info.url = GURL("https://www.google.com"); | |
| 956 | |
| 957 Initialize(request_info, false, false); | |
| 958 | |
| 959 // Enable delayed TCP and set time delay for waiting job. | |
| 960 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
| 961 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | |
| 962 quic_stream_factory->set_require_confirmation(false); | |
| 963 ServerNetworkStats stats1; | |
| 964 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | |
| 965 session_->http_server_properties()->SetServerNetworkStats( | |
| 966 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | |
| 967 | |
| 968 // Set a SPDY alternative service for the server. | |
| 969 url::SchemeHostPort server(request_info.url); | |
| 970 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
| 971 SetAlternativeService(request_info, alternative_service); | |
| 972 | |
| 973 request_.reset( | |
| 974 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 975 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | |
| 976 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 977 EXPECT_TRUE(job_controller_->main_job()); | |
| 978 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 979 | |
| 980 // |alternative_job| fails but should not report status to Request. | |
| 981 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
| 982 | |
| 983 // The alternative job stalls as host resolution hangs when creating the QUIC | |
| 984 // request and controller should resume the main job with delay. | |
| 985 // OnStreamFailed should resume the main job immediately. | |
| 986 EXPECT_CALL(*job_factory_.main_job(), Resume()) | |
| 987 .Times(1) | |
| 923 .WillOnce(Invoke(testing::CreateFunctor( | 988 .WillOnce(Invoke(testing::CreateFunctor( |
| 924 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 989 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 925 base::TimeDelta::FromMicroseconds(15)))); | 990 base::TimeDelta::FromMicroseconds(0)))); |
|
Ryan Hamilton
2017/02/15 00:52:08
How does this verify that the main job is started?
Zhongyi Shi
2017/02/15 01:39:06
This method check Resume() is called on main_job.
| |
| 991 | |
| 992 job_controller_->OnStreamFailed(job_factory_.alternative_job(), | |
| 993 ERR_NETWORK_CHANGED, SSLConfig()); | |
| 926 | 994 |
| 927 base::RunLoop().RunUntilIdle(); | 995 base::RunLoop().RunUntilIdle(); |
| 928 } | 996 } |
| 929 | |
| 930 // Verifies that the alternative proxy server job is not created if the URL | 997 // Verifies that the alternative proxy server job is not created if the URL |
| 931 // scheme is HTTPS. | 998 // scheme is HTTPS. |
| 932 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { | 999 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { |
| 933 // Using hanging resolver will cause the alternative job to hang indefinitely. | 1000 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 934 HangingResolver* resolver = new HangingResolver(); | 1001 HangingResolver* resolver = new HangingResolver(); |
| 935 session_deps_.host_resolver.reset(resolver); | 1002 session_deps_.host_resolver.reset(resolver); |
| 936 | 1003 |
| 937 HttpRequestInfo request_info; | 1004 HttpRequestInfo request_info; |
| 938 request_info.method = "GET"; | 1005 request_info.method = "GET"; |
| 939 request_info.url = GURL("https://mail.example.org/"); | 1006 request_info.url = GURL("https://mail.example.org/"); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1228 Preconnect(kNumPreconects); | 1295 Preconnect(kNumPreconects); |
| 1229 // If experiment is enabled, only 1 stream is requested. | 1296 // If experiment is enabled, only 1 stream is requested. |
| 1230 EXPECT_EQ( | 1297 EXPECT_EQ( |
| 1231 (int)actual_num_connects, | 1298 (int)actual_num_connects, |
| 1232 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1299 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 1233 base::RunLoop().RunUntilIdle(); | 1300 base::RunLoop().RunUntilIdle(); |
| 1234 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1301 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1235 } | 1302 } |
| 1236 | 1303 |
| 1237 } // namespace net | 1304 } // namespace net |
| OLD | NEW |