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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 232 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
233 | 233 |
234 // There's no other alternative job. Thus when a stream is ready, it should | 234 // There's no other alternative job. Thus when a stream is ready, it should |
235 // notify Request. | 235 // notify Request. |
236 HttpStream* http_stream = | 236 HttpStream* http_stream = |
237 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 237 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
238 job_factory_.main_job()->SetStream(http_stream); | 238 job_factory_.main_job()->SetStream(http_stream); |
239 | 239 |
240 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 240 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
241 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 241 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
242 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 242 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); |
243 ProxyInfo()); | |
244 } | 243 } |
245 | 244 |
246 // Test we cancel Jobs correctly when the Request is explicitly canceled | 245 // Test we cancel Jobs correctly when the Request is explicitly canceled |
247 // before any Job is bound to Request. | 246 // before any Job is bound to Request. |
248 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 247 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
249 ProxyConfig proxy_config; | 248 ProxyConfig proxy_config; |
250 proxy_config.set_auto_detect(true); | 249 proxy_config.set_auto_detect(true); |
251 // Use asynchronous proxy resolver. | 250 // Use asynchronous proxy resolver. |
252 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 251 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
253 new MockAsyncProxyResolverFactory(false); | 252 new MockAsyncProxyResolverFactory(false); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 350 |
352 // Main job succeeds, starts serving Request and it should report status | 351 // Main job succeeds, starts serving Request and it should report status |
353 // to Request. The alternative job will mark the main job complete and gets | 352 // to Request. The alternative job will mark the main job complete and gets |
354 // orphaned. | 353 // orphaned. |
355 HttpStream* http_stream = | 354 HttpStream* http_stream = |
356 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 355 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
357 job_factory_.main_job()->SetStream(http_stream); | 356 job_factory_.main_job()->SetStream(http_stream); |
358 | 357 |
359 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 358 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
360 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 359 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
361 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 360 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); |
362 ProxyInfo()); | |
363 | 361 |
364 // JobController shouldn't report the status of second job as request | 362 // JobController shouldn't report the status of second job as request |
365 // is already successfully served. | 363 // is already successfully served. |
366 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 364 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
367 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 365 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
368 SSLConfig()); | 366 SSLConfig()); |
369 | 367 |
370 VerifyBrokenAlternateProtocolMapping(request_info, true); | 368 VerifyBrokenAlternateProtocolMapping(request_info, true); |
371 // Reset the request as it's been successfully served. | 369 // Reset the request as it's been successfully served. |
372 request_.reset(); | 370 request_.reset(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 404 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
407 SSLConfig()); | 405 SSLConfig()); |
408 | 406 |
409 // |alternative_job| succeeds and should report status to Request. | 407 // |alternative_job| succeeds and should report status to Request. |
410 HttpStream* http_stream = | 408 HttpStream* http_stream = |
411 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 409 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
412 job_factory_.alternative_job()->SetStream(http_stream); | 410 job_factory_.alternative_job()->SetStream(http_stream); |
413 | 411 |
414 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 412 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
415 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 413 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
416 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 414 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
417 ProxyInfo()); | |
418 VerifyBrokenAlternateProtocolMapping(request_info, false); | 415 VerifyBrokenAlternateProtocolMapping(request_info, false); |
419 } | 416 } |
420 | 417 |
421 TEST_F(HttpStreamFactoryImplJobControllerTest, | 418 TEST_F(HttpStreamFactoryImplJobControllerTest, |
422 MainJobSucceedsAfterAltJobFailed) { | 419 MainJobSucceedsAfterAltJobFailed) { |
423 ProxyConfig proxy_config; | 420 ProxyConfig proxy_config; |
424 proxy_config.set_auto_detect(true); | 421 proxy_config.set_auto_detect(true); |
425 // Use asynchronous proxy resolver. | 422 // Use asynchronous proxy resolver. |
426 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 423 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
427 new MockAsyncProxyResolverFactory(false); | 424 new MockAsyncProxyResolverFactory(false); |
(...skipping 23 matching lines...) Expand all Loading... |
451 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 448 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
452 SSLConfig()); | 449 SSLConfig()); |
453 | 450 |
454 // |main_job| succeeds and should report status to Request. | 451 // |main_job| succeeds and should report status to Request. |
455 HttpStream* http_stream = | 452 HttpStream* http_stream = |
456 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 453 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
457 job_factory_.main_job()->SetStream(http_stream); | 454 job_factory_.main_job()->SetStream(http_stream); |
458 | 455 |
459 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 456 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
460 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 457 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
461 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 458 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); |
462 ProxyInfo()); | |
463 | 459 |
464 VerifyBrokenAlternateProtocolMapping(request_info, true); | 460 VerifyBrokenAlternateProtocolMapping(request_info, true); |
465 } | 461 } |
466 | 462 |
467 // Regression test for crbug/621069. | 463 // Regression test for crbug/621069. |
468 // Get load state after main job fails and before alternative job succeeds. | 464 // Get load state after main job fails and before alternative job succeeds. |
469 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 465 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
470 ProxyConfig proxy_config; | 466 ProxyConfig proxy_config; |
471 proxy_config.set_auto_detect(true); | 467 proxy_config.set_auto_detect(true); |
472 // Use asynchronous proxy resolver. | 468 // Use asynchronous proxy resolver. |
(...skipping 29 matching lines...) Expand all Loading... |
502 // Controller should use alternative job to get load state. | 498 // Controller should use alternative job to get load state. |
503 job_controller_->GetLoadState(); | 499 job_controller_->GetLoadState(); |
504 | 500 |
505 // |alternative_job| succeeds and should report status to Request. | 501 // |alternative_job| succeeds and should report status to Request. |
506 HttpStream* http_stream = | 502 HttpStream* http_stream = |
507 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 503 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
508 job_factory_.alternative_job()->SetStream(http_stream); | 504 job_factory_.alternative_job()->SetStream(http_stream); |
509 | 505 |
510 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 506 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
511 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 507 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
512 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 508 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
513 ProxyInfo()); | |
514 } | 509 } |
515 | 510 |
516 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | 511 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { |
517 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 512 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
518 // to stall the alternative job and report to controller to maybe resume the | 513 // to stall the alternative job and report to controller to maybe resume the |
519 // main job. | 514 // main job. |
520 ProxyConfig proxy_config; | 515 ProxyConfig proxy_config; |
521 proxy_config.set_auto_detect(true); | 516 proxy_config.set_auto_detect(true); |
522 proxy_config.set_pac_mandatory(true); | 517 proxy_config.set_pac_mandatory(true); |
523 session_deps_.proxy_service.reset(new ProxyService( | 518 session_deps_.proxy_service.reset(new ProxyService( |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 923 |
929 // Main job succeeds, starts serving Request and it should report status | 924 // Main job succeeds, starts serving Request and it should report status |
930 // to Request. The alternative job will mark the main job complete and gets | 925 // to Request. The alternative job will mark the main job complete and gets |
931 // orphaned. | 926 // orphaned. |
932 HttpStream* http_stream = | 927 HttpStream* http_stream = |
933 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 928 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
934 job_factory_.main_job()->SetStream(http_stream); | 929 job_factory_.main_job()->SetStream(http_stream); |
935 | 930 |
936 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 931 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
937 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 932 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
938 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 933 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); |
939 job_factory_.main_job()->proxy_info()); | |
940 | 934 |
941 // JobController shouldn't report the status of alternative server job as | 935 // JobController shouldn't report the status of alternative server job as |
942 // request is already successfully served. | 936 // request is already successfully served. |
943 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 937 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
944 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 938 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, |
945 SSLConfig()); | 939 SSLConfig()); |
946 | 940 |
947 // Reset the request as it's been successfully served. | 941 // Reset the request as it's been successfully served. |
948 request_.reset(); | 942 request_.reset(); |
949 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 943 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
950 | 944 |
951 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", | 945 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", |
952 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, | 946 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, |
953 1); | 947 1); |
954 } | 948 } |
955 | 949 |
956 } // namespace net | 950 } // namespace net |
OLD | NEW |