OLD | NEW |
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/bind.h" | 10 #include "base/bind.h" |
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 } | 1236 } |
1237 | 1237 |
1238 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data, | 1238 MockUDPClientSocket::MockUDPClientSocket(SocketDataProvider* data, |
1239 net::NetLog* net_log) | 1239 net::NetLog* net_log) |
1240 : connected_(false), | 1240 : connected_(false), |
1241 data_(data), | 1241 data_(data), |
1242 read_offset_(0), | 1242 read_offset_(0), |
1243 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), | 1243 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), |
1244 need_read_data_(true), | 1244 need_read_data_(true), |
1245 source_port_(123), | 1245 source_port_(123), |
| 1246 network_(NetworkChangeNotifier::kInvalidNetworkHandle), |
1246 pending_read_buf_(NULL), | 1247 pending_read_buf_(NULL), |
1247 pending_read_buf_len_(0), | 1248 pending_read_buf_len_(0), |
1248 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_NONE)), | 1249 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_NONE)), |
1249 weak_factory_(this) { | 1250 weak_factory_(this) { |
1250 DCHECK(data_); | 1251 DCHECK(data_); |
1251 data_->Initialize(this); | 1252 data_->Initialize(this); |
1252 peer_addr_ = data->connect_data().peer_addr; | 1253 peer_addr_ = data->connect_data().peer_addr; |
1253 } | 1254 } |
1254 | 1255 |
1255 MockUDPClientSocket::~MockUDPClientSocket() { | 1256 MockUDPClientSocket::~MockUDPClientSocket() { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1334 *address = IPEndPoint(ip, source_port_); | 1335 *address = IPEndPoint(ip, source_port_); |
1335 return OK; | 1336 return OK; |
1336 } | 1337 } |
1337 | 1338 |
1338 const BoundNetLog& MockUDPClientSocket::NetLog() const { | 1339 const BoundNetLog& MockUDPClientSocket::NetLog() const { |
1339 return net_log_; | 1340 return net_log_; |
1340 } | 1341 } |
1341 | 1342 |
1342 int MockUDPClientSocket::BindToNetwork( | 1343 int MockUDPClientSocket::BindToNetwork( |
1343 NetworkChangeNotifier::NetworkHandle network) { | 1344 NetworkChangeNotifier::NetworkHandle network) { |
1344 return ERR_NOT_IMPLEMENTED; | 1345 network_ = network; |
| 1346 return OK; |
1345 } | 1347 } |
1346 | 1348 |
1347 int MockUDPClientSocket::BindToDefaultNetwork() { | 1349 int MockUDPClientSocket::BindToDefaultNetwork() { |
1348 return ERR_NOT_IMPLEMENTED; | 1350 network_ = kDefaultNetworkForTests; |
| 1351 return OK; |
1349 } | 1352 } |
1350 | 1353 |
1351 NetworkChangeNotifier::NetworkHandle MockUDPClientSocket::GetBoundNetwork() | 1354 NetworkChangeNotifier::NetworkHandle MockUDPClientSocket::GetBoundNetwork() |
1352 const { | 1355 const { |
1353 return NetworkChangeNotifier::kInvalidNetworkHandle; | 1356 return network_; |
1354 } | 1357 } |
1355 | 1358 |
1356 int MockUDPClientSocket::Connect(const IPEndPoint& address) { | 1359 int MockUDPClientSocket::Connect(const IPEndPoint& address) { |
1357 if (!data_) | 1360 if (!data_) |
1358 return ERR_UNEXPECTED; | 1361 return ERR_UNEXPECTED; |
1359 connected_ = true; | 1362 connected_ = true; |
1360 peer_addr_ = address; | 1363 peer_addr_ = address; |
1361 return data_->connect_data().result; | 1364 return data_->connect_data().result; |
1362 } | 1365 } |
1363 | 1366 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 } | 1699 } |
1697 | 1700 |
1698 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { | 1701 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { |
1699 int64_t total = 0; | 1702 int64_t total = 0; |
1700 for (const MockWrite* write = writes; write != writes + writes_size; ++write) | 1703 for (const MockWrite* write = writes; write != writes + writes_size; ++write) |
1701 total += write->data_len; | 1704 total += write->data_len; |
1702 return total; | 1705 return total; |
1703 } | 1706 } |
1704 | 1707 |
1705 } // namespace net | 1708 } // namespace net |
OLD | NEW |