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

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

Issue 4118004: Update NetLog to be thread safe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Final sync with trunk Created 10 years 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/socks5_client_socket.h" 5 #include "net/socket/socks5_client_socket.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 data_writes, arraysize(data_writes), 124 data_writes, arraysize(data_writes),
125 "localhost", 80, &net_log_)); 125 "localhost", 80, &net_log_));
126 126
127 // At this state the TCP connection is completed but not the SOCKS handshake. 127 // At this state the TCP connection is completed but not the SOCKS handshake.
128 EXPECT_TRUE(tcp_sock_->IsConnected()); 128 EXPECT_TRUE(tcp_sock_->IsConnected());
129 EXPECT_FALSE(user_sock_->IsConnected()); 129 EXPECT_FALSE(user_sock_->IsConnected());
130 130
131 int rv = user_sock_->Connect(&callback_); 131 int rv = user_sock_->Connect(&callback_);
132 EXPECT_EQ(ERR_IO_PENDING, rv); 132 EXPECT_EQ(ERR_IO_PENDING, rv);
133 EXPECT_FALSE(user_sock_->IsConnected()); 133 EXPECT_FALSE(user_sock_->IsConnected());
134 EXPECT_TRUE(LogContainsBeginEvent(net_log_.entries(), 0, 134
135 net::CapturingNetLog::EntryList net_log_entries;
136 net_log_.GetEntries(&net_log_entries);
137 EXPECT_TRUE(LogContainsBeginEvent(net_log_entries, 0,
135 NetLog::TYPE_SOCKS5_CONNECT)); 138 NetLog::TYPE_SOCKS5_CONNECT));
136 139
137 rv = callback_.WaitForResult(); 140 rv = callback_.WaitForResult();
138 141
139 EXPECT_EQ(OK, rv); 142 EXPECT_EQ(OK, rv);
140 EXPECT_TRUE(user_sock_->IsConnected()); 143 EXPECT_TRUE(user_sock_->IsConnected());
141 EXPECT_TRUE(LogContainsEndEvent(net_log_.entries(), -1, 144
145 net_log_.GetEntries(&net_log_entries);
146 EXPECT_TRUE(LogContainsEndEvent(net_log_entries, -1,
142 NetLog::TYPE_SOCKS5_CONNECT)); 147 NetLog::TYPE_SOCKS5_CONNECT));
143 148
144 scoped_refptr<IOBuffer> buffer(new IOBuffer(payload_write.size())); 149 scoped_refptr<IOBuffer> buffer(new IOBuffer(payload_write.size()));
145 memcpy(buffer->data(), payload_write.data(), payload_write.size()); 150 memcpy(buffer->data(), payload_write.data(), payload_write.size());
146 rv = user_sock_->Write(buffer, payload_write.size(), &callback_); 151 rv = user_sock_->Write(buffer, payload_write.size(), &callback_);
147 EXPECT_EQ(ERR_IO_PENDING, rv); 152 EXPECT_EQ(ERR_IO_PENDING, rv);
148 rv = callback_.WaitForResult(); 153 rv = callback_.WaitForResult();
149 EXPECT_EQ(static_cast<int>(payload_write.size()), rv); 154 EXPECT_EQ(static_cast<int>(payload_write.size()), rv);
150 155
151 buffer = new IOBuffer(payload_read.size()); 156 buffer = new IOBuffer(payload_read.size());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 MockWrite(true, partial2, arraysize(partial2)), 246 MockWrite(true, partial2, arraysize(partial2)),
242 MockWrite(true, kOkRequest, arraysize(kOkRequest)) }; 247 MockWrite(true, kOkRequest, arraysize(kOkRequest)) };
243 MockRead data_reads[] = { 248 MockRead data_reads[] = {
244 MockRead(true, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), 249 MockRead(true, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength),
245 MockRead(true, kSOCKS5OkResponse, kSOCKS5OkResponseLength) }; 250 MockRead(true, kSOCKS5OkResponse, kSOCKS5OkResponseLength) };
246 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), 251 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads),
247 data_writes, arraysize(data_writes), 252 data_writes, arraysize(data_writes),
248 hostname, 80, &net_log_)); 253 hostname, 80, &net_log_));
249 int rv = user_sock_->Connect(&callback_); 254 int rv = user_sock_->Connect(&callback_);
250 EXPECT_EQ(ERR_IO_PENDING, rv); 255 EXPECT_EQ(ERR_IO_PENDING, rv);
251 EXPECT_TRUE(LogContainsBeginEvent(net_log_.entries(), 0, 256
257 net::CapturingNetLog::EntryList net_log_entries;
258 net_log_.GetEntries(&net_log_entries);
259 EXPECT_TRUE(LogContainsBeginEvent(net_log_entries, 0,
252 NetLog::TYPE_SOCKS5_CONNECT)); 260 NetLog::TYPE_SOCKS5_CONNECT));
261
253 rv = callback_.WaitForResult(); 262 rv = callback_.WaitForResult();
254 EXPECT_EQ(OK, rv); 263 EXPECT_EQ(OK, rv);
255 EXPECT_TRUE(user_sock_->IsConnected()); 264 EXPECT_TRUE(user_sock_->IsConnected());
256 EXPECT_TRUE(LogContainsEndEvent(net_log_.entries(), -1, 265
266 net_log_.GetEntries(&net_log_entries);
267 EXPECT_TRUE(LogContainsEndEvent(net_log_entries, -1,
257 NetLog::TYPE_SOCKS5_CONNECT)); 268 NetLog::TYPE_SOCKS5_CONNECT));
258 } 269 }
259 270
260 // Test for partial greet response read 271 // Test for partial greet response read
261 { 272 {
262 const char partial1[] = { 0x05 }; 273 const char partial1[] = { 0x05 };
263 const char partial2[] = { 0x00 }; 274 const char partial2[] = { 0x00 };
264 MockWrite data_writes[] = { 275 MockWrite data_writes[] = {
265 MockWrite(true, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), 276 MockWrite(true, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength),
266 MockWrite(true, kOkRequest, arraysize(kOkRequest)) }; 277 MockWrite(true, kOkRequest, arraysize(kOkRequest)) };
267 MockRead data_reads[] = { 278 MockRead data_reads[] = {
268 MockRead(true, partial1, arraysize(partial1)), 279 MockRead(true, partial1, arraysize(partial1)),
269 MockRead(true, partial2, arraysize(partial2)), 280 MockRead(true, partial2, arraysize(partial2)),
270 MockRead(true, kSOCKS5OkResponse, kSOCKS5OkResponseLength) }; 281 MockRead(true, kSOCKS5OkResponse, kSOCKS5OkResponseLength) };
271 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), 282 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads),
272 data_writes, arraysize(data_writes), 283 data_writes, arraysize(data_writes),
273 hostname, 80, &net_log_)); 284 hostname, 80, &net_log_));
274 int rv = user_sock_->Connect(&callback_); 285 int rv = user_sock_->Connect(&callback_);
275 EXPECT_EQ(ERR_IO_PENDING, rv); 286 EXPECT_EQ(ERR_IO_PENDING, rv);
276 EXPECT_TRUE(LogContainsBeginEvent(net_log_.entries(), 0, 287
288 net::CapturingNetLog::EntryList net_log_entries;
289 net_log_.GetEntries(&net_log_entries);
290 EXPECT_TRUE(LogContainsBeginEvent(net_log_entries, 0,
277 NetLog::TYPE_SOCKS5_CONNECT)); 291 NetLog::TYPE_SOCKS5_CONNECT));
278 rv = callback_.WaitForResult(); 292 rv = callback_.WaitForResult();
279 EXPECT_EQ(OK, rv); 293 EXPECT_EQ(OK, rv);
280 EXPECT_TRUE(user_sock_->IsConnected()); 294 EXPECT_TRUE(user_sock_->IsConnected());
281 EXPECT_TRUE(LogContainsEndEvent(net_log_.entries(), -1, 295 net_log_.GetEntries(&net_log_entries);
296 EXPECT_TRUE(LogContainsEndEvent(net_log_entries, -1,
282 NetLog::TYPE_SOCKS5_CONNECT)); 297 NetLog::TYPE_SOCKS5_CONNECT));
283 } 298 }
284 299
285 // Test for partial handshake request write. 300 // Test for partial handshake request write.
286 { 301 {
287 const int kSplitPoint = 3; // Break handshake write into two parts. 302 const int kSplitPoint = 3; // Break handshake write into two parts.
288 MockWrite data_writes[] = { 303 MockWrite data_writes[] = {
289 MockWrite(true, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), 304 MockWrite(true, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength),
290 MockWrite(true, kOkRequest, kSplitPoint), 305 MockWrite(true, kOkRequest, kSplitPoint),
291 MockWrite(true, kOkRequest + kSplitPoint, 306 MockWrite(true, kOkRequest + kSplitPoint,
292 arraysize(kOkRequest) - kSplitPoint) 307 arraysize(kOkRequest) - kSplitPoint)
293 }; 308 };
294 MockRead data_reads[] = { 309 MockRead data_reads[] = {
295 MockRead(true, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), 310 MockRead(true, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength),
296 MockRead(true, kSOCKS5OkResponse, kSOCKS5OkResponseLength) }; 311 MockRead(true, kSOCKS5OkResponse, kSOCKS5OkResponseLength) };
297 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), 312 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads),
298 data_writes, arraysize(data_writes), 313 data_writes, arraysize(data_writes),
299 hostname, 80, &net_log_)); 314 hostname, 80, &net_log_));
300 int rv = user_sock_->Connect(&callback_); 315 int rv = user_sock_->Connect(&callback_);
301 EXPECT_EQ(ERR_IO_PENDING, rv); 316 EXPECT_EQ(ERR_IO_PENDING, rv);
302 EXPECT_TRUE(LogContainsBeginEvent(net_log_.entries(), 0, 317 net::CapturingNetLog::EntryList net_log_entries;
318 net_log_.GetEntries(&net_log_entries);
319 EXPECT_TRUE(LogContainsBeginEvent(net_log_entries, 0,
303 NetLog::TYPE_SOCKS5_CONNECT)); 320 NetLog::TYPE_SOCKS5_CONNECT));
304 rv = callback_.WaitForResult(); 321 rv = callback_.WaitForResult();
305 EXPECT_EQ(OK, rv); 322 EXPECT_EQ(OK, rv);
306 EXPECT_TRUE(user_sock_->IsConnected()); 323 EXPECT_TRUE(user_sock_->IsConnected());
307 EXPECT_TRUE(LogContainsEndEvent(net_log_.entries(), -1, 324 net_log_.GetEntries(&net_log_entries);
325 EXPECT_TRUE(LogContainsEndEvent(net_log_entries, -1,
308 NetLog::TYPE_SOCKS5_CONNECT)); 326 NetLog::TYPE_SOCKS5_CONNECT));
309 } 327 }
310 328
311 // Test for partial handshake response read 329 // Test for partial handshake response read
312 { 330 {
313 const int kSplitPoint = 6; // Break the handshake read into two parts. 331 const int kSplitPoint = 6; // Break the handshake read into two parts.
314 MockWrite data_writes[] = { 332 MockWrite data_writes[] = {
315 MockWrite(true, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), 333 MockWrite(true, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength),
316 MockWrite(true, kOkRequest, arraysize(kOkRequest)) 334 MockWrite(true, kOkRequest, arraysize(kOkRequest))
317 }; 335 };
318 MockRead data_reads[] = { 336 MockRead data_reads[] = {
319 MockRead(true, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), 337 MockRead(true, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength),
320 MockRead(true, kSOCKS5OkResponse, kSplitPoint), 338 MockRead(true, kSOCKS5OkResponse, kSplitPoint),
321 MockRead(true, kSOCKS5OkResponse + kSplitPoint, 339 MockRead(true, kSOCKS5OkResponse + kSplitPoint,
322 kSOCKS5OkResponseLength - kSplitPoint) 340 kSOCKS5OkResponseLength - kSplitPoint)
323 }; 341 };
324 342
325 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads), 343 user_sock_.reset(BuildMockSocket(data_reads, arraysize(data_reads),
326 data_writes, arraysize(data_writes), 344 data_writes, arraysize(data_writes),
327 hostname, 80, &net_log_)); 345 hostname, 80, &net_log_));
328 int rv = user_sock_->Connect(&callback_); 346 int rv = user_sock_->Connect(&callback_);
329 EXPECT_EQ(ERR_IO_PENDING, rv); 347 EXPECT_EQ(ERR_IO_PENDING, rv);
330 EXPECT_TRUE(LogContainsBeginEvent(net_log_.entries(), 0, 348 net::CapturingNetLog::EntryList net_log_entries;
349 net_log_.GetEntries(&net_log_entries);
350 EXPECT_TRUE(LogContainsBeginEvent(net_log_entries, 0,
331 NetLog::TYPE_SOCKS5_CONNECT)); 351 NetLog::TYPE_SOCKS5_CONNECT));
332 rv = callback_.WaitForResult(); 352 rv = callback_.WaitForResult();
333 EXPECT_EQ(OK, rv); 353 EXPECT_EQ(OK, rv);
334 EXPECT_TRUE(user_sock_->IsConnected()); 354 EXPECT_TRUE(user_sock_->IsConnected());
335 EXPECT_TRUE(LogContainsEndEvent(net_log_.entries(), -1, 355 net_log_.GetEntries(&net_log_entries);
356 EXPECT_TRUE(LogContainsEndEvent(net_log_entries, -1,
336 NetLog::TYPE_SOCKS5_CONNECT)); 357 NetLog::TYPE_SOCKS5_CONNECT));
337 } 358 }
338 } 359 }
339 360
340 } // namespace 361 } // namespace
341 362
342 } // namespace net 363 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_base_unittest.cc ('k') | net/socket/socks_client_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698