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 | 8 |
| 9 #include "base/run_loop.cc" | |
| 10 #include "net/dns/mock_host_resolver.h" | |
| 9 #include "net/http/http_basic_stream.h" | 11 #include "net/http/http_basic_stream.h" |
| 10 #include "net/http/http_stream_factory_impl_request.h" | 12 #include "net/http/http_stream_factory_impl_request.h" |
| 11 #include "net/http/http_stream_factory_test_util.h" | 13 #include "net/http/http_stream_factory_test_util.h" |
| 14 #include "net/proxy/mock_proxy_resolver.h" | |
| 15 #include "net/proxy/proxy_config_service_fixed.h" | |
| 12 #include "net/proxy/proxy_info.h" | 16 #include "net/proxy/proxy_info.h" |
| 13 #include "net/proxy/proxy_service.h" | 17 #include "net/proxy/proxy_service.h" |
| 18 #include "net/quic/test_tools/quic_stream_factory_peer.h" | |
| 14 #include "net/spdy/spdy_test_util_common.h" | 19 #include "net/spdy/spdy_test_util_common.h" |
| 15 #include "net/ssl/ssl_failure_state.h" | 20 #include "net/ssl/ssl_failure_state.h" |
| 21 #include "testing/gmock_mutant.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 23 |
| 18 using ::testing::_; | 24 using ::testing::_; |
| 19 using ::testing::Invoke; | 25 using ::testing::Invoke; |
| 20 | 26 |
| 21 namespace net { | 27 namespace net { |
| 22 | 28 |
| 23 namespace { | 29 namespace { |
| 24 | 30 |
| 25 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config, | 31 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config, |
| 26 const ProxyInfo& used_proxy_info, | 32 const ProxyInfo& used_proxy_info, |
| 27 HttpStream* stream) { | 33 HttpStream* stream) { |
| 28 delete stream; | 34 delete stream; |
| 29 } | 35 } |
| 30 | 36 |
| 37 class HangingProxyResolver : public ProxyResolver { | |
| 38 public: | |
| 39 HangingProxyResolver() {} | |
| 40 ~HangingProxyResolver() override {} | |
| 41 | |
| 42 int GetProxyForURL(const GURL& url, | |
| 43 ProxyInfo* results, | |
| 44 const CompletionCallback& callback, | |
| 45 RequestHandle* request, | |
| 46 const BoundNetLog& net_log) override { | |
| 47 return ERR_IO_PENDING; | |
| 48 } | |
| 49 | |
| 50 void CancelRequest(RequestHandle request) override { NOTREACHED(); } | |
| 51 | |
| 52 LoadState GetLoadState(RequestHandle request) const override { | |
| 53 NOTREACHED(); | |
| 54 return LOAD_STATE_IDLE; | |
| 55 } | |
| 56 | |
| 57 private: | |
| 58 DISALLOW_COPY_AND_ASSIGN(HangingProxyResolver); | |
| 59 }; | |
| 60 | |
| 61 class HangingProxyResolverFactory : public ProxyResolverFactory { | |
| 62 public: | |
| 63 explicit HangingProxyResolverFactory(HangingProxyResolver* resolver) | |
| 64 : ProxyResolverFactory(false), resolver_(resolver) {} | |
| 65 | |
| 66 // ProxyResolverFactory override. | |
| 67 int CreateProxyResolver( | |
| 68 const scoped_refptr<ProxyResolverScriptData>& pac_script, | |
| 69 std::unique_ptr<ProxyResolver>* resolver, | |
| 70 const net::CompletionCallback& callback, | |
| 71 std::unique_ptr<Request>* request) override { | |
| 72 resolver->reset(new ForwardingProxyResolver(resolver_)); | |
| 73 return OK; | |
| 74 } | |
| 75 | |
| 76 private: | |
| 77 HangingProxyResolver* resolver_; | |
| 78 }; | |
| 79 | |
| 80 class FailingProxyResolverFactory : public ProxyResolverFactory { | |
| 81 public: | |
| 82 FailingProxyResolverFactory() : ProxyResolverFactory(false) {} | |
| 83 | |
| 84 // ProxyResolverFactory override. | |
| 85 int CreateProxyResolver( | |
| 86 const scoped_refptr<ProxyResolverScriptData>& script_data, | |
| 87 std::unique_ptr<ProxyResolver>* result, | |
| 88 const CompletionCallback& callback, | |
| 89 std::unique_ptr<Request>* request) override { | |
| 90 return ERR_PAC_SCRIPT_FAILED; | |
| 91 } | |
| 92 }; | |
| 93 | |
| 94 class FailingHostResolver : public MockHostResolverBase { | |
| 95 public: | |
| 96 FailingHostResolver() : MockHostResolverBase(false /*use_caching*/) {} | |
| 97 ~FailingHostResolver() override {} | |
| 98 | |
| 99 int Resolve(const RequestInfo& info, | |
| 100 RequestPriority priority, | |
| 101 AddressList* addresses, | |
| 102 const CompletionCallback& callback, | |
| 103 RequestHandle* out_req, | |
| 104 const BoundNetLog& net_log) override { | |
| 105 return ERR_NAME_NOT_RESOLVED; | |
| 106 } | |
| 107 }; | |
| 108 | |
| 109 class HangingResolver : public MockHostResolverBase { | |
| 110 public: | |
| 111 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {} | |
| 112 ~HangingResolver() override {} | |
| 113 | |
| 114 int Resolve(const RequestInfo& info, | |
| 115 RequestPriority priority, | |
| 116 AddressList* addresses, | |
| 117 const CompletionCallback& callback, | |
| 118 RequestHandle* out_req, | |
| 119 const BoundNetLog& net_log) override { | |
| 120 return ERR_IO_PENDING; | |
| 121 ; | |
|
Ryan Hamilton
2016/07/12 00:21:45
nit: extra ;
Zhongyi Shi
2016/07/12 23:03:12
whoops, sorry :(
| |
| 122 } | |
| 123 | |
| 124 void CancelRequest(RequestHandle req) override {} | |
| 125 }; | |
| 31 } // anonymous namespace | 126 } // anonymous namespace |
| 32 | 127 |
| 128 class HttpStreamFactoryImplJobPeer { | |
| 129 public: | |
| 130 static void Start(HttpStreamFactoryImpl::Job* job, | |
| 131 HttpStreamRequest::StreamType stream_type) { | |
| 132 // Start() is mocked for MockHttpStreamFactoryImplJob. | |
| 133 // This is the alternative method to invoke real Start() method on Job. | |
| 134 job->stream_type_ = stream_type; | |
| 135 job->StartInternal(); | |
| 136 } | |
| 137 }; | |
| 138 | |
| 139 class JobControllerPeer { | |
| 140 public: | |
| 141 static void VerifyWaitingTimeForMainJob( | |
| 142 HttpStreamFactoryImpl::JobController* job_controller, | |
| 143 const base::TimeDelta& delay) { | |
| 144 EXPECT_EQ(delay, job_controller->main_job_wait_time_); | |
| 145 } | |
| 146 }; | |
| 147 | |
| 33 class HttpStreamFactoryImplJobControllerTest | 148 class HttpStreamFactoryImplJobControllerTest |
| 34 : public ::testing::Test, | 149 : public ::testing::Test, |
| 35 public ::testing::WithParamInterface<NextProto> { | 150 public ::testing::WithParamInterface<NextProto> { |
| 36 public: | 151 public: |
| 37 HttpStreamFactoryImplJobControllerTest() | 152 HttpStreamFactoryImplJobControllerTest() |
| 38 : session_deps_(GetParam(), ProxyService::CreateDirect()) { | 153 : session_deps_(GetParam(), ProxyService::CreateDirect()) { |
| 39 session_deps_.enable_quic = true; | 154 session_deps_.enable_quic = true; |
| 155 } | |
| 156 | |
| 157 void Initialize() { | |
| 40 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 158 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 41 factory_ = | 159 factory_ = |
| 42 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 160 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 43 job_controller_ = new HttpStreamFactoryImpl::JobController( | 161 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 44 factory_, &request_delegate_, session_.get(), &job_factory_); | 162 factory_, &request_delegate_, session_.get(), &job_factory_); |
| 45 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 163 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
| 46 } | 164 } |
| 47 | 165 |
| 48 ~HttpStreamFactoryImplJobControllerTest() {} | 166 ~HttpStreamFactoryImplJobControllerTest() {} |
| 49 | 167 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 66 | 184 |
| 67 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 185 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
| 68 }; | 186 }; |
| 69 | 187 |
| 70 INSTANTIATE_TEST_CASE_P(NextProto, | 188 INSTANTIATE_TEST_CASE_P(NextProto, |
| 71 HttpStreamFactoryImplJobControllerTest, | 189 HttpStreamFactoryImplJobControllerTest, |
| 72 testing::Values(kProtoSPDY31, kProtoHTTP2)); | 190 testing::Values(kProtoSPDY31, kProtoHTTP2)); |
| 73 | 191 |
| 74 TEST_P(HttpStreamFactoryImplJobControllerTest, | 192 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 75 OnStreamFailedWithNoAlternativeJob) { | 193 OnStreamFailedWithNoAlternativeJob) { |
| 194 Initialize(); | |
| 195 | |
| 76 HttpRequestInfo request_info; | 196 HttpRequestInfo request_info; |
| 77 request_info.method = "GET"; | 197 request_info.method = "GET"; |
| 78 request_info.url = GURL("http://www.google.com"); | 198 request_info.url = GURL("http://www.google.com"); |
| 79 | 199 |
| 80 request_.reset( | 200 request_.reset( |
| 81 job_controller_->Start(request_info, &request_delegate_, nullptr, | 201 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 82 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 202 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 83 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 203 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 84 | 204 |
| 85 EXPECT_TRUE(job_controller_->main_job()); | 205 EXPECT_TRUE(job_controller_->main_job()); |
| 86 | 206 |
| 87 // There's no other alternative job. Thus when stream failed, it should | 207 // There's no other alternative job. Thus when stream failed, it should |
| 88 // notify Request of the stream failure. | 208 // notify Request of the stream failure. |
| 89 EXPECT_CALL(request_delegate_, | 209 EXPECT_CALL(request_delegate_, |
| 90 OnStreamFailed(ERR_FAILED, _, SSL_FAILURE_NONE)) | 210 OnStreamFailed(ERR_FAILED, _, SSL_FAILURE_NONE)) |
| 91 .Times(1); | 211 .Times(1); |
| 92 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 212 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 93 SSLConfig(), SSL_FAILURE_NONE); | 213 SSLConfig(), SSL_FAILURE_NONE); |
| 94 } | 214 } |
| 95 | 215 |
| 96 TEST_P(HttpStreamFactoryImplJobControllerTest, | 216 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 97 OnStreamReadyWithNoAlternativeJob) { | 217 OnStreamReadyWithNoAlternativeJob) { |
| 218 Initialize(); | |
| 219 | |
| 98 HttpRequestInfo request_info; | 220 HttpRequestInfo request_info; |
| 99 request_info.method = "GET"; | 221 request_info.method = "GET"; |
| 100 request_info.url = GURL("http://www.google.com"); | 222 request_info.url = GURL("http://www.google.com"); |
| 101 | 223 |
| 102 request_.reset( | 224 request_.reset( |
| 103 job_controller_->Start(request_info, &request_delegate_, nullptr, | 225 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 104 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 226 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 105 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 227 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 106 EXPECT_TRUE(job_controller_->main_job()); | 228 EXPECT_TRUE(job_controller_->main_job()); |
| 107 | 229 |
| 108 // There's no other alternative job. Thus when stream is ready, it should | 230 // There's no other alternative job. Thus when stream is ready, it should |
| 109 // notify Request. | 231 // notify Request. |
| 110 HttpStream* http_stream = | 232 HttpStream* http_stream = |
| 111 new HttpBasicStream(new ClientSocketHandle(), false); | 233 new HttpBasicStream(new ClientSocketHandle(), false); |
| 112 job_factory_.main_job()->SetStream(http_stream); | 234 job_factory_.main_job()->SetStream(http_stream); |
| 113 | 235 |
| 114 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 236 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 115 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 237 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 116 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 238 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), |
| 117 ProxyInfo()); | 239 ProxyInfo()); |
| 118 } | 240 } |
| 119 | 241 |
| 120 // Test we cancel Jobs correctly when the Request is explicitly canceled | 242 // Test we cancel Jobs correctly when the Request is explicitly canceled |
| 121 // before any Job is bound to Request. | 243 // before any Job is bound to Request. |
| 122 TEST_P(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 244 TEST_P(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
| 245 Initialize(); | |
| 246 | |
| 123 HttpRequestInfo request_info; | 247 HttpRequestInfo request_info; |
| 124 request_info.method = "GET"; | 248 request_info.method = "GET"; |
| 125 request_info.url = GURL("https://www.google.com"); | 249 request_info.url = GURL("https://www.google.com"); |
| 126 | 250 |
| 127 url::SchemeHostPort server(request_info.url); | 251 url::SchemeHostPort server(request_info.url); |
| 128 AlternativeService alternative_service(QUIC, server.host(), 443); | 252 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 129 SetAlternativeService(request_info, alternative_service); | 253 SetAlternativeService(request_info, alternative_service); |
| 130 | 254 |
| 131 request_.reset( | 255 request_.reset( |
| 132 job_controller_->Start(request_info, &request_delegate_, nullptr, | 256 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 133 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 257 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 134 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 258 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 135 EXPECT_TRUE(job_controller_->main_job()); | 259 EXPECT_TRUE(job_controller_->main_job()); |
| 136 EXPECT_TRUE(job_controller_->alternative_job()); | 260 EXPECT_TRUE(job_controller_->alternative_job()); |
| 137 | 261 |
| 138 // Reset the Request will cancel all the Jobs since there's no Job determined | 262 // Reset the Request will cancel all the Jobs since there's no Job determined |
| 139 // to serve Request yet and JobController will notify the factory to delete | 263 // to serve Request yet and JobController will notify the factory to delete |
| 140 // itself upon completion. | 264 // itself upon completion. |
| 141 request_.reset(); | 265 request_.reset(); |
| 142 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 266 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 143 } | 267 } |
| 144 | 268 |
| 145 TEST_P(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 269 TEST_P(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 270 Initialize(); | |
| 271 | |
| 146 HttpRequestInfo request_info; | 272 HttpRequestInfo request_info; |
| 147 request_info.method = "GET"; | 273 request_info.method = "GET"; |
| 148 request_info.url = GURL("https://www.google.com"); | 274 request_info.url = GURL("https://www.google.com"); |
| 149 | 275 |
| 150 url::SchemeHostPort server(request_info.url); | 276 url::SchemeHostPort server(request_info.url); |
| 151 AlternativeService alternative_service(QUIC, server.host(), 443); | 277 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 152 SetAlternativeService(request_info, alternative_service); | 278 SetAlternativeService(request_info, alternative_service); |
| 153 | 279 |
| 154 request_.reset( | 280 request_.reset( |
| 155 job_controller_->Start(request_info, &request_delegate_, nullptr, | 281 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 171 // The failure of second Job should be reported to Request as there's no more | 297 // The failure of second Job should be reported to Request as there's no more |
| 172 // pending Job to serve the Request. | 298 // pending Job to serve the Request. |
| 173 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_UNKNOWN)) | 299 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_UNKNOWN)) |
| 174 .Times(1); | 300 .Times(1); |
| 175 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 301 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 176 SSLConfig(), SSL_FAILURE_UNKNOWN); | 302 SSLConfig(), SSL_FAILURE_UNKNOWN); |
| 177 } | 303 } |
| 178 | 304 |
| 179 TEST_P(HttpStreamFactoryImplJobControllerTest, | 305 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 180 SecondJobFailsAfterFirstJobSucceeds) { | 306 SecondJobFailsAfterFirstJobSucceeds) { |
| 307 Initialize(); | |
| 308 | |
| 181 HttpRequestInfo request_info; | 309 HttpRequestInfo request_info; |
| 182 request_info.method = "GET"; | 310 request_info.method = "GET"; |
| 183 request_info.url = GURL("https://www.google.com"); | 311 request_info.url = GURL("https://www.google.com"); |
| 184 | 312 |
| 185 url::SchemeHostPort server(request_info.url); | 313 url::SchemeHostPort server(request_info.url); |
| 186 AlternativeService alternative_service(QUIC, server.host(), 443); | 314 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 187 SetAlternativeService(request_info, alternative_service); | 315 SetAlternativeService(request_info, alternative_service); |
| 188 | 316 |
| 189 request_.reset( | 317 request_.reset( |
| 190 job_controller_->Start(request_info, &request_delegate_, nullptr, | 318 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 213 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 341 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
| 214 SSLConfig(), SSL_FAILURE_NONE); | 342 SSLConfig(), SSL_FAILURE_NONE); |
| 215 | 343 |
| 216 // Reset the request as it's been successfully served. | 344 // Reset the request as it's been successfully served. |
| 217 request_.reset(); | 345 request_.reset(); |
| 218 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 346 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 219 } | 347 } |
| 220 | 348 |
| 221 TEST_P(HttpStreamFactoryImplJobControllerTest, | 349 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 222 SecondJobSucceedsAfterFirstJobFailed) { | 350 SecondJobSucceedsAfterFirstJobFailed) { |
| 351 Initialize(); | |
| 352 | |
| 223 HttpRequestInfo request_info; | 353 HttpRequestInfo request_info; |
| 224 request_info.method = "GET"; | 354 request_info.method = "GET"; |
| 225 request_info.url = GURL("https://www.google.com"); | 355 request_info.url = GURL("https://www.google.com"); |
| 226 | 356 |
| 227 url::SchemeHostPort server(request_info.url); | 357 url::SchemeHostPort server(request_info.url); |
| 228 AlternativeService alternative_service(QUIC, server.host(), 443); | 358 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 229 SetAlternativeService(request_info, alternative_service); | 359 SetAlternativeService(request_info, alternative_service); |
| 230 | 360 |
| 231 request_.reset( | 361 request_.reset( |
| 232 job_controller_->Start(request_info, &request_delegate_, nullptr, | 362 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 251 | 381 |
| 252 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 382 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 253 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 383 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 254 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 384 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
| 255 ProxyInfo()); | 385 ProxyInfo()); |
| 256 } | 386 } |
| 257 | 387 |
| 258 // Regression test for crbug/621069. | 388 // Regression test for crbug/621069. |
| 259 // Get load state after main job fails and before alternative job succeeds. | 389 // Get load state after main job fails and before alternative job succeeds. |
| 260 TEST_P(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 390 TEST_P(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
| 391 Initialize(); | |
| 392 | |
| 261 HttpRequestInfo request_info; | 393 HttpRequestInfo request_info; |
| 262 request_info.method = "GET"; | 394 request_info.method = "GET"; |
| 263 request_info.url = GURL("https://www.google.com"); | 395 request_info.url = GURL("https://www.google.com"); |
| 264 | 396 |
| 265 url::SchemeHostPort server(request_info.url); | 397 url::SchemeHostPort server(request_info.url); |
| 266 AlternativeService alternative_service(QUIC, server.host(), 443); | 398 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 267 SetAlternativeService(request_info, alternative_service); | 399 SetAlternativeService(request_info, alternative_service); |
| 268 | 400 |
| 269 request_.reset( | 401 request_.reset( |
| 270 job_controller_->Start(request_info, &request_delegate_, nullptr, | 402 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 289 HttpStream* http_stream = | 421 HttpStream* http_stream = |
| 290 new HttpBasicStream(new ClientSocketHandle(), false); | 422 new HttpBasicStream(new ClientSocketHandle(), false); |
| 291 job_factory_.alternative_job()->SetStream(http_stream); | 423 job_factory_.alternative_job()->SetStream(http_stream); |
| 292 | 424 |
| 293 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 425 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 294 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 426 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 295 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 427 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
| 296 ProxyInfo()); | 428 ProxyInfo()); |
| 297 } | 429 } |
| 298 | 430 |
| 431 TEST_P(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | |
| 432 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | |
| 433 // to stall the alternative job and report to controller to resume the main | |
| 434 // job. | |
| 435 ProxyConfig proxy_config; | |
| 436 proxy_config.set_auto_detect(true); | |
| 437 proxy_config.set_pac_mandatory(true); | |
| 438 session_deps_.proxy_service.reset(new ProxyService( | |
| 439 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | |
| 440 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | |
| 441 | |
| 442 Initialize(); | |
| 443 | |
| 444 HttpRequestInfo request_info; | |
| 445 request_info.method = "GET"; | |
| 446 request_info.url = GURL("https://www.google.com"); | |
| 447 | |
| 448 url::SchemeHostPort server(request_info.url); | |
| 449 AlternativeService alternative_service(QUIC, server.host(), 443); | |
| 450 SetAlternativeService(request_info, alternative_service); | |
| 451 | |
| 452 request_.reset( | |
| 453 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 454 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 455 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 456 EXPECT_TRUE(job_controller_->main_job()); | |
| 457 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 458 | |
| 459 // |alternative_job| fails but should not report status to Request. | |
| 460 // Job controller should not resume the main job as it's not in wait state. | |
| 461 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | |
| 462 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(), | |
| 463 HttpStreamRequest::HTTP_STREAM); | |
| 464 | |
| 465 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 466 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
|
Ryan Hamilton
2016/07/12 00:21:45
Is MarkOtherJobComplete going away in a future CL?
Zhongyi Shi
2016/07/12 23:03:12
Yeah, this one is more for resume logic. It should
| |
| 467 base::RunLoop().RunUntilIdle(); | |
| 468 | |
| 469 EXPECT_FALSE(job_controller_->alternative_job()); | |
| 470 | |
| 471 // |main_job| succeeds and should report status to Request. | |
| 472 HttpStream* http_stream = | |
| 473 new HttpBasicStream(new ClientSocketHandle(), false); | |
| 474 job_factory_.main_job()->SetStream(http_stream); | |
| 475 | |
| 476 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 477 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
| 478 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | |
| 479 ProxyInfo()); | |
| 480 } | |
| 481 | |
| 482 TEST_P(HttpStreamFactoryImplJobControllerTest, | |
| 483 DoNotResumeMainJobWhenAltJobPending) { | |
| 484 ProxyConfig proxy_config; | |
| 485 proxy_config.set_auto_detect(true); | |
| 486 proxy_config.set_pac_url(GURL("http://fooproxyurl")); | |
| 487 HangingProxyResolver hanging_proxy_resolver; | |
| 488 session_deps_.proxy_service.reset(new ProxyService( | |
| 489 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | |
| 490 base::WrapUnique( | |
| 491 new HangingProxyResolverFactory(&hanging_proxy_resolver)), | |
| 492 nullptr)); | |
| 493 | |
| 494 Initialize(); | |
| 495 | |
| 496 HttpRequestInfo request_info; | |
| 497 request_info.method = "GET"; | |
| 498 request_info.url = GURL("http://www.google.com"); | |
| 499 | |
| 500 // Set a SPDY alternative service for the server. | |
| 501 url::SchemeHostPort server(request_info.url); | |
| 502 AlternativeService alternative_service(NPN_HTTP_2, server.host(), 443); | |
| 503 SetAlternativeService(request_info, alternative_service); | |
| 504 | |
| 505 request_.reset( | |
| 506 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 507 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 508 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 509 EXPECT_TRUE(job_controller_->main_job()); | |
| 510 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 511 | |
| 512 // The alternative job stalls but not failing and controller should | |
| 513 // not resume the main job. | |
| 514 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | |
| 515 | |
| 516 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(), | |
| 517 HttpStreamRequest::HTTP_STREAM); | |
|
Ryan Hamilton
2016/07/12 00:21:45
Why do we need to use a Peer here?
Zhongyi Shi
2016/07/12 23:03:12
Job::Start() is called by JobController::CreateJob
| |
| 518 base::RunLoop().RunUntilIdle(); | |
| 519 } | |
| 520 | |
| 521 TEST_P(HttpStreamFactoryImplJobControllerTest, InvalidPortToResumeMainJob) { | |
| 522 Initialize(); | |
| 523 | |
| 524 HttpRequestInfo request_info; | |
| 525 request_info.method = "GET"; | |
| 526 request_info.url = GURL("https://www.google.com"); | |
| 527 | |
| 528 url::SchemeHostPort server(request_info.url); | |
| 529 // Using a restricted port 101 for QUIC should fail. | |
| 530 AlternativeService alternative_service(QUIC, server.host(), 101); | |
| 531 SetAlternativeService(request_info, alternative_service); | |
| 532 | |
| 533 request_.reset( | |
| 534 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 535 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 536 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 537 EXPECT_TRUE(job_controller_->main_job()); | |
| 538 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 539 | |
| 540 HttpStreamFactoryImplJobPeer::Start(job_factory_.main_job(), | |
| 541 HttpStreamRequest::HTTP_STREAM); | |
| 542 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); | |
| 543 | |
| 544 // |alternative_job| fails but should not report status to Request. | |
| 545 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 546 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(), | |
| 547 HttpStreamRequest::HTTP_STREAM); | |
| 548 | |
| 549 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 550 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 551 base::RunLoop().RunUntilIdle(); | |
| 552 | |
| 553 EXPECT_FALSE(job_controller_->alternative_job()); | |
| 554 | |
| 555 // |main_job| succeeds and should report status to Request. | |
| 556 HttpStream* http_stream = | |
| 557 new HttpBasicStream(new ClientSocketHandle(), false); | |
| 558 job_factory_.main_job()->SetStream(http_stream); | |
| 559 | |
| 560 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 561 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
| 562 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | |
| 563 ProxyInfo()); | |
| 564 } | |
| 565 | |
| 566 TEST_P(HttpStreamFactoryImplJobControllerTest, | |
| 567 NoAvailableQuicSessionToResumeMainJob) { | |
| 568 // Use failing HostResolver which is unable to resolve the host name for QUIC. | |
| 569 // No QUIC session is created and thus should resume the main job. | |
| 570 FailingHostResolver* resolver = new FailingHostResolver(); | |
| 571 session_deps_.host_resolver.reset(resolver); | |
| 572 | |
| 573 Initialize(); | |
| 574 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
| 575 DCHECK(quic_stream_factory); | |
| 576 | |
| 577 HttpRequestInfo request_info; | |
| 578 request_info.method = "GET"; | |
| 579 request_info.url = GURL("https://www.google.com"); | |
| 580 | |
| 581 url::SchemeHostPort server(request_info.url); | |
| 582 AlternativeService alternative_service(QUIC, server.host(), 443); | |
| 583 SetAlternativeService(request_info, alternative_service); | |
| 584 | |
| 585 request_.reset( | |
| 586 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 587 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 588 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 589 EXPECT_TRUE(job_controller_->main_job()); | |
| 590 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 591 | |
| 592 HttpStreamFactoryImplJobPeer::Start(job_factory_.main_job(), | |
| 593 HttpStreamRequest::HTTP_STREAM); | |
| 594 | |
| 595 // |alternative_job| fails as host resolution fails and should resume the | |
| 596 // main job. | |
| 597 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 598 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(), | |
| 599 HttpStreamRequest::HTTP_STREAM); | |
| 600 | |
| 601 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 602 // Request shouldn't be notified as the main job is still pending status. | |
| 603 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); | |
| 604 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 605 base::RunLoop().RunUntilIdle(); | |
| 606 | |
| 607 EXPECT_FALSE(job_controller_->alternative_job()); | |
| 608 | |
| 609 // |main_job| succeeds and should report status to Request. | |
| 610 HttpStream* http_stream = | |
| 611 new HttpBasicStream(new ClientSocketHandle(), false); | |
| 612 job_factory_.main_job()->SetStream(http_stream); | |
| 613 | |
| 614 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 615 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
| 616 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | |
| 617 ProxyInfo()); | |
| 618 } | |
| 619 | |
| 620 TEST_P(HttpStreamFactoryImplJobControllerTest, | |
| 621 NoAvailableSpdySessionToResumeMainJob) { | |
| 622 // Disable QUIC. | |
| 623 session_deps_.enable_quic = false; | |
| 624 // Use failing HostResolver which is unable to resolve the host name. | |
| 625 // No SPDY session is created and thus should resume the main job. | |
| 626 FailingHostResolver* resolver = new FailingHostResolver(); | |
| 627 session_deps_.host_resolver.reset(resolver); | |
| 628 | |
| 629 Initialize(); | |
| 630 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
| 631 DCHECK(quic_stream_factory); | |
| 632 | |
| 633 HttpRequestInfo request_info; | |
| 634 request_info.method = "GET"; | |
| 635 request_info.url = GURL("http://www.google.com"); | |
| 636 | |
| 637 // Set a SPDY alternative service for the server. | |
| 638 url::SchemeHostPort server(request_info.url); | |
| 639 AlternativeService alternative_service(NPN_HTTP_2, server.host(), 443); | |
| 640 SetAlternativeService(request_info, alternative_service); | |
| 641 | |
| 642 request_.reset( | |
| 643 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 644 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 645 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 646 EXPECT_TRUE(job_controller_->main_job()); | |
| 647 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 648 | |
| 649 HttpStreamFactoryImplJobPeer::Start(job_factory_.main_job(), | |
| 650 HttpStreamRequest::HTTP_STREAM); | |
| 651 | |
| 652 // |alternative_job| fails as host resolution fails and should resume the | |
| 653 // main job. | |
| 654 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 655 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(), | |
| 656 HttpStreamRequest::HTTP_STREAM); | |
| 657 | |
| 658 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 659 // Request shouldn't be notified as the main job is still pending status. | |
| 660 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); | |
| 661 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 662 base::RunLoop().RunUntilIdle(); | |
| 663 | |
| 664 EXPECT_FALSE(job_controller_->alternative_job()); | |
| 665 | |
| 666 // |main_job| succeeds and should report status to Request. | |
| 667 HttpStream* http_stream = | |
| 668 new HttpBasicStream(new ClientSocketHandle(), false); | |
| 669 job_factory_.main_job()->SetStream(http_stream); | |
| 670 | |
| 671 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
| 672 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
| 673 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | |
| 674 ProxyInfo()); | |
| 675 } | |
| 676 | |
| 677 TEST_P(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | |
| 678 session_deps_.proxy_service.reset( | |
| 679 ProxyService::CreateFixedFromPacResult("QUIC mail.example.org:70") | |
| 680 .release()); | |
| 681 HangingResolver* resolver = new HangingResolver(); | |
| 682 session_deps_.host_resolver.reset(resolver); | |
| 683 | |
| 684 Initialize(); | |
| 685 | |
| 686 // Enable delayed TCP and set time delay for waiting job. | |
| 687 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
| 688 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | |
| 689 quic_stream_factory->set_require_confirmation(false); | |
| 690 ServerNetworkStats stats1; | |
| 691 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | |
| 692 session_->http_server_properties()->SetServerNetworkStats( | |
| 693 url::SchemeHostPort(GURL("https://mail.example.org:70/")), stats1); | |
| 694 | |
| 695 HttpRequestInfo request_info; | |
| 696 request_info.method = "GET"; | |
| 697 request_info.url = GURL("http://www.google.com"); | |
| 698 | |
| 699 // Set a SPDY alternative service for the server. | |
| 700 url::SchemeHostPort server(request_info.url); | |
| 701 AlternativeService alternative_service(NPN_HTTP_2, server.host(), 443); | |
| 702 SetAlternativeService(request_info, alternative_service); | |
| 703 | |
| 704 request_.reset( | |
| 705 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 706 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 707 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 708 EXPECT_TRUE(job_controller_->main_job()); | |
| 709 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 710 | |
| 711 // Start the main job then wait. | |
| 712 HttpStreamFactoryImplJobPeer::Start(job_factory_.main_job(), | |
| 713 HttpStreamRequest::HTTP_STREAM); | |
|
Ryan Hamilton
2016/07/12 00:21:45
Can we avoid the peer by making the PAC resolution
Zhongyi Shi
2016/07/12 23:03:12
I thought you were saying use the asyn PAC resolve
| |
| 714 | |
| 715 // The alternative job stalls as host resolution hangs when creating the QUIC | |
| 716 // request and controller should resume the main job after delay. | |
| 717 // Verify the waiting time for delayed main job. | |
| 718 EXPECT_CALL(*job_factory_.main_job(), Resume()) | |
| 719 .WillOnce(Invoke(testing::CreateFunctor( | |
| 720 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | |
| 721 base::TimeDelta::FromMicroseconds(15)))); | |
| 722 | |
| 723 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(), | |
| 724 HttpStreamRequest::HTTP_STREAM); | |
| 725 base::RunLoop().RunUntilIdle(); | |
| 726 } | |
| 299 } // namespace net | 727 } // namespace net |
| OLD | NEW |