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

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

Issue 6930014: Rename ClientSocket to StreamSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/transport_client_socket_pool.h" 5 #include "net/socket/transport_client_socket_pool.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 #include "net/base/mock_host_resolver.h" 11 #include "net/base/mock_host_resolver.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
14 #include "net/socket/client_socket.h"
15 #include "net/socket/client_socket_factory.h" 14 #include "net/socket/client_socket_factory.h"
16 #include "net/socket/client_socket_handle.h" 15 #include "net/socket/client_socket_handle.h"
17 #include "net/socket/client_socket_pool_histograms.h" 16 #include "net/socket/client_socket_pool_histograms.h"
18 #include "net/socket/socket_test_util.h" 17 #include "net/socket/socket_test_util.h"
19 #include "net/socket/ssl_host_info.h" 18 #include "net/socket/ssl_host_info.h"
19 #include "net/socket/stream_socket.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace net { 22 namespace net {
23 23
24 using internal::ClientSocketPoolBaseHelper; 24 using internal::ClientSocketPoolBaseHelper;
25 25
26 namespace { 26 namespace {
27 27
28 const int kMaxSockets = 32; 28 const int kMaxSockets = 32;
29 const int kMaxSocketsPerGroup = 6; 29 const int kMaxSocketsPerGroup = 6;
30 const net::RequestPriority kDefaultPriority = LOW; 30 const net::RequestPriority kDefaultPriority = LOW;
31 31
32 class MockClientSocket : public ClientSocket { 32 class MockClientSocket : public StreamSocket {
33 public: 33 public:
34 MockClientSocket() : connected_(false) {} 34 MockClientSocket() : connected_(false) {}
35 35
36 // ClientSocket methods: 36 // StreamSocket methods:
37 virtual int Connect(CompletionCallback* callback) { 37 virtual int Connect(CompletionCallback* callback) {
38 connected_ = true; 38 connected_ = true;
39 return OK; 39 return OK;
40 } 40 }
41 virtual void Disconnect() { 41 virtual void Disconnect() {
42 connected_ = false; 42 connected_ = false;
43 } 43 }
44 virtual bool IsConnected() const { 44 virtual bool IsConnected() const {
45 return connected_; 45 return connected_;
46 } 46 }
(...skipping 25 matching lines...) Expand all
72 return ERR_FAILED; 72 return ERR_FAILED;
73 } 73 }
74 virtual bool SetReceiveBufferSize(int32 size) { return true; } 74 virtual bool SetReceiveBufferSize(int32 size) { return true; }
75 virtual bool SetSendBufferSize(int32 size) { return true; } 75 virtual bool SetSendBufferSize(int32 size) { return true; }
76 76
77 private: 77 private:
78 bool connected_; 78 bool connected_;
79 BoundNetLog net_log_; 79 BoundNetLog net_log_;
80 }; 80 };
81 81
82 class MockFailingClientSocket : public ClientSocket { 82 class MockFailingClientSocket : public StreamSocket {
83 public: 83 public:
84 MockFailingClientSocket() {} 84 MockFailingClientSocket() {}
85 85
86 // ClientSocket methods: 86 // StreamSocket methods:
87 virtual int Connect(CompletionCallback* callback) { 87 virtual int Connect(CompletionCallback* callback) {
88 return ERR_CONNECTION_FAILED; 88 return ERR_CONNECTION_FAILED;
89 } 89 }
90 90
91 virtual void Disconnect() {} 91 virtual void Disconnect() {}
92 92
93 virtual bool IsConnected() const { 93 virtual bool IsConnected() const {
94 return false; 94 return false;
95 } 95 }
96 virtual bool IsConnectedAndIdle() const { 96 virtual bool IsConnectedAndIdle() const {
(...skipping 24 matching lines...) Expand all
121 CompletionCallback* callback) { 121 CompletionCallback* callback) {
122 return ERR_FAILED; 122 return ERR_FAILED;
123 } 123 }
124 virtual bool SetReceiveBufferSize(int32 size) { return true; } 124 virtual bool SetReceiveBufferSize(int32 size) { return true; }
125 virtual bool SetSendBufferSize(int32 size) { return true; } 125 virtual bool SetSendBufferSize(int32 size) { return true; }
126 126
127 private: 127 private:
128 BoundNetLog net_log_; 128 BoundNetLog net_log_;
129 }; 129 };
130 130
131 class MockPendingClientSocket : public ClientSocket { 131 class MockPendingClientSocket : public StreamSocket {
132 public: 132 public:
133 // |should_connect| indicates whether the socket should successfully complete 133 // |should_connect| indicates whether the socket should successfully complete
134 // or fail. 134 // or fail.
135 // |should_stall| indicates that this socket should never connect. 135 // |should_stall| indicates that this socket should never connect.
136 // |delay_ms| is the delay, in milliseconds, before simulating a connect. 136 // |delay_ms| is the delay, in milliseconds, before simulating a connect.
137 MockPendingClientSocket(bool should_connect, bool should_stall, int delay_ms) 137 MockPendingClientSocket(bool should_connect, bool should_stall, int delay_ms)
138 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 138 : method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
139 should_connect_(should_connect), 139 should_connect_(should_connect),
140 should_stall_(should_stall), 140 should_stall_(should_stall),
141 delay_ms_(delay_ms), 141 delay_ms_(delay_ms),
142 is_connected_(false) {} 142 is_connected_(false) {}
143 143
144 // ClientSocket methods: 144 // StreamSocket methods:
145 virtual int Connect(CompletionCallback* callback) { 145 virtual int Connect(CompletionCallback* callback) {
146 MessageLoop::current()->PostDelayedTask( 146 MessageLoop::current()->PostDelayedTask(
147 FROM_HERE, 147 FROM_HERE,
148 method_factory_.NewRunnableMethod( 148 method_factory_.NewRunnableMethod(
149 &MockPendingClientSocket::DoCallback, callback), delay_ms_); 149 &MockPendingClientSocket::DoCallback, callback), delay_ms_);
150 return ERR_IO_PENDING; 150 return ERR_IO_PENDING;
151 } 151 }
152 152
153 virtual void Disconnect() {} 153 virtual void Disconnect() {}
154 154
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 MOCK_DELAYED_CLIENT_SOCKET, 219 MOCK_DELAYED_CLIENT_SOCKET,
220 // A stalled socket that never connects at all. 220 // A stalled socket that never connects at all.
221 MOCK_STALLED_CLIENT_SOCKET, 221 MOCK_STALLED_CLIENT_SOCKET,
222 }; 222 };
223 223
224 MockClientSocketFactory() 224 MockClientSocketFactory()
225 : allocation_count_(0), client_socket_type_(MOCK_CLIENT_SOCKET), 225 : allocation_count_(0), client_socket_type_(MOCK_CLIENT_SOCKET),
226 client_socket_types_(NULL), client_socket_index_(0), 226 client_socket_types_(NULL), client_socket_index_(0),
227 client_socket_index_max_(0) {} 227 client_socket_index_max_(0) {}
228 228
229 virtual ClientSocket* CreateTransportClientSocket( 229 virtual StreamSocket* CreateTransportClientSocket(
230 const AddressList& addresses, 230 const AddressList& addresses,
231 NetLog* /* net_log */, 231 NetLog* /* net_log */,
232 const NetLog::Source& /* source */) { 232 const NetLog::Source& /* source */) {
233 allocation_count_++; 233 allocation_count_++;
234 234
235 ClientSocketType type = client_socket_type_; 235 ClientSocketType type = client_socket_type_;
236 if (client_socket_types_ && 236 if (client_socket_types_ &&
237 client_socket_index_ < client_socket_index_max_) { 237 client_socket_index_ < client_socket_index_max_) {
238 type = client_socket_types_[client_socket_index_++]; 238 type = client_socket_types_[client_socket_index_++];
239 } 239 }
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 EXPECT_FALSE(handle.socket()); 931 EXPECT_FALSE(handle.socket());
932 handle.Reset(); 932 handle.Reset();
933 933
934 // Reset for the next case. 934 // Reset for the next case.
935 host_resolver_->set_synchronous_mode(false); 935 host_resolver_->set_synchronous_mode(false);
936 } 936 }
937 937
938 } // namespace 938 } // namespace
939 939
940 } // namespace net 940 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/transport_client_socket_pool.cc ('k') | net/socket/transport_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698