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 } | |
| 122 | |
| 123 void CancelRequest(RequestHandle req) override {} | |
| 124 }; | |
| 31 } // anonymous namespace | 125 } // anonymous namespace |
| 32 | 126 |
| 127 class HttpStreamFactoryImplJobPeer { | |
| 128 public: | |
| 129 static void Start(HttpStreamFactoryImpl::Job* job, | |
| 130 HttpStreamRequest::StreamType stream_type) { | |
| 131 // Start() is mocked for MockHttpStreamFactoryImplJob. | |
| 132 // This is the alternative method to invoke real Start() method on Job. | |
| 133 job->stream_type_ = stream_type; | |
| 134 job->StartInternal(); | |
| 135 } | |
| 136 }; | |
| 137 | |
| 138 class JobControllerPeer { | |
| 139 public: | |
| 140 static void VerifyWaitingTimeForMainJob( | |
| 141 HttpStreamFactoryImpl::JobController* job_controller, | |
| 142 const base::TimeDelta& delay) { | |
| 143 EXPECT_EQ(delay, job_controller->main_job_wait_time_); | |
| 144 } | |
| 145 }; | |
| 146 | |
| 33 class HttpStreamFactoryImplJobControllerTest | 147 class HttpStreamFactoryImplJobControllerTest |
| 34 : public ::testing::Test, | 148 : public ::testing::Test, |
| 35 public ::testing::WithParamInterface<NextProto> { | 149 public ::testing::WithParamInterface<NextProto> { |
| 36 public: | 150 public: |
| 37 HttpStreamFactoryImplJobControllerTest() | 151 HttpStreamFactoryImplJobControllerTest() |
| 38 : session_deps_(GetParam(), ProxyService::CreateDirect()) { | 152 : session_deps_(GetParam(), ProxyService::CreateDirect()) { |
| 39 session_deps_.enable_quic = true; | 153 session_deps_.enable_quic = true; |
| 154 } | |
| 155 | |
| 156 void Initialize() { | |
| 40 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 157 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 41 factory_ = | 158 factory_ = |
| 42 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 159 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 43 job_controller_ = new HttpStreamFactoryImpl::JobController( | 160 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 44 factory_, &request_delegate_, session_.get(), &job_factory_); | 161 factory_, &request_delegate_, session_.get(), &job_factory_); |
| 45 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 162 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
| 46 } | 163 } |
| 47 | 164 |
| 48 ~HttpStreamFactoryImplJobControllerTest() {} | 165 ~HttpStreamFactoryImplJobControllerTest() {} |
| 49 | 166 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 66 | 183 |
| 67 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 184 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
| 68 }; | 185 }; |
| 69 | 186 |
| 70 INSTANTIATE_TEST_CASE_P(NextProto, | 187 INSTANTIATE_TEST_CASE_P(NextProto, |
| 71 HttpStreamFactoryImplJobControllerTest, | 188 HttpStreamFactoryImplJobControllerTest, |
| 72 testing::Values(kProtoSPDY31, kProtoHTTP2)); | 189 testing::Values(kProtoSPDY31, kProtoHTTP2)); |
| 73 | 190 |
| 74 TEST_P(HttpStreamFactoryImplJobControllerTest, | 191 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 75 OnStreamFailedWithNoAlternativeJob) { | 192 OnStreamFailedWithNoAlternativeJob) { |
| 193 Initialize(); | |
| 194 | |
| 76 HttpRequestInfo request_info; | 195 HttpRequestInfo request_info; |
| 77 request_info.method = "GET"; | 196 request_info.method = "GET"; |
| 78 request_info.url = GURL("http://www.google.com"); | 197 request_info.url = GURL("http://www.google.com"); |
| 79 | 198 |
| 80 request_.reset( | 199 request_.reset( |
| 81 job_controller_->Start(request_info, &request_delegate_, nullptr, | 200 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 82 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 201 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 83 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 202 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 84 | 203 |
| 85 EXPECT_TRUE(job_controller_->main_job()); | 204 EXPECT_TRUE(job_controller_->main_job()); |
| 86 | 205 |
| 87 // There's no other alternative job. Thus when stream failed, it should | 206 // There's no other alternative job. Thus when stream failed, it should |
| 88 // notify Request of the stream failure. | 207 // notify Request of the stream failure. |
| 89 EXPECT_CALL(request_delegate_, | 208 EXPECT_CALL(request_delegate_, |
| 90 OnStreamFailed(ERR_FAILED, _, SSL_FAILURE_NONE)) | 209 OnStreamFailed(ERR_FAILED, _, SSL_FAILURE_NONE)) |
| 91 .Times(1); | 210 .Times(1); |
| 92 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 211 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 93 SSLConfig(), SSL_FAILURE_NONE); | 212 SSLConfig(), SSL_FAILURE_NONE); |
| 94 } | 213 } |
| 95 | 214 |
| 96 TEST_P(HttpStreamFactoryImplJobControllerTest, | 215 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 97 OnStreamReadyWithNoAlternativeJob) { | 216 OnStreamReadyWithNoAlternativeJob) { |
| 217 Initialize(); | |
| 218 | |
| 98 HttpRequestInfo request_info; | 219 HttpRequestInfo request_info; |
| 99 request_info.method = "GET"; | 220 request_info.method = "GET"; |
| 100 request_info.url = GURL("http://www.google.com"); | 221 request_info.url = GURL("http://www.google.com"); |
| 101 | 222 |
| 102 request_.reset( | 223 request_.reset( |
| 103 job_controller_->Start(request_info, &request_delegate_, nullptr, | 224 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 104 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 225 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 105 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 226 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 106 EXPECT_TRUE(job_controller_->main_job()); | 227 EXPECT_TRUE(job_controller_->main_job()); |
| 107 | 228 |
| 108 // There's no other alternative job. Thus when stream is ready, it should | 229 // There's no other alternative job. Thus when stream is ready, it should |
| 109 // notify Request. | 230 // notify Request. |
| 110 HttpStream* http_stream = | 231 HttpStream* http_stream = |
| 111 new HttpBasicStream(new ClientSocketHandle(), false); | 232 new HttpBasicStream(new ClientSocketHandle(), false); |
| 112 job_factory_.main_job()->SetStream(http_stream); | 233 job_factory_.main_job()->SetStream(http_stream); |
| 113 | 234 |
| 114 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 235 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 115 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 236 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 116 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 237 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), |
| 117 ProxyInfo()); | 238 ProxyInfo()); |
| 118 } | 239 } |
| 119 | 240 |
| 120 // Test we cancel Jobs correctly when the Request is explicitly canceled | 241 // Test we cancel Jobs correctly when the Request is explicitly canceled |
| 121 // before any Job is bound to Request. | 242 // before any Job is bound to Request. |
| 122 TEST_P(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 243 TEST_P(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
| 244 Initialize(); | |
| 245 | |
| 123 HttpRequestInfo request_info; | 246 HttpRequestInfo request_info; |
| 124 request_info.method = "GET"; | 247 request_info.method = "GET"; |
| 125 request_info.url = GURL("https://www.google.com"); | 248 request_info.url = GURL("https://www.google.com"); |
| 126 | 249 |
| 127 url::SchemeHostPort server(request_info.url); | 250 url::SchemeHostPort server(request_info.url); |
| 128 AlternativeService alternative_service(QUIC, server.host(), 443); | 251 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 129 SetAlternativeService(request_info, alternative_service); | 252 SetAlternativeService(request_info, alternative_service); |
| 130 | 253 |
| 131 request_.reset( | 254 request_.reset( |
| 132 job_controller_->Start(request_info, &request_delegate_, nullptr, | 255 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 133 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 256 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 134 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 257 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 135 EXPECT_TRUE(job_controller_->main_job()); | 258 EXPECT_TRUE(job_controller_->main_job()); |
| 136 EXPECT_TRUE(job_controller_->alternative_job()); | 259 EXPECT_TRUE(job_controller_->alternative_job()); |
| 137 | 260 |
| 138 // Reset the Request will cancel all the Jobs since there's no Job determined | 261 // 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 | 262 // to serve Request yet and JobController will notify the factory to delete |
| 140 // itself upon completion. | 263 // itself upon completion. |
| 141 request_.reset(); | 264 request_.reset(); |
| 142 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 265 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 143 } | 266 } |
| 144 | 267 |
| 145 TEST_P(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 268 TEST_P(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 269 Initialize(); | |
| 270 | |
| 146 HttpRequestInfo request_info; | 271 HttpRequestInfo request_info; |
| 147 request_info.method = "GET"; | 272 request_info.method = "GET"; |
| 148 request_info.url = GURL("https://www.google.com"); | 273 request_info.url = GURL("https://www.google.com"); |
| 149 | 274 |
| 150 url::SchemeHostPort server(request_info.url); | 275 url::SchemeHostPort server(request_info.url); |
| 151 AlternativeService alternative_service(QUIC, server.host(), 443); | 276 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 152 SetAlternativeService(request_info, alternative_service); | 277 SetAlternativeService(request_info, alternative_service); |
| 153 | 278 |
| 154 request_.reset( | 279 request_.reset( |
| 155 job_controller_->Start(request_info, &request_delegate_, nullptr, | 280 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 | 296 // The failure of second Job should be reported to Request as there's no more |
| 172 // pending Job to serve the Request. | 297 // pending Job to serve the Request. |
| 173 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_UNKNOWN)) | 298 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_UNKNOWN)) |
| 174 .Times(1); | 299 .Times(1); |
| 175 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 300 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 176 SSLConfig(), SSL_FAILURE_UNKNOWN); | 301 SSLConfig(), SSL_FAILURE_UNKNOWN); |
| 177 } | 302 } |
| 178 | 303 |
| 179 TEST_P(HttpStreamFactoryImplJobControllerTest, | 304 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 180 SecondJobFailsAfterFirstJobSucceeds) { | 305 SecondJobFailsAfterFirstJobSucceeds) { |
| 306 Initialize(); | |
| 307 | |
| 181 HttpRequestInfo request_info; | 308 HttpRequestInfo request_info; |
| 182 request_info.method = "GET"; | 309 request_info.method = "GET"; |
| 183 request_info.url = GURL("https://www.google.com"); | 310 request_info.url = GURL("https://www.google.com"); |
| 184 | 311 |
| 185 url::SchemeHostPort server(request_info.url); | 312 url::SchemeHostPort server(request_info.url); |
| 186 AlternativeService alternative_service(QUIC, server.host(), 443); | 313 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 187 SetAlternativeService(request_info, alternative_service); | 314 SetAlternativeService(request_info, alternative_service); |
| 188 | 315 |
| 189 request_.reset( | 316 request_.reset( |
| 190 job_controller_->Start(request_info, &request_delegate_, nullptr, | 317 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, | 340 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
| 214 SSLConfig(), SSL_FAILURE_NONE); | 341 SSLConfig(), SSL_FAILURE_NONE); |
| 215 | 342 |
| 216 // Reset the request as it's been successfully served. | 343 // Reset the request as it's been successfully served. |
| 217 request_.reset(); | 344 request_.reset(); |
| 218 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 345 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 219 } | 346 } |
| 220 | 347 |
| 221 TEST_P(HttpStreamFactoryImplJobControllerTest, | 348 TEST_P(HttpStreamFactoryImplJobControllerTest, |
| 222 SecondJobSucceedsAfterFirstJobFailed) { | 349 SecondJobSucceedsAfterFirstJobFailed) { |
| 350 Initialize(); | |
| 351 | |
| 223 HttpRequestInfo request_info; | 352 HttpRequestInfo request_info; |
| 224 request_info.method = "GET"; | 353 request_info.method = "GET"; |
| 225 request_info.url = GURL("https://www.google.com"); | 354 request_info.url = GURL("https://www.google.com"); |
| 226 | 355 |
| 227 url::SchemeHostPort server(request_info.url); | 356 url::SchemeHostPort server(request_info.url); |
| 228 AlternativeService alternative_service(QUIC, server.host(), 443); | 357 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 229 SetAlternativeService(request_info, alternative_service); | 358 SetAlternativeService(request_info, alternative_service); |
| 230 | 359 |
| 231 request_.reset( | 360 request_.reset( |
| 232 job_controller_->Start(request_info, &request_delegate_, nullptr, | 361 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 251 | 380 |
| 252 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 381 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 253 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 382 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 254 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 383 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
| 255 ProxyInfo()); | 384 ProxyInfo()); |
| 256 } | 385 } |
| 257 | 386 |
| 258 // Regression test for crbug/621069. | 387 // Regression test for crbug/621069. |
| 259 // Get load state after main job fails and before alternative job succeeds. | 388 // Get load state after main job fails and before alternative job succeeds. |
| 260 TEST_P(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 389 TEST_P(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
| 390 Initialize(); | |
| 391 | |
| 261 HttpRequestInfo request_info; | 392 HttpRequestInfo request_info; |
| 262 request_info.method = "GET"; | 393 request_info.method = "GET"; |
| 263 request_info.url = GURL("https://www.google.com"); | 394 request_info.url = GURL("https://www.google.com"); |
| 264 | 395 |
| 265 url::SchemeHostPort server(request_info.url); | 396 url::SchemeHostPort server(request_info.url); |
| 266 AlternativeService alternative_service(QUIC, server.host(), 443); | 397 AlternativeService alternative_service(QUIC, server.host(), 443); |
| 267 SetAlternativeService(request_info, alternative_service); | 398 SetAlternativeService(request_info, alternative_service); |
| 268 | 399 |
| 269 request_.reset( | 400 request_.reset( |
| 270 job_controller_->Start(request_info, &request_delegate_, nullptr, | 401 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 289 HttpStream* http_stream = | 420 HttpStream* http_stream = |
| 290 new HttpBasicStream(new ClientSocketHandle(), false); | 421 new HttpBasicStream(new ClientSocketHandle(), false); |
| 291 job_factory_.alternative_job()->SetStream(http_stream); | 422 job_factory_.alternative_job()->SetStream(http_stream); |
| 292 | 423 |
| 293 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 424 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 294 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 425 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 295 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 426 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
| 296 ProxyInfo()); | 427 ProxyInfo()); |
| 297 } | 428 } |
| 298 | 429 |
| 430 TEST_P(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | |
| 431 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | |
| 432 // to stall the alternative job and report to controller to maybe resume the | |
| 433 // main job. | |
| 434 ProxyConfig proxy_config; | |
| 435 proxy_config.set_auto_detect(true); | |
| 436 proxy_config.set_pac_mandatory(true); | |
| 437 session_deps_.proxy_service.reset(new ProxyService( | |
| 438 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | |
| 439 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | |
| 440 | |
| 441 Initialize(); | |
| 442 | |
| 443 HttpRequestInfo request_info; | |
| 444 request_info.method = "GET"; | |
| 445 request_info.url = GURL("https://www.google.com"); | |
| 446 | |
| 447 url::SchemeHostPort server(request_info.url); | |
| 448 AlternativeService alternative_service(QUIC, server.host(), 443); | |
| 449 SetAlternativeService(request_info, alternative_service); | |
| 450 job_factory_.DisableMockStartForJobs(); | |
| 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 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 460 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_NONE)) | |
| 461 .Times(1); | |
| 462 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 463 base::RunLoop().RunUntilIdle(); | |
| 464 } | |
| 465 | |
| 466 TEST_P(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | |
| 467 // Using a restricted port 101 for QUIC should fail and the alternative job | |
| 468 // should post OnStreamFailedCall on the controller to resume the main job. | |
| 469 Initialize(); | |
| 470 | |
| 471 HttpRequestInfo request_info; | |
| 472 request_info.method = "GET"; | |
| 473 request_info.url = GURL("https://www.google.com"); | |
| 474 | |
| 475 url::SchemeHostPort server(request_info.url); | |
| 476 AlternativeService alternative_service(QUIC, server.host(), 101); | |
| 477 SetAlternativeService(request_info, alternative_service); | |
| 478 job_factory_.DisableMockStartForJobs(); | |
| 479 | |
| 480 request_.reset( | |
| 481 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 482 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 483 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 484 | |
| 485 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); | |
| 486 | |
| 487 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 488 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 489 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 490 base::RunLoop().RunUntilIdle(); | |
| 491 } | |
| 492 | |
| 493 TEST_P(HttpStreamFactoryImplJobControllerTest, | |
| 494 NoAvailableSpdySessionToResumeMainJob) { | |
| 495 // Test the alternative job is not resumed when the alternative job is | |
| 496 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds, | |
| 497 // the latter part of this test tests controller resumes the main job | |
| 498 // when there's no SPDY session for the alternative job. | |
| 499 ProxyConfig proxy_config; | |
| 500 proxy_config.set_auto_detect(true); | |
| 501 // Use asynchronous proxy resolver. | |
| 502 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 503 new MockAsyncProxyResolverFactory(false); | |
| 504 session_deps_.proxy_service.reset(new ProxyService( | |
| 505 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | |
| 506 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 507 | |
| 508 HangingResolver* host_resolver = new HangingResolver(); | |
| 509 session_deps_.host_resolver.reset(host_resolver); | |
| 510 session_deps_.host_resolver->set_synchronous_mode(false); | |
| 511 | |
| 512 Initialize(); | |
| 513 | |
| 514 HttpRequestInfo request_info; | |
| 515 request_info.method = "GET"; | |
| 516 request_info.url = GURL("http://www.google.com"); | |
| 517 | |
| 518 // Set a SPDY alternative service for the server. | |
| 519 url::SchemeHostPort server(request_info.url); | |
| 520 AlternativeService alternative_service(NPN_HTTP_2, server.host(), 443); | |
| 521 SetAlternativeService(request_info, alternative_service); | |
| 522 job_factory_.DisableMockStartForJobs(); | |
|
Ryan Hamilton
2016/07/19 17:48:15
Discussed offline, let's move to using the 'normal
| |
| 523 | |
| 524 request_.reset( | |
| 525 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 526 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 527 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 528 // Both jobs should be created but stalled as proxy resolution not completed. | |
| 529 EXPECT_TRUE(job_controller_->main_job()); | |
| 530 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 531 | |
| 532 MockAsyncProxyResolver resolver; | |
| 533 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
| 534 net::OK, &resolver); | |
| 535 | |
| 536 // Resolve proxy for the main job which then proceed to wait for the | |
| 537 // alternative job which is IO_PENDING. | |
| 538 int main_job_request_id = | |
| 539 resolver.pending_requests()[0]->url().SchemeIs("http") ? 0 : 1; | |
| 540 | |
| 541 resolver.pending_requests()[main_job_request_id]->results()->UseNamedProxy( | |
| 542 "result1:80"); | |
| 543 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK); | |
| 544 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
| 545 | |
| 546 // Resolve proxy for the alternative job to proceed to create a connection. | |
| 547 // Use hanging HostResolver to fail creation of a SPDY session for the | |
| 548 // alternative job. The alternative job will be IO_PENDING thus should resume | |
| 549 // the main job. | |
| 550 resolver.pending_requests()[0]->CompleteNow(net::OK); | |
| 551 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); | |
| 552 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 553 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 554 | |
| 555 base::RunLoop().RunUntilIdle(); | |
| 556 } | |
| 557 | |
| 558 TEST_P(HttpStreamFactoryImplJobControllerTest, | |
| 559 NoAvailableQuicSessionToResumeMainJob) { | |
| 560 // Use failing HostResolver which is unable to resolve the host name for QUIC. | |
| 561 // No QUIC session is created and thus should resume the main job. | |
| 562 FailingHostResolver* host_resolver = new FailingHostResolver(); | |
| 563 session_deps_.host_resolver.reset(host_resolver); | |
| 564 | |
| 565 ProxyConfig proxy_config; | |
| 566 proxy_config.set_auto_detect(true); | |
| 567 // Use asynchronous proxy resolver. | |
| 568 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
| 569 new MockAsyncProxyResolverFactory(false); | |
| 570 session_deps_.proxy_service.reset(new ProxyService( | |
| 571 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | |
| 572 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
| 573 | |
| 574 Initialize(); | |
| 575 | |
| 576 HttpRequestInfo request_info; | |
| 577 request_info.method = "GET"; | |
| 578 request_info.url = GURL("https://www.google.com"); | |
| 579 | |
| 580 url::SchemeHostPort server(request_info.url); | |
| 581 AlternativeService alternative_service(QUIC, server.host(), 443); | |
| 582 SetAlternativeService(request_info, alternative_service); | |
| 583 job_factory_.DisableMockStartForJobs(); | |
| 584 // Hack to use different URL for the main job to help differentiate the proxy | |
| 585 // requests. | |
| 586 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | |
| 587 | |
|
Zhongyi Shi
2016/07/15 18:42:49
The original url has to use HTTPS so as to racing
eroman
2016/07/15 19:30:33
Does this test specifically need to test using PAC
| |
| 588 request_.reset( | |
| 589 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 590 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 591 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 592 EXPECT_TRUE(job_controller_->main_job()); | |
| 593 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 594 | |
| 595 MockAsyncProxyResolver resolver; | |
| 596 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
| 597 net::OK, &resolver); | |
| 598 | |
| 599 // Resolve proxy for the main job which then proceed to wait for the | |
| 600 // alternative job which is IO_PENDING. | |
| 601 int main_job_request_id = | |
| 602 resolver.pending_requests()[0]->url().SchemeIs("http") ? 0 : 1; | |
| 603 | |
| 604 resolver.pending_requests()[main_job_request_id]->results()->UseNamedProxy( | |
| 605 "result1:80"); | |
| 606 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK); | |
| 607 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
| 608 | |
| 609 // Resolve proxy for the alternative job to proceed to create a connection. | |
| 610 // Use failing HostResolver to fail creation of a QUIC session for the | |
| 611 // alternative job. The alternative job will thus resume the main job. | |
| 612 resolver.pending_requests()[0]->results()->UseNamedProxy("result1:80"); | |
| 613 resolver.pending_requests()[0]->CompleteNow(net::OK); | |
| 614 | |
| 615 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
| 616 // Request shouldn't be notified as the main job is still pending status. | |
| 617 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); | |
| 618 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
| 619 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
| 620 | |
| 621 base::RunLoop().RunUntilIdle(); | |
| 622 } | |
| 623 | |
| 624 TEST_P(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | |
| 625 session_deps_.proxy_service.reset( | |
| 626 ProxyService::CreateFixedFromPacResult("QUIC mail.example.org:70") | |
| 627 .release()); | |
| 628 HangingResolver* resolver = new HangingResolver(); | |
| 629 session_deps_.host_resolver.reset(resolver); | |
| 630 | |
| 631 Initialize(); | |
| 632 | |
| 633 // Enable delayed TCP and set time delay for waiting job. | |
| 634 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
| 635 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | |
| 636 quic_stream_factory->set_require_confirmation(false); | |
| 637 ServerNetworkStats stats1; | |
| 638 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | |
| 639 session_->http_server_properties()->SetServerNetworkStats( | |
| 640 url::SchemeHostPort(GURL("https://mail.example.org:70/")), stats1); | |
| 641 | |
| 642 HttpRequestInfo request_info; | |
| 643 request_info.method = "GET"; | |
| 644 request_info.url = GURL("http://www.google.com"); | |
| 645 | |
| 646 // Set a SPDY alternative service for the server. | |
| 647 url::SchemeHostPort server(request_info.url); | |
| 648 AlternativeService alternative_service(NPN_HTTP_2, server.host(), 443); | |
| 649 SetAlternativeService(request_info, alternative_service); | |
| 650 job_factory_.DisableMockStartForJobs(); | |
| 651 | |
| 652 request_.reset( | |
| 653 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
| 654 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
| 655 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
| 656 EXPECT_TRUE(job_controller_->main_job()); | |
| 657 EXPECT_TRUE(job_controller_->alternative_job()); | |
| 658 | |
| 659 // The alternative job stalls as host resolution hangs when creating the QUIC | |
| 660 // request and controller should resume the main job after delay. | |
| 661 // Verify the waiting time for delayed main job. | |
| 662 EXPECT_CALL(*job_factory_.main_job(), Resume()) | |
| 663 .WillOnce(Invoke(testing::CreateFunctor( | |
| 664 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | |
| 665 base::TimeDelta::FromMicroseconds(15)))); | |
| 666 | |
| 667 base::RunLoop().RunUntilIdle(); | |
| 668 } | |
| 299 } // namespace net | 669 } // namespace net |
| OLD | NEW |