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

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: fix a include typo Created 4 years, 4 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.h"
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"
18 #include "net/quic/test_tools/quic_stream_factory_peer.h"
14 #include "net/spdy/spdy_test_util_common.h" 19 #include "net/spdy/spdy_test_util_common.h"
20 #include "testing/gmock_mutant.h"
15 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
16 22
17 using ::testing::_; 23 using ::testing::_;
18 using ::testing::Invoke; 24 using ::testing::Invoke;
19 25
20 namespace net { 26 namespace net {
21 27
22 namespace { 28 namespace {
23 29
24 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config, 30 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config,
25 const ProxyInfo& used_proxy_info, 31 const ProxyInfo& used_proxy_info,
26 HttpStream* stream) { 32 HttpStream* stream) {
27 delete stream; 33 delete stream;
28 } 34 }
29 35
36 class HangingProxyResolver : public ProxyResolver {
37 public:
38 HangingProxyResolver() {}
39 ~HangingProxyResolver() override {}
40
41 int GetProxyForURL(const GURL& url,
42 ProxyInfo* results,
43 const CompletionCallback& callback,
44 RequestHandle* request,
45 const BoundNetLog& net_log) override {
46 return ERR_IO_PENDING;
47 }
48
49 void CancelRequest(RequestHandle request) override { NOTREACHED(); }
50
51 LoadState GetLoadState(RequestHandle request) const override {
52 NOTREACHED();
53 return LOAD_STATE_IDLE;
54 }
55
56 private:
57 DISALLOW_COPY_AND_ASSIGN(HangingProxyResolver);
58 };
59
60 class HangingProxyResolverFactory : public ProxyResolverFactory {
61 public:
62 explicit HangingProxyResolverFactory(HangingProxyResolver* resolver)
63 : ProxyResolverFactory(false), resolver_(resolver) {}
64
65 // ProxyResolverFactory override.
66 int CreateProxyResolver(
67 const scoped_refptr<ProxyResolverScriptData>& pac_script,
68 std::unique_ptr<ProxyResolver>* resolver,
69 const net::CompletionCallback& callback,
70 std::unique_ptr<Request>* request) override {
71 resolver->reset(new ForwardingProxyResolver(resolver_));
72 return OK;
73 }
74
75 private:
76 HangingProxyResolver* resolver_;
77 };
78
79 class FailingProxyResolverFactory : public ProxyResolverFactory {
80 public:
81 FailingProxyResolverFactory() : ProxyResolverFactory(false) {}
82
83 // ProxyResolverFactory override.
84 int CreateProxyResolver(
85 const scoped_refptr<ProxyResolverScriptData>& script_data,
86 std::unique_ptr<ProxyResolver>* result,
87 const CompletionCallback& callback,
88 std::unique_ptr<Request>* request) override {
89 return ERR_PAC_SCRIPT_FAILED;
90 }
91 };
92
93 class FailingHostResolver : public MockHostResolverBase {
94 public:
95 FailingHostResolver() : MockHostResolverBase(false /*use_caching*/) {}
96 ~FailingHostResolver() override {}
97
98 int Resolve(const RequestInfo& info,
99 RequestPriority priority,
100 AddressList* addresses,
101 const CompletionCallback& callback,
102 RequestHandle* out_req,
103 const BoundNetLog& net_log) override {
104 return ERR_NAME_NOT_RESOLVED;
105 }
106 };
107
108 class HangingResolver : public MockHostResolverBase {
109 public:
110 HangingResolver() : MockHostResolverBase(false /*use_caching*/) {}
111 ~HangingResolver() override {}
112
113 int Resolve(const RequestInfo& info,
114 RequestPriority priority,
115 AddressList* addresses,
116 const CompletionCallback& callback,
117 RequestHandle* out_req,
118 const BoundNetLog& net_log) override {
119 return ERR_IO_PENDING;
120 }
121
122 void CancelRequest(RequestHandle req) override {}
123 };
30 } // anonymous namespace 124 } // anonymous namespace
31 125
126 class HttpStreamFactoryImplJobPeer {
127 public:
128 static void Start(HttpStreamFactoryImpl::Job* job,
129 HttpStreamRequest::StreamType stream_type) {
130 // Start() is mocked for MockHttpStreamFactoryImplJob.
131 // This is the alternative method to invoke real Start() method on Job.
132 job->stream_type_ = stream_type;
133 job->StartInternal();
134 }
135 };
136
137 class JobControllerPeer {
138 public:
139 static void VerifyWaitingTimeForMainJob(
140 HttpStreamFactoryImpl::JobController* job_controller,
141 const base::TimeDelta& delay) {
142 EXPECT_EQ(delay, job_controller->main_job_wait_time_);
143 }
144 };
145
32 class HttpStreamFactoryImplJobControllerTest 146 class HttpStreamFactoryImplJobControllerTest
33 : public ::testing::Test, 147 : public ::testing::Test,
34 public ::testing::WithParamInterface<NextProto> { 148 public ::testing::WithParamInterface<NextProto> {
35 public: 149 public:
36 HttpStreamFactoryImplJobControllerTest() 150 HttpStreamFactoryImplJobControllerTest()
37 : session_deps_(ProxyService::CreateDirect()) { 151 : session_deps_(ProxyService::CreateDirect()) {
38 session_deps_.enable_quic = true; 152 session_deps_.enable_quic = true;
153 }
154
155 void Initialize() {
39 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); 156 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_);
40 factory_ = 157 factory_ =
41 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); 158 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory());
42 job_controller_ = new HttpStreamFactoryImpl::JobController( 159 job_controller_ = new HttpStreamFactoryImpl::JobController(
43 factory_, &request_delegate_, session_.get(), &job_factory_); 160 factory_, &request_delegate_, session_.get(), &job_factory_);
44 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); 161 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_);
45 } 162 }
46 163
47 ~HttpStreamFactoryImplJobControllerTest() {} 164 ~HttpStreamFactoryImplJobControllerTest() {}
48 165
(...skipping 12 matching lines...) Expand all
61 std::unique_ptr<HttpNetworkSession> session_; 178 std::unique_ptr<HttpNetworkSession> session_;
62 HttpStreamFactoryImpl* factory_; 179 HttpStreamFactoryImpl* factory_;
63 HttpStreamFactoryImpl::JobController* job_controller_; 180 HttpStreamFactoryImpl::JobController* job_controller_;
64 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; 181 std::unique_ptr<HttpStreamFactoryImpl::Request> request_;
65 182
66 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); 183 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest);
67 }; 184 };
68 185
69 TEST_F(HttpStreamFactoryImplJobControllerTest, 186 TEST_F(HttpStreamFactoryImplJobControllerTest,
70 OnStreamFailedWithNoAlternativeJob) { 187 OnStreamFailedWithNoAlternativeJob) {
188 ProxyConfig proxy_config;
189 proxy_config.set_auto_detect(true);
190 // Use asynchronous proxy resolver.
191 MockAsyncProxyResolverFactory* proxy_resolver_factory =
192 new MockAsyncProxyResolverFactory(false);
193 session_deps_.proxy_service.reset(new ProxyService(
194 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
195 base::WrapUnique(proxy_resolver_factory), nullptr));
196 Initialize();
197
71 HttpRequestInfo request_info; 198 HttpRequestInfo request_info;
72 request_info.method = "GET"; 199 request_info.method = "GET";
73 request_info.url = GURL("http://www.google.com"); 200 request_info.url = GURL("http://www.google.com");
74 201
75 request_.reset( 202 request_.reset(
76 job_controller_->Start(request_info, &request_delegate_, nullptr, 203 job_controller_->Start(request_info, &request_delegate_, nullptr,
77 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 204 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
78 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 205 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
79 206
80 EXPECT_TRUE(job_controller_->main_job()); 207 EXPECT_TRUE(job_controller_->main_job());
81 208
82 // There's no other alternative job. Thus when stream failed, it should 209 // There's no other alternative job. Thus when stream failed, it should
83 // notify Request of the stream failure. 210 // notify Request of the stream failure.
84 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); 211 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1);
85 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 212 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
86 SSLConfig()); 213 SSLConfig());
87 } 214 }
88 215
89 TEST_F(HttpStreamFactoryImplJobControllerTest, 216 TEST_F(HttpStreamFactoryImplJobControllerTest,
90 OnStreamReadyWithNoAlternativeJob) { 217 OnStreamReadyWithNoAlternativeJob) {
218 ProxyConfig proxy_config;
219 proxy_config.set_auto_detect(true);
220 // Use asynchronous proxy resolver.
221 MockAsyncProxyResolverFactory* proxy_resolver_factory =
222 new MockAsyncProxyResolverFactory(false);
223 session_deps_.proxy_service.reset(new ProxyService(
224 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
225 base::WrapUnique(proxy_resolver_factory), nullptr));
226 Initialize();
227
91 HttpRequestInfo request_info; 228 HttpRequestInfo request_info;
92 request_info.method = "GET"; 229 request_info.method = "GET";
93 request_info.url = GURL("http://www.google.com"); 230 request_info.url = GURL("http://www.google.com");
94 231
95 request_.reset( 232 request_.reset(
96 job_controller_->Start(request_info, &request_delegate_, nullptr, 233 job_controller_->Start(request_info, &request_delegate_, nullptr,
97 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 234 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
98 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 235 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
99 EXPECT_TRUE(job_controller_->main_job());
100 236
101 // There's no other alternative job. Thus when stream is ready, it should 237 // There's no other alternative job. Thus when stream is ready, it should
102 // notify Request. 238 // notify Request.
103 HttpStream* http_stream = 239 HttpStream* http_stream =
104 new HttpBasicStream(new ClientSocketHandle(), false); 240 new HttpBasicStream(new ClientSocketHandle(), false);
105 job_factory_.main_job()->SetStream(http_stream); 241 job_factory_.main_job()->SetStream(http_stream);
106 242
107 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 243 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
108 .WillOnce(Invoke(DeleteHttpStreamPointer)); 244 .WillOnce(Invoke(DeleteHttpStreamPointer));
109 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), 245 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(),
110 ProxyInfo()); 246 ProxyInfo());
111 } 247 }
112 248
113 // Test we cancel Jobs correctly when the Request is explicitly canceled 249 // Test we cancel Jobs correctly when the Request is explicitly canceled
114 // before any Job is bound to Request. 250 // before any Job is bound to Request.
115 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { 251 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) {
252 ProxyConfig proxy_config;
253 proxy_config.set_auto_detect(true);
254 // Use asynchronous proxy resolver.
255 MockAsyncProxyResolverFactory* proxy_resolver_factory =
256 new MockAsyncProxyResolverFactory(false);
257 session_deps_.proxy_service.reset(new ProxyService(
258 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
259 base::WrapUnique(proxy_resolver_factory), nullptr));
260 Initialize();
261
116 HttpRequestInfo request_info; 262 HttpRequestInfo request_info;
117 request_info.method = "GET"; 263 request_info.method = "GET";
118 request_info.url = GURL("https://www.google.com"); 264 request_info.url = GURL("https://www.google.com");
119 265
120 url::SchemeHostPort server(request_info.url); 266 url::SchemeHostPort server(request_info.url);
121 AlternativeService alternative_service(QUIC, server.host(), 443); 267 AlternativeService alternative_service(QUIC, server.host(), 443);
122 SetAlternativeService(request_info, alternative_service); 268 SetAlternativeService(request_info, alternative_service);
123 269
124 request_.reset( 270 request_.reset(
125 job_controller_->Start(request_info, &request_delegate_, nullptr, 271 job_controller_->Start(request_info, &request_delegate_, nullptr,
126 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 272 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
127 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 273 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
128 EXPECT_TRUE(job_controller_->main_job()); 274 EXPECT_TRUE(job_controller_->main_job());
129 EXPECT_TRUE(job_controller_->alternative_job()); 275 EXPECT_TRUE(job_controller_->alternative_job());
130 276
131 // Reset the Request will cancel all the Jobs since there's no Job determined 277 // Reset the Request will cancel all the Jobs since there's no Job determined
132 // to serve Request yet and JobController will notify the factory to delete 278 // to serve Request yet and JobController will notify the factory to delete
133 // itself upon completion. 279 // itself upon completion.
134 request_.reset(); 280 request_.reset();
135 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 281 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
136 } 282 }
137 283
138 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { 284 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) {
285 ProxyConfig proxy_config;
286 proxy_config.set_auto_detect(true);
287 // Use asynchronous proxy resolver.
288 MockAsyncProxyResolverFactory* proxy_resolver_factory =
289 new MockAsyncProxyResolverFactory(false);
290 session_deps_.proxy_service.reset(new ProxyService(
291 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
292 base::WrapUnique(proxy_resolver_factory), nullptr));
293 Initialize();
294
139 HttpRequestInfo request_info; 295 HttpRequestInfo request_info;
140 request_info.method = "GET"; 296 request_info.method = "GET";
141 request_info.url = GURL("https://www.google.com"); 297 request_info.url = GURL("https://www.google.com");
142 298
143 url::SchemeHostPort server(request_info.url); 299 url::SchemeHostPort server(request_info.url);
144 AlternativeService alternative_service(QUIC, server.host(), 443); 300 AlternativeService alternative_service(QUIC, server.host(), 443);
145 SetAlternativeService(request_info, alternative_service); 301 SetAlternativeService(request_info, alternative_service);
146 302
147 request_.reset( 303 request_.reset(
148 job_controller_->Start(request_info, &request_delegate_, nullptr, 304 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 14 matching lines...) Expand all
163 319
164 // The failure of second Job should be reported to Request as there's no more 320 // The failure of second Job should be reported to Request as there's no more
165 // pending Job to serve the Request. 321 // pending Job to serve the Request.
166 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); 322 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1);
167 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 323 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
168 SSLConfig()); 324 SSLConfig());
169 } 325 }
170 326
171 TEST_F(HttpStreamFactoryImplJobControllerTest, 327 TEST_F(HttpStreamFactoryImplJobControllerTest,
172 SecondJobFailsAfterFirstJobSucceeds) { 328 SecondJobFailsAfterFirstJobSucceeds) {
329 ProxyConfig proxy_config;
330 proxy_config.set_auto_detect(true);
331 // Use asynchronous proxy resolver.
332 MockAsyncProxyResolverFactory* proxy_resolver_factory =
333 new MockAsyncProxyResolverFactory(false);
334 session_deps_.proxy_service.reset(new ProxyService(
335 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
336 base::WrapUnique(proxy_resolver_factory), nullptr));
337 Initialize();
338
173 HttpRequestInfo request_info; 339 HttpRequestInfo request_info;
174 request_info.method = "GET"; 340 request_info.method = "GET";
175 request_info.url = GURL("https://www.google.com"); 341 request_info.url = GURL("https://www.google.com");
176 342
177 url::SchemeHostPort server(request_info.url); 343 url::SchemeHostPort server(request_info.url);
178 AlternativeService alternative_service(QUIC, server.host(), 443); 344 AlternativeService alternative_service(QUIC, server.host(), 443);
179 SetAlternativeService(request_info, alternative_service); 345 SetAlternativeService(request_info, alternative_service);
180 346
181 request_.reset( 347 request_.reset(
182 job_controller_->Start(request_info, &request_delegate_, nullptr, 348 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 22 matching lines...) Expand all
205 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, 371 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED,
206 SSLConfig()); 372 SSLConfig());
207 373
208 // Reset the request as it's been successfully served. 374 // Reset the request as it's been successfully served.
209 request_.reset(); 375 request_.reset();
210 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 376 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
211 } 377 }
212 378
213 TEST_F(HttpStreamFactoryImplJobControllerTest, 379 TEST_F(HttpStreamFactoryImplJobControllerTest,
214 SecondJobSucceedsAfterFirstJobFailed) { 380 SecondJobSucceedsAfterFirstJobFailed) {
381 ProxyConfig proxy_config;
382 proxy_config.set_auto_detect(true);
383 // Use asynchronous proxy resolver.
384 MockAsyncProxyResolverFactory* proxy_resolver_factory =
385 new MockAsyncProxyResolverFactory(false);
386 session_deps_.proxy_service.reset(new ProxyService(
387 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
388 base::WrapUnique(proxy_resolver_factory), nullptr));
389 Initialize();
390
215 HttpRequestInfo request_info; 391 HttpRequestInfo request_info;
216 request_info.method = "GET"; 392 request_info.method = "GET";
217 request_info.url = GURL("https://www.google.com"); 393 request_info.url = GURL("https://www.google.com");
218 394
219 url::SchemeHostPort server(request_info.url); 395 url::SchemeHostPort server(request_info.url);
220 AlternativeService alternative_service(QUIC, server.host(), 443); 396 AlternativeService alternative_service(QUIC, server.host(), 443);
221 SetAlternativeService(request_info, alternative_service); 397 SetAlternativeService(request_info, alternative_service);
222 398
223 request_.reset( 399 request_.reset(
224 job_controller_->Start(request_info, &request_delegate_, nullptr, 400 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 18 matching lines...) Expand all
243 419
244 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 420 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
245 .WillOnce(Invoke(DeleteHttpStreamPointer)); 421 .WillOnce(Invoke(DeleteHttpStreamPointer));
246 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), 422 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(),
247 ProxyInfo()); 423 ProxyInfo());
248 } 424 }
249 425
250 // Regression test for crbug/621069. 426 // Regression test for crbug/621069.
251 // Get load state after main job fails and before alternative job succeeds. 427 // Get load state after main job fails and before alternative job succeeds.
252 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { 428 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) {
429 ProxyConfig proxy_config;
430 proxy_config.set_auto_detect(true);
431 // Use asynchronous proxy resolver.
432 MockAsyncProxyResolverFactory* proxy_resolver_factory =
433 new MockAsyncProxyResolverFactory(false);
434 session_deps_.proxy_service.reset(new ProxyService(
435 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
436 base::WrapUnique(proxy_resolver_factory), nullptr));
437 Initialize();
438
253 HttpRequestInfo request_info; 439 HttpRequestInfo request_info;
254 request_info.method = "GET"; 440 request_info.method = "GET";
255 request_info.url = GURL("https://www.google.com"); 441 request_info.url = GURL("https://www.google.com");
256 442
257 url::SchemeHostPort server(request_info.url); 443 url::SchemeHostPort server(request_info.url);
258 AlternativeService alternative_service(QUIC, server.host(), 443); 444 AlternativeService alternative_service(QUIC, server.host(), 443);
259 SetAlternativeService(request_info, alternative_service); 445 SetAlternativeService(request_info, alternative_service);
260 446
261 request_.reset( 447 request_.reset(
262 job_controller_->Start(request_info, &request_delegate_, nullptr, 448 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 18 matching lines...) Expand all
281 HttpStream* http_stream = 467 HttpStream* http_stream =
282 new HttpBasicStream(new ClientSocketHandle(), false); 468 new HttpBasicStream(new ClientSocketHandle(), false);
283 job_factory_.alternative_job()->SetStream(http_stream); 469 job_factory_.alternative_job()->SetStream(http_stream);
284 470
285 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 471 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
286 .WillOnce(Invoke(DeleteHttpStreamPointer)); 472 .WillOnce(Invoke(DeleteHttpStreamPointer));
287 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), 473 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(),
288 ProxyInfo()); 474 ProxyInfo());
289 } 475 }
290 476
477 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) {
478 // Use failing ProxyResolverFactory which is unable to create ProxyResolver
479 // to stall the alternative job and report to controller to maybe resume the
480 // main job.
481 ProxyConfig proxy_config;
482 proxy_config.set_auto_detect(true);
483 proxy_config.set_pac_mandatory(true);
484 session_deps_.proxy_service.reset(new ProxyService(
485 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
486 base::WrapUnique(new FailingProxyResolverFactory), nullptr));
487
488 Initialize();
489
490 HttpRequestInfo request_info;
491 request_info.method = "GET";
492 request_info.url = GURL("https://www.google.com");
493
494 url::SchemeHostPort server(request_info.url);
495 AlternativeService alternative_service(QUIC, server.host(), 443);
496 SetAlternativeService(request_info, alternative_service);
497
498 request_.reset(
499 job_controller_->Start(request_info, &request_delegate_, nullptr,
500 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
501 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
502 EXPECT_TRUE(job_controller_->main_job());
503 EXPECT_TRUE(job_controller_->alternative_job());
504
505 // Wait until OnStreamFailedCallback is executed on the alternative job.
506 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1);
507 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
508 base::RunLoop().RunUntilIdle();
509 }
510
511 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) {
512 // Using a restricted port 101 for QUIC should fail and the alternative job
513 // should post OnStreamFailedCall on the controller to resume the main job.
514 Initialize();
515
516 HttpRequestInfo request_info;
517 request_info.method = "GET";
518 request_info.url = GURL("https://www.google.com");
519
520 url::SchemeHostPort server(request_info.url);
521 AlternativeService alternative_service(QUIC, server.host(), 101);
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
529 EXPECT_TRUE(job_factory_.main_job()->is_waiting());
530
531 // Wait until OnStreamFailedCallback is executed on the alternative job.
532 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
533 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
534 base::RunLoop().RunUntilIdle();
535 }
536
537 TEST_F(HttpStreamFactoryImplJobControllerTest,
538 NoAvailableSpdySessionToResumeMainJob) {
539 // Test the alternative job is not resumed when the alternative job is
540 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds,
541 // the latter part of this test tests controller resumes the main job
542 // when there's no SPDY session for the alternative job.
543 ProxyConfig proxy_config;
544 proxy_config.set_auto_detect(true);
545 // Use asynchronous proxy resolver.
546 MockAsyncProxyResolverFactory* proxy_resolver_factory =
547 new MockAsyncProxyResolverFactory(false);
548 session_deps_.proxy_service.reset(new ProxyService(
549 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
550 base::WrapUnique(proxy_resolver_factory), nullptr));
551
552 HangingResolver* host_resolver = new HangingResolver();
553 session_deps_.host_resolver.reset(host_resolver);
554 session_deps_.host_resolver->set_synchronous_mode(false);
555
556 Initialize();
557
558 HttpRequestInfo request_info;
559 request_info.method = "GET";
560 request_info.url = GURL("https://www.google.com");
561
562 // Set a SPDY alternative service for the server.
563 url::SchemeHostPort server(request_info.url);
564 AlternativeService alternative_service(QUIC, server.host(), 443);
565 SetAlternativeService(request_info, alternative_service);
566 // Hack to use different URL for the main job to help differentiate the proxy
567 // requests.
568 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com"));
569
570 request_.reset(
571 job_controller_->Start(request_info, &request_delegate_, nullptr,
572 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
573 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
574 // Both jobs should be created but stalled as proxy resolution not completed.
575 EXPECT_TRUE(job_controller_->main_job());
576 EXPECT_TRUE(job_controller_->alternative_job());
577
578 MockAsyncProxyResolver resolver;
579 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
580 net::OK, &resolver);
581
582 // Resolve proxy for the main job which then proceed to wait for the
583 // alternative job which is IO_PENDING.
584 int main_job_request_id =
585 resolver.pending_requests()[0]->url().SchemeIs("http") ? 0 : 1;
586
587 resolver.pending_requests()[main_job_request_id]->results()->UseNamedProxy(
588 "result1:80");
589 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK);
590 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
591
592 // Resolve proxy for the alternative job to proceed to create a connection.
593 // Use hanging HostResolver to fail creation of a SPDY session for the
594 // alternative job. The alternative job will be IO_PENDING thus should resume
595 // the main job.
596 resolver.pending_requests()[0]->CompleteNow(net::OK);
597 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
598 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
599 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
600
601 base::RunLoop().RunUntilIdle();
602 }
603
604 TEST_F(HttpStreamFactoryImplJobControllerTest,
605 NoAvailableQuicSessionToResumeMainJob) {
606 // Use failing HostResolver which is unable to resolve the host name for QUIC.
607 // No QUIC session is created and thus should resume the main job.
608 FailingHostResolver* host_resolver = new FailingHostResolver();
609 session_deps_.host_resolver.reset(host_resolver);
610
611 ProxyConfig proxy_config;
612 proxy_config.set_auto_detect(true);
613 // Use asynchronous proxy resolver.
614 MockAsyncProxyResolverFactory* proxy_resolver_factory =
615 new MockAsyncProxyResolverFactory(false);
616 session_deps_.proxy_service.reset(new ProxyService(
617 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)),
618 base::WrapUnique(proxy_resolver_factory), nullptr));
619
620 Initialize();
621
622 HttpRequestInfo request_info;
623 request_info.method = "GET";
624 request_info.url = GURL("https://www.google.com");
625
626 url::SchemeHostPort server(request_info.url);
627 AlternativeService alternative_service(QUIC, server.host(), 443);
628 SetAlternativeService(request_info, alternative_service);
629 // Hack to use different URL for the main job to help differentiate the proxy
630 // requests.
631 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com"));
632
633 request_.reset(
634 job_controller_->Start(request_info, &request_delegate_, nullptr,
635 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
636 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
637 EXPECT_TRUE(job_controller_->main_job());
638 EXPECT_TRUE(job_controller_->alternative_job());
639
640 MockAsyncProxyResolver resolver;
641 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder(
642 net::OK, &resolver);
643
644 // Resolve proxy for the main job which then proceed to wait for the
645 // alternative job which is IO_PENDING.
646 int main_job_request_id =
647 resolver.pending_requests()[0]->url().SchemeIs("http") ? 0 : 1;
648
649 resolver.pending_requests()[main_job_request_id]->results()->UseNamedProxy(
650 "result1:80");
651 resolver.pending_requests()[main_job_request_id]->CompleteNow(net::OK);
652 EXPECT_TRUE(job_controller_->main_job()->is_waiting());
653
654 // Resolve proxy for the alternative job to proceed to create a connection.
655 // Use failing HostResolver to fail creation of a QUIC session for the
656 // alternative job. The alternative job will thus resume the main job.
657 resolver.pending_requests()[0]->results()->UseNamedProxy("result1:80");
658 resolver.pending_requests()[0]->CompleteNow(net::OK);
659
660 // Wait until OnStreamFailedCallback is executed on the alternative job.
661 // Request shouldn't be notified as the main job is still pending status.
662 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
663 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1);
664 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
665
666 base::RunLoop().RunUntilIdle();
667 }
668
669 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) {
670 HangingResolver* resolver = new HangingResolver();
671 session_deps_.host_resolver.reset(resolver);
672
673 Initialize();
674
675 // Enable delayed TCP and set time delay for waiting job.
676 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory();
677 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true);
678 quic_stream_factory->set_require_confirmation(false);
679 ServerNetworkStats stats1;
680 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
681 session_->http_server_properties()->SetServerNetworkStats(
682 url::SchemeHostPort(GURL("https://www.google.com")), stats1);
683
684 HttpRequestInfo request_info;
685 request_info.method = "GET";
686 request_info.url = GURL("https://www.google.com");
687
688 // Set a SPDY alternative service for the server.
689 url::SchemeHostPort server(request_info.url);
690 AlternativeService alternative_service(QUIC, server.host(), 443);
691 SetAlternativeService(request_info, alternative_service);
692
693 request_.reset(
694 job_controller_->Start(request_info, &request_delegate_, nullptr,
695 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
696 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
697 EXPECT_TRUE(job_controller_->main_job());
698 EXPECT_TRUE(job_controller_->alternative_job());
699
700 // The alternative job stalls as host resolution hangs when creating the QUIC
701 // request and controller should resume the main job after delay.
702 // Verify the waiting time for delayed main job.
703 EXPECT_CALL(*job_factory_.main_job(), Resume())
704 .WillOnce(Invoke(testing::CreateFunctor(
705 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_,
706 base::TimeDelta::FromMicroseconds(15))));
707
708 base::RunLoop().RunUntilIdle();
709 }
291 } // namespace net 710 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.cc ('k') | net/http/http_stream_factory_impl_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698