| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 HttpRequestInfo request_info; | 212 HttpRequestInfo request_info; |
| 213 request_info.method = "GET"; | 213 request_info.method = "GET"; |
| 214 request_info.url = GURL("http://www.google.com"); | 214 request_info.url = GURL("http://www.google.com"); |
| 215 | 215 |
| 216 request_.reset( | 216 request_.reset( |
| 217 job_controller_->Start(request_info, &request_delegate_, nullptr, | 217 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 218 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 218 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 219 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 219 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 220 | 220 |
| 221 // There's no other alternative job. Thus when a stream is ready, it should | 221 // There's no other alternative job. Thus when stream is ready, it should |
| 222 // notify Request. | 222 // notify Request. |
| 223 HttpStream* http_stream = | 223 HttpStream* http_stream = |
| 224 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 224 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
| 225 job_factory_.main_job()->SetStream(http_stream); | 225 job_factory_.main_job()->SetStream(http_stream); |
| 226 | 226 |
| 227 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 227 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 228 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 228 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 229 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 229 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), |
| 230 ProxyInfo()); | 230 ProxyInfo()); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Test we cancel Jobs correctly when the Request is explicitly canceled | 233 // Test we cancel Jobs correctly when the Request is explicitly canceled |
| 234 // before any Job is bound to Request. | 234 // before any Job is bound to Request. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 job_controller_->Start(request_info, &request_delegate_, nullptr, | 332 job_controller_->Start(request_info, &request_delegate_, nullptr, |
| 333 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 333 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
| 334 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 334 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
| 335 EXPECT_TRUE(job_controller_->main_job()); | 335 EXPECT_TRUE(job_controller_->main_job()); |
| 336 EXPECT_TRUE(job_controller_->alternative_job()); | 336 EXPECT_TRUE(job_controller_->alternative_job()); |
| 337 | 337 |
| 338 // Main job succeeds, starts serving Request and it should report status | 338 // Main job succeeds, starts serving Request and it should report status |
| 339 // to Request. The alternative job will mark the main job complete and gets | 339 // to Request. The alternative job will mark the main job complete and gets |
| 340 // orphaned. | 340 // orphaned. |
| 341 HttpStream* http_stream = | 341 HttpStream* http_stream = |
| 342 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 342 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
| 343 job_factory_.main_job()->SetStream(http_stream); | 343 job_factory_.main_job()->SetStream(http_stream); |
| 344 | 344 |
| 345 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 345 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 346 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 346 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 347 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) | 347 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) |
| 348 .Times(1); | 348 .Times(1); |
| 349 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), | 349 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), |
| 350 ProxyInfo()); | 350 ProxyInfo()); |
| 351 | 351 |
| 352 // JobController shouldn't report the status of second job as request | 352 // JobController shouldn't report the status of second job as request |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // The alternative job will mark the main job complete. | 391 // The alternative job will mark the main job complete. |
| 392 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 392 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
| 393 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) | 393 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) |
| 394 .Times(1); | 394 .Times(1); |
| 395 | 395 |
| 396 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 396 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 397 SSLConfig()); | 397 SSLConfig()); |
| 398 | 398 |
| 399 // |alternative_job| succeeds and should report status to Request. | 399 // |alternative_job| succeeds and should report status to Request. |
| 400 HttpStream* http_stream = | 400 HttpStream* http_stream = |
| 401 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 401 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
| 402 job_factory_.alternative_job()->SetStream(http_stream); | 402 job_factory_.alternative_job()->SetStream(http_stream); |
| 403 | 403 |
| 404 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 404 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 405 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 405 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 406 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 406 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
| 407 ProxyInfo()); | 407 ProxyInfo()); |
| 408 } | 408 } |
| 409 | 409 |
| 410 // Regression test for crbug/621069. | 410 // Regression test for crbug/621069. |
| 411 // Get load state after main job fails and before alternative job succeeds. | 411 // Get load state after main job fails and before alternative job succeeds. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 442 .Times(1); | 442 .Times(1); |
| 443 | 443 |
| 444 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 444 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
| 445 SSLConfig()); | 445 SSLConfig()); |
| 446 | 446 |
| 447 // Controller should use alternative job to get load state. | 447 // Controller should use alternative job to get load state. |
| 448 job_controller_->GetLoadState(); | 448 job_controller_->GetLoadState(); |
| 449 | 449 |
| 450 // |alternative_job| succeeds and should report status to Request. | 450 // |alternative_job| succeeds and should report status to Request. |
| 451 HttpStream* http_stream = | 451 HttpStream* http_stream = |
| 452 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 452 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false); |
| 453 job_factory_.alternative_job()->SetStream(http_stream); | 453 job_factory_.alternative_job()->SetStream(http_stream); |
| 454 | 454 |
| 455 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 455 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
| 456 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 456 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
| 457 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), | 457 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), |
| 458 ProxyInfo()); | 458 ProxyInfo()); |
| 459 } | 459 } |
| 460 | 460 |
| 461 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | 461 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { |
| 462 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 462 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 base::RunLoop().RunUntilIdle(); | 852 base::RunLoop().RunUntilIdle(); |
| 853 EXPECT_FALSE(job_controller_->alternative_job()); | 853 EXPECT_FALSE(job_controller_->alternative_job()); |
| 854 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 854 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
| 855 // Since the main job did not complete successfully, the alternative proxy | 855 // Since the main job did not complete successfully, the alternative proxy |
| 856 // server should not be marked as bad. | 856 // server should not be marked as bad. |
| 857 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | 857 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
| 858 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 858 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
| 859 } | 859 } |
| 860 | 860 |
| 861 } // namespace net | 861 } // namespace net |
| OLD | NEW |