| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "net/base/address_family.h" |
| 13 #include "net/base/host_resolver_proc.h" |
| 12 #include "net/base/ssl_info.h" | 14 #include "net/base/ssl_info.h" |
| 13 #include "net/socket/socket.h" | 15 #include "net/socket/socket.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace net { | 18 namespace net { |
| 17 | 19 |
| 18 MockClientSocket::MockClientSocket() | 20 MockClientSocket::MockClientSocket() |
| 19 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 21 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), |
| 20 connected_(false) { | 22 connected_(false) { |
| 21 } | 23 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool MockClientSocket::IsConnected() const { | 44 bool MockClientSocket::IsConnected() const { |
| 43 return connected_; | 45 return connected_; |
| 44 } | 46 } |
| 45 | 47 |
| 46 bool MockClientSocket::IsConnectedAndIdle() const { | 48 bool MockClientSocket::IsConnectedAndIdle() const { |
| 47 return connected_; | 49 return connected_; |
| 48 } | 50 } |
| 49 | 51 |
| 50 int MockClientSocket::GetPeerName(struct sockaddr* name, socklen_t* namelen) { | 52 int MockClientSocket::GetPeerAddress(AddressList* address) const { |
| 51 memset(reinterpret_cast<char *>(name), 0, *namelen); | 53 return net::SystemHostResolverProc("localhost", ADDRESS_FAMILY_UNSPECIFIED, |
| 52 return net::OK; | 54 address); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void MockClientSocket::RunCallbackAsync(net::CompletionCallback* callback, | 57 void MockClientSocket::RunCallbackAsync(net::CompletionCallback* callback, |
| 56 int result) { | 58 int result) { |
| 57 MessageLoop::current()->PostTask(FROM_HERE, | 59 MessageLoop::current()->PostTask(FROM_HERE, |
| 58 method_factory_.NewRunnableMethod( | 60 method_factory_.NewRunnableMethod( |
| 59 &MockClientSocket::RunCallback, callback, result)); | 61 &MockClientSocket::RunCallback, callback, result)); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void MockClientSocket::RunCallback(net::CompletionCallback* callback, | 64 void MockClientSocket::RunCallback(net::CompletionCallback* callback, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 SSLSocketDataProvider* data) { | 365 SSLSocketDataProvider* data) { |
| 364 mock_ssl_data_.Add(data); | 366 mock_ssl_data_.Add(data); |
| 365 } | 367 } |
| 366 | 368 |
| 367 void MockClientSocketFactory::ResetNextMockIndexes() { | 369 void MockClientSocketFactory::ResetNextMockIndexes() { |
| 368 mock_data_.ResetNextIndex(); | 370 mock_data_.ResetNextIndex(); |
| 369 mock_ssl_data_.ResetNextIndex(); | 371 mock_ssl_data_.ResetNextIndex(); |
| 370 } | 372 } |
| 371 | 373 |
| 372 MockTCPClientSocket* MockClientSocketFactory::GetMockTCPClientSocket( | 374 MockTCPClientSocket* MockClientSocketFactory::GetMockTCPClientSocket( |
| 373 int index) const { | 375 size_t index) const { |
| 376 DCHECK_LT(index, tcp_client_sockets_.size()); |
| 374 return tcp_client_sockets_[index]; | 377 return tcp_client_sockets_[index]; |
| 375 } | 378 } |
| 376 | 379 |
| 377 MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket( | 380 MockSSLClientSocket* MockClientSocketFactory::GetMockSSLClientSocket( |
| 378 int index) const { | 381 size_t index) const { |
| 382 DCHECK_LT(index, ssl_client_sockets_.size()); |
| 379 return ssl_client_sockets_[index]; | 383 return ssl_client_sockets_[index]; |
| 380 } | 384 } |
| 381 | 385 |
| 382 ClientSocket* MockClientSocketFactory::CreateTCPClientSocket( | 386 ClientSocket* MockClientSocketFactory::CreateTCPClientSocket( |
| 383 const AddressList& addresses) { | 387 const AddressList& addresses) { |
| 384 SocketDataProvider* data_provider = mock_data_.GetNext(); | 388 SocketDataProvider* data_provider = mock_data_.GetNext(); |
| 385 MockTCPClientSocket* socket = | 389 MockTCPClientSocket* socket = |
| 386 new MockTCPClientSocket(addresses, data_provider); | 390 new MockTCPClientSocket(addresses, data_provider); |
| 387 data_provider->set_socket(socket); | 391 data_provider->set_socket(socket); |
| 388 tcp_client_sockets_.push_back(socket); | 392 tcp_client_sockets_.push_back(socket); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 } | 466 } |
| 463 | 467 |
| 464 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { | 468 void ClientSocketPoolTest::ReleaseAllConnections(KeepAlive keep_alive) { |
| 465 bool released_one; | 469 bool released_one; |
| 466 do { | 470 do { |
| 467 released_one = ReleaseOneConnection(keep_alive); | 471 released_one = ReleaseOneConnection(keep_alive); |
| 468 } while (released_one); | 472 } while (released_one); |
| 469 } | 473 } |
| 470 | 474 |
| 471 } // namespace net | 475 } // namespace net |
| OLD | NEW |