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

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

Issue 454513002: This CL is a follow up to https://codereview.chromium.org/353713005. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed formatting change Created 6 years, 4 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
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/socket/ssl_client_socket_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
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), 276 was_npn_negotiated(false),
277 protocol_negotiated(kProtoUnknown), 277 protocol_negotiated(kProtoUnknown),
278 client_cert_sent(false), 278 client_cert_sent(false),
279 cert_request_info(NULL), 279 cert_request_info(NULL),
280 channel_id_sent(false), 280 channel_id_sent(false),
281 connection_status(0), 281 connection_status(0),
282 should_block_on_connect(false), 282 should_pause_on_connect(false),
283 is_in_session_cache(false) { 283 is_in_session_cache(false) {
284 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_TLS1_2, 284 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_TLS1_2,
285 &connection_status); 285 &connection_status);
286 // Set to TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 286 // Set to TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305
287 SSLConnectionStatusSetCipherSuite(0xcc14, &connection_status); 287 SSLConnectionStatusSetCipherSuite(0xcc14, &connection_status);
288 } 288 }
289 289
290 SSLSocketDataProvider::~SSLSocketDataProvider() { 290 SSLSocketDataProvider::~SSLSocketDataProvider() {
291 } 291 }
292 292
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 const CompletionCallback& callback) { 1342 const CompletionCallback& callback) {
1343 return transport_->socket()->Read(buf, buf_len, callback); 1343 return transport_->socket()->Read(buf, buf_len, callback);
1344 } 1344 }
1345 1345
1346 int MockSSLClientSocket::Write(IOBuffer* buf, int buf_len, 1346 int MockSSLClientSocket::Write(IOBuffer* buf, int buf_len,
1347 const CompletionCallback& callback) { 1347 const CompletionCallback& callback) {
1348 return transport_->socket()->Write(buf, buf_len, callback); 1348 return transport_->socket()->Write(buf, buf_len, callback);
1349 } 1349 }
1350 1350
1351 int MockSSLClientSocket::Connect(const CompletionCallback& callback) { 1351 int MockSSLClientSocket::Connect(const CompletionCallback& callback) {
1352 next_connect_state_ = STATE_TRANSPORT_CONNECT; 1352 next_connect_state_ = STATE_SSL_CONNECT;
1353 reached_connect_ = true; 1353 reached_connect_ = true;
1354 int rv = DoConnectLoop(OK); 1354 int rv = DoConnectLoop(OK);
1355 if (rv == ERR_IO_PENDING) 1355 if (rv == ERR_IO_PENDING)
1356 connect_callback_ = callback; 1356 connect_callback_ = callback;
1357 return rv; 1357 return rv;
1358 } 1358 }
1359 1359
1360 void MockSSLClientSocket::Disconnect() { 1360 void MockSSLClientSocket::Disconnect() {
1361 weak_factory_.InvalidateWeakPtrs(); 1361 weak_factory_.InvalidateWeakPtrs();
1362 MockClientSocket::Disconnect(); 1362 MockClientSocket::Disconnect();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 1453
1454 void MockSSLClientSocket::OnReadComplete(const MockRead& data) { 1454 void MockSSLClientSocket::OnReadComplete(const MockRead& data) {
1455 NOTIMPLEMENTED(); 1455 NOTIMPLEMENTED();
1456 } 1456 }
1457 1457
1458 void MockSSLClientSocket::OnConnectComplete(const MockConnect& data) { 1458 void MockSSLClientSocket::OnConnectComplete(const MockConnect& data) {
1459 NOTIMPLEMENTED(); 1459 NOTIMPLEMENTED();
1460 } 1460 }
1461 1461
1462 void MockSSLClientSocket::RestartPausedConnect() { 1462 void MockSSLClientSocket::RestartPausedConnect() {
1463 DCHECK(data_->should_block_on_connect); 1463 DCHECK(data_->should_pause_on_connect);
1464 DCHECK_EQ(next_connect_state_, STATE_SSL_CONNECT_COMPLETE); 1464 DCHECK_EQ(next_connect_state_, STATE_SSL_CONNECT_COMPLETE);
1465 OnIOComplete(data_->connect.result); 1465 OnIOComplete(data_->connect.result);
1466 } 1466 }
1467 1467
1468 void MockSSLClientSocket::OnIOComplete(int result) { 1468 void MockSSLClientSocket::OnIOComplete(int result) {
1469 int rv = DoConnectLoop(result); 1469 int rv = DoConnectLoop(result);
1470 if (rv != ERR_IO_PENDING) 1470 if (rv != ERR_IO_PENDING)
1471 base::ResetAndReturn(&connect_callback_).Run(rv); 1471 base::ResetAndReturn(&connect_callback_).Run(rv);
1472 } 1472 }
1473 1473
1474 int MockSSLClientSocket::DoConnectLoop(int result) { 1474 int MockSSLClientSocket::DoConnectLoop(int result) {
1475 DCHECK_NE(next_connect_state_, STATE_NONE); 1475 DCHECK_NE(next_connect_state_, STATE_NONE);
1476 1476
1477 int rv = result; 1477 int rv = result;
1478 do { 1478 do {
1479 ConnectState state = next_connect_state_; 1479 ConnectState state = next_connect_state_;
1480 next_connect_state_ = STATE_NONE; 1480 next_connect_state_ = STATE_NONE;
1481 switch (state) { 1481 switch (state) {
1482 case STATE_TRANSPORT_CONNECT:
1483 rv = DoTransportConnect();
1484 break;
1485 case STATE_TRANSPORT_CONNECT_COMPLETE:
1486 rv = DoTransportConnectComplete(rv);
1487 break;
1488 case STATE_SSL_CONNECT: 1482 case STATE_SSL_CONNECT:
1489 rv = DoSSLConnect(); 1483 rv = DoSSLConnect();
1490 break; 1484 break;
1491 case STATE_SSL_CONNECT_COMPLETE: 1485 case STATE_SSL_CONNECT_COMPLETE:
1492 rv = DoSSLConnectComplete(rv); 1486 rv = DoSSLConnectComplete(rv);
1493 break; 1487 break;
1494 default: 1488 default:
1495 NOTREACHED() << "bad state"; 1489 NOTREACHED() << "bad state";
1496 rv = ERR_UNEXPECTED; 1490 rv = ERR_UNEXPECTED;
1497 break; 1491 break;
1498 } 1492 }
1499 } while (rv != ERR_IO_PENDING && next_connect_state_ != STATE_NONE); 1493 } while (rv != ERR_IO_PENDING && next_connect_state_ != STATE_NONE);
1500 1494
1501 return rv; 1495 return rv;
1502 } 1496 }
1503 1497
1504 int MockSSLClientSocket::DoTransportConnect() {
1505 next_connect_state_ = STATE_TRANSPORT_CONNECT_COMPLETE;
1506 return transport_->socket()->Connect(
1507 base::Bind(&MockSSLClientSocket::OnIOComplete, base::Unretained(this)));
1508 }
1509
1510 int MockSSLClientSocket::DoTransportConnectComplete(int result) {
1511 if (result == OK)
1512 next_connect_state_ = STATE_SSL_CONNECT;
1513 return result;
1514 }
1515
1516 int MockSSLClientSocket::DoSSLConnect() { 1498 int MockSSLClientSocket::DoSSLConnect() {
1517 next_connect_state_ = STATE_SSL_CONNECT_COMPLETE; 1499 next_connect_state_ = STATE_SSL_CONNECT_COMPLETE;
1518 1500
1519 if (data_->should_block_on_connect) 1501 if (data_->should_pause_on_connect)
1520 return ERR_IO_PENDING; 1502 return ERR_IO_PENDING;
1521 1503
1522 if (data_->connect.mode == ASYNC) { 1504 if (data_->connect.mode == ASYNC) {
1523 base::MessageLoop::current()->PostTask( 1505 base::MessageLoop::current()->PostTask(
1524 FROM_HERE, 1506 FROM_HERE,
1525 base::Bind(&MockSSLClientSocket::OnIOComplete, 1507 base::Bind(&MockSSLClientSocket::OnIOComplete,
1526 weak_factory_.GetWeakPtr(), 1508 weak_factory_.GetWeakPtr(),
1527 data_->connect.result)); 1509 data_->connect.result));
1528 return ERR_IO_PENDING; 1510 return ERR_IO_PENDING;
1529 } 1511 }
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 1979
1998 const char kSOCKS5OkRequest[] = 1980 const char kSOCKS5OkRequest[] =
1999 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1981 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
2000 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1982 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
2001 1983
2002 const char kSOCKS5OkResponse[] = 1984 const char kSOCKS5OkResponse[] =
2003 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1985 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
2004 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1986 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
2005 1987
2006 } // namespace net 1988 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/socket/ssl_client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698