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

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

Issue 1097773003: Clean up NPN/ALPN-related SSLClientSocket bits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: const Created 5 years, 8 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 const size_t length) { 266 const size_t length) {
267 if (!allow_unconsumed_reads_) { 267 if (!allow_unconsumed_reads_) {
268 EXPECT_TRUE(reads_.empty()) << "Unconsumed read: " << reads_.front().data; 268 EXPECT_TRUE(reads_.empty()) << "Unconsumed read: " << reads_.front().data;
269 } 269 }
270 reads_.push_back(MockRead(ASYNC, data, length)); 270 reads_.push_back(MockRead(ASYNC, data, length));
271 } 271 }
272 272
273 SSLSocketDataProvider::SSLSocketDataProvider(IoMode mode, int result) 273 SSLSocketDataProvider::SSLSocketDataProvider(IoMode mode, int result)
274 : connect(mode, result), 274 : connect(mode, result),
275 next_proto_status(SSLClientSocket::kNextProtoUnsupported), 275 next_proto_status(SSLClientSocket::kNextProtoUnsupported),
276 was_npn_negotiated(false),
277 protocol_negotiated(kProtoUnknown),
278 client_cert_sent(false), 276 client_cert_sent(false),
279 cert_request_info(NULL), 277 cert_request_info(NULL),
280 channel_id_sent(false), 278 channel_id_sent(false),
281 connection_status(0) { 279 connection_status(0) {
282 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_TLS1_2, 280 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_TLS1_2,
283 &connection_status); 281 &connection_status);
284 // Set to TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 282 // Set to TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
285 SSLConnectionStatusSetCipherSuite(0xcc14, &connection_status); 283 SSLConnectionStatusSetCipherSuite(0xcc14, &connection_status);
286 } 284 }
287 285
288 SSLSocketDataProvider::~SSLSocketDataProvider() { 286 SSLSocketDataProvider::~SSLSocketDataProvider() {
289 } 287 }
290 288
291 void SSLSocketDataProvider::SetNextProto(NextProto proto) { 289 void SSLSocketDataProvider::SetNextProto(NextProto proto) {
292 was_npn_negotiated = true;
293 next_proto_status = SSLClientSocket::kNextProtoNegotiated; 290 next_proto_status = SSLClientSocket::kNextProtoNegotiated;
294 protocol_negotiated = proto;
295 next_proto = SSLClientSocket::NextProtoToString(proto); 291 next_proto = SSLClientSocket::NextProtoToString(proto);
296 } 292 }
297 293
298 DelayedSocketData::DelayedSocketData( 294 DelayedSocketData::DelayedSocketData(
299 int write_delay, MockRead* reads, size_t reads_count, 295 int write_delay, MockRead* reads, size_t reads_count,
300 MockWrite* writes, size_t writes_count) 296 MockWrite* writes, size_t writes_count)
301 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), 297 : StaticSocketDataProvider(reads, reads_count, writes, writes_count),
302 write_delay_(write_delay), 298 write_delay_(write_delay),
303 read_in_progress_(false), 299 read_in_progress_(false),
304 weak_factory_(this) { 300 weak_factory_(this) {
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 int MockClientSocket::GetTLSUniqueChannelBinding(std::string* out) { 773 int MockClientSocket::GetTLSUniqueChannelBinding(std::string* out) {
778 out->assign(MockClientSocket::kTlsUnique); 774 out->assign(MockClientSocket::kTlsUnique);
779 return OK; 775 return OK;
780 } 776 }
781 777
782 ChannelIDService* MockClientSocket::GetChannelIDService() const { 778 ChannelIDService* MockClientSocket::GetChannelIDService() const {
783 NOTREACHED(); 779 NOTREACHED();
784 return NULL; 780 return NULL;
785 } 781 }
786 782
787 SSLClientSocket::NextProtoStatus 783 SSLClientSocket::NextProtoStatus MockClientSocket::GetNextProto(
788 MockClientSocket::GetNextProto(std::string* proto) { 784 std::string* proto) const {
789 proto->clear(); 785 proto->clear();
790 return SSLClientSocket::kNextProtoUnsupported; 786 return SSLClientSocket::kNextProtoUnsupported;
791 } 787 }
792 788
793 scoped_refptr<X509Certificate> 789 scoped_refptr<X509Certificate>
794 MockClientSocket::GetUnverifiedServerCertificateChain() const { 790 MockClientSocket::GetUnverifiedServerCertificateChain() const {
795 NOTREACHED(); 791 NOTREACHED();
796 return NULL; 792 return NULL;
797 } 793 }
798 794
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 MockSSLClientSocket::MockSSLClientSocket( 1308 MockSSLClientSocket::MockSSLClientSocket(
1313 scoped_ptr<ClientSocketHandle> transport_socket, 1309 scoped_ptr<ClientSocketHandle> transport_socket,
1314 const HostPortPair& host_port_pair, 1310 const HostPortPair& host_port_pair,
1315 const SSLConfig& ssl_config, 1311 const SSLConfig& ssl_config,
1316 SSLSocketDataProvider* data) 1312 SSLSocketDataProvider* data)
1317 : MockClientSocket( 1313 : MockClientSocket(
1318 // Have to use the right BoundNetLog for LoadTimingInfo regression 1314 // Have to use the right BoundNetLog for LoadTimingInfo regression
1319 // tests. 1315 // tests.
1320 transport_socket->socket()->NetLog()), 1316 transport_socket->socket()->NetLog()),
1321 transport_(transport_socket.Pass()), 1317 transport_(transport_socket.Pass()),
1322 data_(data), 1318 data_(data) {
1323 is_npn_state_set_(false),
1324 new_npn_value_(false),
1325 is_protocol_negotiated_set_(false),
1326 protocol_negotiated_(kProtoUnknown) {
1327 DCHECK(data_); 1319 DCHECK(data_);
1328 peer_addr_ = data->connect.peer_addr; 1320 peer_addr_ = data->connect.peer_addr;
1329 } 1321 }
1330 1322
1331 MockSSLClientSocket::~MockSSLClientSocket() { 1323 MockSSLClientSocket::~MockSSLClientSocket() {
1332 Disconnect(); 1324 Disconnect();
1333 } 1325 }
1334 1326
1335 int MockSSLClientSocket::Read(IOBuffer* buf, int buf_len, 1327 int MockSSLClientSocket::Read(IOBuffer* buf, int buf_len,
1336 const CompletionCallback& callback) { 1328 const CompletionCallback& callback) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 if (data_->cert_request_info) { 1386 if (data_->cert_request_info) {
1395 cert_request_info->host_and_port = 1387 cert_request_info->host_and_port =
1396 data_->cert_request_info->host_and_port; 1388 data_->cert_request_info->host_and_port;
1397 cert_request_info->client_certs = data_->cert_request_info->client_certs; 1389 cert_request_info->client_certs = data_->cert_request_info->client_certs;
1398 } else { 1390 } else {
1399 cert_request_info->Reset(); 1391 cert_request_info->Reset();
1400 } 1392 }
1401 } 1393 }
1402 1394
1403 SSLClientSocket::NextProtoStatus MockSSLClientSocket::GetNextProto( 1395 SSLClientSocket::NextProtoStatus MockSSLClientSocket::GetNextProto(
1404 std::string* proto) { 1396 std::string* proto) const {
1405 *proto = data_->next_proto; 1397 *proto = data_->next_proto;
1406 return data_->next_proto_status; 1398 return data_->next_proto_status;
1407 } 1399 }
1408 1400
1409 bool MockSSLClientSocket::set_was_npn_negotiated(bool negotiated) {
1410 is_npn_state_set_ = true;
1411 return new_npn_value_ = negotiated;
1412 }
1413
1414 bool MockSSLClientSocket::WasNpnNegotiated() const {
1415 if (is_npn_state_set_)
1416 return new_npn_value_;
1417 return data_->was_npn_negotiated;
1418 }
1419
1420 NextProto MockSSLClientSocket::GetNegotiatedProtocol() const {
1421 if (is_protocol_negotiated_set_)
1422 return protocol_negotiated_;
1423 return data_->protocol_negotiated;
1424 }
1425
1426 void MockSSLClientSocket::set_protocol_negotiated(
1427 NextProto protocol_negotiated) {
1428 is_protocol_negotiated_set_ = true;
1429 protocol_negotiated_ = protocol_negotiated;
1430 }
1431
1432 bool MockSSLClientSocket::WasChannelIDSent() const { 1401 bool MockSSLClientSocket::WasChannelIDSent() const {
1433 return data_->channel_id_sent; 1402 return data_->channel_id_sent;
1434 } 1403 }
1435 1404
1436 void MockSSLClientSocket::set_channel_id_sent(bool channel_id_sent) { 1405 void MockSSLClientSocket::set_channel_id_sent(bool channel_id_sent) {
1437 data_->channel_id_sent = channel_id_sent; 1406 data_->channel_id_sent = channel_id_sent;
1438 } 1407 }
1439 1408
1440 ChannelIDService* MockSSLClientSocket::GetChannelIDService() const { 1409 ChannelIDService* MockSSLClientSocket::GetChannelIDService() const {
1441 return data_->channel_id_service; 1410 return data_->channel_id_service;
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 1894
1926 const char kSOCKS5OkRequest[] = 1895 const char kSOCKS5OkRequest[] =
1927 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1896 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
1928 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1897 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
1929 1898
1930 const char kSOCKS5OkResponse[] = 1899 const char kSOCKS5OkResponse[] =
1931 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1900 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
1932 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1901 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
1933 1902
1934 } // namespace net 1903 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698