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

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

Issue 1755005: SPDY: Fix Alternate-Protocol. (Closed)
Patch Set: Address mbelshe's comments. Created 10 years, 8 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
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/spdy/spdy_framer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/socket_test_util.h" 5 #include "net/socket/socket_test_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 : MockClientSocket(transport_socket->NetLog().net_log()), 249 : MockClientSocket(transport_socket->NetLog().net_log()),
250 transport_(transport_socket), 250 transport_(transport_socket),
251 data_(data) { 251 data_(data) {
252 DCHECK(data_); 252 DCHECK(data_);
253 } 253 }
254 254
255 MockSSLClientSocket::~MockSSLClientSocket() { 255 MockSSLClientSocket::~MockSSLClientSocket() {
256 Disconnect(); 256 Disconnect();
257 } 257 }
258 258
259 void MockSSLClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) {
260 ssl_info->Reset();
261 }
262
263 int MockSSLClientSocket::Connect(net::CompletionCallback* callback) { 259 int MockSSLClientSocket::Connect(net::CompletionCallback* callback) {
264 ConnectCallback* connect_callback = new ConnectCallback( 260 ConnectCallback* connect_callback = new ConnectCallback(
265 this, callback, data_->connect.result); 261 this, callback, data_->connect.result);
266 int rv = transport_->Connect(connect_callback); 262 int rv = transport_->Connect(connect_callback);
267 if (rv == net::OK) { 263 if (rv == net::OK) {
268 delete connect_callback; 264 delete connect_callback;
269 if (data_->connect.async) { 265 if (data_->connect.async) {
270 RunCallbackAsync(callback, data_->connect.result); 266 RunCallbackAsync(callback, data_->connect.result);
271 return net::ERR_IO_PENDING; 267 return net::ERR_IO_PENDING;
272 } 268 }
(...skipping 13 matching lines...) Expand all
286 int MockSSLClientSocket::Read(net::IOBuffer* buf, int buf_len, 282 int MockSSLClientSocket::Read(net::IOBuffer* buf, int buf_len,
287 net::CompletionCallback* callback) { 283 net::CompletionCallback* callback) {
288 return transport_->Read(buf, buf_len, callback); 284 return transport_->Read(buf, buf_len, callback);
289 } 285 }
290 286
291 int MockSSLClientSocket::Write(net::IOBuffer* buf, int buf_len, 287 int MockSSLClientSocket::Write(net::IOBuffer* buf, int buf_len,
292 net::CompletionCallback* callback) { 288 net::CompletionCallback* callback) {
293 return transport_->Write(buf, buf_len, callback); 289 return transport_->Write(buf, buf_len, callback);
294 } 290 }
295 291
292 void MockSSLClientSocket::GetSSLInfo(net::SSLInfo* ssl_info) {
293 ssl_info->Reset();
294 }
295
296 SSLClientSocket::NextProtoStatus MockSSLClientSocket::GetNextProto(
297 std::string* proto) {
298 *proto = data_->next_proto;
299 return data_->next_proto_status;
300 }
301
296 MockRead StaticSocketDataProvider::GetNextRead() { 302 MockRead StaticSocketDataProvider::GetNextRead() {
297 DCHECK(!at_read_eof()); 303 DCHECK(!at_read_eof());
298 reads_[read_index_].time_stamp = base::Time::Now(); 304 reads_[read_index_].time_stamp = base::Time::Now();
299 return reads_[read_index_++]; 305 return reads_[read_index_++];
300 } 306 }
301 307
302 MockWriteResult StaticSocketDataProvider::OnWrite(const std::string& data) { 308 MockWriteResult StaticSocketDataProvider::OnWrite(const std::string& data) {
303 if (!writes_) { 309 if (!writes_) {
304 // Not using mock writes; succeed synchronously. 310 // Not using mock writes; succeed synchronously.
305 return MockWriteResult(false, data.length()); 311 return MockWriteResult(false, data.length());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 reads_.clear(); 385 reads_.clear();
380 } 386 }
381 387
382 void DynamicSocketDataProvider::SimulateRead(const char* data) { 388 void DynamicSocketDataProvider::SimulateRead(const char* data) {
383 if (!allow_unconsumed_reads_) { 389 if (!allow_unconsumed_reads_) {
384 EXPECT_TRUE(reads_.empty()) << "Unconsumed read: " << reads_.front().data; 390 EXPECT_TRUE(reads_.empty()) << "Unconsumed read: " << reads_.front().data;
385 } 391 }
386 reads_.push_back(MockRead(data)); 392 reads_.push_back(MockRead(data));
387 } 393 }
388 394
395 DelayedSocketData::DelayedSocketData(
396 int write_delay, MockRead* reads, size_t reads_count,
397 MockWrite* writes, size_t writes_count)
398 : StaticSocketDataProvider(reads, reads_count, writes, writes_count),
399 write_delay_(write_delay),
400 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
401 DCHECK_GE(write_delay_, 0);
402 }
403
404 DelayedSocketData::DelayedSocketData(
405 const MockConnect& connect, int write_delay, MockRead* reads,
406 size_t reads_count, MockWrite* writes, size_t writes_count)
407 : StaticSocketDataProvider(reads, reads_count, writes, writes_count),
408 write_delay_(write_delay),
409 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
410 DCHECK_GE(write_delay_, 0);
411 set_connect_data(connect);
412 }
413
414 MockRead DelayedSocketData::GetNextRead() {
415 if (write_delay_)
416 return MockRead(true, ERR_IO_PENDING);
417 return StaticSocketDataProvider::GetNextRead();
418 }
419
420 MockWriteResult DelayedSocketData::OnWrite(const std::string& data) {
421 MockWriteResult rv = StaticSocketDataProvider::OnWrite(data);
422 // Now that our write has completed, we can allow reads to continue.
423 if (!--write_delay_)
424 MessageLoop::current()->PostDelayedTask(FROM_HERE,
425 factory_.NewRunnableMethod(&DelayedSocketData::CompleteRead), 100);
426 return rv;
427 }
428
429 void DelayedSocketData::Reset() {
430 set_socket(NULL);
431 factory_.RevokeAll();
432 StaticSocketDataProvider::Reset();
433 }
434
435 void DelayedSocketData::CompleteRead() {
436 if (socket())
437 socket()->OnReadComplete(GetNextRead());
438 }
439
389 void MockClientSocketFactory::AddSocketDataProvider( 440 void MockClientSocketFactory::AddSocketDataProvider(
390 SocketDataProvider* data) { 441 SocketDataProvider* data) {
391 mock_data_.Add(data); 442 mock_data_.Add(data);
392 } 443 }
393 444
394 void MockClientSocketFactory::AddSSLSocketDataProvider( 445 void MockClientSocketFactory::AddSSLSocketDataProvider(
395 SSLSocketDataProvider* data) { 446 SSLSocketDataProvider* data) {
396 mock_ssl_data_.Add(data); 447 mock_ssl_data_.Add(data);
397 } 448 }
398 449
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 561
511 const char kSOCKS5OkRequest[] = 562 const char kSOCKS5OkRequest[] =
512 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; 563 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 };
513 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); 564 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest);
514 565
515 const char kSOCKS5OkResponse[] = 566 const char kSOCKS5OkResponse[] =
516 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; 567 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 };
517 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); 568 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse);
518 569
519 } // namespace net 570 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/spdy/spdy_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698