OLD | NEW |
---|---|
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_stream_factory_impl_job_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "net/base/test_proxy_delegate.h" | |
11 #include "net/dns/mock_host_resolver.h" | 12 #include "net/dns/mock_host_resolver.h" |
12 #include "net/http/http_basic_stream.h" | 13 #include "net/http/http_basic_stream.h" |
13 #include "net/http/http_stream_factory_impl_request.h" | 14 #include "net/http/http_stream_factory_impl_request.h" |
14 #include "net/http/http_stream_factory_test_util.h" | 15 #include "net/http/http_stream_factory_test_util.h" |
15 #include "net/proxy/mock_proxy_resolver.h" | 16 #include "net/proxy/mock_proxy_resolver.h" |
16 #include "net/proxy/proxy_config_service_fixed.h" | 17 #include "net/proxy/proxy_config_service_fixed.h" |
17 #include "net/proxy/proxy_info.h" | 18 #include "net/proxy/proxy_info.h" |
18 #include "net/proxy/proxy_service.h" | 19 #include "net/proxy/proxy_service.h" |
19 #include "net/quic/test_tools/quic_stream_factory_peer.h" | 20 #include "net/quic/test_tools/quic_stream_factory_peer.h" |
20 #include "net/spdy/spdy_test_util_common.h" | 21 #include "net/spdy/spdy_test_util_common.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | |
21 #include "testing/gmock_mutant.h" | 23 #include "testing/gmock_mutant.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
23 | 25 |
24 using ::testing::_; | 26 using ::testing::_; |
25 using ::testing::Invoke; | 27 using ::testing::Invoke; |
26 | 28 |
27 namespace net { | 29 namespace net { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 | 103 |
102 class HttpStreamFactoryImplJobControllerTest | 104 class HttpStreamFactoryImplJobControllerTest |
103 : public ::testing::Test, | 105 : public ::testing::Test, |
104 public ::testing::WithParamInterface<NextProto> { | 106 public ::testing::WithParamInterface<NextProto> { |
105 public: | 107 public: |
106 HttpStreamFactoryImplJobControllerTest() | 108 HttpStreamFactoryImplJobControllerTest() |
107 : session_deps_(ProxyService::CreateDirect()) { | 109 : session_deps_(ProxyService::CreateDirect()) { |
108 session_deps_.enable_quic = true; | 110 session_deps_.enable_quic = true; |
109 } | 111 } |
110 | 112 |
111 void Initialize() { | 113 void Initialize(bool use_alternative_proxy) { |
114 if (use_alternative_proxy) { | |
115 std::unique_ptr<ProxyService> proxy_service = | |
116 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | |
117 session_deps_.proxy_service.reset(proxy_service.release()); | |
118 | |
119 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( | |
120 new TestProxyDelegate()); | |
121 test_proxy_delegate_ = test_proxy_delegate.get(); | |
122 | |
123 test_proxy_delegate->set_alternative_proxy_server( | |
124 ProxyServer::FromPacString("QUIC myproxy.org:443")); | |
125 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); | |
126 session_deps_.proxy_delegate.reset(test_proxy_delegate.release()); | |
127 } | |
112 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 128 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
113 factory_ = | 129 factory_ = |
114 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 130 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
115 job_controller_ = new HttpStreamFactoryImpl::JobController( | 131 job_controller_ = new HttpStreamFactoryImpl::JobController( |
116 factory_, &request_delegate_, session_.get(), &job_factory_); | 132 factory_, &request_delegate_, session_.get(), &job_factory_); |
117 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 133 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
118 } | 134 } |
119 | 135 |
136 TestProxyDelegate* test_proxy_delegate() const { | |
137 return test_proxy_delegate_; | |
138 } | |
139 | |
120 ~HttpStreamFactoryImplJobControllerTest() {} | 140 ~HttpStreamFactoryImplJobControllerTest() {} |
121 | 141 |
122 void SetAlternativeService(const HttpRequestInfo& request_info, | 142 void SetAlternativeService(const HttpRequestInfo& request_info, |
123 AlternativeService alternative_service) { | 143 AlternativeService alternative_service) { |
124 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 144 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
125 url::SchemeHostPort server(request_info.url); | 145 url::SchemeHostPort server(request_info.url); |
126 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 146 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
127 session_->http_server_properties()->SetAlternativeService( | 147 session_->http_server_properties()->SetAlternativeService( |
128 server, alternative_service, expiration); | 148 server, alternative_service, expiration); |
129 } | 149 } |
130 | 150 |
151 // Not owned by |this|. | |
152 TestProxyDelegate* test_proxy_delegate_; | |
131 TestJobFactory job_factory_; | 153 TestJobFactory job_factory_; |
132 MockHttpStreamRequestDelegate request_delegate_; | 154 MockHttpStreamRequestDelegate request_delegate_; |
133 SpdySessionDependencies session_deps_; | 155 SpdySessionDependencies session_deps_; |
134 std::unique_ptr<HttpNetworkSession> session_; | 156 std::unique_ptr<HttpNetworkSession> session_; |
135 HttpStreamFactoryImpl* factory_; | 157 HttpStreamFactoryImpl* factory_; |
136 HttpStreamFactoryImpl::JobController* job_controller_; | 158 HttpStreamFactoryImpl::JobController* job_controller_; |
137 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; | 159 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; |
138 | 160 |
139 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 161 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
140 }; | 162 }; |
141 | 163 |
142 TEST_F(HttpStreamFactoryImplJobControllerTest, | 164 TEST_F(HttpStreamFactoryImplJobControllerTest, |
143 OnStreamFailedWithNoAlternativeJob) { | 165 OnStreamFailedWithNoAlternativeJob) { |
144 ProxyConfig proxy_config; | 166 ProxyConfig proxy_config; |
145 proxy_config.set_auto_detect(true); | 167 proxy_config.set_auto_detect(true); |
146 // Use asynchronous proxy resolver. | 168 // Use asynchronous proxy resolver. |
147 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 169 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
148 new MockAsyncProxyResolverFactory(false); | 170 new MockAsyncProxyResolverFactory(false); |
149 session_deps_.proxy_service.reset(new ProxyService( | 171 session_deps_.proxy_service.reset(new ProxyService( |
150 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 172 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
151 base::WrapUnique(proxy_resolver_factory), nullptr)); | 173 base::WrapUnique(proxy_resolver_factory), nullptr)); |
152 Initialize(); | 174 Initialize(false); |
153 | 175 |
154 HttpRequestInfo request_info; | 176 HttpRequestInfo request_info; |
155 request_info.method = "GET"; | 177 request_info.method = "GET"; |
156 request_info.url = GURL("http://www.google.com"); | 178 request_info.url = GURL("http://www.google.com"); |
157 | 179 |
158 request_.reset( | 180 request_.reset( |
159 job_controller_->Start(request_info, &request_delegate_, nullptr, | 181 job_controller_->Start(request_info, &request_delegate_, nullptr, |
160 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 182 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
161 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 183 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
162 | 184 |
163 EXPECT_TRUE(job_controller_->main_job()); | 185 EXPECT_TRUE(job_controller_->main_job()); |
164 | 186 |
165 // There's no other alternative job. Thus when stream failed, it should | 187 // There's no other alternative job. Thus when stream failed, it should |
166 // notify Request of the stream failure. | 188 // notify Request of the stream failure. |
167 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 189 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
168 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 190 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, |
169 SSLConfig()); | 191 SSLConfig()); |
170 } | 192 } |
171 | 193 |
172 TEST_F(HttpStreamFactoryImplJobControllerTest, | 194 TEST_F(HttpStreamFactoryImplJobControllerTest, |
173 OnStreamReadyWithNoAlternativeJob) { | 195 OnStreamReadyWithNoAlternativeJob) { |
174 ProxyConfig proxy_config; | 196 ProxyConfig proxy_config; |
175 proxy_config.set_auto_detect(true); | 197 proxy_config.set_auto_detect(true); |
176 // Use asynchronous proxy resolver. | 198 // Use asynchronous proxy resolver. |
177 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 199 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
178 new MockAsyncProxyResolverFactory(false); | 200 new MockAsyncProxyResolverFactory(false); |
179 session_deps_.proxy_service.reset(new ProxyService( | 201 session_deps_.proxy_service.reset(new ProxyService( |
180 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 202 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
181 base::WrapUnique(proxy_resolver_factory), nullptr)); | 203 base::WrapUnique(proxy_resolver_factory), nullptr)); |
182 Initialize(); | 204 Initialize(false); |
183 | 205 |
184 HttpRequestInfo request_info; | 206 HttpRequestInfo request_info; |
185 request_info.method = "GET"; | 207 request_info.method = "GET"; |
186 request_info.url = GURL("http://www.google.com"); | 208 request_info.url = GURL("http://www.google.com"); |
187 | 209 |
188 request_.reset( | 210 request_.reset( |
189 job_controller_->Start(request_info, &request_delegate_, nullptr, | 211 job_controller_->Start(request_info, &request_delegate_, nullptr, |
190 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 212 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
191 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 213 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
192 | 214 |
(...skipping 13 matching lines...) Expand all Loading... | |
206 // before any Job is bound to Request. | 228 // before any Job is bound to Request. |
207 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 229 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
208 ProxyConfig proxy_config; | 230 ProxyConfig proxy_config; |
209 proxy_config.set_auto_detect(true); | 231 proxy_config.set_auto_detect(true); |
210 // Use asynchronous proxy resolver. | 232 // Use asynchronous proxy resolver. |
211 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 233 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
212 new MockAsyncProxyResolverFactory(false); | 234 new MockAsyncProxyResolverFactory(false); |
213 session_deps_.proxy_service.reset(new ProxyService( | 235 session_deps_.proxy_service.reset(new ProxyService( |
214 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 236 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
215 base::WrapUnique(proxy_resolver_factory), nullptr)); | 237 base::WrapUnique(proxy_resolver_factory), nullptr)); |
216 Initialize(); | 238 Initialize(false); |
217 | 239 |
218 HttpRequestInfo request_info; | 240 HttpRequestInfo request_info; |
219 request_info.method = "GET"; | 241 request_info.method = "GET"; |
220 request_info.url = GURL("https://www.google.com"); | 242 request_info.url = GURL("https://www.google.com"); |
221 | 243 |
222 url::SchemeHostPort server(request_info.url); | 244 url::SchemeHostPort server(request_info.url); |
223 AlternativeService alternative_service(QUIC, server.host(), 443); | 245 AlternativeService alternative_service(QUIC, server.host(), 443); |
224 SetAlternativeService(request_info, alternative_service); | 246 SetAlternativeService(request_info, alternative_service); |
225 | 247 |
226 request_.reset( | 248 request_.reset( |
(...skipping 12 matching lines...) Expand all Loading... | |
239 | 261 |
240 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 262 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
241 ProxyConfig proxy_config; | 263 ProxyConfig proxy_config; |
242 proxy_config.set_auto_detect(true); | 264 proxy_config.set_auto_detect(true); |
243 // Use asynchronous proxy resolver. | 265 // Use asynchronous proxy resolver. |
244 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 266 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
245 new MockAsyncProxyResolverFactory(false); | 267 new MockAsyncProxyResolverFactory(false); |
246 session_deps_.proxy_service.reset(new ProxyService( | 268 session_deps_.proxy_service.reset(new ProxyService( |
247 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 269 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
248 base::WrapUnique(proxy_resolver_factory), nullptr)); | 270 base::WrapUnique(proxy_resolver_factory), nullptr)); |
249 Initialize(); | 271 Initialize(false); |
250 | 272 |
251 HttpRequestInfo request_info; | 273 HttpRequestInfo request_info; |
252 request_info.method = "GET"; | 274 request_info.method = "GET"; |
253 request_info.url = GURL("https://www.google.com"); | 275 request_info.url = GURL("https://www.google.com"); |
254 | 276 |
255 url::SchemeHostPort server(request_info.url); | 277 url::SchemeHostPort server(request_info.url); |
256 AlternativeService alternative_service(QUIC, server.host(), 443); | 278 AlternativeService alternative_service(QUIC, server.host(), 443); |
257 SetAlternativeService(request_info, alternative_service); | 279 SetAlternativeService(request_info, alternative_service); |
258 | 280 |
259 request_.reset( | 281 request_.reset( |
(...skipping 23 matching lines...) Expand all Loading... | |
283 TEST_F(HttpStreamFactoryImplJobControllerTest, | 305 TEST_F(HttpStreamFactoryImplJobControllerTest, |
284 SecondJobFailsAfterFirstJobSucceeds) { | 306 SecondJobFailsAfterFirstJobSucceeds) { |
285 ProxyConfig proxy_config; | 307 ProxyConfig proxy_config; |
286 proxy_config.set_auto_detect(true); | 308 proxy_config.set_auto_detect(true); |
287 // Use asynchronous proxy resolver. | 309 // Use asynchronous proxy resolver. |
288 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 310 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
289 new MockAsyncProxyResolverFactory(false); | 311 new MockAsyncProxyResolverFactory(false); |
290 session_deps_.proxy_service.reset(new ProxyService( | 312 session_deps_.proxy_service.reset(new ProxyService( |
291 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 313 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
292 base::WrapUnique(proxy_resolver_factory), nullptr)); | 314 base::WrapUnique(proxy_resolver_factory), nullptr)); |
293 Initialize(); | 315 Initialize(false); |
294 | 316 |
295 HttpRequestInfo request_info; | 317 HttpRequestInfo request_info; |
296 request_info.method = "GET"; | 318 request_info.method = "GET"; |
297 request_info.url = GURL("https://www.google.com"); | 319 request_info.url = GURL("https://www.google.com"); |
298 | 320 |
299 url::SchemeHostPort server(request_info.url); | 321 url::SchemeHostPort server(request_info.url); |
300 AlternativeService alternative_service(QUIC, server.host(), 443); | 322 AlternativeService alternative_service(QUIC, server.host(), 443); |
301 SetAlternativeService(request_info, alternative_service); | 323 SetAlternativeService(request_info, alternative_service); |
302 | 324 |
303 request_.reset( | 325 request_.reset( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 TEST_F(HttpStreamFactoryImplJobControllerTest, | 357 TEST_F(HttpStreamFactoryImplJobControllerTest, |
336 SecondJobSucceedsAfterFirstJobFailed) { | 358 SecondJobSucceedsAfterFirstJobFailed) { |
337 ProxyConfig proxy_config; | 359 ProxyConfig proxy_config; |
338 proxy_config.set_auto_detect(true); | 360 proxy_config.set_auto_detect(true); |
339 // Use asynchronous proxy resolver. | 361 // Use asynchronous proxy resolver. |
340 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 362 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
341 new MockAsyncProxyResolverFactory(false); | 363 new MockAsyncProxyResolverFactory(false); |
342 session_deps_.proxy_service.reset(new ProxyService( | 364 session_deps_.proxy_service.reset(new ProxyService( |
343 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 365 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
344 base::WrapUnique(proxy_resolver_factory), nullptr)); | 366 base::WrapUnique(proxy_resolver_factory), nullptr)); |
345 Initialize(); | 367 Initialize(false); |
346 | 368 |
347 HttpRequestInfo request_info; | 369 HttpRequestInfo request_info; |
348 request_info.method = "GET"; | 370 request_info.method = "GET"; |
349 request_info.url = GURL("https://www.google.com"); | 371 request_info.url = GURL("https://www.google.com"); |
350 | 372 |
351 url::SchemeHostPort server(request_info.url); | 373 url::SchemeHostPort server(request_info.url); |
352 AlternativeService alternative_service(QUIC, server.host(), 443); | 374 AlternativeService alternative_service(QUIC, server.host(), 443); |
353 SetAlternativeService(request_info, alternative_service); | 375 SetAlternativeService(request_info, alternative_service); |
354 | 376 |
355 request_.reset( | 377 request_.reset( |
(...skipping 27 matching lines...) Expand all Loading... | |
383 // Get load state after main job fails and before alternative job succeeds. | 405 // Get load state after main job fails and before alternative job succeeds. |
384 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 406 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
385 ProxyConfig proxy_config; | 407 ProxyConfig proxy_config; |
386 proxy_config.set_auto_detect(true); | 408 proxy_config.set_auto_detect(true); |
387 // Use asynchronous proxy resolver. | 409 // Use asynchronous proxy resolver. |
388 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 410 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
389 new MockAsyncProxyResolverFactory(false); | 411 new MockAsyncProxyResolverFactory(false); |
390 session_deps_.proxy_service.reset(new ProxyService( | 412 session_deps_.proxy_service.reset(new ProxyService( |
391 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 413 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
392 base::WrapUnique(proxy_resolver_factory), nullptr)); | 414 base::WrapUnique(proxy_resolver_factory), nullptr)); |
393 Initialize(); | 415 Initialize(false); |
394 | 416 |
395 HttpRequestInfo request_info; | 417 HttpRequestInfo request_info; |
396 request_info.method = "GET"; | 418 request_info.method = "GET"; |
397 request_info.url = GURL("https://www.google.com"); | 419 request_info.url = GURL("https://www.google.com"); |
398 | 420 |
399 url::SchemeHostPort server(request_info.url); | 421 url::SchemeHostPort server(request_info.url); |
400 AlternativeService alternative_service(QUIC, server.host(), 443); | 422 AlternativeService alternative_service(QUIC, server.host(), 443); |
401 SetAlternativeService(request_info, alternative_service); | 423 SetAlternativeService(request_info, alternative_service); |
402 | 424 |
403 request_.reset( | 425 request_.reset( |
(...skipping 30 matching lines...) Expand all Loading... | |
434 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 456 // Use failing ProxyResolverFactory which is unable to create ProxyResolver |
435 // to stall the alternative job and report to controller to maybe resume the | 457 // to stall the alternative job and report to controller to maybe resume the |
436 // main job. | 458 // main job. |
437 ProxyConfig proxy_config; | 459 ProxyConfig proxy_config; |
438 proxy_config.set_auto_detect(true); | 460 proxy_config.set_auto_detect(true); |
439 proxy_config.set_pac_mandatory(true); | 461 proxy_config.set_pac_mandatory(true); |
440 session_deps_.proxy_service.reset(new ProxyService( | 462 session_deps_.proxy_service.reset(new ProxyService( |
441 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 463 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
442 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | 464 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
443 | 465 |
444 Initialize(); | 466 Initialize(false); |
445 | 467 |
446 HttpRequestInfo request_info; | 468 HttpRequestInfo request_info; |
447 request_info.method = "GET"; | 469 request_info.method = "GET"; |
448 request_info.url = GURL("https://www.google.com"); | 470 request_info.url = GURL("https://www.google.com"); |
449 | 471 |
450 url::SchemeHostPort server(request_info.url); | 472 url::SchemeHostPort server(request_info.url); |
451 AlternativeService alternative_service(QUIC, server.host(), 443); | 473 AlternativeService alternative_service(QUIC, server.host(), 443); |
452 SetAlternativeService(request_info, alternative_service); | 474 SetAlternativeService(request_info, alternative_service); |
453 | 475 |
454 request_.reset( | 476 request_.reset( |
455 job_controller_->Start(request_info, &request_delegate_, nullptr, | 477 job_controller_->Start(request_info, &request_delegate_, nullptr, |
456 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | 478 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, |
457 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | 479 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); |
458 EXPECT_TRUE(job_controller_->main_job()); | 480 EXPECT_TRUE(job_controller_->main_job()); |
459 EXPECT_TRUE(job_controller_->alternative_job()); | 481 EXPECT_TRUE(job_controller_->alternative_job()); |
460 | 482 |
461 // Wait until OnStreamFailedCallback is executed on the alternative job. | 483 // Wait until OnStreamFailedCallback is executed on the alternative job. |
462 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 484 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
463 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | 485 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); |
464 base::RunLoop().RunUntilIdle(); | 486 base::RunLoop().RunUntilIdle(); |
465 } | 487 } |
466 | 488 |
467 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 489 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
468 // Using a restricted port 101 for QUIC should fail and the alternative job | 490 // Using a restricted port 101 for QUIC should fail and the alternative job |
469 // should post OnStreamFailedCall on the controller to resume the main job. | 491 // should post OnStreamFailedCall on the controller to resume the main job. |
470 Initialize(); | 492 Initialize(false); |
471 | 493 |
472 HttpRequestInfo request_info; | 494 HttpRequestInfo request_info; |
473 request_info.method = "GET"; | 495 request_info.method = "GET"; |
474 request_info.url = GURL("https://www.google.com"); | 496 request_info.url = GURL("https://www.google.com"); |
475 | 497 |
476 url::SchemeHostPort server(request_info.url); | 498 url::SchemeHostPort server(request_info.url); |
477 AlternativeService alternative_service(QUIC, server.host(), 101); | 499 AlternativeService alternative_service(QUIC, server.host(), 101); |
478 SetAlternativeService(request_info, alternative_service); | 500 SetAlternativeService(request_info, alternative_service); |
479 | 501 |
480 request_.reset( | 502 request_.reset( |
(...skipping 21 matching lines...) Expand all Loading... | |
502 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 524 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
503 new MockAsyncProxyResolverFactory(false); | 525 new MockAsyncProxyResolverFactory(false); |
504 session_deps_.proxy_service.reset(new ProxyService( | 526 session_deps_.proxy_service.reset(new ProxyService( |
505 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 527 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
506 base::WrapUnique(proxy_resolver_factory), nullptr)); | 528 base::WrapUnique(proxy_resolver_factory), nullptr)); |
507 | 529 |
508 HangingResolver* host_resolver = new HangingResolver(); | 530 HangingResolver* host_resolver = new HangingResolver(); |
509 session_deps_.host_resolver.reset(host_resolver); | 531 session_deps_.host_resolver.reset(host_resolver); |
510 session_deps_.host_resolver->set_synchronous_mode(false); | 532 session_deps_.host_resolver->set_synchronous_mode(false); |
511 | 533 |
512 Initialize(); | 534 Initialize(false); |
513 | 535 |
514 HttpRequestInfo request_info; | 536 HttpRequestInfo request_info; |
515 request_info.method = "GET"; | 537 request_info.method = "GET"; |
516 request_info.url = GURL("https://www.google.com"); | 538 request_info.url = GURL("https://www.google.com"); |
517 | 539 |
518 // Set a SPDY alternative service for the server. | 540 // Set a SPDY alternative service for the server. |
519 url::SchemeHostPort server(request_info.url); | 541 url::SchemeHostPort server(request_info.url); |
520 AlternativeService alternative_service(QUIC, server.host(), 443); | 542 AlternativeService alternative_service(QUIC, server.host(), 443); |
521 SetAlternativeService(request_info, alternative_service); | 543 SetAlternativeService(request_info, alternative_service); |
522 // Hack to use different URL for the main job to help differentiate the proxy | 544 // Hack to use different URL for the main job to help differentiate the proxy |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
566 | 588 |
567 ProxyConfig proxy_config; | 589 ProxyConfig proxy_config; |
568 proxy_config.set_auto_detect(true); | 590 proxy_config.set_auto_detect(true); |
569 // Use asynchronous proxy resolver. | 591 // Use asynchronous proxy resolver. |
570 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 592 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
571 new MockAsyncProxyResolverFactory(false); | 593 new MockAsyncProxyResolverFactory(false); |
572 session_deps_.proxy_service.reset(new ProxyService( | 594 session_deps_.proxy_service.reset(new ProxyService( |
573 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 595 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
574 base::WrapUnique(proxy_resolver_factory), nullptr)); | 596 base::WrapUnique(proxy_resolver_factory), nullptr)); |
575 | 597 |
576 Initialize(); | 598 Initialize(false); |
577 | 599 |
578 HttpRequestInfo request_info; | 600 HttpRequestInfo request_info; |
579 request_info.method = "GET"; | 601 request_info.method = "GET"; |
580 request_info.url = GURL("https://www.google.com"); | 602 request_info.url = GURL("https://www.google.com"); |
581 | 603 |
582 url::SchemeHostPort server(request_info.url); | 604 url::SchemeHostPort server(request_info.url); |
583 AlternativeService alternative_service(QUIC, server.host(), 443); | 605 AlternativeService alternative_service(QUIC, server.host(), 443); |
584 SetAlternativeService(request_info, alternative_service); | 606 SetAlternativeService(request_info, alternative_service); |
585 // Hack to use different URL for the main job to help differentiate the proxy | 607 // Hack to use different URL for the main job to help differentiate the proxy |
586 // requests. | 608 // requests. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 641 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
620 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | 642 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); |
621 | 643 |
622 base::RunLoop().RunUntilIdle(); | 644 base::RunLoop().RunUntilIdle(); |
623 } | 645 } |
624 | 646 |
625 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 647 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
626 HangingResolver* resolver = new HangingResolver(); | 648 HangingResolver* resolver = new HangingResolver(); |
627 session_deps_.host_resolver.reset(resolver); | 649 session_deps_.host_resolver.reset(resolver); |
628 | 650 |
629 Initialize(); | 651 Initialize(false); |
630 | 652 |
631 // Enable delayed TCP and set time delay for waiting job. | 653 // Enable delayed TCP and set time delay for waiting job. |
632 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 654 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
633 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | 655 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); |
634 quic_stream_factory->set_require_confirmation(false); | 656 quic_stream_factory->set_require_confirmation(false); |
635 ServerNetworkStats stats1; | 657 ServerNetworkStats stats1; |
636 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 658 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
637 session_->http_server_properties()->SetServerNetworkStats( | 659 session_->http_server_properties()->SetServerNetworkStats( |
638 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 660 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
639 | 661 |
(...skipping 16 matching lines...) Expand all Loading... | |
656 // The alternative job stalls as host resolution hangs when creating the QUIC | 678 // The alternative job stalls as host resolution hangs when creating the QUIC |
657 // request and controller should resume the main job after delay. | 679 // request and controller should resume the main job after delay. |
658 // Verify the waiting time for delayed main job. | 680 // Verify the waiting time for delayed main job. |
659 EXPECT_CALL(*job_factory_.main_job(), Resume()) | 681 EXPECT_CALL(*job_factory_.main_job(), Resume()) |
660 .WillOnce(Invoke(testing::CreateFunctor( | 682 .WillOnce(Invoke(testing::CreateFunctor( |
661 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | 683 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, |
662 base::TimeDelta::FromMicroseconds(15)))); | 684 base::TimeDelta::FromMicroseconds(15)))); |
663 | 685 |
664 base::RunLoop().RunUntilIdle(); | 686 base::RunLoop().RunUntilIdle(); |
665 } | 687 } |
688 | |
689 // Verifies that the main job is resumed properly after a delay when the | |
690 // alternative proxy server job hangs. | |
691 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { | |
Zhongyi Shi
2016/08/20 06:15:40
Now that you are here, shall we add a test case co
tbansal1
2016/08/22 15:42:33
Done.
| |
692 // Using hanging resolver will cause the alternative job to hang indefinitely. | |
693 HangingResolver* resolver = new HangingResolver(); | |
694 session_deps_.host_resolver.reset(resolver); | |
695 | |
696 Initialize(true); | |
697 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | |
698 | |
699 // Enable delayed TCP and set time delay for waiting job. | |
700 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
701 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | |
702 quic_stream_factory->set_require_confirmation(false); | |
703 ServerNetworkStats stats1; | |
704 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | |
705 session_->http_server_properties()->SetServerNetworkStats( | |
706 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | |
707 | |
708 HttpRequestInfo request_info; | |
709 request_info.method = "GET"; | |
710 request_info.url = GURL("http://mail.example.org/"); | |
711 | |
712 request_.reset( | |
713 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
714 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
715 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
716 EXPECT_TRUE(job_controller_->main_job()); | |
717 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
718 EXPECT_TRUE(job_controller_->alternative_job()); | |
719 | |
720 // The alternative proxy server job stalls when connecting to the alternative | |
721 // proxy server, and controller should resume the main job after delay. | |
722 // Verify the waiting time for delayed main job. | |
723 EXPECT_CALL(*job_factory_.main_job(), Resume()) | |
724 .WillOnce(Invoke(testing::CreateFunctor( | |
725 &JobControllerPeer::VerifyWaitingTimeForMainJob, job_controller_, | |
726 base::TimeDelta::FromMicroseconds(15)))); | |
727 | |
728 base::RunLoop().RunUntilIdle(); | |
729 // Since the main job did not complete successfully, the alternative proxy | |
730 // server should not be marked as bad. | |
731 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | |
732 } | |
733 | |
734 // Verifies that the alternative proxy server job fails immediately, and the | |
735 // main job is not blocked. | |
Zhongyi Shi
2016/08/20 06:15:40
nit: remove redundant space in comments.
tbansal1
2016/08/22 15:42:33
Done.
| |
736 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { | |
737 // Using failing resolver will cause the alternative job to fail. | |
738 FailingHostResolver* resolver = new FailingHostResolver(); | |
739 session_deps_.host_resolver.reset(resolver); | |
740 | |
741 Initialize(true); | |
742 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | |
743 | |
744 // Enable delayed TCP and set time delay for waiting job. | |
745 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | |
746 test::QuicStreamFactoryPeer::SetDelayTcpRace(quic_stream_factory, true); | |
747 quic_stream_factory->set_require_confirmation(false); | |
748 ServerNetworkStats stats1; | |
749 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); | |
750 session_->http_server_properties()->SetServerNetworkStats( | |
751 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | |
752 | |
753 HttpRequestInfo request_info; | |
754 request_info.method = "GET"; | |
755 request_info.url = GURL("http://mail.example.org/"); | |
756 | |
757 request_.reset( | |
758 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
759 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, | |
760 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
761 EXPECT_TRUE(job_controller_->main_job()); | |
762 EXPECT_TRUE(job_controller_->alternative_job()); | |
763 | |
764 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | |
765 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); | |
766 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); | |
767 | |
768 // Since the alternative proxy server job fails to connect, the main job | |
769 // should not be blocked. | |
770 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | |
771 | |
772 base::RunLoop().RunUntilIdle(); | |
773 EXPECT_FALSE(job_controller_->alternative_job()); | |
774 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | |
775 // Since the main job did not complete successfully, the alternative proxy | |
776 // server should not be marked as bad. | |
777 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | |
778 } | |
779 | |
666 } // namespace net | 780 } // namespace net |
OLD | NEW |