| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 271 } |
| 272 | 272 |
| 273 SSLSocketDataProvider::~SSLSocketDataProvider() { | 273 SSLSocketDataProvider::~SSLSocketDataProvider() { |
| 274 } | 274 } |
| 275 | 275 |
| 276 void SSLSocketDataProvider::SetNextProto(NextProto proto) { | 276 void SSLSocketDataProvider::SetNextProto(NextProto proto) { |
| 277 next_proto_status = SSLClientSocket::kNextProtoNegotiated; | 277 next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 278 next_proto = SSLClientSocket::NextProtoToString(proto); | 278 next_proto = SSLClientSocket::NextProtoToString(proto); |
| 279 } | 279 } |
| 280 | 280 |
| 281 DelayedSocketData::DelayedSocketData( | |
| 282 int write_delay, MockRead* reads, size_t reads_count, | |
| 283 MockWrite* writes, size_t writes_count) | |
| 284 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), | |
| 285 write_delay_(write_delay), | |
| 286 read_in_progress_(false), | |
| 287 weak_factory_(this) { | |
| 288 DCHECK_GE(write_delay_, 0); | |
| 289 } | |
| 290 | |
| 291 DelayedSocketData::DelayedSocketData( | |
| 292 const MockConnect& connect, int write_delay, MockRead* reads, | |
| 293 size_t reads_count, MockWrite* writes, size_t writes_count) | |
| 294 : StaticSocketDataProvider(reads, reads_count, writes, writes_count), | |
| 295 write_delay_(write_delay), | |
| 296 read_in_progress_(false), | |
| 297 weak_factory_(this) { | |
| 298 DCHECK_GE(write_delay_, 0); | |
| 299 set_connect_data(connect); | |
| 300 } | |
| 301 | |
| 302 DelayedSocketData::~DelayedSocketData() { | |
| 303 } | |
| 304 | |
| 305 void DelayedSocketData::ForceNextRead() { | |
| 306 DCHECK(read_in_progress_); | |
| 307 write_delay_ = 0; | |
| 308 CompleteRead(); | |
| 309 } | |
| 310 | |
| 311 MockRead DelayedSocketData::OnRead() { | |
| 312 MockRead out = MockRead(ASYNC, ERR_IO_PENDING); | |
| 313 if (write_delay_ <= 0) | |
| 314 out = StaticSocketDataProvider::OnRead(); | |
| 315 read_in_progress_ = (out.result == ERR_IO_PENDING); | |
| 316 return out; | |
| 317 } | |
| 318 | |
| 319 MockWriteResult DelayedSocketData::OnWrite(const std::string& data) { | |
| 320 MockWriteResult rv = StaticSocketDataProvider::OnWrite(data); | |
| 321 // Now that our write has completed, we can allow reads to continue. | |
| 322 if (!--write_delay_ && read_in_progress_) | |
| 323 base::MessageLoop::current()->PostDelayedTask( | |
| 324 FROM_HERE, | |
| 325 base::Bind(&DelayedSocketData::CompleteRead, | |
| 326 weak_factory_.GetWeakPtr()), | |
| 327 base::TimeDelta::FromMilliseconds(100)); | |
| 328 return rv; | |
| 329 } | |
| 330 | |
| 331 void DelayedSocketData::Reset() { | |
| 332 set_socket(NULL); | |
| 333 read_in_progress_ = false; | |
| 334 weak_factory_.InvalidateWeakPtrs(); | |
| 335 StaticSocketDataProvider::Reset(); | |
| 336 } | |
| 337 | |
| 338 void DelayedSocketData::CompleteRead() { | |
| 339 if (socket() && read_in_progress_) | |
| 340 socket()->OnReadComplete(OnRead()); | |
| 341 } | |
| 342 | |
| 343 SequencedSocketData::SequencedSocketData(MockRead* reads, | 281 SequencedSocketData::SequencedSocketData(MockRead* reads, |
| 344 size_t reads_count, | 282 size_t reads_count, |
| 345 MockWrite* writes, | 283 MockWrite* writes, |
| 346 size_t writes_count) | 284 size_t writes_count) |
| 347 : helper_(reads, reads_count, writes, writes_count), | 285 : helper_(reads, reads_count, writes, writes_count), |
| 348 sequence_number_(0), | 286 sequence_number_(0), |
| 349 read_state_(IDLE), | 287 read_state_(IDLE), |
| 350 write_state_(IDLE), | 288 write_state_(IDLE), |
| 351 weak_factory_(this) { | 289 weak_factory_(this) { |
| 352 // Check that reads and writes have a contiguous set of sequence numbers | 290 // Check that reads and writes have a contiguous set of sequence numbers |
| (...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2104 | 2042 |
| 2105 const char kSOCKS5OkRequest[] = | 2043 const char kSOCKS5OkRequest[] = |
| 2106 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 2044 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
| 2107 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 2045 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
| 2108 | 2046 |
| 2109 const char kSOCKS5OkResponse[] = | 2047 const char kSOCKS5OkResponse[] = |
| 2110 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 2048 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 2111 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 2049 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
| 2112 | 2050 |
| 2113 } // namespace net | 2051 } // namespace net |
| OLD | NEW |