Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: net/http/http_stream_factory_impl_job_controller_unittest.cc

Issue 2619583002: Clean up HttpStreamFactoryImpl::JobController when Impl::Jobs complete (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 364 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
365 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, 365 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED,
366 SSLConfig()); 366 SSLConfig());
367 367
368 VerifyBrokenAlternateProtocolMapping(request_info, true); 368 VerifyBrokenAlternateProtocolMapping(request_info, true);
369 // Reset the request as it's been successfully served. 369 // Reset the request as it's been successfully served.
370 request_.reset(); 370 request_.reset();
371 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 371 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
372 } 372 }
373 373
374 // Regression test for crbug.com/678768.
375 TEST_F(HttpStreamFactoryImplJobControllerTest,
376 AltJobSucceedsControllerDestroyed) {
377 ProxyConfig proxy_config;
378 proxy_config.set_auto_detect(true);
379 // Use asynchronous proxy resolver.
380 MockAsyncProxyResolverFactory* proxy_resolver_factory =
381 new MockAsyncProxyResolverFactory(false);
382 session_deps_.proxy_service.reset(
383 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
384 base::WrapUnique(proxy_resolver_factory), nullptr));
385 Initialize(false);
386
387 HttpRequestInfo request_info;
388 request_info.method = "GET";
389 request_info.url = GURL("https://www.google.com");
390
391 url::SchemeHostPort server(request_info.url);
392 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
393 SetAlternativeService(request_info, alternative_service);
394 // Hack to use different URL for the main job to help differentiate the proxy
395 // requests.
396 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com"));
397 request_.reset(
398 job_controller_->Start(request_info, &request_delegate_, nullptr,
399 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
400 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
401 EXPECT_TRUE(job_controller_->main_job());
402 EXPECT_TRUE(job_controller_->alternative_job());
403 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_));
404
405 base::RunLoop().RunUntilIdle();
406 MockAsyncProxyResolver resolver;
407 ASSERT_EQ(1u, proxy_resolver_factory->pending_requests().size());
408 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
409 net::OK, &resolver);
410
411 // Resolve proxy for the main job which then proceed to wait for the
412 // alternative job which is IO_PENDING.
413 ASSERT_EQ(2u, resolver.pending_jobs().size());
414 int main_job_request_id =
415 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1;
416 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy(
417 "result1:80");
418 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK);
419 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
420
421 ASSERT_EQ(1u, resolver.pending_jobs().size());
422 // Resolve proxy for the alternative job to proceed to create a connection.
423 // Use failing HostResolver to fail creation of a QUIC session for the
424 // alternative job. The alternative job will thus resume the main job.
425 resolver.pending_jobs()[0]->results()->UseNamedProxy("result1:80");
426 resolver.pending_jobs()[0]->CompleteNow(net::OK);
xunjieli 2017/01/06 17:55:59 Note: The existing test fixture is a bit weird. QU
427
428 // |alternative_job| succeeds and should report status to Request.
429 HttpStream* http_stream =
430 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false);
431 job_factory_.alternative_job()->SetStream(http_stream);
432 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
433 .WillOnce(Invoke(DeleteHttpStreamPointer));
434 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig());
435
436 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
437 request_.reset();
438 VerifyBrokenAlternateProtocolMapping(request_info, false);
439 // This fails without the fix for crbug.com/678768.
440 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
441 }
442
374 TEST_F(HttpStreamFactoryImplJobControllerTest, 443 TEST_F(HttpStreamFactoryImplJobControllerTest,
375 AltJobSucceedsAfterMainJobFailed) { 444 AltJobSucceedsAfterMainJobFailed) {
376 ProxyConfig proxy_config; 445 ProxyConfig proxy_config;
377 proxy_config.set_auto_detect(true); 446 proxy_config.set_auto_detect(true);
378 // Use asynchronous proxy resolver. 447 // Use asynchronous proxy resolver.
379 MockAsyncProxyResolverFactory* proxy_resolver_factory = 448 MockAsyncProxyResolverFactory* proxy_resolver_factory =
380 new MockAsyncProxyResolverFactory(false); 449 new MockAsyncProxyResolverFactory(false);
381 session_deps_.proxy_service.reset( 450 session_deps_.proxy_service.reset(
382 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), 451 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
383 base::WrapUnique(proxy_resolver_factory), nullptr)); 452 base::WrapUnique(proxy_resolver_factory), nullptr));
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 // Reset the request as it's been successfully served. 1010 // Reset the request as it's been successfully served.
942 request_.reset(); 1011 request_.reset();
943 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 1012 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
944 1013
945 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", 1014 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage",
946 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, 1015 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */,
947 1); 1016 1);
948 } 1017 }
949 1018
950 } // namespace net 1019 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698