| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 class HttpStreamFactoryImplJobControllerTest | 117 class HttpStreamFactoryImplJobControllerTest |
| 118 : public ::testing::Test, | 118 : public ::testing::Test, |
| 119 public ::testing::WithParamInterface<NextProto> { | 119 public ::testing::WithParamInterface<NextProto> { |
| 120 public: | 120 public: |
| 121 HttpStreamFactoryImplJobControllerTest() | 121 HttpStreamFactoryImplJobControllerTest() |
| 122 : session_deps_(ProxyService::CreateDirect()) { | 122 : session_deps_(ProxyService::CreateDirect()) { |
| 123 session_deps_.enable_quic = true; | 123 session_deps_.enable_quic = true; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void Initialize(bool use_alternative_proxy) { | 126 void Initialize(const HttpRequestInfo& request_info, |
| 127 bool use_alternative_proxy, |
| 128 bool is_preconnect) { |
| 127 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( | 129 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( |
| 128 new TestProxyDelegate()); | 130 new TestProxyDelegate()); |
| 129 test_proxy_delegate_ = test_proxy_delegate.get(); | 131 test_proxy_delegate_ = test_proxy_delegate.get(); |
| 130 | 132 |
| 131 test_proxy_delegate->set_alternative_proxy_server( | 133 test_proxy_delegate->set_alternative_proxy_server( |
| 132 ProxyServer::FromPacString("QUIC myproxy.org:443")); | 134 ProxyServer::FromPacString("QUIC myproxy.org:443")); |
| 133 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); | 135 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); |
| 134 session_deps_.proxy_delegate = std::move(test_proxy_delegate); | 136 session_deps_.proxy_delegate = std::move(test_proxy_delegate); |
| 135 | 137 |
| 136 if (use_alternative_proxy) { | 138 if (use_alternative_proxy) { |
| 137 std::unique_ptr<ProxyService> proxy_service = | 139 std::unique_ptr<ProxyService> proxy_service = |
| 138 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | 140 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); |
| 139 session_deps_.proxy_service = std::move(proxy_service); | 141 session_deps_.proxy_service = std::move(proxy_service); |
| 140 } | 142 } |
| 141 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 143 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 142 factory_ = | 144 factory_ = |
| 143 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 145 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
| 144 job_controller_ = new HttpStreamFactoryImpl::JobController( | 146 job_controller_ = new HttpStreamFactoryImpl::JobController( |
| 145 factory_, &request_delegate_, session_.get(), &job_factory_); | 147 factory_, &request_delegate_, session_.get(), &job_factory_, |
| 148 request_info, is_preconnect); |
| 146 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 149 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
| 147 } | 150 } |
| 148 | 151 |
| 149 TestProxyDelegate* test_proxy_delegate() const { | 152 TestProxyDelegate* test_proxy_delegate() const { |
| 150 return test_proxy_delegate_; | 153 return test_proxy_delegate_; |
| 151 } | 154 } |
| 152 | 155 |
| 153 ~HttpStreamFactoryImplJobControllerTest() {} | 156 ~HttpStreamFactoryImplJobControllerTest() {} |
| 154 | 157 |
| 155 void SetAlternativeService(const HttpRequestInfo& request_info, | 158 void SetAlternativeService(const HttpRequestInfo& request_info, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 TEST_F(HttpStreamFactoryImplJobControllerTest, | 191 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 189 OnStreamFailedWithNoAlternativeJob) { | 192 OnStreamFailedWithNoAlternativeJob) { |
| 190 ProxyConfig proxy_config; | 193 ProxyConfig proxy_config; |
| 191 proxy_config.set_auto_detect(true); | 194 proxy_config.set_auto_detect(true); |
| 192 // Use asynchronous proxy resolver. | 195 // Use asynchronous proxy resolver. |
| 193 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 196 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 194 new MockAsyncProxyResolverFactory(false); | 197 new MockAsyncProxyResolverFactory(false); |
| 195 session_deps_.proxy_service.reset( | 198 session_deps_.proxy_service.reset( |
| 196 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 199 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 197 base::WrapUnique(proxy_resolver_factory), nullptr)); | 200 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 198 Initialize(false); | |
| 199 | 201 |
| 200 HttpRequestInfo request_info; | 202 HttpRequestInfo request_info; |
| 201 request_info.method = "GET"; | 203 request_info.method = "GET"; |
| 202 request_info.url = GURL("http://www.google.com"); | 204 request_info.url = GURL("http://www.google.com"); |
| 203 | 205 |
| 206 Initialize(request_info, false, false); |
| 207 |
| 204 request_.reset( | 208 request_.reset( |
| 205 job_controller_->Start(request_info, &request_delegate_, nullptr, | 209 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 206 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 210 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 207 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 211 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 208 | 212 |
| 209 EXPECT_TRUE(job_controller_->main_job()); | 213 EXPECT_TRUE(job_controller_->main_job()); |
| 210 | 214 |
| 211 // There's no other alternative job. Thus when stream failed, it should | 215 // There's no other alternative job. Thus when stream failed, it should |
| 212 // notify Request of the stream failure. | 216 // notify Request of the stream failure. |
| 213 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 217 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
| 214 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 218 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 215 SSLConfig()); | 219 SSLConfig()); |
| 216 } | 220 } |
| 217 | 221 |
| 218 TEST_F(HttpStreamFactoryImplJobControllerTest, | 222 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 219 OnStreamReadyWithNoAlternativeJob) { | 223 OnStreamReadyWithNoAlternativeJob) { |
| 220 ProxyConfig proxy_config; | 224 ProxyConfig proxy_config; |
| 221 proxy_config.set_auto_detect(true); | 225 proxy_config.set_auto_detect(true); |
| 222 // Use asynchronous proxy resolver. | 226 // Use asynchronous proxy resolver. |
| 223 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 227 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 224 new MockAsyncProxyResolverFactory(false); | 228 new MockAsyncProxyResolverFactory(false); |
| 225 session_deps_.proxy_service.reset( | 229 session_deps_.proxy_service.reset( |
| 226 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 230 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 227 base::WrapUnique(proxy_resolver_factory), nullptr)); | 231 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 228 Initialize(false); | |
| 229 | |
| 230 HttpRequestInfo request_info; | 232 HttpRequestInfo request_info; |
| 231 request_info.method = "GET"; | 233 request_info.method = "GET"; |
| 232 request_info.url = GURL("http://www.google.com"); | 234 request_info.url = GURL("http://www.google.com"); |
| 233 | 235 |
| 236 Initialize(request_info, false, false); |
| 237 |
| 234 request_.reset( | 238 request_.reset( |
| 235 job_controller_->Start(request_info, &request_delegate_, nullptr, | 239 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 236 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 240 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 237 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 241 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 238 | 242 |
| 239 // There's no other alternative job. Thus when a stream is ready, it should | 243 // There's no other alternative job. Thus when a stream is ready, it should |
| 240 // notify Request. | 244 // notify Request. |
| 241 HttpStream* http_stream = | 245 HttpStream* http_stream = |
| 242 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 246 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
| 243 job_factory_.main_job()->SetStream(http_stream); | 247 job_factory_.main_job()->SetStream(http_stream); |
| 244 | 248 |
| 245 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 249 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 246 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 250 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 247 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | 251 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); |
| 248 } | 252 } |
| 249 | 253 |
| 250 // Test we cancel Jobs correctly when the Request is explicitly canceled | 254 // Test we cancel Jobs correctly when the Request is explicitly canceled |
| 251 // before any Job is bound to Request. | 255 // before any Job is bound to Request. |
| 252 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 256 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
| 253 ProxyConfig proxy_config; | 257 ProxyConfig proxy_config; |
| 254 proxy_config.set_auto_detect(true); | 258 proxy_config.set_auto_detect(true); |
| 255 // Use asynchronous proxy resolver. | 259 // Use asynchronous proxy resolver. |
| 256 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 260 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 257 new MockAsyncProxyResolverFactory(false); | 261 new MockAsyncProxyResolverFactory(false); |
| 258 session_deps_.proxy_service.reset(new ProxyService( | 262 session_deps_.proxy_service.reset(new ProxyService( |
| 259 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 263 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 260 base::WrapUnique(proxy_resolver_factory), nullptr)); | 264 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 261 Initialize(false); | |
| 262 | 265 |
| 263 HttpRequestInfo request_info; | 266 HttpRequestInfo request_info; |
| 264 request_info.method = "GET"; | 267 request_info.method = "GET"; |
| 265 request_info.url = GURL("https://www.google.com"); | 268 request_info.url = GURL("https://www.google.com"); |
| 266 | 269 |
| 270 Initialize(request_info, false, false); |
| 267 url::SchemeHostPort server(request_info.url); | 271 url::SchemeHostPort server(request_info.url); |
| 268 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 272 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 269 SetAlternativeService(request_info, alternative_service); | 273 SetAlternativeService(request_info, alternative_service); |
| 270 | 274 |
| 271 request_.reset( | 275 request_.reset( |
| 272 job_controller_->Start(request_info, &request_delegate_, nullptr, | 276 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 273 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 277 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 274 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 278 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 275 EXPECT_TRUE(job_controller_->main_job()); | 279 EXPECT_TRUE(job_controller_->main_job()); |
| 276 EXPECT_TRUE(job_controller_->alternative_job()); | 280 EXPECT_TRUE(job_controller_->alternative_job()); |
| 277 | 281 |
| 278 // Reset the Request will cancel all the Jobs since there's no Job determined | 282 // Reset the Request will cancel all the Jobs since there's no Job determined |
| 279 // to serve Request yet and JobController will notify the factory to delete | 283 // to serve Request yet and JobController will notify the factory to delete |
| 280 // itself upon completion. | 284 // itself upon completion. |
| 281 request_.reset(); | 285 request_.reset(); |
| 282 VerifyBrokenAlternateProtocolMapping(request_info, false); | 286 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 283 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 287 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 284 } | 288 } |
| 285 | 289 |
| 286 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 290 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 287 ProxyConfig proxy_config; | 291 ProxyConfig proxy_config; |
| 288 proxy_config.set_auto_detect(true); | 292 proxy_config.set_auto_detect(true); |
| 289 // Use asynchronous proxy resolver. | 293 // Use asynchronous proxy resolver. |
| 290 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 294 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 291 new MockAsyncProxyResolverFactory(false); | 295 new MockAsyncProxyResolverFactory(false); |
| 292 session_deps_.proxy_service.reset( | 296 session_deps_.proxy_service.reset( |
| 293 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 297 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 294 base::WrapUnique(proxy_resolver_factory), nullptr)); | 298 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 295 Initialize(false); | |
| 296 | 299 |
| 297 HttpRequestInfo request_info; | 300 HttpRequestInfo request_info; |
| 298 request_info.method = "GET"; | 301 request_info.method = "GET"; |
| 299 request_info.url = GURL("https://www.google.com"); | 302 request_info.url = GURL("https://www.google.com"); |
| 300 | 303 |
| 304 Initialize(request_info, false, false); |
| 301 url::SchemeHostPort server(request_info.url); | 305 url::SchemeHostPort server(request_info.url); |
| 302 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 306 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 303 SetAlternativeService(request_info, alternative_service); | 307 SetAlternativeService(request_info, alternative_service); |
| 304 | 308 |
| 305 request_.reset( | 309 request_.reset( |
| 306 job_controller_->Start(request_info, &request_delegate_, nullptr, | 310 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 307 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 311 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 308 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 312 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 309 EXPECT_TRUE(job_controller_->main_job()); | 313 EXPECT_TRUE(job_controller_->main_job()); |
| 310 EXPECT_TRUE(job_controller_->alternative_job()); | 314 EXPECT_TRUE(job_controller_->alternative_job()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 329 TEST_F(HttpStreamFactoryImplJobControllerTest, | 333 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 330 AltJobFailsAfterMainJobSucceeds) { | 334 AltJobFailsAfterMainJobSucceeds) { |
| 331 ProxyConfig proxy_config; | 335 ProxyConfig proxy_config; |
| 332 proxy_config.set_auto_detect(true); | 336 proxy_config.set_auto_detect(true); |
| 333 // Use asynchronous proxy resolver. | 337 // Use asynchronous proxy resolver. |
| 334 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 338 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 335 new MockAsyncProxyResolverFactory(false); | 339 new MockAsyncProxyResolverFactory(false); |
| 336 session_deps_.proxy_service.reset( | 340 session_deps_.proxy_service.reset( |
| 337 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 341 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 338 base::WrapUnique(proxy_resolver_factory), nullptr)); | 342 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 339 Initialize(false); | |
| 340 | 343 |
| 341 HttpRequestInfo request_info; | 344 HttpRequestInfo request_info; |
| 342 request_info.method = "GET"; | 345 request_info.method = "GET"; |
| 343 request_info.url = GURL("https://www.google.com"); | 346 request_info.url = GURL("https://www.google.com"); |
| 344 | 347 |
| 348 Initialize(request_info, false, false); |
| 345 url::SchemeHostPort server(request_info.url); | 349 url::SchemeHostPort server(request_info.url); |
| 346 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 350 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 347 SetAlternativeService(request_info, alternative_service); | 351 SetAlternativeService(request_info, alternative_service); |
| 348 | 352 |
| 349 request_.reset( | 353 request_.reset( |
| 350 job_controller_->Start(request_info, &request_delegate_, nullptr, | 354 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 351 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 355 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 352 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 356 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 353 EXPECT_TRUE(job_controller_->main_job()); | 357 EXPECT_TRUE(job_controller_->main_job()); |
| 354 EXPECT_TRUE(job_controller_->alternative_job()); | 358 EXPECT_TRUE(job_controller_->alternative_job()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 381 // Regression test for crbug.com/678768. | 385 // Regression test for crbug.com/678768. |
| 382 TEST_F(HttpStreamFactoryImplJobControllerTest, | 386 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 383 AltJobSucceedsMainJobBlockedControllerDestroyed) { | 387 AltJobSucceedsMainJobBlockedControllerDestroyed) { |
| 384 ProxyConfig proxy_config; | 388 ProxyConfig proxy_config; |
| 385 proxy_config.set_auto_detect(true); | 389 proxy_config.set_auto_detect(true); |
| 386 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 390 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 387 new MockAsyncProxyResolverFactory(false); | 391 new MockAsyncProxyResolverFactory(false); |
| 388 session_deps_.proxy_service.reset( | 392 session_deps_.proxy_service.reset( |
| 389 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 393 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 390 base::WrapUnique(proxy_resolver_factory), nullptr)); | 394 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 391 Initialize(false); | |
| 392 | |
| 393 HttpRequestInfo request_info; | 395 HttpRequestInfo request_info; |
| 394 request_info.method = "GET"; | 396 request_info.method = "GET"; |
| 395 request_info.url = GURL("https://www.google.com"); | 397 request_info.url = GURL("https://www.google.com"); |
| 396 | 398 |
| 399 Initialize(request_info, false, false); |
| 400 |
| 397 url::SchemeHostPort server(request_info.url); | 401 url::SchemeHostPort server(request_info.url); |
| 398 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 402 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 399 SetAlternativeService(request_info, alternative_service); | 403 SetAlternativeService(request_info, alternative_service); |
| 400 request_.reset( | 404 request_.reset( |
| 401 job_controller_->Start(request_info, &request_delegate_, nullptr, | 405 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 402 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 406 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 403 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 407 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 404 EXPECT_TRUE(job_controller_->main_job()); | 408 EXPECT_TRUE(job_controller_->main_job()); |
| 405 EXPECT_TRUE(job_controller_->alternative_job()); | 409 EXPECT_TRUE(job_controller_->alternative_job()); |
| 406 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 410 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 428 // JobController will be cleaned up. | 432 // JobController will be cleaned up. |
| 429 TEST_F(HttpStreamFactoryImplJobControllerTest, | 433 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 430 OrphanedJobCompletesControllerDestroyed) { | 434 OrphanedJobCompletesControllerDestroyed) { |
| 431 ProxyConfig proxy_config; | 435 ProxyConfig proxy_config; |
| 432 proxy_config.set_auto_detect(true); | 436 proxy_config.set_auto_detect(true); |
| 433 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 437 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 434 new MockAsyncProxyResolverFactory(false); | 438 new MockAsyncProxyResolverFactory(false); |
| 435 session_deps_.proxy_service.reset( | 439 session_deps_.proxy_service.reset( |
| 436 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 440 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 437 base::WrapUnique(proxy_resolver_factory), nullptr)); | 441 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 438 Initialize(false); | |
| 439 | |
| 440 HttpRequestInfo request_info; | 442 HttpRequestInfo request_info; |
| 441 request_info.method = "GET"; | 443 request_info.method = "GET"; |
| 442 request_info.url = GURL("https://www.google.com"); | 444 request_info.url = GURL("https://www.google.com"); |
| 443 | 445 |
| 446 Initialize(request_info, false, false); |
| 447 |
| 444 url::SchemeHostPort server(request_info.url); | 448 url::SchemeHostPort server(request_info.url); |
| 445 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 449 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 446 SetAlternativeService(request_info, alternative_service); | 450 SetAlternativeService(request_info, alternative_service); |
| 447 // Hack to use different URL for the main job to help differentiate the proxy | 451 // Hack to use different URL for the main job to help differentiate the proxy |
| 448 // requests. | 452 // requests. |
| 449 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | 453 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); |
| 450 request_.reset( | 454 request_.reset( |
| 451 job_controller_->Start(request_info, &request_delegate_, nullptr, | 455 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 452 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 456 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 453 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 457 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 TEST_F(HttpStreamFactoryImplJobControllerTest, | 499 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 496 AltJobSucceedsAfterMainJobFailed) { | 500 AltJobSucceedsAfterMainJobFailed) { |
| 497 ProxyConfig proxy_config; | 501 ProxyConfig proxy_config; |
| 498 proxy_config.set_auto_detect(true); | 502 proxy_config.set_auto_detect(true); |
| 499 // Use asynchronous proxy resolver. | 503 // Use asynchronous proxy resolver. |
| 500 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 504 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 501 new MockAsyncProxyResolverFactory(false); | 505 new MockAsyncProxyResolverFactory(false); |
| 502 session_deps_.proxy_service.reset( | 506 session_deps_.proxy_service.reset( |
| 503 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 507 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 504 base::WrapUnique(proxy_resolver_factory), nullptr)); | 508 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 505 Initialize(false); | |
| 506 | |
| 507 HttpRequestInfo request_info; | 509 HttpRequestInfo request_info; |
| 508 request_info.method = "GET"; | 510 request_info.method = "GET"; |
| 509 request_info.url = GURL("https://www.google.com"); | 511 request_info.url = GURL("https://www.google.com"); |
| 510 | 512 |
| 513 Initialize(request_info, false, false); |
| 514 |
| 511 url::SchemeHostPort server(request_info.url); | 515 url::SchemeHostPort server(request_info.url); |
| 512 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 516 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 513 SetAlternativeService(request_info, alternative_service); | 517 SetAlternativeService(request_info, alternative_service); |
| 514 | 518 |
| 515 request_.reset( | 519 request_.reset( |
| 516 job_controller_->Start(request_info, &request_delegate_, nullptr, | 520 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 517 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 521 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 518 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 522 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 519 EXPECT_TRUE(job_controller_->main_job()); | 523 EXPECT_TRUE(job_controller_->main_job()); |
| 520 EXPECT_TRUE(job_controller_->alternative_job()); | 524 EXPECT_TRUE(job_controller_->alternative_job()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 539 TEST_F(HttpStreamFactoryImplJobControllerTest, | 543 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 540 MainJobSucceedsAfterAltJobFailed) { | 544 MainJobSucceedsAfterAltJobFailed) { |
| 541 ProxyConfig proxy_config; | 545 ProxyConfig proxy_config; |
| 542 proxy_config.set_auto_detect(true); | 546 proxy_config.set_auto_detect(true); |
| 543 // Use asynchronous proxy resolver. | 547 // Use asynchronous proxy resolver. |
| 544 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 548 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 545 new MockAsyncProxyResolverFactory(false); | 549 new MockAsyncProxyResolverFactory(false); |
| 546 session_deps_.proxy_service.reset( | 550 session_deps_.proxy_service.reset( |
| 547 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 551 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 548 base::WrapUnique(proxy_resolver_factory), nullptr)); | 552 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 549 Initialize(false); | |
| 550 | |
| 551 HttpRequestInfo request_info; | 553 HttpRequestInfo request_info; |
| 552 request_info.method = "GET"; | 554 request_info.method = "GET"; |
| 553 request_info.url = GURL("https://www.google.com"); | 555 request_info.url = GURL("https://www.google.com"); |
| 554 | 556 |
| 557 Initialize(request_info, false, false); |
| 558 |
| 555 url::SchemeHostPort server(request_info.url); | 559 url::SchemeHostPort server(request_info.url); |
| 556 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 560 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 557 SetAlternativeService(request_info, alternative_service); | 561 SetAlternativeService(request_info, alternative_service); |
| 558 | 562 |
| 559 request_.reset( | 563 request_.reset( |
| 560 job_controller_->Start(request_info, &request_delegate_, nullptr, | 564 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 561 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 565 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 562 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 566 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 563 EXPECT_TRUE(job_controller_->main_job()); | 567 EXPECT_TRUE(job_controller_->main_job()); |
| 564 EXPECT_TRUE(job_controller_->alternative_job()); | 568 EXPECT_TRUE(job_controller_->alternative_job()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 585 // Get load state after main job fails and before alternative job succeeds. | 589 // Get load state after main job fails and before alternative job succeeds. |
| 586 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 590 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
| 587 ProxyConfig proxy_config; | 591 ProxyConfig proxy_config; |
| 588 proxy_config.set_auto_detect(true); | 592 proxy_config.set_auto_detect(true); |
| 589 // Use asynchronous proxy resolver. | 593 // Use asynchronous proxy resolver. |
| 590 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 594 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 591 new MockAsyncProxyResolverFactory(false); | 595 new MockAsyncProxyResolverFactory(false); |
| 592 session_deps_.proxy_service.reset(new ProxyService( | 596 session_deps_.proxy_service.reset(new ProxyService( |
| 593 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 597 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
| 594 base::WrapUnique(proxy_resolver_factory), nullptr)); | 598 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 595 Initialize(false); | |
| 596 | 599 |
| 597 HttpRequestInfo request_info; | 600 HttpRequestInfo request_info; |
| 598 request_info.method = "GET"; | 601 request_info.method = "GET"; |
| 599 request_info.url = GURL("https://www.google.com"); | 602 request_info.url = GURL("https://www.google.com"); |
| 600 | 603 |
| 604 Initialize(request_info, false, false); |
| 601 url::SchemeHostPort server(request_info.url); | 605 url::SchemeHostPort server(request_info.url); |
| 602 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 606 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 603 SetAlternativeService(request_info, alternative_service); | 607 SetAlternativeService(request_info, alternative_service); |
| 604 | 608 |
| 605 request_.reset( | 609 request_.reset( |
| 606 job_controller_->Start(request_info, &request_delegate_, nullptr, | 610 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 607 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 611 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 608 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 612 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 609 EXPECT_TRUE(job_controller_->main_job()); | 613 EXPECT_TRUE(job_controller_->main_job()); |
| 610 EXPECT_TRUE(job_controller_->alternative_job()); | 614 EXPECT_TRUE(job_controller_->alternative_job()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 633 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 637 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
| 634 // to stall the alternative job and report to controller to maybe resume the | 638 // to stall the alternative job and report to controller to maybe resume the |
| 635 // main job. | 639 // main job. |
| 636 ProxyConfig proxy_config; | 640 ProxyConfig proxy_config; |
| 637 proxy_config.set_auto_detect(true); | 641 proxy_config.set_auto_detect(true); |
| 638 proxy_config.set_pac_mandatory(true); | 642 proxy_config.set_pac_mandatory(true); |
| 639 session_deps_.proxy_service.reset(new ProxyService( | 643 session_deps_.proxy_service.reset(new ProxyService( |
| 640 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 644 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 641 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | 645 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 642 | 646 |
| 643 Initialize(false); | |
| 644 | |
| 645 HttpRequestInfo request_info; | 647 HttpRequestInfo request_info; |
| 646 request_info.method = "GET"; | 648 request_info.method = "GET"; |
| 647 request_info.url = GURL("https://www.google.com"); | 649 request_info.url = GURL("https://www.google.com"); |
| 648 | 650 |
| 651 Initialize(request_info, false, false); |
| 649 url::SchemeHostPort server(request_info.url); | 652 url::SchemeHostPort server(request_info.url); |
| 650 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 653 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 651 SetAlternativeService(request_info, alternative_service); | 654 SetAlternativeService(request_info, alternative_service); |
| 652 | 655 |
| 653 request_.reset( | 656 request_.reset( |
| 654 job_controller_->Start(request_info, &request_delegate_, nullptr, | 657 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 655 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 658 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 656 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 659 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 657 EXPECT_TRUE(job_controller_->main_job()); | 660 EXPECT_TRUE(job_controller_->main_job()); |
| 658 EXPECT_TRUE(job_controller_->alternative_job()); | 661 EXPECT_TRUE(job_controller_->alternative_job()); |
| 659 | 662 |
| 660 // Wait until OnStreamFailedCallback is executed on the alternative job. | 663 // Wait until OnStreamFailedCallback is executed on the alternative job. |
| 661 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 664 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
| 662 base::RunLoop().RunUntilIdle(); | 665 base::RunLoop().RunUntilIdle(); |
| 663 } | 666 } |
| 664 | 667 |
| 665 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 668 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
| 666 // Using a restricted port 101 for QUIC should fail and the alternative job | |
| 667 // should post OnStreamFailedCall on the controller to resume the main job. | |
| 668 Initialize(false); | |
| 669 | |
| 670 HttpRequestInfo request_info; | 669 HttpRequestInfo request_info; |
| 671 request_info.method = "GET"; | 670 request_info.method = "GET"; |
| 672 request_info.url = GURL("https://www.google.com"); | 671 request_info.url = GURL("https://www.google.com"); |
| 673 | 672 |
| 673 // Using a restricted port 101 for QUIC should fail and the alternative job |
| 674 // should post OnStreamFailedCall on the controller to resume the main job. |
| 675 Initialize(request_info, false, false); |
| 676 |
| 674 url::SchemeHostPort server(request_info.url); | 677 url::SchemeHostPort server(request_info.url); |
| 675 AlternativeService alternative_service(kProtoQUIC, server.host(), 101); | 678 AlternativeService alternative_service(kProtoQUIC, server.host(), 101); |
| 676 SetAlternativeService(request_info, alternative_service); | 679 SetAlternativeService(request_info, alternative_service); |
| 677 | 680 |
| 678 request_.reset( | 681 request_.reset( |
| 679 job_controller_->Start(request_info, &request_delegate_, nullptr, | 682 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 680 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 683 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 681 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 684 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 682 | 685 |
| 683 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); | 686 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 699 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 702 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 700 new MockAsyncProxyResolverFactory(false); | 703 new MockAsyncProxyResolverFactory(false); |
| 701 session_deps_.proxy_service.reset( | 704 session_deps_.proxy_service.reset( |
| 702 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 705 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 703 base::WrapUnique(proxy_resolver_factory), nullptr)); | 706 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 704 | 707 |
| 705 HangingResolver* host_resolver = new HangingResolver(); | 708 HangingResolver* host_resolver = new HangingResolver(); |
| 706 session_deps_.host_resolver.reset(host_resolver); | 709 session_deps_.host_resolver.reset(host_resolver); |
| 707 session_deps_.host_resolver->set_synchronous_mode(false); | 710 session_deps_.host_resolver->set_synchronous_mode(false); |
| 708 | 711 |
| 709 Initialize(false); | |
| 710 | |
| 711 HttpRequestInfo request_info; | 712 HttpRequestInfo request_info; |
| 712 request_info.method = "GET"; | 713 request_info.method = "GET"; |
| 713 request_info.url = GURL("https://www.google.com"); | 714 request_info.url = GURL("https://www.google.com"); |
| 714 | 715 |
| 716 Initialize(request_info, false, false); |
| 717 |
| 715 // Set a SPDY alternative service for the server. | 718 // Set a SPDY alternative service for the server. |
| 716 url::SchemeHostPort server(request_info.url); | 719 url::SchemeHostPort server(request_info.url); |
| 717 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 720 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 718 SetAlternativeService(request_info, alternative_service); | 721 SetAlternativeService(request_info, alternative_service); |
| 719 // Hack to use different URL for the main job to help differentiate the proxy | 722 // Hack to use different URL for the main job to help differentiate the proxy |
| 720 // requests. | 723 // requests. |
| 721 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | 724 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); |
| 722 | 725 |
| 723 request_.reset( | 726 request_.reset( |
| 724 job_controller_->Start(request_info, &request_delegate_, nullptr, | 727 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 | 765 |
| 763 ProxyConfig proxy_config; | 766 ProxyConfig proxy_config; |
| 764 proxy_config.set_auto_detect(true); | 767 proxy_config.set_auto_detect(true); |
| 765 // Use asynchronous proxy resolver. | 768 // Use asynchronous proxy resolver. |
| 766 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 769 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 767 new MockAsyncProxyResolverFactory(false); | 770 new MockAsyncProxyResolverFactory(false); |
| 768 session_deps_.proxy_service.reset( | 771 session_deps_.proxy_service.reset( |
| 769 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 772 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 770 base::WrapUnique(proxy_resolver_factory), nullptr)); | 773 base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 771 | 774 |
| 772 Initialize(false); | |
| 773 | |
| 774 HttpRequestInfo request_info; | 775 HttpRequestInfo request_info; |
| 775 request_info.method = "GET"; | 776 request_info.method = "GET"; |
| 776 request_info.url = GURL("https://www.google.com"); | 777 request_info.url = GURL("https://www.google.com"); |
| 777 | 778 |
| 779 Initialize(request_info, false, false); |
| 778 url::SchemeHostPort server(request_info.url); | 780 url::SchemeHostPort server(request_info.url); |
| 779 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 781 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 780 SetAlternativeService(request_info, alternative_service); | 782 SetAlternativeService(request_info, alternative_service); |
| 781 // Hack to use different URL for the main job to help differentiate the proxy | 783 // Hack to use different URL for the main job to help differentiate the proxy |
| 782 // requests. | 784 // requests. |
| 783 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | 785 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); |
| 784 | 786 |
| 785 request_.reset( | 787 request_.reset( |
| 786 job_controller_->Start(request_info, &request_delegate_, nullptr, | 788 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 787 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 789 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 814 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 816 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 815 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 817 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
| 816 | 818 |
| 817 base::RunLoop().RunUntilIdle(); | 819 base::RunLoop().RunUntilIdle(); |
| 818 } | 820 } |
| 819 | 821 |
| 820 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 822 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
| 821 HangingResolver* resolver = new HangingResolver(); | 823 HangingResolver* resolver = new HangingResolver(); |
| 822 session_deps_.host_resolver.reset(resolver); | 824 session_deps_.host_resolver.reset(resolver); |
| 823 | 825 |
| 824 Initialize(false); | 826 HttpRequestInfo request_info; |
| 827 request_info.method = "GET"; |
| 828 request_info.url = GURL("https://www.google.com"); |
| 829 |
| 830 Initialize(request_info, false, false); |
| 825 | 831 |
| 826 // Enable delayed TCP and set time delay for waiting job. | 832 // Enable delayed TCP and set time delay for waiting job. |
| 827 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 833 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 828 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | 834 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 829 quic_stream_factory->set_require_confirmation(false); | 835 quic_stream_factory->set_require_confirmation(false); |
| 830 ServerNetworkStats stats1; | 836 ServerNetworkStats stats1; |
| 831 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 837 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 832 session_->http_server_properties()->SetServerNetworkStats( | 838 session_->http_server_properties()->SetServerNetworkStats( |
| 833 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 839 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
| 834 | 840 |
| 835 HttpRequestInfo request_info; | |
| 836 request_info.method = "GET"; | |
| 837 request_info.url = GURL("https://www.google.com"); | |
| 838 | |
| 839 // Set a SPDY alternative service for the server. | 841 // Set a SPDY alternative service for the server. |
| 840 url::SchemeHostPort server(request_info.url); | 842 url::SchemeHostPort server(request_info.url); |
| 841 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 843 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 842 SetAlternativeService(request_info, alternative_service); | 844 SetAlternativeService(request_info, alternative_service); |
| 843 | 845 |
| 844 request_.reset( | 846 request_.reset( |
| 845 job_controller_->Start(request_info, &request_delegate_, nullptr, | 847 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 846 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 848 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 847 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 849 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 848 EXPECT_TRUE(job_controller_->main_job()); | 850 EXPECT_TRUE(job_controller_->main_job()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 859 base::RunLoop().RunUntilIdle(); | 861 base::RunLoop().RunUntilIdle(); |
| 860 } | 862 } |
| 861 | 863 |
| 862 // Verifies that the alternative proxy server job is not created if the URL | 864 // Verifies that the alternative proxy server job is not created if the URL |
| 863 // scheme is HTTPS. | 865 // scheme is HTTPS. |
| 864 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { | 866 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpsURL) { |
| 865 // Using hanging resolver will cause the alternative job to hang indefinitely. | 867 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 866 HangingResolver* resolver = new HangingResolver(); | 868 HangingResolver* resolver = new HangingResolver(); |
| 867 session_deps_.host_resolver.reset(resolver); | 869 session_deps_.host_resolver.reset(resolver); |
| 868 | 870 |
| 869 Initialize(true); | |
| 870 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | |
| 871 | |
| 872 HttpRequestInfo request_info; | 871 HttpRequestInfo request_info; |
| 873 request_info.method = "GET"; | 872 request_info.method = "GET"; |
| 874 request_info.url = GURL("https://mail.example.org/"); | 873 request_info.url = GURL("https://mail.example.org/"); |
| 874 Initialize(request_info, false, false); |
| 875 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 875 | 876 |
| 876 request_.reset( | 877 request_.reset( |
| 877 job_controller_->Start(request_info, &request_delegate_, nullptr, | 878 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 878 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 879 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 879 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 880 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 880 EXPECT_TRUE(job_controller_->main_job()); | 881 EXPECT_TRUE(job_controller_->main_job()); |
| 881 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 882 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 882 EXPECT_FALSE(job_controller_->alternative_job()); | 883 EXPECT_FALSE(job_controller_->alternative_job()); |
| 883 | 884 |
| 884 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 885 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 885 base::RunLoop().RunUntilIdle(); | 886 base::RunLoop().RunUntilIdle(); |
| 886 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 887 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 887 } | 888 } |
| 888 | 889 |
| 889 // Verifies that the alternative proxy server job is not created if the main job | 890 // Verifies that the alternative proxy server job is not created if the main job |
| 890 // does not fetch the resource through a proxy. | 891 // does not fetch the resource through a proxy. |
| 891 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { | 892 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { |
| 892 // Using hanging resolver will cause the alternative job to hang indefinitely. | 893 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 893 HangingResolver* resolver = new HangingResolver(); | 894 HangingResolver* resolver = new HangingResolver(); |
| 894 session_deps_.host_resolver.reset(resolver); | 895 session_deps_.host_resolver.reset(resolver); |
| 895 | 896 |
| 896 Initialize(false); | |
| 897 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | |
| 898 | |
| 899 HttpRequestInfo request_info; | 897 HttpRequestInfo request_info; |
| 900 request_info.method = "GET"; | 898 request_info.method = "GET"; |
| 901 request_info.url = GURL("http://mail.example.org/"); | 899 request_info.url = GURL("http://mail.example.org/"); |
| 902 | 900 |
| 901 Initialize(request_info, false, false); |
| 902 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 903 |
| 903 request_.reset( | 904 request_.reset( |
| 904 job_controller_->Start(request_info, &request_delegate_, nullptr, | 905 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 905 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 906 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 906 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 907 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 907 EXPECT_TRUE(job_controller_->main_job()); | 908 EXPECT_TRUE(job_controller_->main_job()); |
| 908 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 909 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
| 909 EXPECT_FALSE(job_controller_->alternative_job()); | 910 EXPECT_FALSE(job_controller_->alternative_job()); |
| 910 | 911 |
| 911 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 912 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
| 912 base::RunLoop().RunUntilIdle(); | 913 base::RunLoop().RunUntilIdle(); |
| 913 | 914 |
| 914 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 915 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 915 } | 916 } |
| 916 | 917 |
| 917 // Verifies that the main job is resumed properly after a delay when the | 918 // Verifies that the main job is resumed properly after a delay when the |
| 918 // alternative proxy server job hangs. | 919 // alternative proxy server job hangs. |
| 919 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { | 920 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { |
| 920 // Using hanging resolver will cause the alternative job to hang indefinitely. | 921 // Using hanging resolver will cause the alternative job to hang indefinitely. |
| 921 HangingResolver* resolver = new HangingResolver(); | 922 HangingResolver* resolver = new HangingResolver(); |
| 922 session_deps_.host_resolver.reset(resolver); | 923 session_deps_.host_resolver.reset(resolver); |
| 923 | 924 |
| 924 Initialize(true); | 925 HttpRequestInfo request_info; |
| 926 request_info.method = "GET"; |
| 927 request_info.url = GURL("http://mail.example.org/"); |
| 928 Initialize(request_info, true, false); |
| 929 |
| 925 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 930 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 926 | 931 |
| 927 // Enable delayed TCP and set time delay for waiting job. | 932 // Enable delayed TCP and set time delay for waiting job. |
| 928 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 933 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 929 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | 934 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 930 quic_stream_factory->set_require_confirmation(false); | 935 quic_stream_factory->set_require_confirmation(false); |
| 931 ServerNetworkStats stats1; | 936 ServerNetworkStats stats1; |
| 932 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 937 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 933 session_->http_server_properties()->SetServerNetworkStats( | 938 session_->http_server_properties()->SetServerNetworkStats( |
| 934 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 939 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 935 | 940 |
| 936 HttpRequestInfo request_info; | |
| 937 request_info.method = "GET"; | |
| 938 request_info.url = GURL("http://mail.example.org/"); | |
| 939 | |
| 940 request_.reset( | 941 request_.reset( |
| 941 job_controller_->Start(request_info, &request_delegate_, nullptr, | 942 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 942 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 943 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 943 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 944 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 944 EXPECT_TRUE(job_controller_->main_job()); | 945 EXPECT_TRUE(job_controller_->main_job()); |
| 945 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 946 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 946 EXPECT_TRUE(job_controller_->alternative_job()); | 947 EXPECT_TRUE(job_controller_->alternative_job()); |
| 947 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 948 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
| 948 | 949 |
| 949 // The alternative proxy server job stalls when connecting to the alternative | 950 // The alternative proxy server job stalls when connecting to the alternative |
| (...skipping 25 matching lines...) Expand all Loading... |
| 975 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 976 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 976 } | 977 } |
| 977 | 978 |
| 978 // Verifies that the alternative proxy server job fails immediately, and the | 979 // Verifies that the alternative proxy server job fails immediately, and the |
| 979 // main job is not blocked. | 980 // main job is not blocked. |
| 980 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { | 981 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { |
| 981 // Using failing resolver will cause the alternative job to fail. | 982 // Using failing resolver will cause the alternative job to fail. |
| 982 FailingHostResolver* resolver = new FailingHostResolver(); | 983 FailingHostResolver* resolver = new FailingHostResolver(); |
| 983 session_deps_.host_resolver.reset(resolver); | 984 session_deps_.host_resolver.reset(resolver); |
| 984 | 985 |
| 985 Initialize(true); | 986 HttpRequestInfo request_info; |
| 987 request_info.method = "GET"; |
| 988 request_info.url = GURL("http://mail.example.org/"); |
| 989 Initialize(request_info, true, false); |
| 986 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 990 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
| 987 | 991 |
| 988 // Enable delayed TCP and set time delay for waiting job. | 992 // Enable delayed TCP and set time delay for waiting job. |
| 989 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 993 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
| 990 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | 994 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
| 991 quic_stream_factory->set_require_confirmation(false); | 995 quic_stream_factory->set_require_confirmation(false); |
| 992 ServerNetworkStats stats1; | 996 ServerNetworkStats stats1; |
| 993 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); | 997 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); |
| 994 session_->http_server_properties()->SetServerNetworkStats( | 998 session_->http_server_properties()->SetServerNetworkStats( |
| 995 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 999 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
| 996 | 1000 |
| 997 HttpRequestInfo request_info; | |
| 998 request_info.method = "GET"; | |
| 999 request_info.url = GURL("http://mail.example.org/"); | |
| 1000 | |
| 1001 request_.reset( | 1001 request_.reset( |
| 1002 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1002 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 1003 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1003 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 1004 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 1004 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 1005 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1005 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 1006 EXPECT_TRUE(job_controller_->alternative_job()); | 1006 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1007 | 1007 |
| 1008 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); | 1008 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); |
| 1009 | 1009 |
| 1010 // Since the alternative proxy server job is started in the next message loop, | 1010 // Since the alternative proxy server job is started in the next message loop, |
| 1011 // the main job would remain blocked until the alternative proxy starts, and | 1011 // the main job would remain blocked until the alternative proxy starts, and |
| 1012 // fails. | 1012 // fails. |
| 1013 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 1013 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
| 1014 .WillOnce(Invoke(testing::CreateFunctor( | 1014 .WillOnce(Invoke(testing::CreateFunctor( |
| 1015 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 1015 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
| 1016 base::TimeDelta::FromMicroseconds(0)))); | 1016 base::TimeDelta::FromMicroseconds(0)))); |
| 1017 | 1017 |
| 1018 base::RunLoop().RunUntilIdle(); | 1018 base::RunLoop().RunUntilIdle(); |
| 1019 EXPECT_FALSE(job_controller_->alternative_job()); | 1019 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1020 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1020 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 1021 // Since the main job did not complete successfully, the alternative proxy | 1021 // Since the main job did not complete successfully, the alternative proxy |
| 1022 // server should not be marked as bad. | 1022 // server should not be marked as bad. |
| 1023 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | 1023 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
| 1024 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1024 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 TEST_F(HttpStreamFactoryImplJobControllerTest, | 1027 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 1028 AlternativeProxyServerJobFailsAfterMainJobSucceeds) { | 1028 AlternativeProxyServerJobFailsAfterMainJobSucceeds) { |
| 1029 base::HistogramTester histogram_tester; | 1029 base::HistogramTester histogram_tester; |
| 1030 Initialize(true); | |
| 1031 | |
| 1032 HttpRequestInfo request_info; | 1030 HttpRequestInfo request_info; |
| 1033 request_info.method = "GET"; | 1031 request_info.method = "GET"; |
| 1034 request_info.url = GURL("http://www.google.com"); | 1032 request_info.url = GURL("http://www.google.com"); |
| 1033 Initialize(request_info, true, false); |
| 1035 | 1034 |
| 1036 url::SchemeHostPort server(request_info.url); | 1035 url::SchemeHostPort server(request_info.url); |
| 1037 | 1036 |
| 1038 request_.reset( | 1037 request_.reset( |
| 1039 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1038 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 1040 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1039 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, |
| 1041 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 1040 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 1042 EXPECT_TRUE(job_controller_->main_job()); | 1041 EXPECT_TRUE(job_controller_->main_job()); |
| 1043 EXPECT_TRUE(job_controller_->alternative_job()); | 1042 EXPECT_TRUE(job_controller_->alternative_job()); |
| 1044 | 1043 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1068 1); | 1067 1); |
| 1069 } | 1068 } |
| 1070 | 1069 |
| 1071 // When preconnect to a H2 supported server, only 1 connection is opened. | 1070 // When preconnect to a H2 supported server, only 1 connection is opened. |
| 1072 TEST_F(HttpStreamFactoryImplJobControllerTest, | 1071 TEST_F(HttpStreamFactoryImplJobControllerTest, |
| 1073 PreconnectMultipleStreamsToH2Server) { | 1072 PreconnectMultipleStreamsToH2Server) { |
| 1074 MockRead reads[] = {MockRead(ASYNC, OK)}; | 1073 MockRead reads[] = {MockRead(ASYNC, OK)}; |
| 1075 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); | 1074 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); |
| 1076 session_deps_.socket_factory->AddSocketDataProvider(&data); | 1075 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1077 | 1076 |
| 1078 Initialize(false); | |
| 1079 HttpRequestInfo request_info; | 1077 HttpRequestInfo request_info; |
| 1080 request_info.method = "GET"; | 1078 request_info.method = "GET"; |
| 1081 request_info.url = GURL("http://www.example.com"); | 1079 request_info.url = GURL("http://www.example.com"); |
| 1080 Initialize(request_info, false, /*is_preconnect=*/true); |
| 1082 | 1081 |
| 1083 url::SchemeHostPort server(request_info.url); | 1082 url::SchemeHostPort server(request_info.url); |
| 1084 | 1083 |
| 1085 // Sets server support Http/2. | 1084 // Sets server support Http/2. |
| 1086 session_->http_server_properties()->SetSupportsSpdy(server, true); | 1085 session_->http_server_properties()->SetSupportsSpdy(server, true); |
| 1087 | 1086 |
| 1088 job_controller_->Preconnect(/*num_streams=*/5, request_info, SSLConfig(), | 1087 job_controller_->Preconnect(/*num_streams=*/5, request_info, SSLConfig(), |
| 1089 SSLConfig()); | 1088 SSLConfig()); |
| 1090 // Only one job is started. | 1089 // Only one job is started. |
| 1091 EXPECT_TRUE(job_controller_->main_job()); | 1090 EXPECT_TRUE(job_controller_->main_job()); |
| 1092 EXPECT_FALSE(job_controller_->alternative_job()); | 1091 EXPECT_FALSE(job_controller_->alternative_job()); |
| 1093 // There is only 1 connect even though multiple streams were requested. | 1092 // There is only 1 connect even though multiple streams were requested. |
| 1094 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( | 1093 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( |
| 1095 job_controller_->main_job())); | 1094 job_controller_->main_job())); |
| 1096 | 1095 |
| 1097 base::RunLoop().RunUntilIdle(); | 1096 base::RunLoop().RunUntilIdle(); |
| 1098 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1097 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 1099 } | 1098 } |
| 1100 | 1099 |
| 1101 } // namespace net | 1100 } // namespace net |
| OLD | NEW |