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/run_loop.h" | 10 #include "base/run_loop.h" |
10 #include "net/dns/mock_host_resolver.h" | 11 #include "net/dns/mock_host_resolver.h" |
11 #include "net/http/http_basic_stream.h" | 12 #include "net/http/http_basic_stream.h" |
12 #include "net/http/http_stream_factory_impl_request.h" | 13 #include "net/http/http_stream_factory_impl_request.h" |
13 #include "net/http/http_stream_factory_test_util.h" | 14 #include "net/http/http_stream_factory_test_util.h" |
14 #include "net/proxy/mock_proxy_resolver.h" | 15 #include "net/proxy/mock_proxy_resolver.h" |
15 #include "net/proxy/proxy_config_service_fixed.h" | 16 #include "net/proxy/proxy_config_service_fixed.h" |
16 #include "net/proxy/proxy_info.h" | 17 #include "net/proxy/proxy_info.h" |
17 #include "net/proxy/proxy_service.h" | 18 #include "net/proxy/proxy_service.h" |
18 #include "net/quic/test_tools/quic_stream_factory_peer.h" | 19 #include "net/quic/test_tools/quic_stream_factory_peer.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 request_info.url = GURL("http://www.google.com"); | 229 request_info.url = GURL("http://www.google.com"); |
229 | 230 |
230 request_.reset( | 231 request_.reset( |
231 job_controller_->Start(request_info, &request_delegate_, nullptr, | 232 job_controller_->Start(request_info, &request_delegate_, nullptr, |
232 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 233 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
233 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 234 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
234 | 235 |
235 // There's no other alternative job. Thus when stream is ready, it should | 236 // There's no other alternative job. Thus when stream is ready, it should |
236 // notify Request. | 237 // notify Request. |
237 HttpStream* http_stream = | 238 HttpStream* http_stream = |
238 new HttpBasicStream(new ClientSocketHandle(), false); | 239 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
239 job_factory_.main_job()->SetStream(http_stream); | 240 job_factory_.main_job()->SetStream(http_stream); |
240 | 241 |
241 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 242 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
242 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 243 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
243 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 244 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), |
244 ProxyInfo()); | 245 ProxyInfo()); |
245 } | 246 } |
246 | 247 |
247 // Test we cancel Jobs correctly when the Request is explicitly canceled | 248 // Test we cancel Jobs correctly when the Request is explicitly canceled |
248 // before any Job is bound to Request. | 249 // before any Job is bound to Request. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 job_controller_->Start(request_info, &request_delegate_, nullptr, | 347 job_controller_->Start(request_info, &request_delegate_, nullptr, |
347 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 348 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
348 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 349 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
349 EXPECT_TRUE(job_controller_->main_job()); | 350 EXPECT_TRUE(job_controller_->main_job()); |
350 EXPECT_TRUE(job_controller_->alternative_job()); | 351 EXPECT_TRUE(job_controller_->alternative_job()); |
351 | 352 |
352 // Main job succeeds, starts serving Request and it should report status | 353 // 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 | 354 // to Request. The alternative job will mark the main job complete and gets |
354 // orphaned. | 355 // orphaned. |
355 HttpStream* http_stream = | 356 HttpStream* http_stream = |
356 new HttpBasicStream(new ClientSocketHandle(), false); | 357 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
357 job_factory_.main_job()->SetStream(http_stream); | 358 job_factory_.main_job()->SetStream(http_stream); |
358 | 359 |
359 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 360 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
360 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 361 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
361 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) | 362 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) |
362 .Times(1); | 363 .Times(1); |
363 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 364 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), |
364 ProxyInfo()); | 365 ProxyInfo()); |
365 | 366 |
366 // JobController shouldn't report the status of second job as request | 367 // JobController shouldn't report the status of second job as request |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 // The alternative job will mark the main job complete. | 406 // The alternative job will mark the main job complete. |
406 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 407 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
407 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) | 408 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) |
408 .Times(1); | 409 .Times(1); |
409 | 410 |
410 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 411 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
411 SSLConfig()); | 412 SSLConfig()); |
412 | 413 |
413 // |alternative_job| succeeds and should report status to Request. | 414 // |alternative_job| succeeds and should report status to Request. |
414 HttpStream* http_stream = | 415 HttpStream* http_stream = |
415 new HttpBasicStream(new ClientSocketHandle(), false); | 416 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
416 job_factory_.alternative_job()->SetStream(http_stream); | 417 job_factory_.alternative_job()->SetStream(http_stream); |
417 | 418 |
418 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 419 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
419 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 420 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
420 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 421 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
421 ProxyInfo()); | 422 ProxyInfo()); |
422 } | 423 } |
423 | 424 |
424 // Regression test for crbug/621069. | 425 // Regression test for crbug/621069. |
425 // Get load state after main job fails and before alternative job succeeds. | 426 // Get load state after main job fails and before alternative job succeeds. |
(...skipping 30 matching lines...) Expand all Loading... |
456 .Times(1); | 457 .Times(1); |
457 | 458 |
458 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 459 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
459 SSLConfig()); | 460 SSLConfig()); |
460 | 461 |
461 // Controller should use alternative job to get load state. | 462 // Controller should use alternative job to get load state. |
462 job_controller_->GetLoadState(); | 463 job_controller_->GetLoadState(); |
463 | 464 |
464 // |alternative_job| succeeds and should report status to Request. | 465 // |alternative_job| succeeds and should report status to Request. |
465 HttpStream* http_stream = | 466 HttpStream* http_stream = |
466 new HttpBasicStream(new ClientSocketHandle(), false); | 467 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
467 job_factory_.alternative_job()->SetStream(http_stream); | 468 job_factory_.alternative_job()->SetStream(http_stream); |
468 | 469 |
469 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 470 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
470 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 471 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
471 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 472 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
472 ProxyInfo()); | 473 ProxyInfo()); |
473 } | 474 } |
474 | 475 |
475 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | 476 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { |
476 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 477 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 // request and controller should resume the main job after delay. | 700 // request and controller should resume the main job after delay. |
700 // Verify the waiting time for delayed main job. | 701 // Verify the waiting time for delayed main job. |
701 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 702 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
702 .WillOnce(Invoke(testing::CreateFunctor( | 703 .WillOnce(Invoke(testing::CreateFunctor( |
703 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 704 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
704 base::TimeDelta::FromMicroseconds(15)))); | 705 base::TimeDelta::FromMicroseconds(15)))); |
705 | 706 |
706 base::RunLoop().RunUntilIdle(); | 707 base::RunLoop().RunUntilIdle(); |
707 } | 708 } |
708 } // namespace net | 709 } // namespace net |
OLD | NEW |