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

Side by Side Diff: net/socket/socket_test_util.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: Added checks to determine if false start connections fail, and moved location of enable_job_waiting… 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/socket/socket_test_util.h" 5 #include "net/socket/socket_test_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 return; 646 return;
647 } 647 }
648 DCHECK_EQ(read, reads_count); 648 DCHECK_EQ(read, reads_count);
649 DCHECK_EQ(write, writes_count); 649 DCHECK_EQ(write, writes_count);
650 } 650 }
651 651
652 MockClientSocketFactory::MockClientSocketFactory() {} 652 MockClientSocketFactory::MockClientSocketFactory() {}
653 653
654 MockClientSocketFactory::~MockClientSocketFactory() {} 654 MockClientSocketFactory::~MockClientSocketFactory() {}
655 655
656 bool MockClientSocketFactory::leader_connected_ = false;
657
656 void MockClientSocketFactory::AddSocketDataProvider( 658 void MockClientSocketFactory::AddSocketDataProvider(
657 SocketDataProvider* data) { 659 SocketDataProvider* data) {
658 mock_data_.Add(data); 660 mock_data_.Add(data);
659 } 661 }
660 662
661 void MockClientSocketFactory::AddSSLSocketDataProvider( 663 void MockClientSocketFactory::AddSSLSocketDataProvider(
662 SSLSocketDataProvider* data) { 664 SSLSocketDataProvider* data) {
663 mock_ssl_data_.Add(data); 665 mock_ssl_data_.Add(data);
664 } 666 }
665 667
666 void MockClientSocketFactory::ResetNextMockIndexes() { 668 void MockClientSocketFactory::ResetNextMockIndexes() {
667 mock_data_.ResetNextIndex(); 669 mock_data_.ResetNextIndex();
668 mock_ssl_data_.ResetNextIndex(); 670 mock_ssl_data_.ResetNextIndex();
669 } 671 }
670 672
673 void MockClientSocketFactory::LeaderConnected() {
674 leader_connected_ = true;
675 }
676
677 bool MockClientSocketFactory::IsLeaderConnected() {
678 return leader_connected_;
679 }
680
671 scoped_ptr<DatagramClientSocket> 681 scoped_ptr<DatagramClientSocket>
672 MockClientSocketFactory::CreateDatagramClientSocket( 682 MockClientSocketFactory::CreateDatagramClientSocket(
673 DatagramSocket::BindType bind_type, 683 DatagramSocket::BindType bind_type,
674 const RandIntCallback& rand_int_cb, 684 const RandIntCallback& rand_int_cb,
675 net::NetLog* net_log, 685 net::NetLog* net_log,
676 const net::NetLog::Source& source) { 686 const net::NetLog::Source& source) {
677 SocketDataProvider* data_provider = mock_data_.GetNext(); 687 SocketDataProvider* data_provider = mock_data_.GetNext();
678 scoped_ptr<MockUDPClientSocket> socket( 688 scoped_ptr<MockUDPClientSocket> socket(
679 new MockUDPClientSocket(data_provider, net_log)); 689 new MockUDPClientSocket(data_provider, net_log));
680 data_provider->set_socket(socket.get()); 690 data_provider->set_socket(socket.get());
(...skipping 11 matching lines...) Expand all
692 new MockTCPClientSocket(addresses, net_log, data_provider)); 702 new MockTCPClientSocket(addresses, net_log, data_provider));
693 data_provider->set_socket(socket.get()); 703 data_provider->set_socket(socket.get());
694 return socket.PassAs<StreamSocket>(); 704 return socket.PassAs<StreamSocket>();
695 } 705 }
696 706
697 scoped_ptr<SSLClientSocket> MockClientSocketFactory::CreateSSLClientSocket( 707 scoped_ptr<SSLClientSocket> MockClientSocketFactory::CreateSSLClientSocket(
698 scoped_ptr<ClientSocketHandle> transport_socket, 708 scoped_ptr<ClientSocketHandle> transport_socket,
699 const HostPortPair& host_and_port, 709 const HostPortPair& host_and_port,
700 const SSLConfig& ssl_config, 710 const SSLConfig& ssl_config,
701 const SSLClientSocketContext& context) { 711 const SSLClientSocketContext& context) {
702 return scoped_ptr<SSLClientSocket>( 712 scoped_ptr<MockSSLClientSocket> socket(
703 new MockSSLClientSocket(transport_socket.Pass(), 713 new MockSSLClientSocket(transport_socket.Pass(),
704 host_and_port, ssl_config, 714 host_and_port,
715 ssl_config,
705 mock_ssl_data_.GetNext())); 716 mock_ssl_data_.GetNext()));
717 ssl_client_sockets_.push_back(socket.get());
718 return socket.PassAs<SSLClientSocket>();
706 } 719 }
707 720
708 void MockClientSocketFactory::ClearSSLSessionCache() { 721 void MockClientSocketFactory::ClearSSLSessionCache() {
709 } 722 }
710 723
724 std::vector<MockSSLClientSocket*>
725 MockClientSocketFactory::GetSSLClientSockets() {
726 return ssl_client_sockets_;
727 }
728
711 const char MockClientSocket::kTlsUnique[] = "MOCK_TLSUNIQ"; 729 const char MockClientSocket::kTlsUnique[] = "MOCK_TLSUNIQ";
712 730
713 MockClientSocket::MockClientSocket(const BoundNetLog& net_log) 731 MockClientSocket::MockClientSocket(const BoundNetLog& net_log)
714 : connected_(false), 732 : connected_(false),
715 net_log_(net_log), 733 net_log_(net_log),
716 weak_factory_(this) { 734 weak_factory_(this) {
717 IPAddressNumber ip; 735 IPAddressNumber ip;
718 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); 736 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip));
719 peer_addr_ = IPEndPoint(ip, 0); 737 peer_addr_ = IPEndPoint(ip, 0);
720 } 738 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 } 773 }
756 774
757 const BoundNetLog& MockClientSocket::NetLog() const { 775 const BoundNetLog& MockClientSocket::NetLog() const {
758 return net_log_; 776 return net_log_;
759 } 777 }
760 778
761 void MockClientSocket::GetSSLCertRequestInfo( 779 void MockClientSocket::GetSSLCertRequestInfo(
762 SSLCertRequestInfo* cert_request_info) { 780 SSLCertRequestInfo* cert_request_info) {
763 } 781 }
764 782
783 bool MockClientSocket::InSessionCache() const {
784 return false;
785 }
786
787 void MockClientSocket::WatchSessionForCompletion(
788 const base::Closure& cb) const {
789 }
790
791 void MockClientSocket::SetSocketFailureCallback(const base::Closure& cb) {
792 }
793
794 void MockClientSocket::OnSocketFailure() {
795 }
796
765 int MockClientSocket::ExportKeyingMaterial(const base::StringPiece& label, 797 int MockClientSocket::ExportKeyingMaterial(const base::StringPiece& label,
766 bool has_context, 798 bool has_context,
767 const base::StringPiece& context, 799 const base::StringPiece& context,
768 unsigned char* out, 800 unsigned char* out,
769 unsigned int outlen) { 801 unsigned int outlen) {
770 memset(out, 'A', outlen); 802 memset(out, 'A', outlen);
771 return OK; 803 return OK;
772 } 804 }
773 805
774 int MockClientSocket::GetTLSUniqueChannelBinding(std::string* out) { 806 int MockClientSocket::GetTLSUniqueChannelBinding(std::string* out) {
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 ssl_client_socket->connected_ = true; 1339 ssl_client_socket->connected_ = true;
1308 callback.Run(rv); 1340 callback.Run(rv);
1309 } 1341 }
1310 1342
1311 MockSSLClientSocket::MockSSLClientSocket( 1343 MockSSLClientSocket::MockSSLClientSocket(
1312 scoped_ptr<ClientSocketHandle> transport_socket, 1344 scoped_ptr<ClientSocketHandle> transport_socket,
1313 const HostPortPair& host_port_pair, 1345 const HostPortPair& host_port_pair,
1314 const SSLConfig& ssl_config, 1346 const SSLConfig& ssl_config,
1315 SSLSocketDataProvider* data) 1347 SSLSocketDataProvider* data)
1316 : MockClientSocket( 1348 : MockClientSocket(
1317 // Have to use the right BoundNetLog for LoadTimingInfo regression 1349 // Have to use the right BoundNetLog for LoadTimingInfo regression
1318 // tests. 1350 // tests.
1319 transport_socket->socket()->NetLog()), 1351 transport_socket->socket()->NetLog()),
1352 process_pending_jobs_callback_(
1353 base::Bind(&SSLConnectJobMessenger::OnJobSucceeded,
1354 base::Unretained(new SSLConnectJobMessenger))),
1320 transport_(transport_socket.Pass()), 1355 transport_(transport_socket.Pass()),
1321 data_(data), 1356 data_(data),
1322 is_npn_state_set_(false), 1357 is_npn_state_set_(false),
1323 new_npn_value_(false), 1358 new_npn_value_(false),
1324 is_protocol_negotiated_set_(false), 1359 is_protocol_negotiated_set_(false),
1325 protocol_negotiated_(kProtoUnknown) { 1360 protocol_negotiated_(kProtoUnknown) {
1326 DCHECK(data_); 1361 DCHECK(data_);
1327 peer_addr_ = data->connect.peer_addr; 1362 peer_addr_ = data->connect.peer_addr;
1328 } 1363 }
1329 1364
1330 MockSSLClientSocket::~MockSSLClientSocket() { 1365 MockSSLClientSocket::~MockSSLClientSocket() {
1331 Disconnect(); 1366 Disconnect();
1332 } 1367 }
1333 1368
1334 int MockSSLClientSocket::Read(IOBuffer* buf, int buf_len, 1369 int MockSSLClientSocket::Read(IOBuffer* buf, int buf_len,
1335 const CompletionCallback& callback) { 1370 const CompletionCallback& callback) {
1336 return transport_->socket()->Read(buf, buf_len, callback); 1371 return transport_->socket()->Read(buf, buf_len, callback);
1337 } 1372 }
1338 1373
1339 int MockSSLClientSocket::Write(IOBuffer* buf, int buf_len, 1374 int MockSSLClientSocket::Write(IOBuffer* buf, int buf_len,
1340 const CompletionCallback& callback) { 1375 const CompletionCallback& callback) {
1341 return transport_->socket()->Write(buf, buf_len, callback); 1376 return transport_->socket()->Write(buf, buf_len, callback);
1342 } 1377 }
1343 1378
1344 int MockSSLClientSocket::Connect(const CompletionCallback& callback) { 1379 int MockSSLClientSocket::Connect(const CompletionCallback& callback) {
1380 if (SSLConnectJob::GetEnableJobWaiting()) {
1381 // The socket should only be starting to connect if the leader has already
1382 // connected -- unless the socket is the leader.
1383 if (!MockClientSocketFactory::IsLeaderConnected())
1384 good_ordering_ = false;
1385 else
1386 good_ordering_ = true;
1387 }
1345 int rv = transport_->socket()->Connect( 1388 int rv = transport_->socket()->Connect(
1346 base::Bind(&ConnectCallback, base::Unretained(this), callback)); 1389 base::Bind(&ConnectCallback, base::Unretained(this), callback));
1347 if (rv == OK) { 1390 if (rv == OK) {
1391 if (SSLConnectJob::GetEnableJobWaiting()) {
1392 if (data_->is_leader_) {
1393 good_ordering_ = true;
1394 MockClientSocketFactory::LeaderConnected();
1395 }
1396 process_pending_jobs_callback_.Run();
1397 }
1348 if (data_->connect.result == OK) 1398 if (data_->connect.result == OK)
1349 connected_ = true; 1399 connected_ = true;
1350 if (data_->connect.mode == ASYNC) { 1400 if (data_->connect.mode == ASYNC) {
1351 RunCallbackAsync(callback, data_->connect.result); 1401 RunCallbackAsync(callback, data_->connect.result);
1352 return ERR_IO_PENDING; 1402 return ERR_IO_PENDING;
1353 } 1403 }
1354 return data_->connect.result; 1404 return data_->connect.result;
1355 } 1405 }
1356 return rv; 1406 return rv;
1357 } 1407 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 DCHECK(cert_request_info); 1442 DCHECK(cert_request_info);
1393 if (data_->cert_request_info) { 1443 if (data_->cert_request_info) {
1394 cert_request_info->host_and_port = 1444 cert_request_info->host_and_port =
1395 data_->cert_request_info->host_and_port; 1445 data_->cert_request_info->host_and_port;
1396 cert_request_info->client_certs = data_->cert_request_info->client_certs; 1446 cert_request_info->client_certs = data_->cert_request_info->client_certs;
1397 } else { 1447 } else {
1398 cert_request_info->Reset(); 1448 cert_request_info->Reset();
1399 } 1449 }
1400 } 1450 }
1401 1451
1452 bool MockSSLClientSocket::InSessionCache() const {
1453 if (data_->is_in_session_cache_)
1454 return true;
1455 return false;
wtc 2014/07/08 01:25:41 This is simply return data_->is_in_session_cache
mshelley 2014/07/09 19:50:59 Done.
1456 }
1457
1458 void MockSSLClientSocket::WatchSessionForCompletion(
1459 const base::Closure& cb) const {
1460 process_pending_jobs_callback_ = cb;
1461 }
1462
1463 void MockSSLClientSocket::SetSocketFailureCallback(const base::Closure& cb) {
1464 }
1465
1466 void MockSSLClientSocket::OnSocketFailure() {
1467 }
1468
1402 SSLClientSocket::NextProtoStatus MockSSLClientSocket::GetNextProto( 1469 SSLClientSocket::NextProtoStatus MockSSLClientSocket::GetNextProto(
1403 std::string* proto, std::string* server_protos) { 1470 std::string* proto, std::string* server_protos) {
1404 *proto = data_->next_proto; 1471 *proto = data_->next_proto;
1405 *server_protos = data_->server_protos; 1472 *server_protos = data_->server_protos;
1406 return data_->next_proto_status; 1473 return data_->next_proto_status;
1407 } 1474 }
1408 1475
1409 bool MockSSLClientSocket::set_was_npn_negotiated(bool negotiated) { 1476 bool MockSSLClientSocket::set_was_npn_negotiated(bool negotiated) {
1410 is_npn_state_set_ = true; 1477 is_npn_state_set_ = true;
1411 return new_npn_value_ = negotiated; 1478 return new_npn_value_ = negotiated;
(...skipping 22 matching lines...) Expand all
1434 } 1501 }
1435 1502
1436 void MockSSLClientSocket::set_channel_id_sent(bool channel_id_sent) { 1503 void MockSSLClientSocket::set_channel_id_sent(bool channel_id_sent) {
1437 data_->channel_id_sent = channel_id_sent; 1504 data_->channel_id_sent = channel_id_sent;
1438 } 1505 }
1439 1506
1440 ServerBoundCertService* MockSSLClientSocket::GetServerBoundCertService() const { 1507 ServerBoundCertService* MockSSLClientSocket::GetServerBoundCertService() const {
1441 return data_->server_bound_cert_service; 1508 return data_->server_bound_cert_service;
1442 } 1509 }
1443 1510
1511 bool MockSSLClientSocket::IsGoodOrdering() const {
1512 return good_ordering_;
1513 }
1514
1444 void MockSSLClientSocket::OnReadComplete(const MockRead& data) { 1515 void MockSSLClientSocket::OnReadComplete(const MockRead& data) {
1445 NOTIMPLEMENTED(); 1516 NOTIMPLEMENTED();
1446 } 1517 }
1447 1518
1448 void MockSSLClientSocket::OnConnectComplete(const MockConnect& data) { 1519 void MockSSLClientSocket::OnConnectComplete(const MockConnect& data) {
1449 NOTIMPLEMENTED(); 1520 NOTIMPLEMENTED();
1450 } 1521 }
1451 1522
1452 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data, 1523 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data,
1453 net::NetLog* net_log) 1524 net::NetLog* net_log)
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 1977
1907 const char kSOCKS5OkRequest[] = 1978 const char kSOCKS5OkRequest[] =
1908 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1979 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
1909 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1980 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
1910 1981
1911 const char kSOCKS5OkResponse[] = 1982 const char kSOCKS5OkResponse[] =
1912 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1983 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
1913 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1984 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
1914 1985
1915 } // namespace net 1986 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698