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

Side by Side Diff: net/socket/ssl_client_socket_pool_unittest.cc

Issue 353713005: Implements new, more robust design for communicating between SSLConnectJobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redesigned tests and fixed various other issues. Created 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_proxy_client_socket_pool.h" 5 #include "net/http/http_proxy_client_socket_pool.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/run_loop.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "net/base/auth.h" 13 #include "net/base/auth.h"
13 #include "net/base/load_timing_info.h" 14 #include "net/base/load_timing_info.h"
14 #include "net/base/load_timing_info_test_util.h" 15 #include "net/base/load_timing_info_test_util.h"
15 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
16 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
17 #include "net/cert/cert_verifier.h" 18 #include "net/cert/cert_verifier.h"
18 #include "net/dns/mock_host_resolver.h" 19 #include "net/dns/mock_host_resolver.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; 223 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_;
223 scoped_ptr<SSLClientSocketPool> pool_; 224 scoped_ptr<SSLClientSocketPool> pool_;
224 }; 225 };
225 226
226 INSTANTIATE_TEST_CASE_P( 227 INSTANTIATE_TEST_CASE_P(
227 NextProto, 228 NextProto,
228 SSLClientSocketPoolTest, 229 SSLClientSocketPoolTest,
229 testing::Values(kProtoDeprecatedSPDY2, 230 testing::Values(kProtoDeprecatedSPDY2,
230 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); 231 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4));
231 232
233 // Make sure that sockets still connect after the leader socket's
234 // connection fails.
235 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsFail) {
236 SSLClientSocketPool::set_enable_connect_job_waiting(true);
237
238 StaticSocketDataProvider data1;
239 StaticSocketDataProvider data2;
240 StaticSocketDataProvider data3;
241 StaticSocketDataProvider data4;
242 StaticSocketDataProvider data5;
243 socket_factory_.AddSocketDataProvider(&data1);
244 socket_factory_.AddSocketDataProvider(&data2);
245 socket_factory_.AddSocketDataProvider(&data3);
246 socket_factory_.AddSocketDataProvider(&data4);
247 socket_factory_.AddSocketDataProvider(&data5);
248 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR);
249 ssl.is_in_session_cache_ = false;
250 ssl.block_in_connect_ = true;
251 SSLSocketDataProvider ssl2(ASYNC, OK);
252 ssl2.is_in_session_cache_ = false;
253 ssl2.block_in_connect_ = true;
254 SSLSocketDataProvider ssl3(ASYNC, OK);
255 ssl3.is_in_session_cache_ = false;
256 SSLSocketDataProvider ssl4(ASYNC, OK);
257 ssl4.is_in_session_cache_ = false;
258 SSLSocketDataProvider ssl5(ASYNC, OK);
259 ssl5.is_in_session_cache_ = false;
260
261 socket_factory_.AddSSLSocketDataProvider(&ssl);
262 socket_factory_.AddSSLSocketDataProvider(&ssl2);
263 socket_factory_.AddSSLSocketDataProvider(&ssl3);
264 socket_factory_.AddSSLSocketDataProvider(&ssl4);
265 socket_factory_.AddSSLSocketDataProvider(&ssl5);
266
267 CreatePool(true, false, false);
268 scoped_refptr<SSLSocketParams> params1 =
269 SSLParams(ProxyServer::SCHEME_DIRECT, false);
270 scoped_refptr<SSLSocketParams> params2 =
271 SSLParams(ProxyServer::SCHEME_DIRECT, false);
272 scoped_refptr<SSLSocketParams> params3 =
273 SSLParams(ProxyServer::SCHEME_DIRECT, false);
274 scoped_refptr<SSLSocketParams> params4 =
275 SSLParams(ProxyServer::SCHEME_DIRECT, false);
276 ClientSocketHandle handle1;
277 ClientSocketHandle handle2;
278 ClientSocketHandle handle3;
279 ClientSocketHandle handle4;
280 TestCompletionCallback callback1;
281 TestCompletionCallback callback2;
282 TestCompletionCallback callback3;
283 TestCompletionCallback callback4;
284 handle1.Init(
285 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog());
286 handle2.Init(
287 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog());
288 handle3.Init(
289 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog());
290 handle4.Init(
291 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog());
292
293 base::RunLoop().RunUntilIdle();
294
295 std::vector<MockSSLClientSocket*> sockets =
296 socket_factory_.GetSSLClientSockets();
297
298 // The first socket's connection should have failed, and no other sockets
299 // should have connected yet.
300 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin();
301 it != sockets.end();
302 ++it) {
303 EXPECT_FALSE((*it)->IsConnectedSSL());
304 }
305
306 // Allow the first socket to resume it's connection process.
307 sockets[0]->Connect(sockets[0]->GetResumptionCallback());
308
309 base::RunLoop().RunUntilIdle();
310
311 // The second socket should have connected.
312 EXPECT_TRUE(sockets[1]->IsConnectedSSL());
313
314 // Allow the second socket to continue its connection.
315 sockets[1]->Connect(sockets[1]->GetResumptionCallback());
316 callback4.WaitForResult();
317
318 // Pending connections should ultimately succeed.
319 for (std::vector<MockSSLClientSocket*>::iterator it = ++sockets.begin();
320 it != sockets.end();
321 ++it) {
322 EXPECT_TRUE((*it)->IsConnectedSSL());
323 }
324 }
325
326 // Make sure that no sockets connect before the "leader" socket,
327 // given that the leader has a successful connection.
328 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsSuccess) {
329 SSLClientSocketPool::set_enable_connect_job_waiting(true);
330
331 StaticSocketDataProvider data1;
332 StaticSocketDataProvider data2;
333 StaticSocketDataProvider data3;
334 socket_factory_.AddSocketDataProvider(&data1);
335 socket_factory_.AddSocketDataProvider(&data2);
336 socket_factory_.AddSocketDataProvider(&data3);
337
338 SSLSocketDataProvider ssl(ASYNC, OK);
339 ssl.is_in_session_cache_ = false;
340 ssl.block_in_connect_ = true;
341 SSLSocketDataProvider ssl2(ASYNC, OK);
342 ssl2.is_in_session_cache_ = false;
343 SSLSocketDataProvider ssl3(ASYNC, OK);
344 ssl3.is_in_session_cache_ = false;
345 socket_factory_.AddSSLSocketDataProvider(&ssl);
346 socket_factory_.AddSSLSocketDataProvider(&ssl2);
347 socket_factory_.AddSSLSocketDataProvider(&ssl3);
348
349 CreatePool(true, false, false);
350
351 scoped_refptr<SSLSocketParams> params1 =
352 SSLParams(ProxyServer::SCHEME_DIRECT, false);
353 scoped_refptr<SSLSocketParams> params2 =
354 SSLParams(ProxyServer::SCHEME_DIRECT, false);
355 scoped_refptr<SSLSocketParams> params3 =
356 SSLParams(ProxyServer::SCHEME_DIRECT, false);
357 ClientSocketHandle handle1;
358 ClientSocketHandle handle2;
359 ClientSocketHandle handle3;
360 TestCompletionCallback callback1;
361 TestCompletionCallback callback2;
362 TestCompletionCallback callback3;
363
364 handle1.Init(
365 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog());
366 handle2.Init(
367 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog());
368 handle3.Init(
369 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog());
370
371 // Allow the connections to proceed until the first socket has finished
372 // connecting.
373 base::RunLoop().RunUntilIdle();
374
375 std::vector<MockSSLClientSocket*> sockets =
376 socket_factory_.GetSSLClientSockets();
377
378 EXPECT_TRUE(sockets[0]->IsConnectedSSL());
379 for (std::vector<MockSSLClientSocket*>::iterator it = ++sockets.begin();
380 it != sockets.end();
381 ++it) {
382 EXPECT_FALSE((*it)->IsConnectedSSL());
383 }
384
385 sockets[0]->Connect(sockets[0]->GetResumptionCallback());
386
387 callback3.WaitForResult();
388
389 EXPECT_TRUE(handle1.socket()->IsConnected());
390 EXPECT_TRUE(handle2.socket()->IsConnected());
391 EXPECT_TRUE(handle3.socket()->IsConnected());
392 }
393
232 TEST_P(SSLClientSocketPoolTest, TCPFail) { 394 TEST_P(SSLClientSocketPoolTest, TCPFail) {
233 StaticSocketDataProvider data; 395 StaticSocketDataProvider data;
234 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); 396 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED));
235 socket_factory_.AddSocketDataProvider(&data); 397 socket_factory_.AddSocketDataProvider(&data);
236 398
237 CreatePool(true /* tcp pool */, false, false); 399 CreatePool(true /* tcp pool */, false, false);
238 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, 400 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT,
239 false); 401 false);
240 402
241 ClientSocketHandle handle; 403 ClientSocketHandle handle;
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 ssl.channel_id_sent = true; 1091 ssl.channel_id_sent = true;
930 ssl.SetNextProto(GetParam()); 1092 ssl.SetNextProto(GetParam());
931 TestIPPoolingDisabled(&ssl); 1093 TestIPPoolingDisabled(&ssl);
932 } 1094 }
933 1095
934 // It would be nice to also test the timeouts in SSLClientSocketPool. 1096 // It would be nice to also test the timeouts in SSLClientSocketPool.
935 1097
936 } // namespace 1098 } // namespace
937 1099
938 } // namespace net 1100 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698