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

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

Issue 2093873002: Unwind fallback metrics and SSLFailureState. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_stream_factory_impl_job_controller.h" 5 #include "net/http/http_stream_factory_impl_job_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "net/http/http_basic_stream.h" 9 #include "net/http/http_basic_stream.h"
10 #include "net/http/http_stream_factory_impl_request.h" 10 #include "net/http/http_stream_factory_impl_request.h"
11 #include "net/http/http_stream_factory_test_util.h" 11 #include "net/http/http_stream_factory_test_util.h"
12 #include "net/proxy/proxy_info.h" 12 #include "net/proxy/proxy_info.h"
13 #include "net/proxy/proxy_service.h" 13 #include "net/proxy/proxy_service.h"
14 #include "net/spdy/spdy_test_util_common.h" 14 #include "net/spdy/spdy_test_util_common.h"
15 #include "net/ssl/ssl_failure_state.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 using ::testing::_; 17 using ::testing::_;
19 using ::testing::Invoke; 18 using ::testing::Invoke;
20 19
21 namespace net { 20 namespace net {
22 21
23 namespace { 22 namespace {
24 23
25 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config, 24 void DeleteHttpStreamPointer(const SSLConfig& used_ssl_config,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 78
80 request_.reset( 79 request_.reset(
81 job_controller_->Start(request_info, &request_delegate_, nullptr, 80 job_controller_->Start(request_info, &request_delegate_, nullptr,
82 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 81 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
83 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 82 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
84 83
85 EXPECT_TRUE(job_controller_->main_job()); 84 EXPECT_TRUE(job_controller_->main_job());
86 85
87 // There's no other alternative job. Thus when stream failed, it should 86 // There's no other alternative job. Thus when stream failed, it should
88 // notify Request of the stream failure. 87 // notify Request of the stream failure.
89 EXPECT_CALL(request_delegate_, 88 EXPECT_CALL(request_delegate_, OnStreamFailed(ERR_FAILED, _)).Times(1);
90 OnStreamFailed(ERR_FAILED, _, SSL_FAILURE_NONE))
91 .Times(1);
92 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 89 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
93 SSLConfig(), SSL_FAILURE_NONE); 90 SSLConfig());
94 } 91 }
95 92
96 TEST_P(HttpStreamFactoryImplJobControllerTest, 93 TEST_P(HttpStreamFactoryImplJobControllerTest,
97 OnStreamReadyWithNoAlternativeJob) { 94 OnStreamReadyWithNoAlternativeJob) {
98 HttpRequestInfo request_info; 95 HttpRequestInfo request_info;
99 request_info.method = "GET"; 96 request_info.method = "GET";
100 request_info.url = GURL("http://www.google.com"); 97 request_info.url = GURL("http://www.google.com");
101 98
102 request_.reset( 99 request_.reset(
103 job_controller_->Start(request_info, &request_delegate_, nullptr, 100 job_controller_->Start(request_info, &request_delegate_, nullptr,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 request_.reset( 151 request_.reset(
155 job_controller_->Start(request_info, &request_delegate_, nullptr, 152 job_controller_->Start(request_info, &request_delegate_, nullptr,
156 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 153 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
157 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 154 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
158 EXPECT_TRUE(job_controller_->main_job()); 155 EXPECT_TRUE(job_controller_->main_job());
159 EXPECT_TRUE(job_controller_->alternative_job()); 156 EXPECT_TRUE(job_controller_->alternative_job());
160 157
161 // We have the main job with unknown status when the alternative job is failed 158 // We have the main job with unknown status when the alternative job is failed
162 // thus should not notify Request of the alternative job's failure. But should 159 // thus should not notify Request of the alternative job's failure. But should
163 // notify the main job to mark the alternative job failed. 160 // notify the main job to mark the alternative job failed.
164 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); 161 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
165 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1); 162 EXPECT_CALL(*job_factory_.main_job(), MarkOtherJobComplete(_)).Times(1);
166 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, 163 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED,
167 SSLConfig(), SSL_FAILURE_NONE); 164 SSLConfig());
168 EXPECT_TRUE(!job_controller_->alternative_job()); 165 EXPECT_TRUE(!job_controller_->alternative_job());
169 EXPECT_TRUE(job_controller_->main_job()); 166 EXPECT_TRUE(job_controller_->main_job());
170 167
171 // The failure of second Job should be reported to Request as there's no more 168 // The failure of second Job should be reported to Request as there's no more
172 // pending Job to serve the Request. 169 // pending Job to serve the Request.
173 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, SSL_FAILURE_UNKNOWN)) 170 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(1);
174 .Times(1);
175 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 171 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
176 SSLConfig(), SSL_FAILURE_UNKNOWN); 172 SSLConfig());
177 } 173 }
178 174
179 TEST_P(HttpStreamFactoryImplJobControllerTest, 175 TEST_P(HttpStreamFactoryImplJobControllerTest,
180 SecondJobFailsAfterFirstJobSucceeds) { 176 SecondJobFailsAfterFirstJobSucceeds) {
181 HttpRequestInfo request_info; 177 HttpRequestInfo request_info;
182 request_info.method = "GET"; 178 request_info.method = "GET";
183 request_info.url = GURL("https://www.google.com"); 179 request_info.url = GURL("https://www.google.com");
184 180
185 url::SchemeHostPort server(request_info.url); 181 url::SchemeHostPort server(request_info.url);
186 AlternativeService alternative_service(QUIC, server.host(), 443); 182 AlternativeService alternative_service(QUIC, server.host(), 443);
(...skipping 15 matching lines...) Expand all
202 198
203 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 199 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
204 .WillOnce(Invoke(DeleteHttpStreamPointer)); 200 .WillOnce(Invoke(DeleteHttpStreamPointer));
205 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) 201 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_))
206 .Times(1); 202 .Times(1);
207 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(), 203 job_controller_->OnStreamReady(job_factory_.main_job(), SSLConfig(),
208 ProxyInfo()); 204 ProxyInfo());
209 205
210 // JobController shouldn't report the status of second job as request 206 // JobController shouldn't report the status of second job as request
211 // is already successfully served. 207 // is already successfully served.
212 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); 208 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
213 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED, 209 job_controller_->OnStreamFailed(job_factory_.alternative_job(), ERR_FAILED,
214 SSLConfig(), SSL_FAILURE_NONE); 210 SSLConfig());
215 211
216 // Reset the request as it's been successfully served. 212 // Reset the request as it's been successfully served.
217 request_.reset(); 213 request_.reset();
218 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 214 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
219 } 215 }
220 216
221 TEST_P(HttpStreamFactoryImplJobControllerTest, 217 TEST_P(HttpStreamFactoryImplJobControllerTest,
222 SecondJobSucceedsAfterFirstJobFailed) { 218 SecondJobSucceedsAfterFirstJobFailed) {
223 HttpRequestInfo request_info; 219 HttpRequestInfo request_info;
224 request_info.method = "GET"; 220 request_info.method = "GET";
225 request_info.url = GURL("https://www.google.com"); 221 request_info.url = GURL("https://www.google.com");
226 222
227 url::SchemeHostPort server(request_info.url); 223 url::SchemeHostPort server(request_info.url);
228 AlternativeService alternative_service(QUIC, server.host(), 443); 224 AlternativeService alternative_service(QUIC, server.host(), 443);
229 SetAlternativeService(request_info, alternative_service); 225 SetAlternativeService(request_info, alternative_service);
230 226
231 request_.reset( 227 request_.reset(
232 job_controller_->Start(request_info, &request_delegate_, nullptr, 228 job_controller_->Start(request_info, &request_delegate_, nullptr,
233 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 229 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
234 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 230 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
235 EXPECT_TRUE(job_controller_->main_job()); 231 EXPECT_TRUE(job_controller_->main_job());
236 EXPECT_TRUE(job_controller_->alternative_job()); 232 EXPECT_TRUE(job_controller_->alternative_job());
237 233
238 // |main_job| fails but should not report status to Request. 234 // |main_job| fails but should not report status to Request.
239 // The alternative job will mark the main job complete. 235 // The alternative job will mark the main job complete.
240 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); 236 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
241 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) 237 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_))
242 .Times(1); 238 .Times(1);
243 239
244 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 240 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
245 SSLConfig(), SSL_FAILURE_NONE); 241 SSLConfig());
246 242
247 // |alternative_job| succeeds and should report status to Request. 243 // |alternative_job| succeeds and should report status to Request.
248 HttpStream* http_stream = 244 HttpStream* http_stream =
249 new HttpBasicStream(new ClientSocketHandle(), false); 245 new HttpBasicStream(new ClientSocketHandle(), false);
250 job_factory_.alternative_job()->SetStream(http_stream); 246 job_factory_.alternative_job()->SetStream(http_stream);
251 247
252 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 248 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
253 .WillOnce(Invoke(DeleteHttpStreamPointer)); 249 .WillOnce(Invoke(DeleteHttpStreamPointer));
254 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), 250 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(),
255 ProxyInfo()); 251 ProxyInfo());
(...skipping 12 matching lines...) Expand all
268 264
269 request_.reset( 265 request_.reset(
270 job_controller_->Start(request_info, &request_delegate_, nullptr, 266 job_controller_->Start(request_info, &request_delegate_, nullptr,
271 BoundNetLog(), HttpStreamRequest::HTTP_STREAM, 267 BoundNetLog(), HttpStreamRequest::HTTP_STREAM,
272 DEFAULT_PRIORITY, SSLConfig(), SSLConfig())); 268 DEFAULT_PRIORITY, SSLConfig(), SSLConfig()));
273 EXPECT_TRUE(job_controller_->main_job()); 269 EXPECT_TRUE(job_controller_->main_job());
274 EXPECT_TRUE(job_controller_->alternative_job()); 270 EXPECT_TRUE(job_controller_->alternative_job());
275 271
276 // |main_job| fails but should not report status to Request. 272 // |main_job| fails but should not report status to Request.
277 // The alternative job will mark the main job complete. 273 // The alternative job will mark the main job complete.
278 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _, _)).Times(0); 274 EXPECT_CALL(request_delegate_, OnStreamFailed(_, _)).Times(0);
279 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_)) 275 EXPECT_CALL(*job_factory_.alternative_job(), MarkOtherJobComplete(_))
280 .Times(1); 276 .Times(1);
281 277
282 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED, 278 job_controller_->OnStreamFailed(job_factory_.main_job(), ERR_FAILED,
283 SSLConfig(), SSL_FAILURE_NONE); 279 SSLConfig());
284 280
285 // Controller should use alternative job to get load state. 281 // Controller should use alternative job to get load state.
286 job_controller_->GetLoadState(); 282 job_controller_->GetLoadState();
287 283
288 // |alternative_job| succeeds and should report status to Request. 284 // |alternative_job| succeeds and should report status to Request.
289 HttpStream* http_stream = 285 HttpStream* http_stream =
290 new HttpBasicStream(new ClientSocketHandle(), false); 286 new HttpBasicStream(new ClientSocketHandle(), false);
291 job_factory_.alternative_job()->SetStream(http_stream); 287 job_factory_.alternative_job()->SetStream(http_stream);
292 288
293 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream)) 289 EXPECT_CALL(request_delegate_, OnStreamReady(_, _, http_stream))
294 .WillOnce(Invoke(DeleteHttpStreamPointer)); 290 .WillOnce(Invoke(DeleteHttpStreamPointer));
295 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(), 291 job_controller_->OnStreamReady(job_factory_.alternative_job(), SSLConfig(),
296 ProxyInfo()); 292 ProxyInfo());
297 } 293 }
298 294
299 } // namespace net 295 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698