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

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

Issue 14813024: Introduce RequestWebSocketStream into HttpStreamFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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/websockets/websocket_stream.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 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 870
871 return write_result.result; 871 return write_result.result;
872 } 872 }
873 873
874 int MockTCPClientSocket::Connect(const CompletionCallback& callback) { 874 int MockTCPClientSocket::Connect(const CompletionCallback& callback) {
875 if (connected_) 875 if (connected_)
876 return OK; 876 return OK;
877 connected_ = true; 877 connected_ = true;
878 peer_closed_connection_ = false; 878 peer_closed_connection_ = false;
879 if (data_->connect_data().mode == ASYNC) { 879 if (data_->connect_data().mode == ASYNC) {
880 RunCallbackAsync(callback, data_->connect_data().result); 880 if (data_->connect_data().result == ERR_IO_PENDING)
881 pending_callback_ = callback;
882 else
883 RunCallbackAsync(callback, data_->connect_data().result);
881 return ERR_IO_PENDING; 884 return ERR_IO_PENDING;
882 } 885 }
883 return data_->connect_data().result; 886 return data_->connect_data().result;
884 } 887 }
885 888
886 void MockTCPClientSocket::Disconnect() { 889 void MockTCPClientSocket::Disconnect() {
887 MockClientSocket::Disconnect(); 890 MockClientSocket::Disconnect();
888 pending_callback_.Reset(); 891 pending_callback_.Reset();
889 } 892 }
890 893
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 936
934 // The caller is simulating that this IO completes right now. Don't 937 // The caller is simulating that this IO completes right now. Don't
935 // let CompleteRead() schedule a callback. 938 // let CompleteRead() schedule a callback.
936 read_data_.mode = SYNCHRONOUS; 939 read_data_.mode = SYNCHRONOUS;
937 940
938 CompletionCallback callback = pending_callback_; 941 CompletionCallback callback = pending_callback_;
939 int rv = CompleteRead(); 942 int rv = CompleteRead();
940 RunCallback(callback, rv); 943 RunCallback(callback, rv);
941 } 944 }
942 945
946 void MockTCPClientSocket::OnConnectComplete(const MockConnect& data) {
947 CompletionCallback callback = pending_callback_;
948 RunCallback(callback, data.result);
949 }
950
943 int MockTCPClientSocket::CompleteRead() { 951 int MockTCPClientSocket::CompleteRead() {
944 DCHECK(pending_buf_); 952 DCHECK(pending_buf_);
945 DCHECK(pending_buf_len_ > 0); 953 DCHECK(pending_buf_len_ > 0);
946 954
947 was_used_to_convey_data_ = true; 955 was_used_to_convey_data_ = true;
948 956
949 // Save the pending async IO data and reset our |pending_| state. 957 // Save the pending async IO data and reset our |pending_| state.
950 IOBuffer* buf = pending_buf_; 958 IOBuffer* buf = pending_buf_;
951 int buf_len = pending_buf_len_; 959 int buf_len = pending_buf_len_;
952 CompletionCallback callback = pending_callback_; 960 CompletionCallback callback = pending_callback_;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 *address = IPEndPoint(ip, 123); 1172 *address = IPEndPoint(ip, 123);
1165 return OK; 1173 return OK;
1166 } 1174 }
1167 1175
1168 const BoundNetLog& DeterministicMockUDPClientSocket::NetLog() const { 1176 const BoundNetLog& DeterministicMockUDPClientSocket::NetLog() const {
1169 return helper_.net_log(); 1177 return helper_.net_log();
1170 } 1178 }
1171 1179
1172 void DeterministicMockUDPClientSocket::OnReadComplete(const MockRead& data) {} 1180 void DeterministicMockUDPClientSocket::OnReadComplete(const MockRead& data) {}
1173 1181
1182 void DeterministicMockUDPClientSocket::OnConnectComplete(
1183 const MockConnect& data) {
1184 NOTIMPLEMENTED();
1185 }
1174 1186
1175 DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket( 1187 DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket(
1176 net::NetLog* net_log, 1188 net::NetLog* net_log,
1177 DeterministicSocketData* data) 1189 DeterministicSocketData* data)
1178 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), 1190 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)),
1179 helper_(net_log, data) { 1191 helper_(net_log, data) {
1180 peer_addr_ = data->connect_data().peer_addr; 1192 peer_addr_ = data->connect_data().peer_addr;
1181 } 1193 }
1182 1194
1183 DeterministicMockTCPClientSocket::~DeterministicMockTCPClientSocket() {} 1195 DeterministicMockTCPClientSocket::~DeterministicMockTCPClientSocket() {}
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 bool DeterministicMockTCPClientSocket::WasNpnNegotiated() const { 1266 bool DeterministicMockTCPClientSocket::WasNpnNegotiated() const {
1255 return false; 1267 return false;
1256 } 1268 }
1257 1269
1258 bool DeterministicMockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { 1270 bool DeterministicMockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) {
1259 return false; 1271 return false;
1260 } 1272 }
1261 1273
1262 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {} 1274 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {}
1263 1275
1276 void DeterministicMockTCPClientSocket::OnConnectComplete(
1277 const MockConnect& data) {}
1278
1264 // static 1279 // static
1265 void MockSSLClientSocket::ConnectCallback( 1280 void MockSSLClientSocket::ConnectCallback(
1266 MockSSLClientSocket *ssl_client_socket, 1281 MockSSLClientSocket *ssl_client_socket,
1267 const CompletionCallback& callback, 1282 const CompletionCallback& callback,
1268 int rv) { 1283 int rv) {
1269 if (rv == OK) 1284 if (rv == OK)
1270 ssl_client_socket->connected_ = true; 1285 ssl_client_socket->connected_ = true;
1271 callback.Run(rv); 1286 callback.Run(rv);
1272 } 1287 }
1273 1288
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 } 1415 }
1401 1416
1402 ServerBoundCertService* MockSSLClientSocket::GetServerBoundCertService() const { 1417 ServerBoundCertService* MockSSLClientSocket::GetServerBoundCertService() const {
1403 return data_->server_bound_cert_service; 1418 return data_->server_bound_cert_service;
1404 } 1419 }
1405 1420
1406 void MockSSLClientSocket::OnReadComplete(const MockRead& data) { 1421 void MockSSLClientSocket::OnReadComplete(const MockRead& data) {
1407 NOTIMPLEMENTED(); 1422 NOTIMPLEMENTED();
1408 } 1423 }
1409 1424
1425 void MockSSLClientSocket::OnConnectComplete(const MockConnect& data) {
1426 NOTIMPLEMENTED();
1427 }
1428
1410 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data, 1429 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data,
1411 net::NetLog* net_log) 1430 net::NetLog* net_log)
1412 : connected_(false), 1431 : connected_(false),
1413 data_(data), 1432 data_(data),
1414 read_offset_(0), 1433 read_offset_(0),
1415 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), 1434 read_data_(SYNCHRONOUS, ERR_UNEXPECTED),
1416 need_read_data_(true), 1435 need_read_data_(true),
1417 pending_buf_(NULL), 1436 pending_buf_(NULL),
1418 pending_buf_len_(0), 1437 pending_buf_len_(0),
1419 net_log_(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), 1438 net_log_(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)),
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 1538
1520 // The caller is simulating that this IO completes right now. Don't 1539 // The caller is simulating that this IO completes right now. Don't
1521 // let CompleteRead() schedule a callback. 1540 // let CompleteRead() schedule a callback.
1522 read_data_.mode = SYNCHRONOUS; 1541 read_data_.mode = SYNCHRONOUS;
1523 1542
1524 net::CompletionCallback callback = pending_callback_; 1543 net::CompletionCallback callback = pending_callback_;
1525 int rv = CompleteRead(); 1544 int rv = CompleteRead();
1526 RunCallback(callback, rv); 1545 RunCallback(callback, rv);
1527 } 1546 }
1528 1547
1548 void MockUDPClientSocket::OnConnectComplete(const MockConnect& data) {
1549 NOTIMPLEMENTED();
1550 }
1551
1529 int MockUDPClientSocket::CompleteRead() { 1552 int MockUDPClientSocket::CompleteRead() {
1530 DCHECK(pending_buf_); 1553 DCHECK(pending_buf_);
1531 DCHECK(pending_buf_len_ > 0); 1554 DCHECK(pending_buf_len_ > 0);
1532 1555
1533 // Save the pending async IO data and reset our |pending_| state. 1556 // Save the pending async IO data and reset our |pending_| state.
1534 IOBuffer* buf = pending_buf_; 1557 IOBuffer* buf = pending_buf_;
1535 int buf_len = pending_buf_len_; 1558 int buf_len = pending_buf_len_;
1536 CompletionCallback callback = pending_callback_; 1559 CompletionCallback callback = pending_callback_;
1537 pending_buf_ = NULL; 1560 pending_buf_ = NULL;
1538 pending_buf_len_ = 0; 1561 pending_buf_len_ = 0;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 1871
1849 const char kSOCKS5OkRequest[] = 1872 const char kSOCKS5OkRequest[] =
1850 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 1873 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
1851 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 1874 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
1852 1875
1853 const char kSOCKS5OkResponse[] = 1876 const char kSOCKS5OkResponse[] =
1854 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 1877 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
1855 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 1878 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
1856 1879
1857 } // namespace net 1880 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/websockets/websocket_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698