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