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

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

Issue 23684017: [GCM] Initial work to set up directory structure and introduce socket integration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 7 years, 3 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 | Annotate | Revision Log
« net/socket/socket_test_util.h ('K') | « net/socket/socket_test_util.h ('k') | no next file » | 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 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 std::string data(buf->data(), buf_len); 863 std::string data(buf->data(), buf_len);
864 MockWriteResult write_result = data_->OnWrite(data); 864 MockWriteResult write_result = data_->OnWrite(data);
865 865
866 was_used_to_convey_data_ = true; 866 was_used_to_convey_data_ = true;
867 867
868 if (write_result.mode == ASYNC) { 868 if (write_result.mode == ASYNC) {
869 RunCallbackAsync(callback, write_result.result); 869 RunCallbackAsync(callback, write_result.result);
870 return ERR_IO_PENDING; 870 return ERR_IO_PENDING;
871 } 871 }
872 872
873 if (write_result.result == net::ERR_IO_PENDING)
874 pending_callback_ = callback;
875
873 return write_result.result; 876 return write_result.result;
874 } 877 }
875 878
876 int MockTCPClientSocket::Connect(const CompletionCallback& callback) { 879 int MockTCPClientSocket::Connect(const CompletionCallback& callback) {
877 if (connected_) 880 if (connected_)
878 return OK; 881 return OK;
879 connected_ = true; 882 connected_ = true;
880 peer_closed_connection_ = false; 883 peer_closed_connection_ = false;
881 if (data_->connect_data().mode == ASYNC) { 884 if (data_->connect_data().mode == ASYNC) {
882 if (data_->connect_data().result == ERR_IO_PENDING) 885 if (data_->connect_data().result == ERR_IO_PENDING)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 CompletionCallback callback = pending_callback_; 946 CompletionCallback callback = pending_callback_;
944 int rv = CompleteRead(); 947 int rv = CompleteRead();
945 RunCallback(callback, rv); 948 RunCallback(callback, rv);
946 } 949 }
947 950
948 void MockTCPClientSocket::OnConnectComplete(const MockConnect& data) { 951 void MockTCPClientSocket::OnConnectComplete(const MockConnect& data) {
949 CompletionCallback callback = pending_callback_; 952 CompletionCallback callback = pending_callback_;
950 RunCallback(callback, data.result); 953 RunCallback(callback, data.result);
951 } 954 }
952 955
956 void MockTCPClientSocket::OnWriteComplete(const MockWriteResult& result) {
957 CompletionCallback callback = pending_callback_;
958 RunCallback(callback, result.result);
959 }
960
953 int MockTCPClientSocket::CompleteRead() { 961 int MockTCPClientSocket::CompleteRead() {
954 DCHECK(pending_buf_); 962 DCHECK(pending_buf_);
955 DCHECK(pending_buf_len_ > 0); 963 DCHECK(pending_buf_len_ > 0);
956 964
957 was_used_to_convey_data_ = true; 965 was_used_to_convey_data_ = true;
958 966
959 // Save the pending async IO data and reset our |pending_| state. 967 // Save the pending async IO data and reset our |pending_| state.
960 IOBuffer* buf = pending_buf_; 968 scoped_refptr<IOBuffer> buf = pending_buf_;
961 int buf_len = pending_buf_len_; 969 int buf_len = pending_buf_len_;
962 CompletionCallback callback = pending_callback_; 970 CompletionCallback callback = pending_callback_;
963 pending_buf_ = NULL; 971 pending_buf_ = NULL;
964 pending_buf_len_ = 0; 972 pending_buf_len_ = 0;
965 pending_callback_.Reset(); 973 pending_callback_.Reset();
966 974
967 int result = read_data_.result; 975 int result = read_data_.result;
968 DCHECK(result != ERR_IO_PENDING); 976 DCHECK(result != ERR_IO_PENDING);
969 977
970 if (read_data_.data) { 978 if (read_data_.data) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 return helper_.net_log(); 1187 return helper_.net_log();
1180 } 1188 }
1181 1189
1182 void DeterministicMockUDPClientSocket::OnReadComplete(const MockRead& data) {} 1190 void DeterministicMockUDPClientSocket::OnReadComplete(const MockRead& data) {}
1183 1191
1184 void DeterministicMockUDPClientSocket::OnConnectComplete( 1192 void DeterministicMockUDPClientSocket::OnConnectComplete(
1185 const MockConnect& data) { 1193 const MockConnect& data) {
1186 NOTIMPLEMENTED(); 1194 NOTIMPLEMENTED();
1187 } 1195 }
1188 1196
1197 void DeterministicMockUDPClientSocket::OnWriteComplete(
1198 const MockWriteResult& result) {
1199 NOTIMPLEMENTED();
1200 }
1201
1189 DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket( 1202 DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket(
1190 net::NetLog* net_log, 1203 net::NetLog* net_log,
1191 DeterministicSocketData* data) 1204 DeterministicSocketData* data)
1192 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), 1205 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)),
1193 helper_(net_log, data) { 1206 helper_(net_log, data) {
1194 peer_addr_ = data->connect_data().peer_addr; 1207 peer_addr_ = data->connect_data().peer_addr;
1195 } 1208 }
1196 1209
1197 DeterministicMockTCPClientSocket::~DeterministicMockTCPClientSocket() {} 1210 DeterministicMockTCPClientSocket::~DeterministicMockTCPClientSocket() {}
1198 1211
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1284
1272 bool DeterministicMockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { 1285 bool DeterministicMockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) {
1273 return false; 1286 return false;
1274 } 1287 }
1275 1288
1276 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {} 1289 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {}
1277 1290
1278 void DeterministicMockTCPClientSocket::OnConnectComplete( 1291 void DeterministicMockTCPClientSocket::OnConnectComplete(
1279 const MockConnect& data) {} 1292 const MockConnect& data) {}
1280 1293
1294 void DeterministicMockTCPClientSocket::OnWriteComplete(
1295 const MockWriteResult& result) {}
1296
1281 // static 1297 // static
1282 void MockSSLClientSocket::ConnectCallback( 1298 void MockSSLClientSocket::ConnectCallback(
1283 MockSSLClientSocket* ssl_client_socket, 1299 MockSSLClientSocket* ssl_client_socket,
1284 const CompletionCallback& callback, 1300 const CompletionCallback& callback,
1285 int rv) { 1301 int rv) {
1286 if (rv == OK) 1302 if (rv == OK)
1287 ssl_client_socket->connected_ = true; 1303 ssl_client_socket->connected_ = true;
1288 callback.Run(rv); 1304 callback.Run(rv);
1289 } 1305 }
1290 1306
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 } 1437 }
1422 1438
1423 void MockSSLClientSocket::OnReadComplete(const MockRead& data) { 1439 void MockSSLClientSocket::OnReadComplete(const MockRead& data) {
1424 NOTIMPLEMENTED(); 1440 NOTIMPLEMENTED();
1425 } 1441 }
1426 1442
1427 void MockSSLClientSocket::OnConnectComplete(const MockConnect& data) { 1443 void MockSSLClientSocket::OnConnectComplete(const MockConnect& data) {
1428 NOTIMPLEMENTED(); 1444 NOTIMPLEMENTED();
1429 } 1445 }
1430 1446
1447 void MockSSLClientSocket::OnWriteComplete(const MockWriteResult& result) {
1448 NOTIMPLEMENTED();
1449 }
1450
1431 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data, 1451 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data,
1432 net::NetLog* net_log) 1452 net::NetLog* net_log)
1433 : connected_(false), 1453 : connected_(false),
1434 data_(data), 1454 data_(data),
1435 read_offset_(0), 1455 read_offset_(0),
1436 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), 1456 read_data_(SYNCHRONOUS, ERR_UNEXPECTED),
1437 need_read_data_(true), 1457 need_read_data_(true),
1438 pending_buf_(NULL), 1458 pending_buf_(NULL),
1439 pending_buf_len_(0), 1459 pending_buf_len_(0),
1440 net_log_(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), 1460 net_log_(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)),
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 1564
1545 net::CompletionCallback callback = pending_callback_; 1565 net::CompletionCallback callback = pending_callback_;
1546 int rv = CompleteRead(); 1566 int rv = CompleteRead();
1547 RunCallback(callback, rv); 1567 RunCallback(callback, rv);
1548 } 1568 }
1549 1569
1550 void MockUDPClientSocket::OnConnectComplete(const MockConnect& data) { 1570 void MockUDPClientSocket::OnConnectComplete(const MockConnect& data) {
1551 NOTIMPLEMENTED(); 1571 NOTIMPLEMENTED();
1552 } 1572 }
1553 1573
1574 void MockUDPClientSocket::OnWriteComplete(const MockWriteResult& result) {
1575 NOTIMPLEMENTED();
1576 }
1577
1554 int MockUDPClientSocket::CompleteRead() { 1578 int MockUDPClientSocket::CompleteRead() {
1555 DCHECK(pending_buf_); 1579 DCHECK(pending_buf_);
1556 DCHECK(pending_buf_len_ > 0); 1580 DCHECK(pending_buf_len_ > 0);
1557 1581
1558 // Save the pending async IO data and reset our |pending_| state. 1582 // Save the pending async IO data and reset our |pending_| state.
1559 IOBuffer* buf = pending_buf_; 1583 scoped_refptr<IOBuffer> buf = pending_buf_;
1560 int buf_len = pending_buf_len_; 1584 int buf_len = pending_buf_len_;
1561 CompletionCallback callback = pending_callback_; 1585 CompletionCallback callback = pending_callback_;
1562 pending_buf_ = NULL; 1586 pending_buf_ = NULL;
1563 pending_buf_len_ = 0; 1587 pending_buf_len_ = 0;
1564 pending_callback_.Reset(); 1588 pending_callback_.Reset();
1565 1589
1566 int result = read_data_.result; 1590 int result = read_data_.result;
1567 DCHECK(result != ERR_IO_PENDING); 1591 DCHECK(result != ERR_IO_PENDING);
1568 1592
1569 if (read_data_.data) { 1593 if (read_data_.data) {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 1905
1882 const char kSOCKS5OkRequest[] = 1906 const char kSOCKS5OkRequest[] =
1883 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1907 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
1884 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1908 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
1885 1909
1886 const char kSOCKS5OkResponse[] = 1910 const char kSOCKS5OkResponse[] =
1887 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1911 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
1888 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1912 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
1889 1913
1890 } // namespace net 1914 } // namespace net
OLDNEW
« net/socket/socket_test_util.h ('K') | « net/socket/socket_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698