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

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

Issue 1696005: Add net log entries that summarize transmit and receive byte counts. (Closed)
Patch Set: More tests and address comments Created 10 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
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/socket/socks5_client_socket.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "net/base/address_family.h" 13 #include "net/base/address_family.h"
14 #include "net/base/host_resolver_proc.h" 14 #include "net/base/host_resolver_proc.h"
15 #include "net/base/ssl_info.h" 15 #include "net/base/ssl_info.h"
16 #include "net/socket/socket.h" 16 #include "net/socket/socket.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace net { 19 namespace net {
20 20
21 MockClientSocket::MockClientSocket() 21 MockClientSocket::MockClientSocket(net::NetLog* net_log)
22 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 22 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
23 connected_(false) { 23 connected_(false),
24 net_log_(NetLog::Source(), net_log) {
24 } 25 }
25 26
26 void MockClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) { 27 void MockClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) {
27 NOTREACHED(); 28 NOTREACHED();
28 } 29 }
29 30
30 void MockClientSocket::GetSSLCertRequestInfo( 31 void MockClientSocket::GetSSLCertRequestInfo(
31 net::SSLCertRequestInfo* cert_request_info) { 32 net::SSLCertRequestInfo* cert_request_info) {
32 NOTREACHED(); 33 NOTREACHED();
33 } 34 }
(...skipping 28 matching lines...) Expand all
62 &MockClientSocket::RunCallback, callback, result)); 63 &MockClientSocket::RunCallback, callback, result));
63 } 64 }
64 65
65 void MockClientSocket::RunCallback(net::CompletionCallback* callback, 66 void MockClientSocket::RunCallback(net::CompletionCallback* callback,
66 int result) { 67 int result) {
67 if (callback) 68 if (callback)
68 callback->Run(result); 69 callback->Run(result);
69 } 70 }
70 71
71 MockTCPClientSocket::MockTCPClientSocket(const net::AddressList& addresses, 72 MockTCPClientSocket::MockTCPClientSocket(const net::AddressList& addresses,
73 net::NetLog* net_log,
72 net::SocketDataProvider* data) 74 net::SocketDataProvider* data)
73 : addresses_(addresses), 75 : MockClientSocket(net_log),
76 addresses_(addresses),
74 data_(data), 77 data_(data),
75 read_offset_(0), 78 read_offset_(0),
76 read_data_(false, net::ERR_UNEXPECTED), 79 read_data_(false, net::ERR_UNEXPECTED),
77 need_read_data_(true), 80 need_read_data_(true),
78 peer_closed_connection_(false), 81 peer_closed_connection_(false),
79 pending_buf_(NULL), 82 pending_buf_(NULL),
80 pending_buf_len_(0), 83 pending_buf_len_(0),
81 pending_callback_(NULL) { 84 pending_callback_(NULL) {
82 DCHECK(data_); 85 DCHECK(data_);
83 data_->Reset(); 86 data_->Reset();
84 } 87 }
85 88
86 int MockTCPClientSocket::Connect(net::CompletionCallback* callback, 89 int MockTCPClientSocket::Connect(net::CompletionCallback* callback) {
87 const BoundNetLog& net_log) {
88 if (connected_) 90 if (connected_)
89 return net::OK; 91 return net::OK;
90 connected_ = true; 92 connected_ = true;
91 if (data_->connect_data().async) { 93 if (data_->connect_data().async) {
92 RunCallbackAsync(callback, data_->connect_data().result); 94 RunCallbackAsync(callback, data_->connect_data().result);
93 return net::ERR_IO_PENDING; 95 return net::ERR_IO_PENDING;
94 } 96 }
95 return data_->connect_data().result; 97 return data_->connect_data().result;
96 } 98 }
97 99
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 MockSSLClientSocket* ssl_client_socket_; 239 MockSSLClientSocket* ssl_client_socket_;
238 net::CompletionCallback* user_callback_; 240 net::CompletionCallback* user_callback_;
239 int rv_; 241 int rv_;
240 }; 242 };
241 243
242 MockSSLClientSocket::MockSSLClientSocket( 244 MockSSLClientSocket::MockSSLClientSocket(
243 net::ClientSocket* transport_socket, 245 net::ClientSocket* transport_socket,
244 const std::string& hostname, 246 const std::string& hostname,
245 const net::SSLConfig& ssl_config, 247 const net::SSLConfig& ssl_config,
246 net::SSLSocketDataProvider* data) 248 net::SSLSocketDataProvider* data)
247 : transport_(transport_socket), 249 : MockClientSocket(transport_socket->NetLog().net_log()),
250 transport_(transport_socket),
248 data_(data) { 251 data_(data) {
249 DCHECK(data_); 252 DCHECK(data_);
250 } 253 }
251 254
252 MockSSLClientSocket::~MockSSLClientSocket() { 255 MockSSLClientSocket::~MockSSLClientSocket() {
253 Disconnect(); 256 Disconnect();
254 } 257 }
255 258
256 void MockSSLClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) { 259 void MockSSLClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) {
257 ssl_info->Reset(); 260 ssl_info->Reset();
258 } 261 }
259 262
260 int MockSSLClientSocket::Connect(net::CompletionCallback* callback, 263 int MockSSLClientSocket::Connect(net::CompletionCallback* callback) {
261 const BoundNetLog& net_log) {
262 ConnectCallback* connect_callback = new ConnectCallback( 264 ConnectCallback* connect_callback = new ConnectCallback(
263 this, callback, data_->connect.result); 265 this, callback, data_->connect.result);
264 int rv = transport_->Connect(connect_callback, net_log); 266 int rv = transport_->Connect(connect_callback);
265 if (rv == net::OK) { 267 if (rv == net::OK) {
266 delete connect_callback; 268 delete connect_callback;
267 if (data_->connect.async) { 269 if (data_->connect.async) {
268 RunCallbackAsync(callback, data_->connect.result); 270 RunCallbackAsync(callback, data_->connect.result);
269 return net::ERR_IO_PENDING; 271 return net::ERR_IO_PENDING;
270 } 272 }
271 if (data_->connect.result == net::OK) 273 if (data_->connect.result == net::OK)
272 connected_ = true; 274 connected_ = true;
273 return data_->connect.result; 275 return data_->connect.result;
274 } 276 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 return tcp_client_sockets_[index]; 407 return tcp_client_sockets_[index];
406 } 408 }
407 409
408 MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket( 410 MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket(
409 size_t index) const { 411 size_t index) const {
410 DCHECK_LT(index, ssl_client_sockets_.size()); 412 DCHECK_LT(index, ssl_client_sockets_.size());
411 return ssl_client_sockets_[index]; 413 return ssl_client_sockets_[index];
412 } 414 }
413 415
414 ClientSocket* MockClientSocketFactory::CreateTCPClientSocket( 416 ClientSocket* MockClientSocketFactory::CreateTCPClientSocket(
415 const AddressList& addresses) { 417 const AddressList& addresses, net::NetLog* net_log) {
416 SocketDataProvider* data_provider = mock_data_.GetNext(); 418 SocketDataProvider* data_provider = mock_data_.GetNext();
417 MockTCPClientSocket* socket = 419 MockTCPClientSocket* socket =
418 new MockTCPClientSocket(addresses, data_provider); 420 new MockTCPClientSocket(addresses, net_log, data_provider);
419 data_provider->set_socket(socket); 421 data_provider->set_socket(socket);
420 tcp_client_sockets_.push_back(socket); 422 tcp_client_sockets_.push_back(socket);
421 return socket; 423 return socket;
422 } 424 }
423 425
424 SSLClientSocket* MockClientSocketFactory::CreateSSLClientSocket( 426 SSLClientSocket* MockClientSocketFactory::CreateSSLClientSocket(
425 ClientSocket* transport_socket, 427 ClientSocket* transport_socket,
426 const std::string& hostname, 428 const std::string& hostname,
427 const SSLConfig& ssl_config) { 429 const SSLConfig& ssl_config) {
428 MockSSLClientSocket* socket = 430 MockSSLClientSocket* socket =
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 510
509 const char kSOCKS5OkRequest[] = 511 const char kSOCKS5OkRequest[] =
510 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 512 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
511 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 513 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
512 514
513 const char kSOCKS5OkResponse[] = 515 const char kSOCKS5OkResponse[] =
514 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 516 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
515 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 517 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
516 518
517 } // namespace net 519 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/socket/socks5_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698