| OLD | NEW |
| 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/socks_client_socket_pool.h" | 5 #include "net/socket/socks_client_socket_pool.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "net/base/mock_host_resolver.h" | 12 #include "net/base/mock_host_resolver.h" |
| 13 #include "net/base/mock_network_change_notifier.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 15 #include "net/socket/client_socket_factory.h" | 16 #include "net/socket/client_socket_factory.h" |
| 16 #include "net/socket/client_socket_handle.h" | 17 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/socket_test_util.h" | 18 #include "net/socket/socket_test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 scoped_ptr<ClientSocket> socket_; | 76 scoped_ptr<ClientSocket> socket_; |
| 76 ClientSocketHandle* handle_; | 77 ClientSocketHandle* handle_; |
| 77 CompletionCallback* user_callback_; | 78 CompletionCallback* user_callback_; |
| 78 CompletionCallbackImpl<MockConnectJob> connect_callback_; | 79 CompletionCallbackImpl<MockConnectJob> connect_callback_; |
| 79 | 80 |
| 80 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); | 81 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 MockTCPClientSocketPool(int max_sockets, int max_sockets_per_group, | 84 MockTCPClientSocketPool(int max_sockets, int max_sockets_per_group, |
| 84 const std::string& name, | 85 const std::string& name, |
| 85 ClientSocketFactory* socket_factory) | 86 ClientSocketFactory* socket_factory, |
| 87 NetworkChangeNotifier* network_change_notifier) |
| 86 : TCPClientSocketPool(max_sockets, max_sockets_per_group, name, | 88 : TCPClientSocketPool(max_sockets, max_sockets_per_group, name, |
| 87 NULL, NULL), | 89 NULL, NULL, network_change_notifier), |
| 88 client_socket_factory_(socket_factory), | 90 client_socket_factory_(socket_factory), |
| 89 release_count_(0), | 91 release_count_(0), |
| 90 cancel_count_(0) {} | 92 cancel_count_(0) {} |
| 91 | 93 |
| 92 int release_count() { return release_count_; }; | 94 int release_count() { return release_count_; }; |
| 93 int cancel_count() { return cancel_count_; }; | 95 int cancel_count() { return cancel_count_; }; |
| 94 | 96 |
| 95 // TCPClientSocketPool methods. | 97 // TCPClientSocketPool methods. |
| 96 virtual int RequestSocket(const std::string& group_name, | 98 virtual int RequestSocket(const std::string& group_name, |
| 97 const void* socket_params, | 99 const void* socket_params, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 scoped_ptr<StaticSocketDataProvider> data_; | 164 scoped_ptr<StaticSocketDataProvider> data_; |
| 163 scoped_array<MockWrite> writes_; | 165 scoped_array<MockWrite> writes_; |
| 164 scoped_array<MockWrite> reads_; | 166 scoped_array<MockWrite> reads_; |
| 165 }; | 167 }; |
| 166 | 168 |
| 167 SOCKSClientSocketPoolTest() | 169 SOCKSClientSocketPoolTest() |
| 168 : ignored_tcp_socket_params_( | 170 : ignored_tcp_socket_params_( |
| 169 HostPortPair("proxy", 80), MEDIUM, GURL(), false), | 171 HostPortPair("proxy", 80), MEDIUM, GURL(), false), |
| 170 tcp_socket_pool_(new MockTCPClientSocketPool( | 172 tcp_socket_pool_(new MockTCPClientSocketPool( |
| 171 kMaxSockets, kMaxSocketsPerGroup, "MockTCP", | 173 kMaxSockets, kMaxSocketsPerGroup, "MockTCP", |
| 172 &tcp_client_socket_factory_)), | 174 &tcp_client_socket_factory_, &tcp_notifier_)), |
| 173 ignored_socket_params_(ignored_tcp_socket_params_, true, | 175 ignored_socket_params_(ignored_tcp_socket_params_, true, |
| 174 HostPortPair("host", 80), | 176 HostPortPair("host", 80), |
| 175 MEDIUM, GURL()), | 177 MEDIUM, GURL()), |
| 176 pool_(new SOCKSClientSocketPool( | 178 pool_(new SOCKSClientSocketPool( |
| 177 kMaxSockets, kMaxSocketsPerGroup, "SOCKSUnitTest", NULL, | 179 kMaxSockets, kMaxSocketsPerGroup, "SOCKSUnitTest", NULL, |
| 178 tcp_socket_pool_.get())) { | 180 tcp_socket_pool_.get(), &socks_notifier_)) { |
| 179 } | 181 } |
| 180 | 182 |
| 181 int StartRequest(const std::string& group_name, RequestPriority priority) { | 183 int StartRequest(const std::string& group_name, RequestPriority priority) { |
| 182 return StartRequestUsingPool( | 184 return StartRequestUsingPool( |
| 183 pool_, group_name, priority, ignored_socket_params_); | 185 pool_, group_name, priority, ignored_socket_params_); |
| 184 } | 186 } |
| 185 | 187 |
| 186 TCPSocketParams ignored_tcp_socket_params_; | 188 TCPSocketParams ignored_tcp_socket_params_; |
| 187 MockClientSocketFactory tcp_client_socket_factory_; | 189 MockClientSocketFactory tcp_client_socket_factory_; |
| 190 MockNetworkChangeNotifier tcp_notifier_; |
| 188 scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_; | 191 scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_; |
| 189 | 192 |
| 190 SOCKSSocketParams ignored_socket_params_; | 193 SOCKSSocketParams ignored_socket_params_; |
| 194 MockNetworkChangeNotifier socks_notifier_; |
| 191 scoped_refptr<SOCKSClientSocketPool> pool_; | 195 scoped_refptr<SOCKSClientSocketPool> pool_; |
| 192 }; | 196 }; |
| 193 | 197 |
| 194 TEST_F(SOCKSClientSocketPoolTest, Simple) { | 198 TEST_F(SOCKSClientSocketPoolTest, Simple) { |
| 195 SOCKS5MockData data(false); | 199 SOCKS5MockData data(false); |
| 196 data.data_provider()->set_connect_data(MockConnect(false, 0)); | 200 data.data_provider()->set_connect_data(MockConnect(false, 0)); |
| 197 tcp_client_socket_factory_.AddSocketDataProvider(data.data_provider()); | 201 tcp_client_socket_factory_.AddSocketDataProvider(data.data_provider()); |
| 198 | 202 |
| 199 ClientSocketHandle handle; | 203 ClientSocketHandle handle; |
| 200 int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, pool_, | 204 int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, pool_, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 364 |
| 361 requests_[0]->handle()->Reset(); | 365 requests_[0]->handle()->Reset(); |
| 362 requests_[1]->handle()->Reset(); | 366 requests_[1]->handle()->Reset(); |
| 363 } | 367 } |
| 364 | 368 |
| 365 // It would be nice to also test the timeouts in SOCKSClientSocketPool. | 369 // It would be nice to also test the timeouts in SOCKSClientSocketPool. |
| 366 | 370 |
| 367 } // namespace | 371 } // namespace |
| 368 | 372 |
| 369 } // namespace net | 373 } // namespace net |
| OLD | NEW |