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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
13 #include "base/test/scoped_feature_list.h" | 13 #include "base/test/scoped_feature_list.h" |
14 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | 14 #include "base/test/scoped_mock_time_message_loop_task_runner.h" |
15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
16 #include "net/base/test_proxy_delegate.h" | 16 #include "net/base/test_proxy_delegate.h" |
17 #include "net/dns/mock_host_resolver.h" | 17 #include "net/dns/mock_host_resolver.h" |
18 #include "net/http/http_basic_stream.h" | 18 #include "net/http/http_basic_stream.h" |
19 #include "net/http/http_stream_factory_impl_request.h" | 19 #include "net/http/http_stream_factory_impl_request.h" |
20 #include "net/http/http_stream_factory_test_util.h" | 20 #include "net/http/http_stream_factory_test_util.h" |
21 #include "net/log/net_log_with_source.h" | 21 #include "net/log/net_log_with_source.h" |
22 #include "net/proxy/mock_proxy_resolver.h" | 22 #include "net/proxy/mock_proxy_resolver.h" |
23 #include "net/proxy/proxy_config_service_fixed.h" | 23 #include "net/proxy/proxy_config_service_fixed.h" |
24 #include "net/proxy/proxy_info.h" | 24 #include "net/proxy/proxy_info.h" |
25 #include "net/proxy/proxy_service.h" | 25 #include "net/proxy/proxy_service.h" |
26 #include "net/quic/chromium/quic_stream_factory.h" | |
26 #include "net/quic/chromium/quic_stream_factory_peer.h" | 27 #include "net/quic/chromium/quic_stream_factory_peer.h" |
27 #include "net/socket/socket_test_util.h" | 28 #include "net/socket/socket_test_util.h" |
28 #include "net/spdy/chromium/spdy_test_util_common.h" | 29 #include "net/spdy/chromium/spdy_test_util_common.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gmock_mutant.h" | 31 #include "testing/gmock_mutant.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 using ::testing::_; | 34 using ::testing::_; |
34 using ::testing::Invoke; | 35 using ::testing::Invoke; |
35 | 36 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 int Resolve(const RequestInfo& info, | 83 int Resolve(const RequestInfo& info, |
83 RequestPriority priority, | 84 RequestPriority priority, |
84 AddressList* addresses, | 85 AddressList* addresses, |
85 const CompletionCallback& callback, | 86 const CompletionCallback& callback, |
86 std::unique_ptr<Request>* out_req, | 87 std::unique_ptr<Request>* out_req, |
87 const NetLogWithSource& net_log) override { | 88 const NetLogWithSource& net_log) override { |
88 return ERR_IO_PENDING; | 89 return ERR_IO_PENDING; |
89 } | 90 } |
90 }; | 91 }; |
91 | 92 |
93 // A mock QuicStreamRequest that always succeeds. | |
Bence
2017/04/26 13:55:39
Always returns |net_error|? Or do we really need
xunjieli
2017/04/27 18:15:54
Acknowledged. No longer relevant.
| |
94 class MockQuicStreamRequest : public QuicStreamRequest { | |
95 public: | |
96 MockQuicStreamRequest(int net_error) | |
97 : QuicStreamRequest(nullptr, nullptr), net_error_(net_error) {} | |
98 ~MockQuicStreamRequest() {} | |
99 | |
100 int Request(const HostPortPair& destination, | |
101 PrivacyMode privacy_mode, | |
102 int cert_verify_flags, | |
103 const GURL& url, | |
104 QuicStringPiece method, | |
105 const NetLogWithSource& net_log, | |
106 const CompletionCallback& callback) override { | |
107 return net_error_; | |
108 } | |
109 | |
110 std::unique_ptr<HttpStream> CreateStream() override { | |
111 if (net_error_ != OK) { | |
112 NOTREACHED(); | |
113 return nullptr; | |
114 } | |
115 return base::MakeUnique<HttpBasicStream>( | |
116 base::MakeUnique<ClientSocketHandle>(), false, false); | |
117 } | |
118 | |
119 std::unique_ptr<BidirectionalStreamImpl> CreateBidirectionalStreamImpl() | |
120 override { | |
121 NOTREACHED(); | |
122 return nullptr; | |
123 } | |
124 | |
125 private: | |
126 int net_error_; | |
127 }; | |
128 | |
129 // A mock QuicStreamRequest that always succeeds. | |
Bence
2017/04/26 13:55:39
Please update comment.
xunjieli
2017/04/27 18:15:54
Acknowledged. No longer relevant.
| |
130 class MockQuicStreamRequestFactory : public QuicStreamRequestFactory { | |
131 public: | |
132 MockQuicStreamRequestFactory(int net_error) | |
133 : QuicStreamRequestFactory(), net_error_(net_error) {} | |
134 ~MockQuicStreamRequestFactory() {} | |
135 | |
136 std::unique_ptr<QuicStreamRequest> CreateRequest( | |
137 QuicStreamFactory* factory, | |
138 HttpServerProperties* http_server_properties) override { | |
139 return base::MakeUnique<MockQuicStreamRequest>(net_error_); | |
140 } | |
141 | |
142 private: | |
143 int net_error_; | |
144 }; | |
145 | |
92 // A mock HttpServerProperties that always returns false for IsInitialized(). | 146 // A mock HttpServerProperties that always returns false for IsInitialized(). |
93 class MockHttpServerProperties : public HttpServerPropertiesImpl { | 147 class MockHttpServerProperties : public HttpServerPropertiesImpl { |
94 public: | 148 public: |
95 MockHttpServerProperties() {} | 149 MockHttpServerProperties() {} |
96 ~MockHttpServerProperties() override {} | 150 ~MockHttpServerProperties() override {} |
97 bool IsInitialized() const override { return false; } | 151 bool IsInitialized() const override { return false; } |
98 }; | 152 }; |
99 | 153 |
100 } // anonymous namespace | 154 } // anonymous namespace |
101 | 155 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 ASSERT_FALSE(test_proxy_delegate_); | 213 ASSERT_FALSE(test_proxy_delegate_); |
160 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( | 214 std::unique_ptr<TestProxyDelegate> test_proxy_delegate( |
161 new TestProxyDelegate()); | 215 new TestProxyDelegate()); |
162 test_proxy_delegate_ = test_proxy_delegate.get(); | 216 test_proxy_delegate_ = test_proxy_delegate.get(); |
163 | 217 |
164 test_proxy_delegate->set_alternative_proxy_server( | 218 test_proxy_delegate->set_alternative_proxy_server( |
165 ProxyServer::FromPacString("QUIC myproxy.org:443")); | 219 ProxyServer::FromPacString("QUIC myproxy.org:443")); |
166 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); | 220 EXPECT_TRUE(test_proxy_delegate->alternative_proxy_server().is_quic()); |
167 session_deps_.proxy_delegate = std::move(test_proxy_delegate); | 221 session_deps_.proxy_delegate = std::move(test_proxy_delegate); |
168 | 222 |
223 if (tcp_data_) | |
224 session_deps_.socket_factory->AddSocketDataProvider(tcp_data_.get()); | |
225 | |
169 if (use_alternative_proxy_) { | 226 if (use_alternative_proxy_) { |
170 std::unique_ptr<ProxyService> proxy_service = | 227 std::unique_ptr<ProxyService> proxy_service = |
171 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | 228 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); |
172 session_deps_.proxy_service = std::move(proxy_service); | 229 session_deps_.proxy_service = std::move(proxy_service); |
173 } | 230 } |
174 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 231 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
175 factory_ = | 232 factory_ = |
176 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 233 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
177 job_controller_ = new HttpStreamFactoryImpl::JobController( | 234 job_controller_ = new HttpStreamFactoryImpl::JobController( |
178 factory_, &request_delegate_, session_.get(), &job_factory_, | 235 factory_, &request_delegate_, session_.get(), &job_factory_, |
179 request_info, is_preconnect_, enable_ip_based_pooling_, | 236 request_info, is_preconnect_, enable_ip_based_pooling_, |
180 enable_alternative_services_); | 237 enable_alternative_services_, SSLConfig(), SSLConfig()); |
181 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 238 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
182 } | 239 } |
183 | 240 |
184 TestProxyDelegate* test_proxy_delegate() const { | 241 TestProxyDelegate* test_proxy_delegate() const { |
185 return test_proxy_delegate_; | 242 return test_proxy_delegate_; |
186 } | 243 } |
187 | 244 |
188 ~HttpStreamFactoryImplJobControllerTest() override {} | 245 ~HttpStreamFactoryImplJobControllerTest() override { |
246 if (tcp_data_) { | |
247 EXPECT_TRUE(tcp_data_->AllReadDataConsumed()); | |
248 EXPECT_TRUE(tcp_data_->AllWriteDataConsumed()); | |
249 } | |
250 } | |
189 | 251 |
190 void SetAlternativeService(const HttpRequestInfo& request_info, | 252 void SetAlternativeService(const HttpRequestInfo& request_info, |
191 AlternativeService alternative_service) { | 253 AlternativeService alternative_service) { |
192 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 254 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
193 url::SchemeHostPort server(request_info.url); | 255 url::SchemeHostPort server(request_info.url); |
194 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 256 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
195 session_->http_server_properties()->SetAlternativeService( | 257 session_->http_server_properties()->SetAlternativeService( |
196 server, alternative_service, expiration); | 258 server, alternative_service, expiration); |
197 } | 259 } |
198 | 260 |
199 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, | 261 void VerifyBrokenAlternateProtocolMapping(const HttpRequestInfo& request_info, |
200 bool should_mark_broken) { | 262 bool should_mark_broken) { |
201 const url::SchemeHostPort server(request_info.url); | 263 const url::SchemeHostPort server(request_info.url); |
202 const AlternativeServiceVector alternative_service_vector = | 264 const AlternativeServiceVector alternative_service_vector = |
203 session_->http_server_properties()->GetAlternativeServices(server); | 265 session_->http_server_properties()->GetAlternativeServices(server); |
204 EXPECT_EQ(1u, alternative_service_vector.size()); | 266 EXPECT_EQ(1u, alternative_service_vector.size()); |
205 EXPECT_EQ(should_mark_broken, | 267 EXPECT_EQ(should_mark_broken, |
206 session_->http_server_properties()->IsAlternativeServiceBroken( | 268 session_->http_server_properties()->IsAlternativeServiceBroken( |
207 alternative_service_vector[0])); | 269 alternative_service_vector[0])); |
208 } | 270 } |
209 | 271 |
210 TestJobFactory job_factory_; | 272 TestJobFactory job_factory_; |
211 MockHttpStreamRequestDelegate request_delegate_; | 273 MockHttpStreamRequestDelegate request_delegate_; |
212 SpdySessionDependencies session_deps_; | 274 SpdySessionDependencies session_deps_; |
213 std::unique_ptr<HttpNetworkSession> session_; | 275 std::unique_ptr<HttpNetworkSession> session_; |
214 HttpStreamFactoryImpl* factory_; | 276 HttpStreamFactoryImpl* factory_; |
215 HttpStreamFactoryImpl::JobController* job_controller_; | 277 HttpStreamFactoryImpl::JobController* job_controller_; |
216 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; | 278 std::unique_ptr<HttpStreamFactoryImpl::Request> request_; |
217 | 279 |
280 std::unique_ptr<SequencedSocketData> tcp_data_; | |
281 | |
218 private: | 282 private: |
219 bool use_alternative_proxy_; | 283 bool use_alternative_proxy_; |
220 bool is_preconnect_; | 284 bool is_preconnect_; |
221 bool enable_ip_based_pooling_; | 285 bool enable_ip_based_pooling_; |
222 bool enable_alternative_services_; | 286 bool enable_alternative_services_; |
223 | 287 |
224 // Not owned by |this|. | 288 // Not owned by |this|. |
225 TestProxyDelegate* test_proxy_delegate_; | 289 TestProxyDelegate* test_proxy_delegate_; |
226 | 290 |
227 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); | 291 DISALLOW_COPY_AND_ASSIGN(HttpStreamFactoryImplJobControllerTest); |
228 }; | 292 }; |
229 | 293 |
230 TEST_F(HttpStreamFactoryImplJobControllerTest, | 294 TEST_F(HttpStreamFactoryImplJobControllerTest, |
231 OnStreamFailedWithNoAlternativeJob) { | 295 OnStreamFailedWithNoAlternativeJob) { |
232 ProxyConfig proxy_config; | 296 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
233 proxy_config.set_auto_detect(true); | 297 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
234 // Use asynchronous proxy resolver. | 298 |
299 ProxyConfig proxy_config(ProxyConfig::CreateDirect()); | |
235 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 300 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
236 new MockAsyncProxyResolverFactory(false); | 301 new MockAsyncProxyResolverFactory(false); |
237 session_deps_.proxy_service.reset( | 302 session_deps_.proxy_service.reset( |
238 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 303 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
239 base::WrapUnique(proxy_resolver_factory), nullptr)); | 304 base::WrapUnique(proxy_resolver_factory), nullptr)); |
240 | 305 |
241 HttpRequestInfo request_info; | 306 HttpRequestInfo request_info; |
242 request_info.method = "GET"; | 307 request_info.method = "GET"; |
243 request_info.url = GURL("http://www.google.com"); | 308 request_info.url = GURL("http://www.google.com"); |
244 | 309 |
245 Initialize(request_info); | 310 Initialize(request_info); |
246 | 311 |
247 request_.reset( | 312 request_.reset( |
248 job_controller_->Start(request_info, &request_delegate_, nullptr, | 313 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
249 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 314 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
250 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
251 | 315 |
252 EXPECT_TRUE(job_controller_->main_job()); | 316 EXPECT_TRUE(job_controller_->main_job()); |
253 | 317 |
254 // There's no other alternative job. Thus when stream failed, it should | 318 // There's no other alternative job. Thus when stream failed, it should |
255 // notify Request of the stream failure. | 319 // notify Request of the stream failure. |
256 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); | 320 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1); |
257 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 321 base::RunLoop().RunUntilIdle(); |
258 SSLConfig()); | |
259 } | 322 } |
260 | 323 |
261 TEST_F(HttpStreamFactoryImplJobControllerTest, | 324 TEST_F(HttpStreamFactoryImplJobControllerTest, |
262 OnStreamReadyWithNoAlternativeJob) { | 325 OnStreamReadyWithNoAlternativeJob) { |
263 ProxyConfig proxy_config; | 326 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
264 proxy_config.set_auto_detect(true); | 327 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); |
265 // Use asynchronous proxy resolver. | 328 |
329 ProxyConfig proxy_config(ProxyConfig::CreateDirect()); | |
266 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 330 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
267 new MockAsyncProxyResolverFactory(false); | 331 new MockAsyncProxyResolverFactory(false); |
268 session_deps_.proxy_service.reset( | 332 session_deps_.proxy_service.reset( |
269 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 333 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
270 base::WrapUnique(proxy_resolver_factory), nullptr)); | 334 base::WrapUnique(proxy_resolver_factory), nullptr)); |
271 HttpRequestInfo request_info; | 335 HttpRequestInfo request_info; |
272 request_info.method = "GET"; | 336 request_info.method = "GET"; |
273 request_info.url = GURL("http://www.google.com"); | 337 request_info.url = GURL("http://www.google.com"); |
274 | 338 |
275 Initialize(request_info); | 339 Initialize(request_info); |
276 | 340 |
277 request_.reset( | 341 request_.reset( |
278 job_controller_->Start(request_info, &request_delegate_, nullptr, | 342 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
279 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 343 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
280 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
281 | 344 |
282 // There's no other alternative job. Thus when a stream is ready, it should | 345 // There's no other alternative job. Thus when a stream is ready, it should |
283 // notify Request. | 346 // notify Request. |
284 HttpStream* http_stream = | 347 EXPECT_TRUE(job_controller_->main_job()); |
285 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
286 job_factory_.main_job()->SetStream(http_stream); | |
287 | 348 |
288 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 349 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
289 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 350 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
290 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | 351 base::RunLoop().RunUntilIdle(); |
291 } | 352 } |
292 | 353 |
293 // Test we cancel Jobs correctly when the Request is explicitly canceled | 354 // Test we cancel Jobs correctly when the Request is explicitly canceled |
294 // before any Job is bound to Request. | 355 // before any Job is bound to Request. |
295 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { | 356 TEST_F(HttpStreamFactoryImplJobControllerTest, CancelJobsBeforeBinding) { |
357 // One TCP connect. | |
358 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
359 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); | |
296 ProxyConfig proxy_config; | 360 ProxyConfig proxy_config; |
297 proxy_config.set_auto_detect(true); | |
298 // Use asynchronous proxy resolver. | |
299 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 361 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
300 new MockAsyncProxyResolverFactory(false); | 362 new MockAsyncProxyResolverFactory(false); |
301 session_deps_.proxy_service.reset(new ProxyService( | 363 session_deps_.proxy_service.reset(new ProxyService( |
302 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 364 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
303 base::WrapUnique(proxy_resolver_factory), nullptr)); | 365 base::WrapUnique(proxy_resolver_factory), nullptr)); |
304 | 366 |
305 HttpRequestInfo request_info; | 367 HttpRequestInfo request_info; |
306 request_info.method = "GET"; | 368 request_info.method = "GET"; |
307 request_info.url = GURL("https://www.google.com"); | 369 request_info.url = GURL("https://www.google.com"); |
308 | 370 |
309 Initialize(request_info); | 371 Initialize(request_info); |
310 url::SchemeHostPort server(request_info.url); | 372 url::SchemeHostPort server(request_info.url); |
311 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 373 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
312 SetAlternativeService(request_info, alternative_service); | 374 SetAlternativeService(request_info, alternative_service); |
313 | 375 |
376 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
377 session_->quic_stream_factory(), | |
378 base::MakeUnique<MockQuicStreamRequestFactory>(OK)); | |
379 | |
314 request_.reset( | 380 request_.reset( |
315 job_controller_->Start(request_info, &request_delegate_, nullptr, | 381 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
316 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 382 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
317 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
318 EXPECT_TRUE(job_controller_->main_job()); | 383 EXPECT_TRUE(job_controller_->main_job()); |
319 EXPECT_TRUE(job_controller_->alternative_job()); | 384 EXPECT_TRUE(job_controller_->alternative_job()); |
320 | 385 |
321 // Reset the Request will cancel all the Jobs since there's no Job determined | 386 // Reset the Request will cancel all the Jobs since there's no Job determined |
322 // to serve Request yet and JobController will notify the factory to delete | 387 // to serve Request yet and JobController will notify the factory to delete |
323 // itself upon completion. | 388 // itself upon completion. |
324 request_.reset(); | 389 request_.reset(); |
325 VerifyBrokenAlternateProtocolMapping(request_info, false); | 390 VerifyBrokenAlternateProtocolMapping(request_info, false); |
326 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 391 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
327 } | 392 } |
328 | 393 |
329 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 394 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
395 // One TCP connect and one UDP connect. | |
396 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
397 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); | |
398 | |
330 ProxyConfig proxy_config; | 399 ProxyConfig proxy_config; |
331 proxy_config.set_auto_detect(true); | |
332 // Use asynchronous proxy resolver. | |
333 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 400 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
334 new MockAsyncProxyResolverFactory(false); | 401 new MockAsyncProxyResolverFactory(false); |
335 session_deps_.proxy_service.reset( | 402 session_deps_.proxy_service.reset( |
336 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 403 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
337 base::WrapUnique(proxy_resolver_factory), nullptr)); | 404 base::WrapUnique(proxy_resolver_factory), nullptr)); |
338 | 405 |
339 HttpRequestInfo request_info; | 406 HttpRequestInfo request_info; |
340 request_info.method = "GET"; | 407 request_info.method = "GET"; |
341 request_info.url = GURL("https://www.google.com"); | 408 request_info.url = GURL("https://www.google.com"); |
342 | 409 |
343 Initialize(request_info); | 410 Initialize(request_info); |
344 url::SchemeHostPort server(request_info.url); | 411 url::SchemeHostPort server(request_info.url); |
345 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 412 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
346 SetAlternativeService(request_info, alternative_service); | 413 SetAlternativeService(request_info, alternative_service); |
347 | 414 |
415 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
416 session_->quic_stream_factory(), | |
417 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_FAILED)); | |
418 | |
348 request_.reset( | 419 request_.reset( |
349 job_controller_->Start(request_info, &request_delegate_, nullptr, | 420 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
350 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 421 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
351 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
352 EXPECT_TRUE(job_controller_->main_job()); | 422 EXPECT_TRUE(job_controller_->main_job()); |
353 EXPECT_TRUE(job_controller_->alternative_job()); | 423 EXPECT_TRUE(job_controller_->alternative_job()); |
354 | 424 |
355 // We have the main job with unknown status when the alternative job is failed | |
356 // thus should not notify Request of the alternative job's failure. But should | |
357 // notify the main job to mark the alternative job failed. | |
358 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
359 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | |
360 SSLConfig()); | |
361 EXPECT_TRUE(!job_controller_->alternative_job()); | |
362 EXPECT_TRUE(job_controller_->main_job()); | |
363 | |
364 // The failure of second Job should be reported to Request as there's no more | 425 // The failure of second Job should be reported to Request as there's no more |
365 // pending Job to serve the Request. | 426 // pending Job to serve the Request. |
366 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 427 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); |
367 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 428 base::RunLoop().RunUntilIdle(); |
368 SSLConfig()); | |
369 VerifyBrokenAlternateProtocolMapping(request_info, false); | 429 VerifyBrokenAlternateProtocolMapping(request_info, false); |
430 request_.reset(); | |
431 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | |
370 } | 432 } |
371 | 433 |
372 TEST_F(HttpStreamFactoryImplJobControllerTest, | 434 TEST_F(HttpStreamFactoryImplJobControllerTest, |
373 AltJobFailsAfterMainJobSucceeds) { | 435 AltJobFailsAfterMainJobSucceeds) { |
436 // One TCP connect. | |
437 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
438 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | |
439 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
440 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
441 | |
374 ProxyConfig proxy_config; | 442 ProxyConfig proxy_config; |
375 proxy_config.set_auto_detect(true); | |
376 // Use asynchronous proxy resolver. | |
377 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 443 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
378 new MockAsyncProxyResolverFactory(false); | 444 new MockAsyncProxyResolverFactory(false); |
379 session_deps_.proxy_service.reset( | 445 session_deps_.proxy_service.reset( |
380 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 446 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
381 base::WrapUnique(proxy_resolver_factory), nullptr)); | 447 base::WrapUnique(proxy_resolver_factory), nullptr)); |
382 | 448 |
383 HttpRequestInfo request_info; | 449 HttpRequestInfo request_info; |
384 request_info.method = "GET"; | 450 request_info.method = "GET"; |
385 request_info.url = GURL("https://www.google.com"); | 451 request_info.url = GURL("https://www.google.com"); |
386 | 452 |
387 Initialize(request_info); | 453 Initialize(request_info); |
388 url::SchemeHostPort server(request_info.url); | 454 url::SchemeHostPort server(request_info.url); |
389 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 455 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
390 SetAlternativeService(request_info, alternative_service); | 456 SetAlternativeService(request_info, alternative_service); |
457 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
458 session_->quic_stream_factory(), | |
459 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_FAILED)); | |
391 | 460 |
392 request_.reset( | 461 request_.reset( |
393 job_controller_->Start(request_info, &request_delegate_, nullptr, | 462 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
394 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 463 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
395 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
396 EXPECT_TRUE(job_controller_->main_job()); | 464 EXPECT_TRUE(job_controller_->main_job()); |
397 EXPECT_TRUE(job_controller_->alternative_job()); | 465 EXPECT_TRUE(job_controller_->alternative_job()); |
398 | 466 |
399 // Main job succeeds, starts serving Request and it should report status | 467 // Main job succeeds, starts serving Request and it should report status |
400 // to Request. The alternative job will mark the main job complete and gets | 468 // to Request. The alternative job will mark the main job complete and gets |
401 // orphaned. | 469 // orphaned. |
402 HttpStream* http_stream = | 470 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
403 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
404 job_factory_.main_job()->SetStream(http_stream); | |
405 | |
406 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
407 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 471 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
408 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | |
409 | |
410 // JobController shouldn't report the status of second job as request | 472 // JobController shouldn't report the status of second job as request |
411 // is already successfully served. | 473 // is already successfully served. |
412 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 474 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
413 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 475 |
414 SSLConfig()); | 476 base::RunLoop().RunUntilIdle(); |
415 | 477 |
416 VerifyBrokenAlternateProtocolMapping(request_info, true); | 478 VerifyBrokenAlternateProtocolMapping(request_info, true); |
417 // Reset the request as it's been successfully served. | 479 // Reset the request as it's been successfully served. |
418 request_.reset(); | 480 request_.reset(); |
419 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 481 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
420 } | 482 } |
421 | 483 |
422 // Tests that if alt job succeeds and main job is blocked, main job should be | 484 // Tests that if alt job succeeds and main job is blocked, main job should be |
423 // cancelled immediately. |request_| completion will clean up the JobController. | 485 // cancelled immediately. |request_| completion will clean up the JobController. |
424 // Regression test for crbug.com/678768. | 486 // Regression test for crbug.com/678768. |
425 TEST_F(HttpStreamFactoryImplJobControllerTest, | 487 TEST_F(HttpStreamFactoryImplJobControllerTest, |
426 AltJobSucceedsMainJobBlockedControllerDestroyed) { | 488 AltJobSucceedsMainJobBlockedControllerDestroyed) { |
427 ProxyConfig proxy_config; | 489 ProxyConfig proxy_config; |
428 proxy_config.set_auto_detect(true); | |
429 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 490 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
430 new MockAsyncProxyResolverFactory(false); | 491 new MockAsyncProxyResolverFactory(false); |
431 session_deps_.proxy_service.reset( | 492 session_deps_.proxy_service.reset( |
432 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 493 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
433 base::WrapUnique(proxy_resolver_factory), nullptr)); | 494 base::WrapUnique(proxy_resolver_factory), nullptr)); |
434 HttpRequestInfo request_info; | 495 HttpRequestInfo request_info; |
435 request_info.method = "GET"; | 496 request_info.method = "GET"; |
436 request_info.url = GURL("https://www.google.com"); | 497 request_info.url = GURL("https://www.google.com"); |
437 | 498 |
438 Initialize(request_info); | 499 Initialize(request_info); |
439 | 500 |
501 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
502 session_->quic_stream_factory(), | |
503 base::MakeUnique<MockQuicStreamRequestFactory>(OK)); | |
504 | |
440 url::SchemeHostPort server(request_info.url); | 505 url::SchemeHostPort server(request_info.url); |
441 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 506 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
442 SetAlternativeService(request_info, alternative_service); | 507 SetAlternativeService(request_info, alternative_service); |
443 request_.reset( | 508 request_.reset( |
444 job_controller_->Start(request_info, &request_delegate_, nullptr, | 509 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
445 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 510 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
446 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
447 EXPECT_TRUE(job_controller_->main_job()); | 511 EXPECT_TRUE(job_controller_->main_job()); |
448 EXPECT_TRUE(job_controller_->alternative_job()); | 512 EXPECT_TRUE(job_controller_->alternative_job()); |
449 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 513 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
450 | 514 |
451 // |alternative_job| succeeds and should report status to Request. | 515 // |alternative_job| succeeds and should report status to |request_delegate_|. |
452 HttpStream* http_stream = | 516 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
453 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
454 job_factory_.alternative_job()->SetStream(http_stream); | |
455 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
456 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 517 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
457 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 518 |
519 base::RunLoop().RunUntilIdle(); | |
458 | 520 |
459 EXPECT_FALSE(job_controller_->main_job()); | 521 EXPECT_FALSE(job_controller_->main_job()); |
460 EXPECT_TRUE(job_controller_->alternative_job()); | 522 EXPECT_TRUE(job_controller_->alternative_job()); |
461 | 523 |
462 // Invoke OnRequestComplete() which should delete |job_controller_| from | 524 // Invoke OnRequestComplete() which should delete |job_controller_| from |
463 // |factory_|. | 525 // |factory_|. |
464 request_.reset(); | 526 request_.reset(); |
465 VerifyBrokenAlternateProtocolMapping(request_info, false); | 527 VerifyBrokenAlternateProtocolMapping(request_info, false); |
466 // This fails without the fix for crbug.com/678768. | 528 // This fails without the fix for crbug.com/678768. |
467 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 529 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
468 } | 530 } |
469 | 531 |
470 // Tests that if an orphaned job completes after |request_| is gone, | 532 // Tests that if an orphaned job completes after |request_| is gone, |
471 // JobController will be cleaned up. | 533 // JobController will be cleaned up. |
472 TEST_F(HttpStreamFactoryImplJobControllerTest, | 534 TEST_F(HttpStreamFactoryImplJobControllerTest, |
473 OrphanedJobCompletesControllerDestroyed) { | 535 OrphanedJobCompletesControllerDestroyed) { |
536 // One TCP connect. | |
537 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
538 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | |
539 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
540 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
541 | |
474 ProxyConfig proxy_config; | 542 ProxyConfig proxy_config; |
475 proxy_config.set_auto_detect(true); | |
476 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 543 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
477 new MockAsyncProxyResolverFactory(false); | 544 new MockAsyncProxyResolverFactory(false); |
478 session_deps_.proxy_service.reset( | 545 session_deps_.proxy_service.reset( |
479 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 546 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
480 base::WrapUnique(proxy_resolver_factory), nullptr)); | 547 base::WrapUnique(proxy_resolver_factory), nullptr)); |
481 HttpRequestInfo request_info; | 548 HttpRequestInfo request_info; |
482 request_info.method = "GET"; | 549 request_info.method = "GET"; |
483 request_info.url = GURL("https://www.google.com"); | 550 request_info.url = GURL("https://www.google.com"); |
484 | 551 |
485 Initialize(request_info); | 552 Initialize(request_info); |
486 | 553 |
554 // Make QuicStreamRequest complete asynchonously. | |
555 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
556 session_->quic_stream_factory(), | |
557 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_IO_PENDING)); | |
558 | |
487 url::SchemeHostPort server(request_info.url); | 559 url::SchemeHostPort server(request_info.url); |
488 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 560 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
489 SetAlternativeService(request_info, alternative_service); | 561 SetAlternativeService(request_info, alternative_service); |
490 // Hack to use different URL for the main job to help differentiate the proxy | 562 |
491 // requests. | |
492 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | |
493 request_.reset( | 563 request_.reset( |
494 job_controller_->Start(request_info, &request_delegate_, nullptr, | 564 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
495 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 565 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
496 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
497 EXPECT_TRUE(job_controller_->main_job()); | 566 EXPECT_TRUE(job_controller_->main_job()); |
498 EXPECT_TRUE(job_controller_->alternative_job()); | 567 EXPECT_TRUE(job_controller_->alternative_job()); |
499 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 568 // main job should not be blockd because alt job returned ERR_IO_PENDING. |
Bence
2017/04/26 13:55:39
s/blockd/blocked/
xunjieli
2017/04/27 18:15:54
Done.
| |
569 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); | |
570 | |
571 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) | |
572 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
500 | 573 |
501 // Complete main job now. | 574 // Complete main job now. |
502 MockAsyncProxyResolver resolver; | 575 base::RunLoop().RunUntilIdle(); |
503 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
504 net::OK, &resolver); | |
505 int main_job_request_id = | |
506 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; | |
507 | 576 |
508 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( | |
509 "result1:80"); | |
510 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); | |
511 | |
512 HttpStream* http_stream = | |
513 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
514 job_factory_.main_job()->SetStream(http_stream); | |
515 | |
516 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
517 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
518 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | |
519 // Invoke OnRequestComplete() which should not delete |job_controller_| from | 577 // Invoke OnRequestComplete() which should not delete |job_controller_| from |
520 // |factory_| because alt job is yet to finish. | 578 // |factory_| because alt job is yet to finish. |
521 request_.reset(); | 579 request_.reset(); |
522 ASSERT_FALSE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 580 ASSERT_FALSE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
523 EXPECT_FALSE(job_controller_->main_job()); | 581 EXPECT_FALSE(job_controller_->main_job()); |
524 EXPECT_TRUE(job_controller_->alternative_job()); | 582 EXPECT_TRUE(job_controller_->alternative_job()); |
525 | 583 |
526 // Make |alternative_job| succeed. | 584 // Make |alternative_job| succeed. |
527 resolver.pending_jobs()[0]->results()->UseNamedProxy("result1:80"); | 585 HttpStream* http_stream = |
528 resolver.pending_jobs()[0]->CompleteNow(net::OK); | |
529 HttpStream* http_stream2 = | |
530 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 586 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
531 job_factory_.alternative_job()->SetStream(http_stream2); | 587 job_factory_.alternative_job()->SetStream(http_stream); |
532 // This should not call request_delegate_::OnStreamReady. | 588 // This should not call request_delegate_::OnStreamReady. |
533 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 589 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
534 // Make sure that controller does not leak. | 590 // Make sure that controller does not leak. |
535 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 591 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
536 } | 592 } |
537 | 593 |
538 TEST_F(HttpStreamFactoryImplJobControllerTest, | 594 TEST_F(HttpStreamFactoryImplJobControllerTest, |
539 AltJobSucceedsAfterMainJobFailed) { | 595 AltJobSucceedsAfterMainJobFailed) { |
596 // One failed TCP connect. | |
597 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
598 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, ERR_FAILED)); | |
599 | |
540 ProxyConfig proxy_config; | 600 ProxyConfig proxy_config; |
541 proxy_config.set_auto_detect(true); | |
542 // Use asynchronous proxy resolver. | |
543 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 601 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
544 new MockAsyncProxyResolverFactory(false); | 602 new MockAsyncProxyResolverFactory(false); |
545 session_deps_.proxy_service.reset( | 603 session_deps_.proxy_service.reset( |
546 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 604 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
547 base::WrapUnique(proxy_resolver_factory), nullptr)); | 605 base::WrapUnique(proxy_resolver_factory), nullptr)); |
548 HttpRequestInfo request_info; | 606 HttpRequestInfo request_info; |
549 request_info.method = "GET"; | 607 request_info.method = "GET"; |
550 request_info.url = GURL("https://www.google.com"); | 608 request_info.url = GURL("https://www.google.com"); |
551 | 609 |
552 Initialize(request_info); | 610 Initialize(request_info); |
553 | 611 |
554 url::SchemeHostPort server(request_info.url); | 612 url::SchemeHostPort server(request_info.url); |
555 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 613 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
556 SetAlternativeService(request_info, alternative_service); | 614 SetAlternativeService(request_info, alternative_service); |
557 | 615 |
558 request_.reset( | 616 test::QuicStreamFactoryPeer::SetStreamRequestFactory( |
559 job_controller_->Start(request_info, &request_delegate_, nullptr, | 617 session_->quic_stream_factory(), |
560 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 618 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_IO_PENDING)); |
561 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
562 EXPECT_TRUE(job_controller_->main_job()); | |
563 EXPECT_TRUE(job_controller_->alternative_job()); | |
564 | 619 |
565 // |main_job| fails but should not report status to Request. | 620 // |main_job| fails but should not report status to Request. |
566 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 621 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
567 | 622 |
568 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 623 request_.reset( |
569 SSLConfig()); | 624 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
625 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); | |
626 EXPECT_TRUE(job_controller_->main_job()); | |
627 EXPECT_TRUE(job_controller_->alternative_job()); | |
570 | 628 |
571 // |alternative_job| succeeds and should report status to Request. | 629 base::RunLoop().RunUntilIdle(); |
630 | |
631 // Make |alternative_job| succeed. | |
572 HttpStream* http_stream = | 632 HttpStream* http_stream = |
573 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 633 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
574 job_factory_.alternative_job()->SetStream(http_stream); | |
575 | 634 |
576 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 635 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
577 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 636 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
637 | |
638 job_factory_.alternative_job()->SetStream(http_stream); | |
578 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 639 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
640 | |
641 // |alternative_job| succeeds and should report status to Request. | |
579 VerifyBrokenAlternateProtocolMapping(request_info, false); | 642 VerifyBrokenAlternateProtocolMapping(request_info, false); |
580 } | 643 } |
581 | 644 |
582 TEST_F(HttpStreamFactoryImplJobControllerTest, | 645 TEST_F(HttpStreamFactoryImplJobControllerTest, |
583 MainJobSucceedsAfterAltJobFailed) { | 646 MainJobSucceedsAfterAltJobFailed) { |
647 // One TCP connect. | |
648 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
649 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | |
650 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
651 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
652 | |
584 base::HistogramTester histogram_tester; | 653 base::HistogramTester histogram_tester; |
585 ProxyConfig proxy_config; | 654 ProxyConfig proxy_config; |
586 proxy_config.set_auto_detect(true); | |
587 // Use asynchronous proxy resolver. | 655 // Use asynchronous proxy resolver. |
588 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 656 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
589 new MockAsyncProxyResolverFactory(false); | 657 new MockAsyncProxyResolverFactory(false); |
590 session_deps_.proxy_service.reset( | 658 session_deps_.proxy_service.reset( |
591 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 659 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
592 base::WrapUnique(proxy_resolver_factory), nullptr)); | 660 base::WrapUnique(proxy_resolver_factory), nullptr)); |
593 HttpRequestInfo request_info; | 661 HttpRequestInfo request_info; |
594 request_info.method = "GET"; | 662 request_info.method = "GET"; |
595 request_info.url = GURL("https://www.google.com"); | 663 request_info.url = GURL("https://www.google.com"); |
596 | 664 |
597 Initialize(request_info); | 665 Initialize(request_info); |
598 | 666 |
599 url::SchemeHostPort server(request_info.url); | 667 url::SchemeHostPort server(request_info.url); |
600 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 668 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
601 SetAlternativeService(request_info, alternative_service); | 669 SetAlternativeService(request_info, alternative_service); |
670 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
671 session_->quic_stream_factory(), | |
672 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_FAILED)); | |
602 | 673 |
603 request_.reset( | 674 request_.reset( |
604 job_controller_->Start(request_info, &request_delegate_, nullptr, | 675 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
605 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 676 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
606 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
607 EXPECT_TRUE(job_controller_->main_job()); | 677 EXPECT_TRUE(job_controller_->main_job()); |
608 EXPECT_TRUE(job_controller_->alternative_job()); | 678 EXPECT_TRUE(job_controller_->alternative_job()); |
609 | 679 |
610 // |alternative_job| fails but should not report status to Request. | 680 // |alternative_job| fails but should not report status to Request. |
611 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 681 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
682 // |main_job| succeeds and should report status to Request. | |
683 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) | |
684 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
612 | 685 |
613 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, | 686 base::RunLoop().RunUntilIdle(); |
614 SSLConfig()); | |
615 | |
616 // |main_job| succeeds and should report status to Request. | |
617 HttpStream* http_stream = | |
618 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
619 job_factory_.main_job()->SetStream(http_stream); | |
620 | |
621 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
622 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
623 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | |
624 | 687 |
625 // Verify that the alternate protocol is marked as broken. | 688 // Verify that the alternate protocol is marked as broken. |
626 VerifyBrokenAlternateProtocolMapping(request_info, true); | 689 VerifyBrokenAlternateProtocolMapping(request_info, true); |
627 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", -ERR_FAILED, | 690 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", -ERR_FAILED, |
628 1); | 691 1); |
629 } | 692 } |
630 | 693 |
631 // Verifies that if the alternative job fails due to a connection change event, | 694 // Verifies that if the alternative job fails due to a connection change event, |
632 // then the alternative service is not marked as broken. | 695 // then the alternative service is not marked as broken. |
633 TEST_F(HttpStreamFactoryImplJobControllerTest, | 696 TEST_F(HttpStreamFactoryImplJobControllerTest, |
634 MainJobSucceedsAfterConnectionChanged) { | 697 MainJobSucceedsAfterConnectionChanged) { |
698 // One TCP connect. | |
699 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
700 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | |
701 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
702 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
703 | |
635 base::HistogramTester histogram_tester; | 704 base::HistogramTester histogram_tester; |
636 ProxyConfig proxy_config; | 705 ProxyConfig proxy_config; |
637 proxy_config.set_auto_detect(true); | |
638 // Use asynchronous proxy resolver. | 706 // Use asynchronous proxy resolver. |
639 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 707 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
640 new MockAsyncProxyResolverFactory(false); | 708 new MockAsyncProxyResolverFactory(false); |
641 session_deps_.proxy_service.reset( | 709 session_deps_.proxy_service.reset( |
642 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 710 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
643 base::WrapUnique(proxy_resolver_factory), nullptr)); | 711 base::WrapUnique(proxy_resolver_factory), nullptr)); |
644 session_deps_.quic_do_not_mark_as_broken_on_network_change = true; | 712 session_deps_.quic_do_not_mark_as_broken_on_network_change = true; |
645 | 713 |
646 HttpRequestInfo request_info; | 714 HttpRequestInfo request_info; |
647 request_info.method = "GET"; | 715 request_info.method = "GET"; |
648 request_info.url = GURL("https://www.google.com"); | 716 request_info.url = GURL("https://www.google.com"); |
649 Initialize(request_info); | 717 Initialize(request_info); |
650 | 718 |
651 url::SchemeHostPort server(request_info.url); | 719 url::SchemeHostPort server(request_info.url); |
652 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 720 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
653 SetAlternativeService(request_info, alternative_service); | 721 SetAlternativeService(request_info, alternative_service); |
654 | 722 |
723 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
724 session_->quic_stream_factory(), | |
725 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_NETWORK_CHANGED)); | |
726 | |
655 request_.reset( | 727 request_.reset( |
656 job_controller_->Start(request_info, &request_delegate_, nullptr, | 728 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
657 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 729 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
658 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
659 EXPECT_TRUE(job_controller_->main_job()); | 730 EXPECT_TRUE(job_controller_->main_job()); |
660 EXPECT_TRUE(job_controller_->alternative_job()); | 731 EXPECT_TRUE(job_controller_->alternative_job()); |
661 | 732 |
662 // |alternative_job| fails but should not report status to Request. | 733 // |alternative_job| fails but should not report status to Request. |
663 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 734 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
664 | |
665 job_controller_->OnStreamFailed(job_factory_.alternative_job(), | |
666 ERR_NETWORK_CHANGED, SSLConfig()); | |
667 | |
668 // |main_job| succeeds and should report status to Request. | 735 // |main_job| succeeds and should report status to Request. |
669 HttpStream* http_stream = | 736 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
670 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
671 job_factory_.main_job()->SetStream(http_stream); | |
672 | |
673 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
674 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 737 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
675 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | 738 base::RunLoop().RunUntilIdle(); |
676 | 739 |
677 // Verify that the alternate protocol is not marked as broken. | 740 // Verify that the alternate protocol is not marked as broken. |
678 VerifyBrokenAlternateProtocolMapping(request_info, false); | 741 VerifyBrokenAlternateProtocolMapping(request_info, false); |
679 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", | 742 histogram_tester.ExpectUniqueSample("Net.AlternateServiceFailed", |
680 -ERR_NETWORK_CHANGED, 1); | 743 -ERR_NETWORK_CHANGED, 1); |
681 } | 744 } |
682 | 745 |
683 // Regression test for crbug/621069. | 746 // Regression test for crbug/621069. |
684 // Get load state after main job fails and before alternative job succeeds. | 747 // Get load state after main job fails and before alternative job succeeds. |
685 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { | 748 TEST_F(HttpStreamFactoryImplJobControllerTest, GetLoadStateAfterMainJobFailed) { |
749 // One failed TCP connect. | |
750 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
751 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); | |
752 | |
686 ProxyConfig proxy_config; | 753 ProxyConfig proxy_config; |
687 proxy_config.set_auto_detect(true); | |
688 // Use asynchronous proxy resolver. | |
689 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 754 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
690 new MockAsyncProxyResolverFactory(false); | 755 new MockAsyncProxyResolverFactory(false); |
691 session_deps_.proxy_service.reset(new ProxyService( | 756 session_deps_.proxy_service.reset(new ProxyService( |
692 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), | 757 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
693 base::WrapUnique(proxy_resolver_factory), nullptr)); | 758 base::WrapUnique(proxy_resolver_factory), nullptr)); |
694 | 759 |
695 HttpRequestInfo request_info; | 760 HttpRequestInfo request_info; |
696 request_info.method = "GET"; | 761 request_info.method = "GET"; |
697 request_info.url = GURL("https://www.google.com"); | 762 request_info.url = GURL("https://www.google.com"); |
698 | 763 |
699 Initialize(request_info); | 764 Initialize(request_info); |
700 url::SchemeHostPort server(request_info.url); | 765 url::SchemeHostPort server(request_info.url); |
701 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 766 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
702 SetAlternativeService(request_info, alternative_service); | 767 SetAlternativeService(request_info, alternative_service); |
703 | 768 |
769 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
770 session_->quic_stream_factory(), | |
771 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_IO_PENDING)); | |
772 | |
704 request_.reset( | 773 request_.reset( |
705 job_controller_->Start(request_info, &request_delegate_, nullptr, | 774 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
706 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 775 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
707 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
708 EXPECT_TRUE(job_controller_->main_job()); | 776 EXPECT_TRUE(job_controller_->main_job()); |
709 EXPECT_TRUE(job_controller_->alternative_job()); | 777 EXPECT_TRUE(job_controller_->alternative_job()); |
710 | 778 |
711 // |main_job| fails but should not report status to Request. | 779 // |main_job| fails but should not report status to Request. |
712 // The alternative job will mark the main job complete. | 780 // The alternative job will mark the main job complete. |
713 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 781 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
714 | 782 |
715 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, | 783 base::RunLoop().RunUntilIdle(); |
716 SSLConfig()); | |
717 | 784 |
718 // Controller should use alternative job to get load state. | 785 // Controller should use alternative job to get load state. |
719 job_controller_->GetLoadState(); | 786 job_controller_->GetLoadState(); |
720 | 787 |
721 // |alternative_job| succeeds and should report status to Request. | 788 // |alternative_job| succeeds and should report status to Request. |
722 HttpStream* http_stream = | 789 HttpStream* http_stream = |
723 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 790 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
724 job_factory_.alternative_job()->SetStream(http_stream); | 791 job_factory_.alternative_job()->SetStream(http_stream); |
725 | 792 |
726 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | 793 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) |
727 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 794 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
728 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); | 795 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig()); |
729 } | 796 } |
730 | 797 |
731 TEST_F(HttpStreamFactoryImplJobControllerTest, DoNotResumeMainJobBeforeWait) { | 798 TEST_F(HttpStreamFactoryImplJobControllerTest, ResumeMainJobWhenAltJobStalls) { |
732 // Use failing ProxyResolverFactory which is unable to create ProxyResolver | 799 // One TCP connect. |
733 // to stall the alternative job and report to controller to maybe resume the | 800 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
734 // main job. | 801 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
802 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
803 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
804 | |
735 ProxyConfig proxy_config; | 805 ProxyConfig proxy_config; |
736 proxy_config.set_auto_detect(true); | 806 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
737 proxy_config.set_pac_mandatory(true); | 807 new MockAsyncProxyResolverFactory(false); |
738 session_deps_.proxy_service.reset(new ProxyService( | 808 session_deps_.proxy_service.reset(new ProxyService( |
739 base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 809 base::WrapUnique(new ProxyConfigServiceFixed(proxy_config)), |
740 base::WrapUnique(new FailingProxyResolverFactory), nullptr)); | 810 base::WrapUnique(proxy_resolver_factory), nullptr)); |
741 | 811 |
742 HttpRequestInfo request_info; | 812 HttpRequestInfo request_info; |
743 request_info.method = "GET"; | 813 request_info.method = "GET"; |
744 request_info.url = GURL("https://www.google.com"); | 814 request_info.url = GURL("https://www.google.com"); |
745 | 815 |
746 Initialize(request_info); | 816 Initialize(request_info); |
747 url::SchemeHostPort server(request_info.url); | 817 url::SchemeHostPort server(request_info.url); |
748 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 818 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
749 SetAlternativeService(request_info, alternative_service); | 819 SetAlternativeService(request_info, alternative_service); |
820 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
821 session_->quic_stream_factory(), | |
822 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_IO_PENDING)); | |
750 | 823 |
751 request_.reset( | 824 request_.reset( |
752 job_controller_->Start(request_info, &request_delegate_, nullptr, | 825 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
753 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 826 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
754 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
755 EXPECT_TRUE(job_controller_->main_job()); | 827 EXPECT_TRUE(job_controller_->main_job()); |
756 EXPECT_TRUE(job_controller_->alternative_job()); | 828 EXPECT_TRUE(job_controller_->alternative_job()); |
757 | 829 |
758 // Wait until OnStreamFailedCallback is executed on the alternative job. | 830 // Alt job is stalled and main job should complete successfully. |
759 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1); | 831 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
832 .WillOnce(Invoke(DeleteHttpStreamPointer)); | |
833 | |
760 base::RunLoop().RunUntilIdle(); | 834 base::RunLoop().RunUntilIdle(); |
761 } | 835 } |
762 | 836 |
763 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { | 837 TEST_F(HttpStreamFactoryImplJobControllerTest, InvalidPortForQuic) { |
764 HttpRequestInfo request_info; | 838 HttpRequestInfo request_info; |
765 request_info.method = "GET"; | 839 request_info.method = "GET"; |
766 request_info.url = GURL("https://www.google.com"); | 840 request_info.url = GURL("https://www.google.com"); |
767 | 841 |
768 // Using a restricted port 101 for QUIC should fail and the alternative job | 842 // Using a restricted port 101 for QUIC should fail and the alternative job |
769 // should post OnStreamFailedCall on the controller to resume the main job. | 843 // should post OnStreamFailedCall on the controller to resume the main job. |
770 Initialize(request_info); | 844 Initialize(request_info); |
771 | 845 |
772 url::SchemeHostPort server(request_info.url); | 846 url::SchemeHostPort server(request_info.url); |
773 AlternativeService alternative_service(kProtoQUIC, server.host(), 101); | 847 AlternativeService alternative_service(kProtoQUIC, server.host(), 101); |
774 SetAlternativeService(request_info, alternative_service); | 848 SetAlternativeService(request_info, alternative_service); |
775 | 849 |
776 request_.reset( | 850 request_.reset( |
777 job_controller_->Start(request_info, &request_delegate_, nullptr, | 851 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
778 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 852 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
779 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
780 | 853 |
781 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); | 854 EXPECT_TRUE(job_factory_.main_job()->is_waiting()); |
782 | 855 |
783 // Wait until OnStreamFailedCallback is executed on the alternative job. | 856 // Wait until OnStreamFailedCallback is executed on the alternative job. |
784 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 857 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
785 base::RunLoop().RunUntilIdle(); | 858 base::RunLoop().RunUntilIdle(); |
786 } | 859 } |
787 | 860 |
788 TEST_F(HttpStreamFactoryImplJobControllerTest, | |
789 NoAvailableSpdySessionToResumeMainJob) { | |
790 // Test the alternative job is not resumed when the alternative job is | |
791 // IO_PENDING for proxy resolution. Once all the proxy resolution succeeds, | |
792 // the latter part of this test tests controller resumes the main job | |
793 // when there's no SPDY session for the alternative job. | |
794 ProxyConfig proxy_config; | |
795 proxy_config.set_auto_detect(true); | |
796 // Use asynchronous proxy resolver. | |
797 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
798 new MockAsyncProxyResolverFactory(false); | |
799 session_deps_.proxy_service.reset( | |
800 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
801 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
802 | |
803 HangingResolver* host_resolver = new HangingResolver(); | |
804 session_deps_.host_resolver.reset(host_resolver); | |
805 session_deps_.host_resolver->set_synchronous_mode(false); | |
806 | |
807 HttpRequestInfo request_info; | |
808 request_info.method = "GET"; | |
809 request_info.url = GURL("https://www.google.com"); | |
810 | |
811 Initialize(request_info); | |
812 | |
813 // Set a SPDY alternative service for the server. | |
814 url::SchemeHostPort server(request_info.url); | |
815 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
816 SetAlternativeService(request_info, alternative_service); | |
817 // Hack to use different URL for the main job to help differentiate the proxy | |
818 // requests. | |
819 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | |
820 | |
821 request_.reset( | |
822 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
823 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | |
824 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
825 // Both jobs should be created but stalled as proxy resolution not completed. | |
826 EXPECT_TRUE(job_controller_->main_job()); | |
827 EXPECT_TRUE(job_controller_->alternative_job()); | |
828 | |
829 MockAsyncProxyResolver resolver; | |
830 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
831 net::OK, &resolver); | |
832 | |
833 // Resolve proxy for the main job which then proceed to wait for the | |
834 // alternative job which is IO_PENDING. | |
835 int main_job_request_id = | |
836 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; | |
837 | |
838 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( | |
839 "result1:80"); | |
840 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); | |
841 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
842 | |
843 // Resolve proxy for the alternative job to proceed to create a connection. | |
844 // Use hanging HostResolver to fail creation of a SPDY session for the | |
845 // alternative job. The alternative job will be IO_PENDING thus should resume | |
846 // the main job. | |
847 resolver.pending_jobs()[0]->CompleteNow(net::OK); | |
848 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
849 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
850 | |
851 base::RunLoop().RunUntilIdle(); | |
852 } | |
853 | |
854 TEST_F(HttpStreamFactoryImplJobControllerTest, | |
855 NoAvailableQuicSessionToResumeMainJob) { | |
856 // Use failing HostResolver which is unable to resolve the host name for QUIC. | |
857 // No QUIC session is created and thus should resume the main job. | |
858 FailingHostResolver* host_resolver = new FailingHostResolver(); | |
859 session_deps_.host_resolver.reset(host_resolver); | |
860 | |
861 ProxyConfig proxy_config; | |
862 proxy_config.set_auto_detect(true); | |
863 // Use asynchronous proxy resolver. | |
864 MockAsyncProxyResolverFactory* proxy_resolver_factory = | |
865 new MockAsyncProxyResolverFactory(false); | |
866 session_deps_.proxy_service.reset( | |
867 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | |
868 base::WrapUnique(proxy_resolver_factory), nullptr)); | |
869 | |
870 HttpRequestInfo request_info; | |
871 request_info.method = "GET"; | |
872 request_info.url = GURL("https://www.google.com"); | |
873 | |
874 Initialize(request_info); | |
875 url::SchemeHostPort server(request_info.url); | |
876 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
877 SetAlternativeService(request_info, alternative_service); | |
878 // Hack to use different URL for the main job to help differentiate the proxy | |
879 // requests. | |
880 job_factory_.UseDifferentURLForMainJob(GURL("http://www.google.com")); | |
881 | |
882 request_.reset( | |
883 job_controller_->Start(request_info, &request_delegate_, nullptr, | |
884 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | |
885 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
886 EXPECT_TRUE(job_controller_->main_job()); | |
887 EXPECT_TRUE(job_controller_->alternative_job()); | |
888 | |
889 MockAsyncProxyResolver resolver; | |
890 proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( | |
891 net::OK, &resolver); | |
892 | |
893 // Resolve proxy for the main job which then proceed to wait for the | |
894 // alternative job which is IO_PENDING. | |
895 int main_job_request_id = | |
896 resolver.pending_jobs()[0]->url().SchemeIs("http") ? 0 : 1; | |
897 | |
898 resolver.pending_jobs()[main_job_request_id]->results()->UseNamedProxy( | |
899 "result1:80"); | |
900 resolver.pending_jobs()[main_job_request_id]->CompleteNow(net::OK); | |
901 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | |
902 | |
903 // Resolve proxy for the alternative job to proceed to create a connection. | |
904 // Use failing HostResolver to fail creation of a QUIC session for the | |
905 // alternative job. The alternative job will thus resume the main job. | |
906 resolver.pending_jobs()[0]->results()->UseNamedProxy("result1:80"); | |
907 resolver.pending_jobs()[0]->CompleteNow(net::OK); | |
908 | |
909 // Wait until OnStreamFailedCallback is executed on the alternative job. | |
910 // Request shouldn't be notified as the main job is still pending status. | |
911 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | |
912 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
913 | |
914 base::RunLoop().RunUntilIdle(); | |
915 } | |
916 | |
917 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { | 861 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCP) { |
918 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; | 862 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; |
919 auto failing_resolver = base::MakeUnique<MockHostResolver>(); | 863 auto failing_resolver = base::MakeUnique<MockHostResolver>(); |
920 failing_resolver->set_ondemand_mode(true); | 864 failing_resolver->set_ondemand_mode(true); |
921 failing_resolver->rules()->AddSimulatedFailure("*google.com"); | 865 failing_resolver->rules()->AddSimulatedFailure("*google.com"); |
922 session_deps_.host_resolver = std::move(failing_resolver); | 866 session_deps_.host_resolver = std::move(failing_resolver); |
923 | 867 |
924 HttpRequestInfo request_info; | 868 HttpRequestInfo request_info; |
925 request_info.method = "GET"; | 869 request_info.method = "GET"; |
926 request_info.url = GURL("https://www.google.com"); | 870 request_info.url = GURL("https://www.google.com"); |
927 | 871 |
928 Initialize(request_info); | 872 Initialize(request_info); |
929 | 873 |
930 // Enable delayed TCP and set time delay for waiting job. | 874 // Enable delayed TCP and set time delay for waiting job. |
931 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 875 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
932 quic_stream_factory->set_require_confirmation(false); | 876 quic_stream_factory->set_require_confirmation(false); |
933 ServerNetworkStats stats1; | 877 ServerNetworkStats stats1; |
934 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 878 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
935 session_->http_server_properties()->SetServerNetworkStats( | 879 session_->http_server_properties()->SetServerNetworkStats( |
936 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 880 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
937 | 881 |
938 // Set a SPDY alternative service for the server. | 882 // Set a QUIC alternative service for the server. |
Bence
2017/04/26 13:55:39
Optional: this comment does not add any value, you
xunjieli
2017/04/27 18:15:54
Done.
| |
939 url::SchemeHostPort server(request_info.url); | 883 url::SchemeHostPort server(request_info.url); |
940 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 884 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
941 SetAlternativeService(request_info, alternative_service); | 885 SetAlternativeService(request_info, alternative_service); |
942 | 886 |
943 request_.reset( | 887 request_.reset( |
944 job_controller_->Start(request_info, &request_delegate_, nullptr, | 888 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
945 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 889 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
946 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
947 EXPECT_TRUE(job_controller_->main_job()); | 890 EXPECT_TRUE(job_controller_->main_job()); |
948 EXPECT_TRUE(job_controller_->alternative_job()); | 891 EXPECT_TRUE(job_controller_->alternative_job()); |
949 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 892 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
950 | 893 |
951 // The alternative job stalls as host resolution hangs when creating the QUIC | 894 // The alternative job stalls as host resolution hangs when creating the QUIC |
952 // request and controller should resume the main job after delay. | 895 // request and controller should resume the main job after delay. |
953 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 896 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
954 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 897 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
955 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 898 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
956 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); | 899 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1002 stats1.srtt = base::TimeDelta::FromSeconds(100); | 945 stats1.srtt = base::TimeDelta::FromSeconds(100); |
1003 session_->http_server_properties()->SetServerNetworkStats( | 946 session_->http_server_properties()->SetServerNetworkStats( |
1004 url::SchemeHostPort(GURL("https://www.google.com")), stats1); | 947 url::SchemeHostPort(GURL("https://www.google.com")), stats1); |
1005 | 948 |
1006 // Set a SPDY alternative service for the server. | 949 // Set a SPDY alternative service for the server. |
1007 url::SchemeHostPort server(request_info.url); | 950 url::SchemeHostPort server(request_info.url); |
1008 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 951 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
1009 SetAlternativeService(request_info, alternative_service); | 952 SetAlternativeService(request_info, alternative_service); |
1010 | 953 |
1011 request_.reset( | 954 request_.reset( |
1012 job_controller_->Start(request_info, &request_delegate_, nullptr, | 955 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1013 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 956 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1014 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1015 EXPECT_TRUE(job_controller_->main_job()); | 957 EXPECT_TRUE(job_controller_->main_job()); |
1016 EXPECT_TRUE(job_controller_->alternative_job()); | 958 EXPECT_TRUE(job_controller_->alternative_job()); |
1017 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 959 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
1018 | 960 |
1019 // The alternative job stalls as host resolution hangs when creating the QUIC | 961 // The alternative job stalls as host resolution hangs when creating the QUIC |
1020 // request and controller should resume the main job after delay. | 962 // request and controller should resume the main job after delay. |
1021 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 963 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
1022 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 964 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
1023 | 965 |
1024 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 966 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1062 | 1004 |
1063 // Set a SPDY alternative service for the server. | 1005 // Set a SPDY alternative service for the server. |
1064 url::SchemeHostPort server(request_info.url); | 1006 url::SchemeHostPort server(request_info.url); |
1065 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 1007 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
1066 SetAlternativeService(request_info, alternative_service); | 1008 SetAlternativeService(request_info, alternative_service); |
1067 | 1009 |
1068 // The alternative job stalls as host resolution hangs when creating the QUIC | 1010 // The alternative job stalls as host resolution hangs when creating the QUIC |
1069 // request and controller should resume the main job with delay. | 1011 // request and controller should resume the main job with delay. |
1070 // OnStreamFailed should resume the main job immediately. | 1012 // OnStreamFailed should resume the main job immediately. |
1071 request_.reset( | 1013 request_.reset( |
1072 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1014 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1073 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1015 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1074 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1075 EXPECT_TRUE(job_controller_->main_job()); | 1016 EXPECT_TRUE(job_controller_->main_job()); |
1076 EXPECT_TRUE(job_controller_->alternative_job()); | 1017 EXPECT_TRUE(job_controller_->alternative_job()); |
1077 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1018 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
1078 | 1019 |
1079 EXPECT_TRUE(test_task_runner->HasPendingTask()); | 1020 EXPECT_TRUE(test_task_runner->HasPendingTask()); |
1080 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1021 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
1081 | 1022 |
1082 // |alternative_job| fails but should not report status to Request. | 1023 // |alternative_job| fails but should not report status to Request. |
1083 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); | 1024 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0); |
1084 // Now unblock Resolver to fail the alternate job. | 1025 // Now unblock Resolver to fail the alternate job. |
(...skipping 23 matching lines...) Expand all Loading... | |
1108 HangingResolver* resolver = new HangingResolver(); | 1049 HangingResolver* resolver = new HangingResolver(); |
1109 session_deps_.host_resolver.reset(resolver); | 1050 session_deps_.host_resolver.reset(resolver); |
1110 | 1051 |
1111 HttpRequestInfo request_info; | 1052 HttpRequestInfo request_info; |
1112 request_info.method = "GET"; | 1053 request_info.method = "GET"; |
1113 request_info.url = GURL("https://mail.example.org/"); | 1054 request_info.url = GURL("https://mail.example.org/"); |
1114 Initialize(request_info); | 1055 Initialize(request_info); |
1115 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1056 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
1116 | 1057 |
1117 request_.reset( | 1058 request_.reset( |
1118 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1059 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1119 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1060 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1120 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1121 EXPECT_TRUE(job_controller_->main_job()); | 1061 EXPECT_TRUE(job_controller_->main_job()); |
1122 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 1062 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
1123 EXPECT_FALSE(job_controller_->alternative_job()); | 1063 EXPECT_FALSE(job_controller_->alternative_job()); |
1124 | 1064 |
1125 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 1065 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
1126 base::RunLoop().RunUntilIdle(); | 1066 base::RunLoop().RunUntilIdle(); |
1127 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1067 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
1128 } | 1068 } |
1129 | 1069 |
1130 // Verifies that the alternative proxy server job is not created if the main job | 1070 // Verifies that the alternative proxy server job is not created if the main job |
1131 // does not fetch the resource through a proxy. | 1071 // does not fetch the resource through a proxy. |
1132 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { | 1072 TEST_F(HttpStreamFactoryImplJobControllerTest, HttpURLWithNoProxy) { |
1133 // Using hanging resolver will cause the alternative job to hang indefinitely. | 1073 // Using hanging resolver will cause the alternative job to hang indefinitely. |
1134 HangingResolver* resolver = new HangingResolver(); | 1074 HangingResolver* resolver = new HangingResolver(); |
1135 session_deps_.host_resolver.reset(resolver); | 1075 session_deps_.host_resolver.reset(resolver); |
1136 | 1076 |
1137 HttpRequestInfo request_info; | 1077 HttpRequestInfo request_info; |
1138 request_info.method = "GET"; | 1078 request_info.method = "GET"; |
1139 request_info.url = GURL("http://mail.example.org/"); | 1079 request_info.url = GURL("http://mail.example.org/"); |
1140 | 1080 |
1141 Initialize(request_info); | 1081 Initialize(request_info); |
1142 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1082 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
1143 | 1083 |
1144 request_.reset( | 1084 request_.reset( |
1145 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1085 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1146 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1086 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1147 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1148 EXPECT_TRUE(job_controller_->main_job()); | 1087 EXPECT_TRUE(job_controller_->main_job()); |
1149 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); | 1088 EXPECT_FALSE(job_controller_->main_job()->is_waiting()); |
1150 EXPECT_FALSE(job_controller_->alternative_job()); | 1089 EXPECT_FALSE(job_controller_->alternative_job()); |
1151 | 1090 |
1152 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | 1091 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); |
1153 base::RunLoop().RunUntilIdle(); | 1092 base::RunLoop().RunUntilIdle(); |
1154 | 1093 |
1155 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1094 EXPECT_EQ(0, test_proxy_delegate()->get_alternative_proxy_invocations()); |
1156 } | 1095 } |
1157 | 1096 |
1158 // Verifies that the main job is resumed properly after a delay when the | 1097 // Verifies that the main job is resumed properly after a delay when the |
1159 // alternative proxy server job hangs. | 1098 // alternative proxy server job hangs. |
1160 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { | 1099 TEST_F(HttpStreamFactoryImplJobControllerTest, DelayedTCPAlternativeProxy) { |
1161 // Overrides the main thread's message loop with a mock tick clock so that we | 1100 // Overrides the main thread's message loop with a mock tick clock so that we |
1162 // could verify the main job is resumed with appropriate delay. | 1101 // could verify the main job is resumed with appropriate delay. |
1163 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; | 1102 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; |
1164 | |
1165 auto failing_resolver = base::MakeUnique<MockHostResolver>(); | |
1166 failing_resolver->set_ondemand_mode(true); | |
1167 failing_resolver->rules()->AddSimulatedFailure("*myproxy.org"); | |
1168 session_deps_.host_resolver = std::move(failing_resolver); | |
1169 | |
1170 UseAlternativeProxy(); | 1103 UseAlternativeProxy(); |
1171 | 1104 |
1172 HttpRequestInfo request_info; | 1105 HttpRequestInfo request_info; |
1173 request_info.method = "GET"; | 1106 request_info.method = "GET"; |
1174 request_info.url = GURL("http://mail.example.org/"); | 1107 request_info.url = GURL("http://mail.example.org/"); |
1175 Initialize(request_info); | 1108 Initialize(request_info); |
1176 | 1109 |
1110 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
1111 session_->quic_stream_factory(), | |
1112 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_IO_PENDING)); | |
1113 | |
1177 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1114 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
1178 | 1115 |
1179 // Enable delayed TCP and set time delay for waiting job. | 1116 // Enable delayed TCP and set time delay for waiting job. |
1180 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 1117 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
1181 quic_stream_factory->set_require_confirmation(false); | 1118 quic_stream_factory->set_require_confirmation(false); |
1182 ServerNetworkStats stats1; | 1119 ServerNetworkStats stats1; |
1183 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 1120 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
1184 session_->http_server_properties()->SetServerNetworkStats( | 1121 session_->http_server_properties()->SetServerNetworkStats( |
1185 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 1122 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
1186 | 1123 |
1187 request_.reset( | 1124 request_.reset( |
1188 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1125 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1189 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1126 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1190 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1191 EXPECT_TRUE(job_controller_->main_job()); | 1127 EXPECT_TRUE(job_controller_->main_job()); |
1192 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1128 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
1193 EXPECT_TRUE(job_controller_->alternative_job()); | 1129 EXPECT_TRUE(job_controller_->alternative_job()); |
1194 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 1130 EXPECT_TRUE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
1195 | 1131 |
1196 // Alternative proxy server job will start in the next message loop. | 1132 // Move forward the delay and verify the main job is resumed. |
1197 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1133 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
1198 | |
1199 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(0); | |
1200 // Run tasks with no remaining delay, this will start the alternative proxy | 1134 // Run tasks with no remaining delay, this will start the alternative proxy |
1201 // server job. The alternative proxy server job stalls when connecting to the | 1135 // server job. The alternative proxy server job stalls when connecting to the |
1202 // alternative proxy server, and should schedule a task to resume the main job | 1136 // alternative proxy server, and should schedule a task to resume the main job |
1203 // after delay. That task will be queued. | 1137 // after delay. That task will be queued. |
1204 test_task_runner->RunUntilIdle(); | |
1205 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1138 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
1206 | |
1207 // Move forward the delay and verify the main job is resumed. | |
1208 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | |
1209 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); | 1139 test_task_runner->FastForwardBy(base::TimeDelta::FromMicroseconds(15)); |
1210 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); | 1140 EXPECT_FALSE(JobControllerPeer::main_job_is_blocked(job_controller_)); |
1211 | 1141 |
1212 test_task_runner->RunUntilIdle(); | 1142 test_task_runner->RunUntilIdle(); |
1213 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | 1143 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
1214 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1144 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
1215 EXPECT_FALSE(test_task_runner->HasPendingTask()); | 1145 EXPECT_FALSE(test_task_runner->HasPendingTask()); |
1216 | 1146 |
1217 // Now unblock Resolver so that alternate job (and QuicStreamFactory::Job) can | 1147 // Resume() function is mocked, so we will still have main job around. |
1218 // be cleaned up. | 1148 EXPECT_TRUE(job_controller_->main_job()); |
1219 session_deps_.host_resolver->ResolveAllPending(); | 1149 EXPECT_TRUE(job_controller_->alternative_job()); |
1220 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | |
1221 test_task_runner->FastForwardUntilNoTasksRemain(); | |
1222 EXPECT_FALSE(job_controller_->alternative_job()); | |
1223 } | 1150 } |
1224 | 1151 |
1225 // Verifies that the alternative proxy server job fails immediately, and the | 1152 // Verifies that if the alternative proxy server job fails immediately, the |
1226 // main job is not blocked. | 1153 // main job is not blocked. |
1227 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { | 1154 TEST_F(HttpStreamFactoryImplJobControllerTest, FailAlternativeProxy) { |
1228 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; | 1155 base::ScopedMockTimeMessageLoopTaskRunner test_task_runner; |
1229 // Using failing resolver will cause the alternative job to fail. | |
1230 FailingHostResolver* resolver = new FailingHostResolver(); | |
1231 session_deps_.host_resolver.reset(resolver); | |
1232 | |
1233 UseAlternativeProxy(); | 1156 UseAlternativeProxy(); |
1234 | 1157 |
1235 HttpRequestInfo request_info; | 1158 HttpRequestInfo request_info; |
1236 request_info.method = "GET"; | 1159 request_info.method = "GET"; |
1237 request_info.url = GURL("http://mail.example.org/"); | 1160 request_info.url = GURL("http://mail.example.org/"); |
1238 Initialize(request_info); | 1161 Initialize(request_info); |
1239 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); | 1162 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_quic()); |
1240 | 1163 |
1241 // Enable delayed TCP and set time delay for waiting job. | 1164 // Enable delayed TCP and set time delay for waiting job. |
1242 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); | 1165 QuicStreamFactory* quic_stream_factory = session_->quic_stream_factory(); |
1243 quic_stream_factory->set_require_confirmation(false); | 1166 quic_stream_factory->set_require_confirmation(false); |
1244 ServerNetworkStats stats1; | 1167 ServerNetworkStats stats1; |
1245 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); | 1168 stats1.srtt = base::TimeDelta::FromMicroseconds(300 * 1000); |
1246 session_->http_server_properties()->SetServerNetworkStats( | 1169 session_->http_server_properties()->SetServerNetworkStats( |
1247 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); | 1170 url::SchemeHostPort(GURL("https://myproxy.org")), stats1); |
1171 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
1172 session_->quic_stream_factory(), | |
1173 base::MakeUnique<MockQuicStreamRequestFactory>(ERR_FAILED)); | |
1248 | 1174 |
1249 request_.reset( | 1175 request_.reset( |
1250 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1176 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1251 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1177 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1252 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1253 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1178 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
1254 EXPECT_TRUE(job_controller_->alternative_job()); | 1179 EXPECT_TRUE(job_controller_->alternative_job()); |
1255 | 1180 |
1256 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); | 1181 EXPECT_EQ(1u, test_task_runner->GetPendingTaskCount()); |
1257 | 1182 |
1258 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); | 1183 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)).Times(0); |
1259 | 1184 |
1260 // Since the alternative proxy server job is started in the next message loop, | 1185 // Since the alternative proxy server job is started in the next message loop, |
1261 // the main job would remain blocked until the alternative proxy starts, and | 1186 // the main job would remain blocked until the alternative proxy starts, and |
1262 // fails. | 1187 // fails. |
1263 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); | 1188 EXPECT_CALL(*job_factory_.main_job(), Resume()).Times(1); |
1264 | 1189 |
1265 // Run tasks with no remaining delay. | 1190 // Run tasks with no remaining delay. |
1266 test_task_runner->RunUntilIdle(); | 1191 test_task_runner->RunUntilIdle(); |
1267 | 1192 |
1268 EXPECT_FALSE(job_controller_->alternative_job()); | 1193 EXPECT_FALSE(job_controller_->alternative_job()); |
1269 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); | 1194 EXPECT_TRUE(job_controller_->main_job()->is_waiting()); |
1270 // Since the main job did not complete successfully, the alternative proxy | 1195 // The alternative proxy server should be marked as bad. |
1271 // server should not be marked as bad. | 1196 EXPECT_FALSE(test_proxy_delegate()->alternative_proxy_server().is_valid()); |
1272 EXPECT_TRUE(test_proxy_delegate()->alternative_proxy_server().is_valid()); | |
1273 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); | 1197 EXPECT_EQ(1, test_proxy_delegate()->get_alternative_proxy_invocations()); |
1274 EXPECT_FALSE(test_task_runner->HasPendingTask()); | 1198 EXPECT_FALSE(test_task_runner->HasPendingTask()); |
1275 } | 1199 } |
1276 | 1200 |
1277 TEST_F(HttpStreamFactoryImplJobControllerTest, | 1201 TEST_F(HttpStreamFactoryImplJobControllerTest, |
1278 AlternativeProxyServerJobFailsAfterMainJobSucceeds) { | 1202 AlternativeProxyServerJobFailsAfterMainJobSucceeds) { |
1279 base::HistogramTester histogram_tester; | 1203 base::HistogramTester histogram_tester; |
1280 | 1204 |
1281 UseAlternativeProxy(); | 1205 UseAlternativeProxy(); |
1282 | 1206 |
1283 HttpRequestInfo request_info; | 1207 HttpRequestInfo request_info; |
1284 request_info.method = "GET"; | 1208 request_info.method = "GET"; |
1285 request_info.url = GURL("http://www.google.com"); | 1209 request_info.url = GURL("http://www.google.com"); |
1286 Initialize(request_info); | 1210 Initialize(request_info); |
1287 | 1211 |
1288 url::SchemeHostPort server(request_info.url); | 1212 url::SchemeHostPort server(request_info.url); |
1289 | 1213 |
1290 request_.reset( | 1214 request_.reset( |
1291 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1215 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1292 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1216 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1293 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1294 EXPECT_TRUE(job_controller_->main_job()); | 1217 EXPECT_TRUE(job_controller_->main_job()); |
1295 EXPECT_TRUE(job_controller_->alternative_job()); | 1218 EXPECT_TRUE(job_controller_->alternative_job()); |
1296 | 1219 |
1297 // Main job succeeds, starts serving Request and it should report status | 1220 // Main job succeeds, starts serving Request and it should report status |
1298 // to Request. The alternative job will mark the main job complete and gets | 1221 // to Request. The alternative job will mark the main job complete and gets |
1299 // orphaned. | 1222 // orphaned. |
1300 HttpStream* http_stream = | 1223 HttpStream* http_stream = |
1301 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | 1224 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); |
1302 job_factory_.main_job()->SetStream(http_stream); | 1225 job_factory_.main_job()->SetStream(http_stream); |
1303 | 1226 |
(...skipping 12 matching lines...) Expand all Loading... | |
1316 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1239 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
1317 | 1240 |
1318 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", | 1241 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", |
1319 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, | 1242 2 /* ALTERNATIVE_PROXY_USAGE_LOST_RACE */, |
1320 1); | 1243 1); |
1321 } | 1244 } |
1322 | 1245 |
1323 // When preconnect to a H2 supported server, only 1 connection is opened. | 1246 // When preconnect to a H2 supported server, only 1 connection is opened. |
1324 TEST_F(HttpStreamFactoryImplJobControllerTest, | 1247 TEST_F(HttpStreamFactoryImplJobControllerTest, |
1325 PreconnectMultipleStreamsToH2Server) { | 1248 PreconnectMultipleStreamsToH2Server) { |
1326 MockRead reads[] = {MockRead(ASYNC, OK)}; | 1249 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
1327 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); | 1250 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); |
1328 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
1329 | |
1330 SetPreconnect(); | 1251 SetPreconnect(); |
1331 | 1252 |
1332 HttpRequestInfo request_info; | 1253 HttpRequestInfo request_info; |
1333 request_info.method = "GET"; | 1254 request_info.method = "GET"; |
1334 request_info.url = GURL("http://www.example.com"); | 1255 request_info.url = GURL("http://www.example.com"); |
1335 Initialize(request_info); | 1256 Initialize(request_info); |
1336 | 1257 |
1337 url::SchemeHostPort server(request_info.url); | 1258 url::SchemeHostPort server(request_info.url); |
1338 | 1259 |
1339 // Sets server support Http/2. | 1260 // Sets server support Http/2. |
1340 session_->http_server_properties()->SetSupportsSpdy(server, true); | 1261 session_->http_server_properties()->SetSupportsSpdy(server, true); |
1341 | 1262 |
1342 job_controller_->Preconnect(/*num_streams=*/5, request_info, SSLConfig(), | 1263 job_controller_->Preconnect(/*num_streams=*/5); |
1343 SSLConfig()); | |
1344 // Only one job is started. | 1264 // Only one job is started. |
1345 EXPECT_TRUE(job_controller_->main_job()); | 1265 EXPECT_TRUE(job_controller_->main_job()); |
1346 EXPECT_FALSE(job_controller_->alternative_job()); | 1266 EXPECT_FALSE(job_controller_->alternative_job()); |
1347 // There is only 1 connect even though multiple streams were requested. | 1267 // There is only 1 connect even though multiple streams were requested. |
1348 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( | 1268 EXPECT_EQ(1, HttpStreamFactoryImplJobPeer::GetNumStreams( |
1349 job_controller_->main_job())); | 1269 job_controller_->main_job())); |
1350 | 1270 |
1351 base::RunLoop().RunUntilIdle(); | 1271 base::RunLoop().RunUntilIdle(); |
1352 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1272 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
1353 } | 1273 } |
1354 | 1274 |
1355 class HttpStreamFactoryImplJobControllerMisdirectedRequestRetry | 1275 class HttpStreamFactoryImplJobControllerMisdirectedRequestRetry |
1356 : public HttpStreamFactoryImplJobControllerTest, | 1276 : public HttpStreamFactoryImplJobControllerTest, |
1357 public ::testing::WithParamInterface<::testing::tuple<bool, bool>> {}; | 1277 public ::testing::WithParamInterface<::testing::tuple<bool, bool>> {}; |
1358 | 1278 |
1359 INSTANTIATE_TEST_CASE_P( | 1279 INSTANTIATE_TEST_CASE_P( |
1360 /* no prefix */, | 1280 /* no prefix */, |
1361 HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, | 1281 HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, |
1362 ::testing::Combine(::testing::Bool(), ::testing::Bool())); | 1282 ::testing::Combine(::testing::Bool(), ::testing::Bool())); |
1363 | 1283 |
1364 TEST_P(HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, | 1284 TEST_P(HttpStreamFactoryImplJobControllerMisdirectedRequestRetry, |
1365 DisableIPBasedPoolingAndAlternativeServices) { | 1285 DisableIPBasedPoolingAndAlternativeServices) { |
1286 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
1287 tcp_data_->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | |
1288 auto ssl_data = base::MakeUnique<SSLSocketDataProvider>(ASYNC, OK); | |
1289 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl_data.get()); | |
1290 | |
1366 const bool enable_ip_based_pooling = ::testing::get<0>(GetParam()); | 1291 const bool enable_ip_based_pooling = ::testing::get<0>(GetParam()); |
1367 const bool enable_alternative_services = ::testing::get<1>(GetParam()); | 1292 const bool enable_alternative_services = ::testing::get<1>(GetParam()); |
1368 | 1293 |
1369 ProxyConfig proxy_config; | 1294 ProxyConfig proxy_config; |
1370 proxy_config.set_auto_detect(true); | |
1371 // Use asynchronous proxy resolver. | 1295 // Use asynchronous proxy resolver. |
1372 MockAsyncProxyResolverFactory* proxy_resolver_factory = | 1296 MockAsyncProxyResolverFactory* proxy_resolver_factory = |
1373 new MockAsyncProxyResolverFactory(false); | 1297 new MockAsyncProxyResolverFactory(false); |
1374 session_deps_.proxy_service.reset( | 1298 session_deps_.proxy_service.reset( |
1375 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), | 1299 new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
1376 base::WrapUnique(proxy_resolver_factory), nullptr)); | 1300 base::WrapUnique(proxy_resolver_factory), nullptr)); |
1377 HttpRequestInfo request_info; | 1301 HttpRequestInfo request_info; |
1378 request_info.method = "GET"; | 1302 request_info.method = "GET"; |
1379 request_info.url = GURL("https://www.google.com"); | 1303 request_info.url = GURL("https://www.google.com"); |
1380 | 1304 |
1381 if (!enable_ip_based_pooling) | 1305 if (!enable_ip_based_pooling) |
1382 DisableIPBasedPooling(); | 1306 DisableIPBasedPooling(); |
1383 if (!enable_alternative_services) | 1307 if (!enable_alternative_services) |
1384 DisableAlternativeServices(); | 1308 DisableAlternativeServices(); |
1385 | 1309 |
1386 Initialize(request_info); | 1310 Initialize(request_info); |
1387 | 1311 |
1388 url::SchemeHostPort server(request_info.url); | 1312 url::SchemeHostPort server(request_info.url); |
1389 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 1313 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
1390 SetAlternativeService(request_info, alternative_service); | 1314 SetAlternativeService(request_info, alternative_service); |
1315 if (enable_alternative_services) { | |
1316 // Mock out Quic request | |
1317 test::QuicStreamFactoryPeer::SetStreamRequestFactory( | |
1318 session_->quic_stream_factory(), | |
1319 base::MakeUnique<MockQuicStreamRequestFactory>(OK)); | |
1320 } | |
1391 | 1321 |
1392 request_.reset( | 1322 request_.reset( |
1393 job_controller_->Start(request_info, &request_delegate_, nullptr, | 1323 job_controller_->Start(&request_delegate_, nullptr, NetLogWithSource(), |
1394 NetLogWithSource(), HttpStreamRequest::HTTP_STREAM, | 1324 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY)); |
1395 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); | |
1396 EXPECT_TRUE(job_controller_->main_job()); | 1325 EXPECT_TRUE(job_controller_->main_job()); |
1397 if (enable_alternative_services) { | 1326 if (enable_alternative_services) { |
1398 EXPECT_TRUE(job_controller_->alternative_job()); | 1327 EXPECT_TRUE(job_controller_->alternative_job()); |
1399 } else { | 1328 } else { |
1400 EXPECT_FALSE(job_controller_->alternative_job()); | 1329 EXPECT_FALSE(job_controller_->alternative_job()); |
1401 } | 1330 } |
1402 | 1331 |
1403 // |main_job| succeeds and should report status to Request. | 1332 // |main_job| succeeds and should report status to Request. |
1404 HttpStream* http_stream = | 1333 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, _)) |
1405 new HttpBasicStream(base::MakeUnique<ClientSocketHandle>(), false, false); | |
1406 job_factory_.main_job()->SetStream(http_stream); | |
1407 | |
1408 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) | |
1409 .WillOnce(Invoke(DeleteHttpStreamPointer)); | 1334 .WillOnce(Invoke(DeleteHttpStreamPointer)); |
1410 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig()); | 1335 base::RunLoop().RunUntilIdle(); |
1411 } | 1336 } |
1412 | 1337 |
1413 class HttpStreamFactoryImplJobControllerPreconnectTest | 1338 class HttpStreamFactoryImplJobControllerPreconnectTest |
1414 : public HttpStreamFactoryImplJobControllerTest, | 1339 : public HttpStreamFactoryImplJobControllerTest, |
1415 public ::testing::WithParamInterface<bool> { | 1340 public ::testing::WithParamInterface<bool> { |
1416 protected: | 1341 protected: |
1417 void SetUp() override { | 1342 void SetUp() override { |
1418 if (GetParam()) { | 1343 if (GetParam()) { |
1419 scoped_feature_list_.InitFromCommandLine("LimitEarlyPreconnects", | 1344 scoped_feature_list_.InitFromCommandLine("LimitEarlyPreconnects", |
1420 std::string()); | 1345 std::string()); |
1421 } | 1346 } |
1422 } | 1347 } |
1423 | 1348 |
1424 void Initialize() { | 1349 void Initialize() { |
1425 session_deps_.http_server_properties = | 1350 session_deps_.http_server_properties = |
1426 base::MakeUnique<MockHttpServerProperties>(); | 1351 base::MakeUnique<MockHttpServerProperties>(); |
1427 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 1352 session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
1428 factory_ = | 1353 factory_ = |
1429 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); | 1354 static_cast<HttpStreamFactoryImpl*>(session_->http_stream_factory()); |
1430 request_info_.method = "GET"; | 1355 request_info_.method = "GET"; |
1431 request_info_.url = GURL("https://www.example.com"); | 1356 request_info_.url = GURL("https://www.example.com"); |
1432 job_controller_ = new HttpStreamFactoryImpl::JobController( | 1357 job_controller_ = new HttpStreamFactoryImpl::JobController( |
1433 factory_, &request_delegate_, session_.get(), &job_factory_, | 1358 factory_, &request_delegate_, session_.get(), &job_factory_, |
1434 request_info_, /* is_preconnect = */ true, | 1359 request_info_, /* is_preconnect = */ true, |
1435 /* enable_ip_based_pooling = */ true, | 1360 /* enable_ip_based_pooling = */ true, |
1436 /* enable_alternative_services = */ true); | 1361 /* enable_alternative_services = */ true, SSLConfig(), SSLConfig()); |
1437 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); | 1362 HttpStreamFactoryImplPeer::AddJobController(factory_, job_controller_); |
1438 } | 1363 } |
1439 | 1364 |
1440 protected: | 1365 protected: |
1441 void Preconnect(int num_streams) { | 1366 void Preconnect(int num_streams) { |
1442 job_controller_->Preconnect(num_streams, request_info_, SSLConfig(), | 1367 job_controller_->Preconnect(num_streams); |
1443 SSLConfig()); | |
1444 // Only one job is started. | 1368 // Only one job is started. |
1445 EXPECT_TRUE(job_controller_->main_job()); | 1369 EXPECT_TRUE(job_controller_->main_job()); |
1446 EXPECT_FALSE(job_controller_->alternative_job()); | 1370 EXPECT_FALSE(job_controller_->alternative_job()); |
1447 } | 1371 } |
1448 | 1372 |
1449 private: | 1373 private: |
1450 base::test::ScopedFeatureList scoped_feature_list_; | 1374 base::test::ScopedFeatureList scoped_feature_list_; |
1451 HttpRequestInfo request_info_; | 1375 HttpRequestInfo request_info_; |
1452 }; | 1376 }; |
1453 | 1377 |
(...skipping 23 matching lines...) Expand all Loading... | |
1477 Preconnect(kNumPreconects); | 1401 Preconnect(kNumPreconects); |
1478 // If experiment is enabled, only 1 stream is requested. | 1402 // If experiment is enabled, only 1 stream is requested. |
1479 EXPECT_EQ( | 1403 EXPECT_EQ( |
1480 (int)actual_num_connects, | 1404 (int)actual_num_connects, |
1481 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 1405 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
1482 base::RunLoop().RunUntilIdle(); | 1406 base::RunLoop().RunUntilIdle(); |
1483 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 1407 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
1484 } | 1408 } |
1485 | 1409 |
1486 } // namespace net | 1410 } // namespace net |
OLD | NEW |