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

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

Issue 1952423002: JobController 2: Remove reference between HttpStreamFactoryImpl::Jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Job_Controller_1
Patch Set: move resume logic up to controller Created 4 years, 5 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/run_loop.cc"
10 #include "net/dns/mock_host_resolver.h"
9 #include "net/http/http_basic_stream.h" 11 #include "net/http/http_basic_stream.h"
10 #include "net/http/http_stream_factory_impl_request.h" 12 #include "net/http/http_stream_factory_impl_request.h"
11 #include "net/http/http_stream_factory_test_util.h" 13 #include "net/http/http_stream_factory_test_util.h"
14 #include "net/proxy/mock_proxy_resolver.h"
15 #include "net/proxy/proxy_config_service_fixed.h"
12 #include "net/proxy/proxy_info.h" 16 #include "net/proxy/proxy_info.h"
13 #include "net/proxy/proxy_service.h" 17 #include "net/proxy/proxy_service.h"
14 #include "net/spdy/spdy_test_util_common.h" 18 #include "net/spdy/spdy_test_util_common.h"
15 #include "net/ssl/ssl_failure_state.h" 19 #include "net/ssl/ssl_failure_state.h"
16 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
17 21
18 using ::testing::_; 22 using ::testing::_;
19 using ::testing::Invoke; 23 using ::testing::Invoke;
20 24
21 namespace net { 25 namespace net {
22 26
23 namespace { 27 namespace {
24 28
25 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config, 29 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config,
26 const ProxyInfo& used_proxy_info, 30 const ProxyInfo& used_proxy_info,
27 HttpStream* stream) { 31 HttpStream* stream) {
28 delete stream; 32 delete stream;
29 } 33 }
30 34
35 class FailingProxyResolverFactory : public ProxyResolverFactory {
36 public:
37 FailingProxyResolverFactory() : ProxyResolverFactory(false) {}
38
39 // ProxyResolverFactory override.
40 int CreateProxyResolver(
41 const scoped_refptr<ProxyResolverScriptData>& script_data,
42 std::unique_ptr<ProxyResolver>* result,
43 const CompletionCallback& callback,
44 std::unique_ptr<Request>* request) override {
45 return ERR_PAC_SCRIPT_FAILED;
46 }
47 };
48
49 class FailingHostResolver : public MockHostResolverBase {
50 public:
51 FailingHostResolver() : MockHostResolverBase(false /*use_caching*/) {}
52 ~FailingHostResolver() override {}
53
54 int Resolve(const RequestInfo& info,
55 RequestPriority priority,
56 AddressList* addresses,
57 const CompletionCallback& callback,
58 RequestHandle* out_req,
59 const BoundNetLog& net_log) override {
60 return ERR_NAME_NOT_RESOLVED;
61 }
62 };
63
31 } // anonymous namespace 64 } // anonymous namespace
32 65
66 class HttpStreamFactoryImplJobPeer {
67 public:
68 static void Start(HttpStreamFactoryImpl::Job* job,
69 HttpStreamRequest::StreamType stream_type) {
70 // Start() is mocked for MockHttpStreamFactoryImplJob.
71 // This is the alternative method to invoke real Start() method on Job.
72 job->stream_type_ = stream_type;
73 job->StartInternal();
74 }
75 };
76
33 class HttpStreamFactoryImplJobControllerTest 77 class HttpStreamFactoryImplJobControllerTest
34 : public ::testing::Test, 78 : public ::testing::Test,
35 public ::testing::WithParamInterface<NextProto> { 79 public ::testing::WithParamInterface<NextProto> {
36 public: 80 public:
37 HttpStreamFactoryImplJobControllerTest() 81 HttpStreamFactoryImplJobControllerTest()
38 : session_deps_(GetParam(), ProxyService::CreateDirect()) { 82 : session_deps_(GetParam(), ProxyService::CreateDirect()) {
39 session_deps_.enable_quic = true; 83 session_deps_.enable_quic = true;
84 }
85
86 void Initialize() {
40 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); 87 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_);
41 factory_ = 88 factory_ =
42 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); 89 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory());
43 job_controller_ = new HttpStreamFactoryImpl::JobController( 90 job_controller_ = new HttpStreamFactoryImpl::JobController(
44 factory_, &request_delegate_, session_.get(), &job_factory_); 91 factory_, &request_delegate_, session_.get(), &job_factory_);
45 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); 92 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_);
46 } 93 }
47 94
48 ~HttpStreamFactoryImplJobControllerTest() {} 95 ~HttpStreamFactoryImplJobControllerTest() {}
49 96
(...skipping 16 matching lines...) Expand all
66 113
67 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); 114 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest);
68 }; 115 };
69 116
70 INSTANTIATE_TEST_CASE_P(NextProto, 117 INSTANTIATE_TEST_CASE_P(NextProto,
71 HttpStreamFactoryImplJobControllerTest, 118 HttpStreamFactoryImplJobControllerTest,
72 testing::Values(kProtoSPDY31, kProtoHTTP2)); 119 testing::Values(kProtoSPDY31, kProtoHTTP2));
73 120
74 TEST_P(HttpStreamFactoryImplJobControllerTest, 121 TEST_P(HttpStreamFactoryImplJobControllerTest,
75 OnStreamFailedWithNoAlternativeJob) { 122 OnStreamFailedWithNoAlternativeJob) {
123 Initialize();
124
76 HttpRequestInfo request_info; 125 HttpRequestInfo request_info;
77 request_info.method = "GET"; 126 request_info.method = "GET";
78 request_info.url = GURL("http://www.google.com"); 127 request_info.url = GURL("http://www.google.com");
79 128
80 request_.reset( 129 request_.reset(
81 job_controller_->Start(request_info, &request_delegate_, nullptr, 130 job_controller_->Start(request_info, &request_delegate_, nullptr,
82 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 131 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
83 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 132 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
84 133
85 EXPECT_TRUE(job_controller_->main_job()); 134 EXPECT_TRUE(job_controller_->main_job());
86 135
87 // There's no other alternative job. Thus when stream failed, it should 136 // There's no other alternative job. Thus when stream failed, it should
88 // notify Request of the stream failure. 137 // notify Request of the stream failure.
89 EXPECT_CALL(request_delegate_, 138 EXPECT_CALL(request_delegate_,
90 OnStreamFailed(ERR_FAILED, _, SSL_FAILURE_NONE)) 139 OnStreamFailed(ERR_FAILED, _, SSL_FAILURE_NONE))
91 .Times(1); 140 .Times(1);
92 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 141 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
93 SSLConfig(), SSL_FAILURE_NONE); 142 SSLConfig(), SSL_FAILURE_NONE);
94 } 143 }
95 144
96 TEST_P(HttpStreamFactoryImplJobControllerTest, 145 TEST_P(HttpStreamFactoryImplJobControllerTest,
97 OnStreamReadyWithNoAlternativeJob) { 146 OnStreamReadyWithNoAlternativeJob) {
147 Initialize();
148
98 HttpRequestInfo request_info; 149 HttpRequestInfo request_info;
99 request_info.method = "GET"; 150 request_info.method = "GET";
100 request_info.url = GURL("http://www.google.com"); 151 request_info.url = GURL("http://www.google.com");
101 152
102 request_.reset( 153 request_.reset(
103 job_controller_->Start(request_info, &request_delegate_, nullptr, 154 job_controller_->Start(request_info, &request_delegate_, nullptr,
104 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 155 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
105 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 156 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
106 EXPECT_TRUE(job_controller_->main_job()); 157 EXPECT_TRUE(job_controller_->main_job());
107 158
108 // There's no other alternative job. Thus when stream is ready, it should 159 // There's no other alternative job. Thus when stream is ready, it should
109 // notify Request. 160 // notify Request.
110 HttpStream* http_stream = 161 HttpStream* http_stream =
111 new HttpBasicStream(new ClientSocketHandle(), false); 162 new HttpBasicStream(new ClientSocketHandle(), false);
112 job_factory_.main_job()->SetStream(http_stream); 163 job_factory_.main_job()->SetStream(http_stream);
113 164
114 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 165 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
115 .WillOnce(Invoke(DeleteHttpStreamPointer)); 166 .WillOnce(Invoke(DeleteHttpStreamPointer));
116 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), 167 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(),
117 ProxyInfo()); 168 ProxyInfo());
118 } 169 }
119 170
120 // Test we cancel Jobs correctly when the Request is explicitly canceled 171 // Test we cancel Jobs correctly when the Request is explicitly canceled
121 // before any Job is bound to Request. 172 // before any Job is bound to Request.
122 TEST_P(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { 173 TEST_P(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) {
174 Initialize();
175
123 HttpRequestInfo request_info; 176 HttpRequestInfo request_info;
124 request_info.method = "GET"; 177 request_info.method = "GET";
125 request_info.url = GURL("https://www.google.com"); 178 request_info.url = GURL("https://www.google.com");
126 179
127 url::SchemeHostPort server(request_info.url); 180 url::SchemeHostPort server(request_info.url);
128 AlternativeService alternative_service(QUIC, server.host(), 443); 181 AlternativeService alternative_service(QUIC, server.host(), 443);
129 SetAlternativeService(request_info, alternative_service); 182 SetAlternativeService(request_info, alternative_service);
130 183
131 request_.reset( 184 request_.reset(
132 job_controller_->Start(request_info, &request_delegate_, nullptr, 185 job_controller_->Start(request_info, &request_delegate_, nullptr,
133 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 186 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
134 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 187 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
135 EXPECT_TRUE(job_controller_->main_job()); 188 EXPECT_TRUE(job_controller_->main_job());
136 EXPECT_TRUE(job_controller_->alternative_job()); 189 EXPECT_TRUE(job_controller_->alternative_job());
137 190
138 // Reset the Request will cancel all the Jobs since there's no Job determined 191 // Reset the Request will cancel all the Jobs since there's no Job determined
139 // to serve Request yet and JobController will notify the factory to delete 192 // to serve Request yet and JobController will notify the factory to delete
140 // itself upon completion. 193 // itself upon completion.
141 request_.reset(); 194 request_.reset();
142 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 195 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
143 } 196 }
144 197
145 TEST_P(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { 198 TEST_P(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) {
199 Initialize();
200
146 HttpRequestInfo request_info; 201 HttpRequestInfo request_info;
147 request_info.method = "GET"; 202 request_info.method = "GET";
148 request_info.url = GURL("https://www.google.com"); 203 request_info.url = GURL("https://www.google.com");
149 204
150 url::SchemeHostPort server(request_info.url); 205 url::SchemeHostPort server(request_info.url);
151 AlternativeService alternative_service(QUIC, server.host(), 443); 206 AlternativeService alternative_service(QUIC, server.host(), 443);
152 SetAlternativeService(request_info, alternative_service); 207 SetAlternativeService(request_info, alternative_service);
153 208
154 request_.reset( 209 request_.reset(
155 job_controller_->Start(request_info, &request_delegate_, nullptr, 210 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 15 matching lines...) Expand all
171 // The failure of second Job should be reported to Request as there's no more 226 // The failure of second Job should be reported to Request as there's no more
172 // pending Job to serve the Request. 227 // pending Job to serve the Request.
173 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_UNKNOWN)) 228 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_UNKNOWN))
174 .Times(1); 229 .Times(1);
175 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 230 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
176 SSLConfig(), SSL_FAILURE_UNKNOWN); 231 SSLConfig(), SSL_FAILURE_UNKNOWN);
177 } 232 }
178 233
179 TEST_P(HttpStreamFactoryImplJobControllerTest, 234 TEST_P(HttpStreamFactoryImplJobControllerTest,
180 SecondJobFailsAfterFirstJobSucceeds) { 235 SecondJobFailsAfterFirstJobSucceeds) {
236 Initialize();
237
181 HttpRequestInfo request_info; 238 HttpRequestInfo request_info;
182 request_info.method = "GET"; 239 request_info.method = "GET";
183 request_info.url = GURL("https://www.google.com"); 240 request_info.url = GURL("https://www.google.com");
184 241
185 url::SchemeHostPort server(request_info.url); 242 url::SchemeHostPort server(request_info.url);
186 AlternativeService alternative_service(QUIC, server.host(), 443); 243 AlternativeService alternative_service(QUIC, server.host(), 443);
187 SetAlternativeService(request_info, alternative_service); 244 SetAlternativeService(request_info, alternative_service);
188 245
189 request_.reset( 246 request_.reset(
190 job_controller_->Start(request_info, &request_delegate_, nullptr, 247 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 22 matching lines...) Expand all
213 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, 270 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED,
214 SSLConfig(), SSL_FAILURE_NONE); 271 SSLConfig(), SSL_FAILURE_NONE);
215 272
216 // Reset the request as it's been successfully served. 273 // Reset the request as it's been successfully served.
217 request_.reset(); 274 request_.reset();
218 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 275 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
219 } 276 }
220 277
221 TEST_P(HttpStreamFactoryImplJobControllerTest, 278 TEST_P(HttpStreamFactoryImplJobControllerTest,
222 SecondJobSucceedsAfterFirstJobFailed) { 279 SecondJobSucceedsAfterFirstJobFailed) {
280 Initialize();
281
223 HttpRequestInfo request_info; 282 HttpRequestInfo request_info;
224 request_info.method = "GET"; 283 request_info.method = "GET";
225 request_info.url = GURL("https://www.google.com"); 284 request_info.url = GURL("https://www.google.com");
226 285
227 url::SchemeHostPort server(request_info.url); 286 url::SchemeHostPort server(request_info.url);
228 AlternativeService alternative_service(QUIC, server.host(), 443); 287 AlternativeService alternative_service(QUIC, server.host(), 443);
229 SetAlternativeService(request_info, alternative_service); 288 SetAlternativeService(request_info, alternative_service);
230 289
231 request_.reset( 290 request_.reset(
232 job_controller_->Start(request_info, &request_delegate_, nullptr, 291 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 18 matching lines...) Expand all
251 310
252 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 311 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
253 .WillOnce(Invoke(DeleteHttpStreamPointer)); 312 .WillOnce(Invoke(DeleteHttpStreamPointer));
254 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), 313 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(),
255 ProxyInfo()); 314 ProxyInfo());
256 } 315 }
257 316
258 // Regression test for crbug/621069. 317 // Regression test for crbug/621069.
259 // Get load state after main job fails and before alternative job succeeds. 318 // Get load state after main job fails and before alternative job succeeds.
260 TEST_P(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { 319 TEST_P(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) {
320 Initialize();
321
261 HttpRequestInfo request_info; 322 HttpRequestInfo request_info;
262 request_info.method = "GET"; 323 request_info.method = "GET";
263 request_info.url = GURL("https://www.google.com"); 324 request_info.url = GURL("https://www.google.com");
264 325
265 url::SchemeHostPort server(request_info.url); 326 url::SchemeHostPort server(request_info.url);
266 AlternativeService alternative_service(QUIC, server.host(), 443); 327 AlternativeService alternative_service(QUIC, server.host(), 443);
267 SetAlternativeService(request_info, alternative_service); 328 SetAlternativeService(request_info, alternative_service);
268 329
269 request_.reset( 330 request_.reset(
270 job_controller_->Start(request_info, &request_delegate_, nullptr, 331 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 18 matching lines...) Expand all
289 HttpStream* http_stream = 350 HttpStream* http_stream =
290 new HttpBasicStream(new ClientSocketHandle(), false); 351 new HttpBasicStream(new ClientSocketHandle(), false);
291 job_factory_.alternative_job()->SetStream(http_stream); 352 job_factory_.alternative_job()->SetStream(http_stream);
292 353
293 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 354 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
294 .WillOnce(Invoke(DeleteHttpStreamPointer)); 355 .WillOnce(Invoke(DeleteHttpStreamPointer));
295 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), 356 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(),
296 ProxyInfo()); 357 ProxyInfo());
297 } 358 }
298 359
360 TEST_P(HttpStreamFactoryImplJobControllerTest, InvalidPortToResumeMainJob) {
361 Initialize();
362
363 HttpRequestInfo request_info;
364 request_info.method = "GET";
365 request_info.url = GURL("https://www.google.com");
366
367 url::SchemeHostPort server(request_info.url);
368 // Using a restricted port 101 for QUIC should fail.
369 AlternativeService alternative_service(QUIC, server.host(), 101);
370 SetAlternativeService(request_info, alternative_service);
371
372 request_.reset(
373 job_controller_->Start(request_info, &request_delegate_, nullptr,
374 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
375 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
376 EXPECT_TRUE(job_controller_->main_job());
377 EXPECT_TRUE(job_controller_->alternative_job());
378
379 // |alternative_job| fails but should not report status to Request.
380 EXPECT_CALL(*job_factory_.main_job(), Resume(_)).Times(1);
381 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(),
382 HttpStreamRequest::HTTP_STREAM);
383
384 // Wait until OnStreamFailedCallback is executed on the alternative job.
385 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
386 base::RunLoop().RunUntilIdle();
387
388 EXPECT_FALSE(job_controller_->alternative_job());
389
390 // |main_job| succeeds and should report status to Request.
391 HttpStream* http_stream =
392 new HttpBasicStream(new ClientSocketHandle(), false);
393 job_factory_.main_job()->SetStream(http_stream);
394
395 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
396 .WillOnce(Invoke(DeleteHttpStreamPointer));
397 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(),
398 ProxyInfo());
399 }
400
401 TEST_P(HttpStreamFactoryImplJobControllerTest,
402 FailToResolveProxyToResumeMainJob) {
403 // Use failing ProxyResolverFactory which is unable to create ProxyResolver to
404 // to stall the alternative job and resume the main job.
405 ProxyConfig proxy_config;
406 proxy_config.set_auto_detect(true);
407 proxy_config.set_pac_mandatory(true);
408 session_deps_.proxy_service.reset(new ProxyService(
409 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
410 base::WrapUnique(new FailingProxyResolverFactory), nullptr));
411
412 Initialize();
413
414 HttpRequestInfo request_info;
415 request_info.method = "GET";
416 request_info.url = GURL("https://www.google.com");
417
418 url::SchemeHostPort server(request_info.url);
419 AlternativeService alternative_service(QUIC, server.host(), 443);
420 SetAlternativeService(request_info, alternative_service);
421
422 request_.reset(
423 job_controller_->Start(request_info, &request_delegate_, nullptr,
424 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
425 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
426 EXPECT_TRUE(job_controller_->main_job());
427 EXPECT_TRUE(job_controller_->alternative_job());
428
429 // |alternative_job| fails but should not report status to Request.
430 EXPECT_CALL(*job_factory_.main_job(), Resume(_)).Times(1);
431 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(),
432 HttpStreamRequest::HTTP_STREAM);
433
434 // Wait until OnStreamFailedCallback is executed on the alternative job.
435 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
436 base::RunLoop().RunUntilIdle();
437
438 EXPECT_FALSE(job_controller_->alternative_job());
439
440 // |main_job| succeeds and should report status to Request.
441 HttpStream* http_stream =
442 new HttpBasicStream(new ClientSocketHandle(), false);
443 job_factory_.main_job()->SetStream(http_stream);
444
445 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
446 .WillOnce(Invoke(DeleteHttpStreamPointer));
447 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(),
448 ProxyInfo());
449 }
450
451 TEST_P(HttpStreamFactoryImplJobControllerTest,
452 NoAvailableQuicSessionToResumeMainJob) {
453 // Use failing HostResolver which is unable to resolve the host name.
454 // No QUIC session is created and thus should resume the main job.
455 FailingHostResolver* resolver = new FailingHostResolver();
456 session_deps_.host_resolver.reset(resolver);
457
458 Initialize();
459 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
460 DCHECK(quic_stream_factory);
461
462 HttpRequestInfo request_info;
463 request_info.method = "GET";
464 request_info.url = GURL("https://www.google.com");
465
466 url::SchemeHostPort server(request_info.url);
467 AlternativeService alternative_service(QUIC, server.host(), 443);
468 SetAlternativeService(request_info, alternative_service);
469
470 request_.reset(
471 job_controller_->Start(request_info, &request_delegate_, nullptr,
472 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
473 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
474 EXPECT_TRUE(job_controller_->main_job());
475 EXPECT_TRUE(job_controller_->alternative_job());
476
477 // |alternative_job| fails as host resolution fails and should resume the
478 // main job.
479 EXPECT_CALL(*job_factory_.main_job(), Resume(_)).Times(1);
480 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(),
481 HttpStreamRequest::HTTP_STREAM);
482
483 // Wait until OnStreamFailedCallback is executed on the alternative job.
484 // Request shouldn't be notified as the main job is still pending status.
485 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0);
486 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
487 base::RunLoop().RunUntilIdle();
488
489 EXPECT_FALSE(job_controller_->alternative_job());
490
491 // |main_job| succeeds and should report status to Request.
492 HttpStream* http_stream =
493 new HttpBasicStream(new ClientSocketHandle(), false);
494 job_factory_.main_job()->SetStream(http_stream);
495
496 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
497 .WillOnce(Invoke(DeleteHttpStreamPointer));
498 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(),
499 ProxyInfo());
500 }
501
502 TEST_P(HttpStreamFactoryImplJobControllerTest,
503 NoAvailableSpdySessionToResumeMainJob) {
504 // Disable QUIC.
505 session_deps_.enable_quic = false;
506 // Use failing HostResolver which is unable to resolve the host name.
507 // No SPDY session is created and thus should resume the main job.
508 FailingHostResolver* resolver = new FailingHostResolver();
509 session_deps_.host_resolver.reset(resolver);
510
511 Initialize();
512 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
513 DCHECK(quic_stream_factory);
514
515 HttpRequestInfo request_info;
516 request_info.method = "GET";
517 request_info.url = GURL("http://www.google.com");
518
519 // Set a SPDY alternative service for the server.
520 url::SchemeHostPort server(request_info.url);
521 AlternativeService alternative_service(NPN_HTTP_2, server.host(), 443);
522 SetAlternativeService(request_info, alternative_service);
523
524 request_.reset(
525 job_controller_->Start(request_info, &request_delegate_, nullptr,
526 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
527 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
528 EXPECT_TRUE(job_controller_->main_job());
529 EXPECT_TRUE(job_controller_->alternative_job());
530
531 // |alternative_job| fails as host resolution fails and should resume the
532 // main job.
533 EXPECT_CALL(*job_factory_.main_job(), Resume(_)).Times(1);
534 HttpStreamFactoryImplJobPeer::Start(job_factory_.alternative_job(),
535 HttpStreamRequest::HTTP_STREAM);
536
537 // Wait until OnStreamFailedCallback is executed on the alternative job.
538 // Request shouldn't be notified as the main job is still pending status.
539 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0);
540 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
541 base::RunLoop().RunUntilIdle();
542
543 EXPECT_FALSE(job_controller_->alternative_job());
544
545 // |main_job| succeeds and should report status to Request.
546 HttpStream* http_stream =
547 new HttpBasicStream(new ClientSocketHandle(), false);
548 job_factory_.main_job()->SetStream(http_stream);
549
550 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
551 .WillOnce(Invoke(DeleteHttpStreamPointer));
552 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(),
553 ProxyInfo());
554 }
555
299 } // namespace net 556 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698