Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: net/socket/socks_client_socket_pool_unittest.cc

Issue 2802015: Massively simplify the NetworkChangeNotifier infrastructure:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/client_socket_pool_histograms.h" 17 #include "net/socket/client_socket_pool_histograms.h"
19 #include "net/socket/socket_test_util.h" 18 #include "net/socket/socket_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 20
22 namespace net { 21 namespace net {
23 22
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 74 }
76 75
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(
85 int max_sockets,
86 int max_sockets_per_group,
86 const scoped_refptr<ClientSocketPoolHistograms>& histograms, 87 const scoped_refptr<ClientSocketPoolHistograms>& histograms,
87 ClientSocketFactory* socket_factory, 88 ClientSocketFactory* socket_factory)
88 NetworkChangeNotifier* network_change_notifier)
89 : TCPClientSocketPool(max_sockets, max_sockets_per_group, histograms, 89 : TCPClientSocketPool(max_sockets, max_sockets_per_group, histograms,
90 NULL, NULL, network_change_notifier, NULL), 90 NULL, NULL, NULL),
91 client_socket_factory_(socket_factory), 91 client_socket_factory_(socket_factory),
92 release_count_(0), 92 release_count_(0),
93 cancel_count_(0) {} 93 cancel_count_(0) {}
94 94
95 int release_count() { return release_count_; }; 95 int release_count() { return release_count_; };
96 int cancel_count() { return cancel_count_; }; 96 int cancel_count() { return cancel_count_; };
97 97
98 // TCPClientSocketPool methods. 98 // TCPClientSocketPool methods.
99 virtual int RequestSocket(const std::string& group_name, 99 virtual int RequestSocket(const std::string& group_name,
100 const void* socket_params, 100 const void* socket_params,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 private: 167 private:
168 scoped_ptr<StaticSocketDataProvider> data_; 168 scoped_ptr<StaticSocketDataProvider> data_;
169 scoped_array<MockWrite> writes_; 169 scoped_array<MockWrite> writes_;
170 scoped_array<MockWrite> reads_; 170 scoped_array<MockWrite> reads_;
171 }; 171 };
172 172
173 SOCKSClientSocketPoolTest() 173 SOCKSClientSocketPoolTest()
174 : ignored_tcp_socket_params_( 174 : ignored_tcp_socket_params_(
175 HostPortPair("proxy", 80), MEDIUM, GURL(), false), 175 HostPortPair("proxy", 80), MEDIUM, GURL(), false),
176 tcp_histograms_(new ClientSocketPoolHistograms("MockTCP")), 176 tcp_histograms_(new ClientSocketPoolHistograms("MockTCP")),
177 tcp_socket_pool_(new MockTCPClientSocketPool( 177 tcp_socket_pool_(new MockTCPClientSocketPool(kMaxSockets,
178 kMaxSockets, kMaxSocketsPerGroup, tcp_histograms_, 178 kMaxSocketsPerGroup, tcp_histograms_, &tcp_client_socket_factory_)),
179 &tcp_client_socket_factory_, &tcp_notifier_)),
180 ignored_socket_params_(ignored_tcp_socket_params_, true, 179 ignored_socket_params_(ignored_tcp_socket_params_, true,
181 HostPortPair("host", 80), 180 HostPortPair("host", 80), MEDIUM, GURL()),
182 MEDIUM, GURL()),
183 socks_histograms_(new ClientSocketPoolHistograms("SOCKSUnitTest")), 181 socks_histograms_(new ClientSocketPoolHistograms("SOCKSUnitTest")),
184 pool_(new SOCKSClientSocketPool( 182 pool_(new SOCKSClientSocketPool(kMaxSockets, kMaxSocketsPerGroup,
185 kMaxSockets, kMaxSocketsPerGroup, socks_histograms_, NULL, 183 socks_histograms_, NULL, tcp_socket_pool_, NULL)) {
186 tcp_socket_pool_, &socks_notifier_, NULL)) {
187 } 184 }
188 185
189 int StartRequest(const std::string& group_name, RequestPriority priority) { 186 int StartRequest(const std::string& group_name, RequestPriority priority) {
190 return StartRequestUsingPool( 187 return StartRequestUsingPool(
191 pool_, group_name, priority, ignored_socket_params_); 188 pool_, group_name, priority, ignored_socket_params_);
192 } 189 }
193 190
194 TCPSocketParams ignored_tcp_socket_params_; 191 TCPSocketParams ignored_tcp_socket_params_;
195 scoped_refptr<ClientSocketPoolHistograms> tcp_histograms_; 192 scoped_refptr<ClientSocketPoolHistograms> tcp_histograms_;
196 MockClientSocketFactory tcp_client_socket_factory_; 193 MockClientSocketFactory tcp_client_socket_factory_;
197 MockNetworkChangeNotifier tcp_notifier_;
198 scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_; 194 scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_;
199 195
200 SOCKSSocketParams ignored_socket_params_; 196 SOCKSSocketParams ignored_socket_params_;
201 scoped_refptr<ClientSocketPoolHistograms> socks_histograms_; 197 scoped_refptr<ClientSocketPoolHistograms> socks_histograms_;
202 MockNetworkChangeNotifier socks_notifier_;
203 scoped_refptr<SOCKSClientSocketPool> pool_; 198 scoped_refptr<SOCKSClientSocketPool> pool_;
204 }; 199 };
205 200
206 TEST_F(SOCKSClientSocketPoolTest, Simple) { 201 TEST_F(SOCKSClientSocketPoolTest, Simple) {
207 SOCKS5MockData data(false); 202 SOCKS5MockData data(false);
208 data.data_provider()->set_connect_data(MockConnect(false, 0)); 203 data.data_provider()->set_connect_data(MockConnect(false, 0));
209 tcp_client_socket_factory_.AddSocketDataProvider(data.data_provider()); 204 tcp_client_socket_factory_.AddSocketDataProvider(data.data_provider());
210 205
211 ClientSocketHandle handle; 206 ClientSocketHandle handle;
212 int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, pool_, 207 int rv = handle.Init("a", ignored_socket_params_, LOW, NULL, pool_,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 367
373 requests_[0]->handle()->Reset(); 368 requests_[0]->handle()->Reset();
374 requests_[1]->handle()->Reset(); 369 requests_[1]->handle()->Reset();
375 } 370 }
376 371
377 // It would be nice to also test the timeouts in SOCKSClientSocketPool. 372 // It would be nice to also test the timeouts in SOCKSClientSocketPool.
378 373
379 } // namespace 374 } // namespace
380 375
381 } // namespace net 376 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698