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