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

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

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 3 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 class FailingHostResolver : public MockHostResolverBase { 55 class FailingHostResolver : public MockHostResolverBase {
56 public: 56 public:
57 FailingHostResolver() : MockHostResolverBase(false /*use_caching*/) {} 57 FailingHostResolver() : MockHostResolverBase(false /*use_caching*/) {}
58 ~FailingHostResolver() override {} 58 ~FailingHostResolver() override {}
59 59
60 int Resolve(const RequestInfo& info, 60 int Resolve(const RequestInfo& info,
61 RequestPriority priority, 61 RequestPriority priority,
62 AddressList* addresses, 62 AddressList* addresses,
63 const CompletionCallback& callback, 63 const CompletionCallback& callback,
64 std::unique_ptr<Request>* out_req, 64 std::unique_ptr<Request>* out_req,
65 const BoundNetLog& net_log) override { 65 const NetLogWithSource& net_log) override {
66 return ERR_NAME_NOT_RESOLVED; 66 return ERR_NAME_NOT_RESOLVED;
67 } 67 }
68 }; 68 };
69 69
70 class HangingResolver : public MockHostResolverBase { 70 class HangingResolver : public MockHostResolverBase {
71 public: 71 public:
72 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {} 72 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {}
73 ~HangingResolver() override {} 73 ~HangingResolver() override {}
74 74
75 int Resolve(const RequestInfo& info, 75 int Resolve(const RequestInfo& info,
76 RequestPriority priority, 76 RequestPriority priority,
77 AddressList* addresses, 77 AddressList* addresses,
78 const CompletionCallback& callback, 78 const CompletionCallback& callback,
79 std::unique_ptr<Request>* out_req, 79 std::unique_ptr<Request>* out_req,
80 const BoundNetLog& net_log) override { 80 const NetLogWithSource& net_log) override {
81 return ERR_IO_PENDING; 81 return ERR_IO_PENDING;
82 } 82 }
83 }; 83 };
84 } // anonymous namespace 84 } // anonymous namespace
85 85
86 class HttpStreamFactoryImplJobPeer { 86 class HttpStreamFactoryImplJobPeer {
87 public: 87 public:
88 static void Start(HttpStreamFactoryImpl::Job* job, 88 static void Start(HttpStreamFactoryImpl::Job* job,
89 HttpStreamRequest::StreamType stream_type) { 89 HttpStreamRequest::StreamType stream_type) {
90 // Start() is mocked for MockHttpStreamFactoryImplJob. 90 // Start() is mocked for MockHttpStreamFactoryImplJob.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), 190 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
191 base::WrapUnique(proxy_resolver_factory), nullptr)); 191 base::WrapUnique(proxy_resolver_factory), nullptr));
192 Initialize(false); 192 Initialize(false);
193 193
194 HttpRequestInfo request_info; 194 HttpRequestInfo request_info;
195 request_info.method = "GET"; 195 request_info.method = "GET";
196 request_info.url = GURL("http://www.google.com"); 196 request_info.url = GURL("http://www.google.com");
197 197
198 request_.reset( 198 request_.reset(
199 job_controller_->Start(request_info, &request_delegate_, nullptr, 199 job_controller_->Start(request_info, &request_delegate_, nullptr,
200 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 200 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
201 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 201 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
202 202
203 EXPECT_TRUE(job_controller_->main_job()); 203 EXPECT_TRUE(job_controller_->main_job());
204 204
205 // There's no other alternative job. Thus when stream failed, it should 205 // There's no other alternative job. Thus when stream failed, it should
206 // notify Request of the stream failure. 206 // notify Request of the stream failure.
207 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); 207 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1);
208 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 208 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
209 SSLConfig()); 209 SSLConfig());
210 } 210 }
211 211
212 TEST_F(HttpStreamFactoryImplJobControllerTest, 212 TEST_F(HttpStreamFactoryImplJobControllerTest,
213 OnStreamReadyWithNoAlternativeJob) { 213 OnStreamReadyWithNoAlternativeJob) {
214 ProxyConfig proxy_config; 214 ProxyConfig proxy_config;
215 proxy_config.set_auto_detect(true); 215 proxy_config.set_auto_detect(true);
216 // Use asynchronous proxy resolver. 216 // Use asynchronous proxy resolver.
217 MockAsyncProxyResolverFactory* proxy_resolver_factory = 217 MockAsyncProxyResolverFactory* proxy_resolver_factory =
218 new MockAsyncProxyResolverFactory(false); 218 new MockAsyncProxyResolverFactory(false);
219 session_deps_.proxy_service.reset( 219 session_deps_.proxy_service.reset(
220 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), 220 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config),
221 base::WrapUnique(proxy_resolver_factory), nullptr)); 221 base::WrapUnique(proxy_resolver_factory), nullptr));
222 Initialize(false); 222 Initialize(false);
223 223
224 HttpRequestInfo request_info; 224 HttpRequestInfo request_info;
225 request_info.method = "GET"; 225 request_info.method = "GET";
226 request_info.url = GURL("http://www.google.com"); 226 request_info.url = GURL("http://www.google.com");
227 227
228 request_.reset( 228 request_.reset(
229 job_controller_->Start(request_info, &request_delegate_, nullptr, 229 job_controller_->Start(request_info, &request_delegate_, nullptr,
230 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 230 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
231 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 231 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
232 232
233 // There's no other alternative job. Thus when a stream is ready, it should 233 // There's no other alternative job. Thus when a stream is ready, it should
234 // notify Request. 234 // notify Request.
235 HttpStream* http_stream = 235 HttpStream* http_stream =
236 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); 236 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false);
237 job_factory_.main_job()->SetStream(http_stream); 237 job_factory_.main_job()->SetStream(http_stream);
238 238
239 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 239 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
240 .WillOnce(Invoke(DeleteHttpStreamPointer)); 240 .WillOnce(Invoke(DeleteHttpStreamPointer));
(...skipping 17 matching lines...) Expand all
258 HttpRequestInfo request_info; 258 HttpRequestInfo request_info;
259 request_info.method = "GET"; 259 request_info.method = "GET";
260 request_info.url = GURL("https://www.google.com"); 260 request_info.url = GURL("https://www.google.com");
261 261
262 url::SchemeHostPort server(request_info.url); 262 url::SchemeHostPort server(request_info.url);
263 AlternativeService alternative_service(QUIC, server.host(), 443); 263 AlternativeService alternative_service(QUIC, server.host(), 443);
264 SetAlternativeService(request_info, alternative_service); 264 SetAlternativeService(request_info, alternative_service);
265 265
266 request_.reset( 266 request_.reset(
267 job_controller_->Start(request_info, &request_delegate_, nullptr, 267 job_controller_->Start(request_info, &request_delegate_, nullptr,
268 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 268 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
269 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 269 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
270 EXPECT_TRUE(job_controller_->main_job()); 270 EXPECT_TRUE(job_controller_->main_job());
271 EXPECT_TRUE(job_controller_->alternative_job()); 271 EXPECT_TRUE(job_controller_->alternative_job());
272 272
273 // Reset the Request will cancel all the Jobs since there's no Job determined 273 // Reset the Request will cancel all the Jobs since there's no Job determined
274 // to serve Request yet and JobController will notify the factory to delete 274 // to serve Request yet and JobController will notify the factory to delete
275 // itself upon completion. 275 // itself upon completion.
276 request_.reset(); 276 request_.reset();
277 VerifyBrokenAlternateProtocolMapping(request_info, false); 277 VerifyBrokenAlternateProtocolMapping(request_info, false);
278 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 278 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
(...skipping 13 matching lines...) Expand all
292 HttpRequestInfo request_info; 292 HttpRequestInfo request_info;
293 request_info.method = "GET"; 293 request_info.method = "GET";
294 request_info.url = GURL("https://www.google.com"); 294 request_info.url = GURL("https://www.google.com");
295 295
296 url::SchemeHostPort server(request_info.url); 296 url::SchemeHostPort server(request_info.url);
297 AlternativeService alternative_service(QUIC, server.host(), 443); 297 AlternativeService alternative_service(QUIC, server.host(), 443);
298 SetAlternativeService(request_info, alternative_service); 298 SetAlternativeService(request_info, alternative_service);
299 299
300 request_.reset( 300 request_.reset(
301 job_controller_->Start(request_info, &request_delegate_, nullptr, 301 job_controller_->Start(request_info, &request_delegate_, nullptr,
302 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 302 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
303 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 303 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
304 EXPECT_TRUE(job_controller_->main_job()); 304 EXPECT_TRUE(job_controller_->main_job());
305 EXPECT_TRUE(job_controller_->alternative_job()); 305 EXPECT_TRUE(job_controller_->alternative_job());
306 306
307 // We have the main job with unknown status when the alternative job is failed 307 // We have the main job with unknown status when the alternative job is failed
308 // thus should not notify Request of the alternative job's failure. But should 308 // thus should not notify Request of the alternative job's failure. But should
309 // notify the main job to mark the alternative job failed. 309 // notify the main job to mark the alternative job failed.
310 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 310 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
311 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, 311 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED,
312 SSLConfig()); 312 SSLConfig());
(...skipping 23 matching lines...) Expand all
336 HttpRequestInfo request_info; 336 HttpRequestInfo request_info;
337 request_info.method = "GET"; 337 request_info.method = "GET";
338 request_info.url = GURL("https://www.google.com"); 338 request_info.url = GURL("https://www.google.com");
339 339
340 url::SchemeHostPort server(request_info.url); 340 url::SchemeHostPort server(request_info.url);
341 AlternativeService alternative_service(QUIC, server.host(), 443); 341 AlternativeService alternative_service(QUIC, server.host(), 443);
342 SetAlternativeService(request_info, alternative_service); 342 SetAlternativeService(request_info, alternative_service);
343 343
344 request_.reset( 344 request_.reset(
345 job_controller_->Start(request_info, &request_delegate_, nullptr, 345 job_controller_->Start(request_info, &request_delegate_, nullptr,
346 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 346 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
347 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 347 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
348 EXPECT_TRUE(job_controller_->main_job()); 348 EXPECT_TRUE(job_controller_->main_job());
349 EXPECT_TRUE(job_controller_->alternative_job()); 349 EXPECT_TRUE(job_controller_->alternative_job());
350 350
351 // Main job succeeds, starts serving Request and it should report status 351 // Main job succeeds, starts serving Request and it should report status
352 // 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
353 // orphaned. 353 // orphaned.
354 HttpStream* http_stream = 354 HttpStream* http_stream =
355 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); 355 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false);
356 job_factory_.main_job()->SetStream(http_stream); 356 job_factory_.main_job()->SetStream(http_stream);
(...skipping 30 matching lines...) Expand all
387 HttpRequestInfo request_info; 387 HttpRequestInfo request_info;
388 request_info.method = "GET"; 388 request_info.method = "GET";
389 request_info.url = GURL("https://www.google.com"); 389 request_info.url = GURL("https://www.google.com");
390 390
391 url::SchemeHostPort server(request_info.url); 391 url::SchemeHostPort server(request_info.url);
392 AlternativeService alternative_service(QUIC, server.host(), 443); 392 AlternativeService alternative_service(QUIC, server.host(), 443);
393 SetAlternativeService(request_info, alternative_service); 393 SetAlternativeService(request_info, alternative_service);
394 394
395 request_.reset( 395 request_.reset(
396 job_controller_->Start(request_info, &request_delegate_, nullptr, 396 job_controller_->Start(request_info, &request_delegate_, nullptr,
397 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 397 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
398 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 398 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
399 EXPECT_TRUE(job_controller_->main_job()); 399 EXPECT_TRUE(job_controller_->main_job());
400 EXPECT_TRUE(job_controller_->alternative_job()); 400 EXPECT_TRUE(job_controller_->alternative_job());
401 401
402 // |main_job| fails but should not report status to Request. 402 // |main_job| fails but should not report status to Request.
403 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 403 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
404 404
405 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 405 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
406 SSLConfig()); 406 SSLConfig());
407 407
(...skipping 24 matching lines...) Expand all
432 HttpRequestInfo request_info; 432 HttpRequestInfo request_info;
433 request_info.method = "GET"; 433 request_info.method = "GET";
434 request_info.url = GURL("https://www.google.com"); 434 request_info.url = GURL("https://www.google.com");
435 435
436 url::SchemeHostPort server(request_info.url); 436 url::SchemeHostPort server(request_info.url);
437 AlternativeService alternative_service(QUIC, server.host(), 443); 437 AlternativeService alternative_service(QUIC, server.host(), 443);
438 SetAlternativeService(request_info, alternative_service); 438 SetAlternativeService(request_info, alternative_service);
439 439
440 request_.reset( 440 request_.reset(
441 job_controller_->Start(request_info, &request_delegate_, nullptr, 441 job_controller_->Start(request_info, &request_delegate_, nullptr,
442 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 442 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
443 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 443 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
444 EXPECT_TRUE(job_controller_->main_job()); 444 EXPECT_TRUE(job_controller_->main_job());
445 EXPECT_TRUE(job_controller_->alternative_job()); 445 EXPECT_TRUE(job_controller_->alternative_job());
446 446
447 // |alternative_job| fails but should not report status to Request. 447 // |alternative_job| fails but should not report status to Request.
448 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 448 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
449 449
450 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, 450 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED,
451 SSLConfig()); 451 SSLConfig());
452 452
(...skipping 26 matching lines...) Expand all
479 HttpRequestInfo request_info; 479 HttpRequestInfo request_info;
480 request_info.method = "GET"; 480 request_info.method = "GET";
481 request_info.url = GURL("https://www.google.com"); 481 request_info.url = GURL("https://www.google.com");
482 482
483 url::SchemeHostPort server(request_info.url); 483 url::SchemeHostPort server(request_info.url);
484 AlternativeService alternative_service(QUIC, server.host(), 443); 484 AlternativeService alternative_service(QUIC, server.host(), 443);
485 SetAlternativeService(request_info, alternative_service); 485 SetAlternativeService(request_info, alternative_service);
486 486
487 request_.reset( 487 request_.reset(
488 job_controller_->Start(request_info, &request_delegate_, nullptr, 488 job_controller_->Start(request_info, &request_delegate_, nullptr,
489 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 489 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
490 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 490 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
491 EXPECT_TRUE(job_controller_->main_job()); 491 EXPECT_TRUE(job_controller_->main_job());
492 EXPECT_TRUE(job_controller_->alternative_job()); 492 EXPECT_TRUE(job_controller_->alternative_job());
493 493
494 // |main_job| fails but should not report status to Request. 494 // |main_job| fails but should not report status to Request.
495 // The alternative job will mark the main job complete. 495 // The alternative job will mark the main job complete.
496 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); 496 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
497 497
498 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 498 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
499 SSLConfig()); 499 SSLConfig());
(...skipping 28 matching lines...) Expand all
528 HttpRequestInfo request_info; 528 HttpRequestInfo request_info;
529 request_info.method = "GET"; 529 request_info.method = "GET";
530 request_info.url = GURL("https://www.google.com"); 530 request_info.url = GURL("https://www.google.com");
531 531
532 url::SchemeHostPort server(request_info.url); 532 url::SchemeHostPort server(request_info.url);
533 AlternativeService alternative_service(QUIC, server.host(), 443); 533 AlternativeService alternative_service(QUIC, server.host(), 443);
534 SetAlternativeService(request_info, alternative_service); 534 SetAlternativeService(request_info, alternative_service);
535 535
536 request_.reset( 536 request_.reset(
537 job_controller_->Start(request_info, &request_delegate_, nullptr, 537 job_controller_->Start(request_info, &request_delegate_, nullptr,
538 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 538 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
539 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 539 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
540 EXPECT_TRUE(job_controller_->main_job()); 540 EXPECT_TRUE(job_controller_->main_job());
541 EXPECT_TRUE(job_controller_->alternative_job()); 541 EXPECT_TRUE(job_controller_->alternative_job());
542 542
543 // Wait until OnStreamFailedCallback is executed on the alternative job. 543 // Wait until OnStreamFailedCallback is executed on the alternative job.
544 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); 544 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1);
545 base::RunLoop().RunUntilIdle(); 545 base::RunLoop().RunUntilIdle();
546 } 546 }
547 547
548 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { 548 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) {
549 // Using a restricted port 101 for QUIC should fail and the alternative job 549 // Using a restricted port 101 for QUIC should fail and the alternative job
550 // should post OnStreamFailedCall on the controller to resume the main job. 550 // should post OnStreamFailedCall on the controller to resume the main job.
551 Initialize(false); 551 Initialize(false);
552 552
553 HttpRequestInfo request_info; 553 HttpRequestInfo request_info;
554 request_info.method = "GET"; 554 request_info.method = "GET";
555 request_info.url = GURL("https://www.google.com"); 555 request_info.url = GURL("https://www.google.com");
556 556
557 url::SchemeHostPort server(request_info.url); 557 url::SchemeHostPort server(request_info.url);
558 AlternativeService alternative_service(QUIC, server.host(), 101); 558 AlternativeService alternative_service(QUIC, server.host(), 101);
559 SetAlternativeService(request_info, alternative_service); 559 SetAlternativeService(request_info, alternative_service);
560 560
561 request_.reset( 561 request_.reset(
562 job_controller_->Start(request_info, &request_delegate_, nullptr, 562 job_controller_->Start(request_info, &request_delegate_, nullptr,
563 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 563 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
564 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 564 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
565 565
566 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); 566 EXPECT_TRUE(job_factory_.main_job()->is_waiting());
567 567
568 // Wait until OnStreamFailedCallback is executed on the alternative job. 568 // Wait until OnStreamFailedCallback is executed on the alternative job.
569 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); 569 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
570 base::RunLoop().RunUntilIdle(); 570 base::RunLoop().RunUntilIdle();
571 } 571 }
572 572
573 TEST_F(HttpStreamFactoryImplJobControllerTest, 573 TEST_F(HttpStreamFactoryImplJobControllerTest,
(...skipping 24 matching lines...) Expand all
598 // Set a SPDY alternative service for the server. 598 // Set a SPDY alternative service for the server.
599 url::SchemeHostPort server(request_info.url); 599 url::SchemeHostPort server(request_info.url);
600 AlternativeService alternative_service(QUIC, server.host(), 443); 600 AlternativeService alternative_service(QUIC, server.host(), 443);
601 SetAlternativeService(request_info, alternative_service); 601 SetAlternativeService(request_info, alternative_service);
602 // Hack to use different URL for the main job to help differentiate the proxy 602 // Hack to use different URL for the main job to help differentiate the proxy
603 // requests. 603 // requests.
604 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); 604 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com"));
605 605
606 request_.reset( 606 request_.reset(
607 job_controller_->Start(request_info, &request_delegate_, nullptr, 607 job_controller_->Start(request_info, &request_delegate_, nullptr,
608 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 608 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
609 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 609 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
610 // Both jobs should be created but stalled as proxy resolution not completed. 610 // Both jobs should be created but stalled as proxy resolution not completed.
611 EXPECT_TRUE(job_controller_->main_job()); 611 EXPECT_TRUE(job_controller_->main_job());
612 EXPECT_TRUE(job_controller_->alternative_job()); 612 EXPECT_TRUE(job_controller_->alternative_job());
613 613
614 MockAsyncProxyResolver resolver; 614 MockAsyncProxyResolver resolver;
615 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( 615 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
616 net::OK, &resolver); 616 net::OK, &resolver);
617 617
618 // Resolve proxy for the main job which then proceed to wait for the 618 // Resolve proxy for the main job which then proceed to wait for the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 660
661 url::SchemeHostPort server(request_info.url); 661 url::SchemeHostPort server(request_info.url);
662 AlternativeService alternative_service(QUIC, server.host(), 443); 662 AlternativeService alternative_service(QUIC, server.host(), 443);
663 SetAlternativeService(request_info, alternative_service); 663 SetAlternativeService(request_info, alternative_service);
664 // Hack to use different URL for the main job to help differentiate the proxy 664 // Hack to use different URL for the main job to help differentiate the proxy
665 // requests. 665 // requests.
666 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); 666 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com"));
667 667
668 request_.reset( 668 request_.reset(
669 job_controller_->Start(request_info, &request_delegate_, nullptr, 669 job_controller_->Start(request_info, &request_delegate_, nullptr,
670 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 670 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
671 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 671 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
672 EXPECT_TRUE(job_controller_->main_job()); 672 EXPECT_TRUE(job_controller_->main_job());
673 EXPECT_TRUE(job_controller_->alternative_job()); 673 EXPECT_TRUE(job_controller_->alternative_job());
674 674
675 MockAsyncProxyResolver resolver; 675 MockAsyncProxyResolver resolver;
676 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( 676 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
677 net::OK, &resolver); 677 net::OK, &resolver);
678 678
679 // Resolve proxy for the main job which then proceed to wait for the 679 // Resolve proxy for the main job which then proceed to wait for the
680 // alternative job which is IO_PENDING. 680 // alternative job which is IO_PENDING.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 request_info.method = "GET"; 719 request_info.method = "GET";
720 request_info.url = GURL("https://www.google.com"); 720 request_info.url = GURL("https://www.google.com");
721 721
722 // Set a SPDY alternative service for the server. 722 // Set a SPDY alternative service for the server.
723 url::SchemeHostPort server(request_info.url); 723 url::SchemeHostPort server(request_info.url);
724 AlternativeService alternative_service(QUIC, server.host(), 443); 724 AlternativeService alternative_service(QUIC, server.host(), 443);
725 SetAlternativeService(request_info, alternative_service); 725 SetAlternativeService(request_info, alternative_service);
726 726
727 request_.reset( 727 request_.reset(
728 job_controller_->Start(request_info, &request_delegate_, nullptr, 728 job_controller_->Start(request_info, &request_delegate_, nullptr,
729 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 729 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
730 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 730 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
731 EXPECT_TRUE(job_controller_->main_job()); 731 EXPECT_TRUE(job_controller_->main_job());
732 EXPECT_TRUE(job_controller_->alternative_job()); 732 EXPECT_TRUE(job_controller_->alternative_job());
733 733
734 // The alternative job stalls as host resolution hangs when creating the QUIC 734 // The alternative job stalls as host resolution hangs when creating the QUIC
735 // request and controller should resume the main job after delay. 735 // request and controller should resume the main job after delay.
736 // Verify the waiting time for delayed main job. 736 // Verify the waiting time for delayed main job.
737 EXPECT_CALL(*job_factory_.main_job(), Resume()) 737 EXPECT_CALL(*job_factory_.main_job(), Resume())
738 .WillOnce(Invoke(testing::CreateFunctor( 738 .WillOnce(Invoke(testing::CreateFunctor(
739 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, 739 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_,
(...skipping 11 matching lines...) Expand all
751 751
752 Initialize(true); 752 Initialize(true);
753 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 753 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
754 754
755 HttpRequestInfo request_info; 755 HttpRequestInfo request_info;
756 request_info.method = "GET"; 756 request_info.method = "GET";
757 request_info.url = GURL("https://mail.example.org/"); 757 request_info.url = GURL("https://mail.example.org/");
758 758
759 request_.reset( 759 request_.reset(
760 job_controller_->Start(request_info, &request_delegate_, nullptr, 760 job_controller_->Start(request_info, &request_delegate_, nullptr,
761 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 761 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
762 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 762 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
763 EXPECT_TRUE(job_controller_->main_job()); 763 EXPECT_TRUE(job_controller_->main_job());
764 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); 764 EXPECT_FALSE(job_controller_->main_job()->is_waiting());
765 EXPECT_FALSE(job_controller_->alternative_job()); 765 EXPECT_FALSE(job_controller_->alternative_job());
766 766
767 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); 767 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0);
768 base::RunLoop().RunUntilIdle(); 768 base::RunLoop().RunUntilIdle();
769 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); 769 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations());
770 } 770 }
771 771
772 // Verifies that the alternative proxy server job is not created if the main job 772 // Verifies that the alternative proxy server job is not created if the main job
773 // does not fetch the resource through a proxy. 773 // does not fetch the resource through a proxy.
774 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { 774 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) {
775 // Using hanging resolver will cause the alternative job to hang indefinitely. 775 // Using hanging resolver will cause the alternative job to hang indefinitely.
776 HangingResolver* resolver = new HangingResolver(); 776 HangingResolver* resolver = new HangingResolver();
777 session_deps_.host_resolver.reset(resolver); 777 session_deps_.host_resolver.reset(resolver);
778 778
779 Initialize(false); 779 Initialize(false);
780 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); 780 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic());
781 781
782 HttpRequestInfo request_info; 782 HttpRequestInfo request_info;
783 request_info.method = "GET"; 783 request_info.method = "GET";
784 request_info.url = GURL("http://mail.example.org/"); 784 request_info.url = GURL("http://mail.example.org/");
785 785
786 request_.reset( 786 request_.reset(
787 job_controller_->Start(request_info, &request_delegate_, nullptr, 787 job_controller_->Start(request_info, &request_delegate_, nullptr,
788 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 788 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
789 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 789 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
790 EXPECT_TRUE(job_controller_->main_job()); 790 EXPECT_TRUE(job_controller_->main_job());
791 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); 791 EXPECT_FALSE(job_controller_->main_job()->is_waiting());
792 EXPECT_FALSE(job_controller_->alternative_job()); 792 EXPECT_FALSE(job_controller_->alternative_job());
793 793
794 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); 794 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0);
795 base::RunLoop().RunUntilIdle(); 795 base::RunLoop().RunUntilIdle();
796 796
797 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); 797 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations());
798 } 798 }
(...skipping 16 matching lines...) Expand all
815 stats1.srtt = base::TimeDelta::FromMicroseconds(10); 815 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
816 session_->http_server_properties()->SetServerNetworkStats( 816 session_->http_server_properties()->SetServerNetworkStats(
817 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); 817 url::SchemeHostPort(GURL("https://myproxy.org")), stats1);
818 818
819 HttpRequestInfo request_info; 819 HttpRequestInfo request_info;
820 request_info.method = "GET"; 820 request_info.method = "GET";
821 request_info.url = GURL("http://mail.example.org/"); 821 request_info.url = GURL("http://mail.example.org/");
822 822
823 request_.reset( 823 request_.reset(
824 job_controller_->Start(request_info, &request_delegate_, nullptr, 824 job_controller_->Start(request_info, &request_delegate_, nullptr,
825 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 825 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
826 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 826 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
827 EXPECT_TRUE(job_controller_->main_job()); 827 EXPECT_TRUE(job_controller_->main_job());
828 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 828 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
829 EXPECT_TRUE(job_controller_->alternative_job()); 829 EXPECT_TRUE(job_controller_->alternative_job());
830 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); 830 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_));
831 831
832 // The alternative proxy server job stalls when connecting to the alternative 832 // The alternative proxy server job stalls when connecting to the alternative
833 // proxy server, and controller should resume the main job after delay. 833 // proxy server, and controller should resume the main job after delay.
834 // Verify the waiting time for delayed main job. 834 // Verify the waiting time for delayed main job.
835 EXPECT_CALL(*job_factory_.main_job(), Resume()) 835 EXPECT_CALL(*job_factory_.main_job(), Resume())
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); 876 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000);
877 session_->http_server_properties()->SetServerNetworkStats( 877 session_->http_server_properties()->SetServerNetworkStats(
878 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); 878 url::SchemeHostPort(GURL("https://myproxy.org")), stats1);
879 879
880 HttpRequestInfo request_info; 880 HttpRequestInfo request_info;
881 request_info.method = "GET"; 881 request_info.method = "GET";
882 request_info.url = GURL("http://mail.example.org/"); 882 request_info.url = GURL("http://mail.example.org/");
883 883
884 request_.reset( 884 request_.reset(
885 job_controller_->Start(request_info, &request_delegate_, nullptr, 885 job_controller_->Start(request_info, &request_delegate_, nullptr,
886 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 886 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
887 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 887 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
888 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); 888 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
889 EXPECT_TRUE(job_controller_->alternative_job()); 889 EXPECT_TRUE(job_controller_->alternative_job());
890 890
891 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); 891 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0);
892 892
893 // Since the alternative proxy server job is started in the next message loop, 893 // Since the alternative proxy server job is started in the next message loop,
894 // the main job would remain blocked until the alternative proxy starts, and 894 // the main job would remain blocked until the alternative proxy starts, and
895 // fails. 895 // fails.
896 EXPECT_CALL(*job_factory_.main_job(), Resume()) 896 EXPECT_CALL(*job_factory_.main_job(), Resume())
(...skipping 16 matching lines...) Expand all
913 Initialize(true); 913 Initialize(true);
914 914
915 HttpRequestInfo request_info; 915 HttpRequestInfo request_info;
916 request_info.method = "GET"; 916 request_info.method = "GET";
917 request_info.url = GURL("http://www.google.com"); 917 request_info.url = GURL("http://www.google.com");
918 918
919 url::SchemeHostPort server(request_info.url); 919 url::SchemeHostPort server(request_info.url);
920 920
921 request_.reset( 921 request_.reset(
922 job_controller_->Start(request_info, &request_delegate_, nullptr, 922 job_controller_->Start(request_info, &request_delegate_, nullptr,
923 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 923 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM,
924 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 924 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
925 EXPECT_TRUE(job_controller_->main_job()); 925 EXPECT_TRUE(job_controller_->main_job());
926 EXPECT_TRUE(job_controller_->alternative_job()); 926 EXPECT_TRUE(job_controller_->alternative_job());
927 927
928 // Main job succeeds, starts serving Request and it should report status 928 // Main job succeeds, starts serving Request and it should report status
929 // to Request. The alternative job will mark the main job complete and gets 929 // to Request. The alternative job will mark the main job complete and gets
930 // orphaned. 930 // orphaned.
931 HttpStream* http_stream = 931 HttpStream* http_stream =
932 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); 932 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false);
933 job_factory_.main_job()->SetStream(http_stream); 933 job_factory_.main_job()->SetStream(http_stream);
(...skipping 12 matching lines...) Expand all
946 // Reset the request as it's been successfully served. 946 // Reset the request as it's been successfully served.
947 request_.reset(); 947 request_.reset();
948 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 948 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
949 949
950 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", 950 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage",
951 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, 951 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */,
952 1); 952 1);
953 } 953 }
954 954
955 } // namespace net 955 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698