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

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

Issue 8568021: Add OVERRIDE to net/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: net only Created 9 years, 1 month 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
« no previous file with comments | « net/socket/client_socket_pool_manager.h ('k') | net/socket/socks5_client_socket.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) 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 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ 5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_
6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <cstring> 9 #include <cstring>
10 #include <deque> 10 #include <deque>
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 size_t write_index() const { return write_index_; } 192 size_t write_index() const { return write_index_; }
193 size_t read_count() const { return read_count_; } 193 size_t read_count() const { return read_count_; }
194 size_t write_count() const { return write_count_; } 194 size_t write_count() const { return write_count_; }
195 195
196 bool at_read_eof() const { return read_index_ >= read_count_; } 196 bool at_read_eof() const { return read_index_ >= read_count_; }
197 bool at_write_eof() const { return write_index_ >= write_count_; } 197 bool at_write_eof() const { return write_index_ >= write_count_; }
198 198
199 virtual void CompleteRead() {} 199 virtual void CompleteRead() {}
200 200
201 // SocketDataProvider methods: 201 // SocketDataProvider methods:
202 virtual MockRead GetNextRead(); 202 virtual MockRead GetNextRead() OVERRIDE;
203 virtual MockWriteResult OnWrite(const std::string& data); 203 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
204 virtual void Reset(); 204 virtual void Reset() OVERRIDE;
205 205
206 private: 206 private:
207 MockRead* reads_; 207 MockRead* reads_;
208 size_t read_index_; 208 size_t read_index_;
209 size_t read_count_; 209 size_t read_count_;
210 MockWrite* writes_; 210 MockWrite* writes_;
211 size_t write_index_; 211 size_t write_index_;
212 size_t write_count_; 212 size_t write_count_;
213 213
214 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); 214 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
215 }; 215 };
216 216
217 // SocketDataProvider which can make decisions about next mock reads based on 217 // SocketDataProvider which can make decisions about next mock reads based on
218 // received writes. It can also be used to enforce order of operations, for 218 // received writes. It can also be used to enforce order of operations, for
219 // example that tested code must send the "Hello!" message before receiving 219 // example that tested code must send the "Hello!" message before receiving
220 // response. This is useful for testing conversation-like protocols like FTP. 220 // response. This is useful for testing conversation-like protocols like FTP.
221 class DynamicSocketDataProvider : public SocketDataProvider { 221 class DynamicSocketDataProvider : public SocketDataProvider {
222 public: 222 public:
223 DynamicSocketDataProvider(); 223 DynamicSocketDataProvider();
224 virtual ~DynamicSocketDataProvider(); 224 virtual ~DynamicSocketDataProvider();
225 225
226 int short_read_limit() const { return short_read_limit_; } 226 int short_read_limit() const { return short_read_limit_; }
227 void set_short_read_limit(int limit) { short_read_limit_ = limit; } 227 void set_short_read_limit(int limit) { short_read_limit_ = limit; }
228 228
229 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; } 229 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; }
230 230
231 // SocketDataProvider methods: 231 // SocketDataProvider methods:
232 virtual MockRead GetNextRead(); 232 virtual MockRead GetNextRead() OVERRIDE;
233 virtual MockWriteResult OnWrite(const std::string& data) = 0; 233 virtual MockWriteResult OnWrite(const std::string& data) = 0;
234 virtual void Reset(); 234 virtual void Reset() OVERRIDE;
235 235
236 protected: 236 protected:
237 // The next time there is a read from this socket, it will return |data|. 237 // The next time there is a read from this socket, it will return |data|.
238 // Before calling SimulateRead next time, the previous data must be consumed. 238 // Before calling SimulateRead next time, the previous data must be consumed.
239 void SimulateRead(const char* data, size_t length); 239 void SimulateRead(const char* data, size_t length);
240 void SimulateRead(const char* data) { 240 void SimulateRead(const char* data) {
241 SimulateRead(data, std::strlen(data)); 241 SimulateRead(data, std::strlen(data));
242 } 242 }
243 243
244 private: 244 private:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // Note: The MockRead and MockWrite lists musts end with a EOF 294 // Note: The MockRead and MockWrite lists musts end with a EOF
295 // e.g. a MockRead(true, 0, 0); 295 // e.g. a MockRead(true, 0, 0);
296 DelayedSocketData(const MockConnect& connect, int write_delay, 296 DelayedSocketData(const MockConnect& connect, int write_delay,
297 MockRead* reads, size_t reads_count, 297 MockRead* reads, size_t reads_count,
298 MockWrite* writes, size_t writes_count); 298 MockWrite* writes, size_t writes_count);
299 virtual ~DelayedSocketData(); 299 virtual ~DelayedSocketData();
300 300
301 void ForceNextRead(); 301 void ForceNextRead();
302 302
303 // StaticSocketDataProvider: 303 // StaticSocketDataProvider:
304 virtual MockRead GetNextRead(); 304 virtual MockRead GetNextRead() OVERRIDE;
305 virtual MockWriteResult OnWrite(const std::string& data); 305 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
306 virtual void Reset(); 306 virtual void Reset() OVERRIDE;
307 virtual void CompleteRead(); 307 virtual void CompleteRead() OVERRIDE;
308 308
309 private: 309 private:
310 int write_delay_; 310 int write_delay_;
311 ScopedRunnableMethodFactory<DelayedSocketData> factory_; 311 ScopedRunnableMethodFactory<DelayedSocketData> factory_;
312 }; 312 };
313 313
314 // A DataProvider where the reads are ordered. 314 // A DataProvider where the reads are ordered.
315 // If a read is requested before its sequence number is reached, we return an 315 // If a read is requested before its sequence number is reached, we return an
316 // ERR_IO_PENDING (that way we don't have to explicitly add a MockRead just to 316 // ERR_IO_PENDING (that way we don't have to explicitly add a MockRead just to
317 // wait). 317 // wait).
(...skipping 26 matching lines...) Expand all
344 MockWrite* writes, size_t writes_count); 344 MockWrite* writes, size_t writes_count);
345 345
346 void SetOldCompletionCallback(OldCompletionCallback* callback) { 346 void SetOldCompletionCallback(OldCompletionCallback* callback) {
347 callback_ = callback; 347 callback_ = callback;
348 } 348 }
349 349
350 // Posts a quit message to the current message loop, if one is running. 350 // Posts a quit message to the current message loop, if one is running.
351 void EndLoop(); 351 void EndLoop();
352 352
353 // StaticSocketDataProvider: 353 // StaticSocketDataProvider:
354 virtual MockRead GetNextRead(); 354 virtual MockRead GetNextRead() OVERRIDE;
355 virtual MockWriteResult OnWrite(const std::string& data); 355 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
356 virtual void Reset(); 356 virtual void Reset() OVERRIDE;
357 virtual void CompleteRead(); 357 virtual void CompleteRead() OVERRIDE;
358 358
359 private: 359 private:
360 friend class base::RefCounted<OrderedSocketData>; 360 friend class base::RefCounted<OrderedSocketData>;
361 virtual ~OrderedSocketData(); 361 virtual ~OrderedSocketData();
362 362
363 int sequence_number_; 363 int sequence_number_;
364 int loop_stop_stage_; 364 int loop_stop_stage_;
365 OldCompletionCallback* callback_; 365 OldCompletionCallback* callback_;
366 bool blocked_; 366 bool blocked_;
367 ScopedRunnableMethodFactory<OrderedSocketData> factory_; 367 ScopedRunnableMethodFactory<OrderedSocketData> factory_;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 MockRead& current_write() { return current_write_; } 452 MockRead& current_write() { return current_write_; }
453 int sequence_number() const { return sequence_number_; } 453 int sequence_number() const { return sequence_number_; }
454 void set_socket(base::WeakPtr<DeterministicMockTCPClientSocket> socket) { 454 void set_socket(base::WeakPtr<DeterministicMockTCPClientSocket> socket) {
455 socket_ = socket; 455 socket_ = socket;
456 } 456 }
457 457
458 // StaticSocketDataProvider: 458 // StaticSocketDataProvider:
459 459
460 // When the socket calls Read(), that calls GetNextRead(), and expects either 460 // When the socket calls Read(), that calls GetNextRead(), and expects either
461 // ERR_IO_PENDING or data. 461 // ERR_IO_PENDING or data.
462 virtual MockRead GetNextRead(); 462 virtual MockRead GetNextRead() OVERRIDE;
463 463
464 // When the socket calls Write(), it always completes synchronously. OnWrite() 464 // When the socket calls Write(), it always completes synchronously. OnWrite()
465 // checks to make sure the written data matches the expected data. The 465 // checks to make sure the written data matches the expected data. The
466 // callback will not be invoked until its sequence number is reached. 466 // callback will not be invoked until its sequence number is reached.
467 virtual MockWriteResult OnWrite(const std::string& data); 467 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE;
468 virtual void Reset(); 468 virtual void Reset() OVERRIDE;
469 virtual void CompleteRead() {} 469 virtual void CompleteRead() OVERRIDE {}
470 470
471 private: 471 private:
472 // Invoke the read and write callbacks, if the timing is appropriate. 472 // Invoke the read and write callbacks, if the timing is appropriate.
473 void InvokeCallbacks(); 473 void InvokeCallbacks();
474 474
475 void NextStep(); 475 void NextStep();
476 476
477 int sequence_number_; 477 int sequence_number_;
478 MockRead current_read_; 478 MockRead current_read_;
479 MockWrite current_write_; 479 MockWrite current_write_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 549 }
550 std::vector<MockUDPClientSocket*>& udp_client_sockets() { 550 std::vector<MockUDPClientSocket*>& udp_client_sockets() {
551 return udp_client_sockets_; 551 return udp_client_sockets_;
552 } 552 }
553 553
554 // ClientSocketFactory 554 // ClientSocketFactory
555 virtual DatagramClientSocket* CreateDatagramClientSocket( 555 virtual DatagramClientSocket* CreateDatagramClientSocket(
556 DatagramSocket::BindType bind_type, 556 DatagramSocket::BindType bind_type,
557 const RandIntCallback& rand_int_cb, 557 const RandIntCallback& rand_int_cb,
558 NetLog* net_log, 558 NetLog* net_log,
559 const NetLog::Source& source); 559 const NetLog::Source& source) OVERRIDE;
560 virtual StreamSocket* CreateTransportClientSocket( 560 virtual StreamSocket* CreateTransportClientSocket(
561 const AddressList& addresses, 561 const AddressList& addresses,
562 NetLog* net_log, 562 NetLog* net_log,
563 const NetLog::Source& source); 563 const NetLog::Source& source) OVERRIDE;
564 virtual SSLClientSocket* CreateSSLClientSocket( 564 virtual SSLClientSocket* CreateSSLClientSocket(
565 ClientSocketHandle* transport_socket, 565 ClientSocketHandle* transport_socket,
566 const HostPortPair& host_and_port, 566 const HostPortPair& host_and_port,
567 const SSLConfig& ssl_config, 567 const SSLConfig& ssl_config,
568 SSLHostInfo* ssl_host_info, 568 SSLHostInfo* ssl_host_info,
569 const SSLClientSocketContext& context); 569 const SSLClientSocketContext& context) OVERRIDE;
570 virtual void ClearSSLSessionCache(); 570 virtual void ClearSSLSessionCache() OVERRIDE;
571 571
572 private: 572 private:
573 SocketDataProviderArray<SocketDataProvider> mock_data_; 573 SocketDataProviderArray<SocketDataProvider> mock_data_;
574 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 574 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
575 575
576 // Store pointers to handed out sockets in case the test wants to get them. 576 // Store pointers to handed out sockets in case the test wants to get them.
577 std::vector<MockUDPClientSocket*> udp_client_sockets_; 577 std::vector<MockUDPClientSocket*> udp_client_sockets_;
578 std::vector<MockTCPClientSocket*> tcp_client_sockets_; 578 std::vector<MockTCPClientSocket*> tcp_client_sockets_;
579 std::vector<MockSSLClientSocket*> ssl_client_sockets_; 579 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
580 }; 580 };
581 581
582 class MockClientSocket : public net::SSLClientSocket { 582 class MockClientSocket : public net::SSLClientSocket {
583 public: 583 public:
584 explicit MockClientSocket(net::NetLog* net_log); 584 explicit MockClientSocket(net::NetLog* net_log);
585 585
586 // Socket methods: 586 // Socket methods:
587 virtual int Read(net::IOBuffer* buf, int buf_len, 587 virtual int Read(net::IOBuffer* buf, int buf_len,
588 net::OldCompletionCallback* callback) = 0; 588 net::OldCompletionCallback* callback) = 0;
589 virtual int Write(net::IOBuffer* buf, int buf_len, 589 virtual int Write(net::IOBuffer* buf, int buf_len,
590 net::OldCompletionCallback* callback) = 0; 590 net::OldCompletionCallback* callback) = 0;
591 virtual bool SetReceiveBufferSize(int32 size); 591 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
592 virtual bool SetSendBufferSize(int32 size); 592 virtual bool SetSendBufferSize(int32 size) OVERRIDE;
593 593
594 // StreamSocket methods: 594 // StreamSocket methods:
595 virtual int Connect(net::OldCompletionCallback* callback) = 0; 595 virtual int Connect(net::OldCompletionCallback* callback) = 0;
596 virtual void Disconnect(); 596 virtual void Disconnect() OVERRIDE;
597 virtual bool IsConnected() const; 597 virtual bool IsConnected() const OVERRIDE;
598 virtual bool IsConnectedAndIdle() const; 598 virtual bool IsConnectedAndIdle() const OVERRIDE;
599 virtual int GetPeerAddress(AddressList* address) const; 599 virtual int GetPeerAddress(AddressList* address) const OVERRIDE;
600 virtual int GetLocalAddress(IPEndPoint* address) const; 600 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
601 virtual const BoundNetLog& NetLog() const; 601 virtual const BoundNetLog& NetLog() const OVERRIDE;
602 virtual void SetSubresourceSpeculation() {} 602 virtual void SetSubresourceSpeculation() OVERRIDE {}
603 virtual void SetOmniboxSpeculation() {} 603 virtual void SetOmniboxSpeculation() OVERRIDE {}
604 604
605 // SSLClientSocket methods: 605 // SSLClientSocket methods:
606 virtual void GetSSLInfo(net::SSLInfo* ssl_info); 606 virtual void GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
607 virtual void GetSSLCertRequestInfo( 607 virtual void GetSSLCertRequestInfo(
608 net::SSLCertRequestInfo* cert_request_info); 608 net::SSLCertRequestInfo* cert_request_info) OVERRIDE;
609 virtual int ExportKeyingMaterial(const base::StringPiece& label, 609 virtual int ExportKeyingMaterial(const base::StringPiece& label,
610 const base::StringPiece& context, 610 const base::StringPiece& context,
611 unsigned char *out, 611 unsigned char *out,
612 unsigned int outlen); 612 unsigned int outlen) OVERRIDE;
613 virtual NextProtoStatus GetNextProto(std::string* proto); 613 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE;
614 614
615 protected: 615 protected:
616 virtual ~MockClientSocket(); 616 virtual ~MockClientSocket();
617 void RunCallbackAsync(net::OldCompletionCallback* callback, int result); 617 void RunCallbackAsync(net::OldCompletionCallback* callback, int result);
618 void RunCallback(net::OldCompletionCallback*, int result); 618 void RunCallback(net::OldCompletionCallback*, int result);
619 619
620 ScopedRunnableMethodFactory<MockClientSocket> method_factory_; 620 ScopedRunnableMethodFactory<MockClientSocket> method_factory_;
621 621
622 // True if Connect completed successfully and Disconnect hasn't been called. 622 // True if Connect completed successfully and Disconnect hasn't been called.
623 bool connected_; 623 bool connected_;
624 624
625 net::BoundNetLog net_log_; 625 net::BoundNetLog net_log_;
626 }; 626 };
627 627
628 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { 628 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
629 public: 629 public:
630 MockTCPClientSocket(const net::AddressList& addresses, net::NetLog* net_log, 630 MockTCPClientSocket(const net::AddressList& addresses, net::NetLog* net_log,
631 net::SocketDataProvider* socket); 631 net::SocketDataProvider* socket);
632 632
633 net::AddressList addresses() const { return addresses_; } 633 net::AddressList addresses() const { return addresses_; }
634 634
635 // Socket methods: 635 // Socket methods:
636 virtual int Read(net::IOBuffer* buf, int buf_len, 636 virtual int Read(net::IOBuffer* buf, int buf_len,
637 net::OldCompletionCallback* callback); 637 net::OldCompletionCallback* callback) OVERRIDE;
638 virtual int Write(net::IOBuffer* buf, int buf_len, 638 virtual int Write(net::IOBuffer* buf, int buf_len,
639 net::OldCompletionCallback* callback); 639 net::OldCompletionCallback* callback) OVERRIDE;
640 640
641 // StreamSocket methods: 641 // StreamSocket methods:
642 virtual int Connect(net::OldCompletionCallback* callback); 642 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
643 virtual void Disconnect(); 643 virtual void Disconnect() OVERRIDE;
644 virtual bool IsConnected() const; 644 virtual bool IsConnected() const OVERRIDE;
645 virtual bool IsConnectedAndIdle() const; 645 virtual bool IsConnectedAndIdle() const OVERRIDE;
646 virtual int GetPeerAddress(AddressList* address) const; 646 virtual int GetPeerAddress(AddressList* address) const OVERRIDE;
647 virtual bool WasEverUsed() const; 647 virtual bool WasEverUsed() const OVERRIDE;
648 virtual bool UsingTCPFastOpen() const; 648 virtual bool UsingTCPFastOpen() const OVERRIDE;
649 virtual int64 NumBytesRead() const; 649 virtual int64 NumBytesRead() const OVERRIDE;
650 virtual base::TimeDelta GetConnectTimeMicros() const; 650 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
651 651
652 // AsyncSocket: 652 // AsyncSocket:
653 virtual void OnReadComplete(const MockRead& data); 653 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
654 654
655 private: 655 private:
656 int CompleteRead(); 656 int CompleteRead();
657 657
658 net::AddressList addresses_; 658 net::AddressList addresses_;
659 659
660 net::SocketDataProvider* data_; 660 net::SocketDataProvider* data_;
661 int read_offset_; 661 int read_offset_;
662 int num_bytes_read_; 662 int num_bytes_read_;
663 net::MockRead read_data_; 663 net::MockRead read_data_;
(...skipping 20 matching lines...) Expand all
684 virtual ~DeterministicMockTCPClientSocket(); 684 virtual ~DeterministicMockTCPClientSocket();
685 685
686 bool write_pending() const { return write_pending_; } 686 bool write_pending() const { return write_pending_; }
687 bool read_pending() const { return read_pending_; } 687 bool read_pending() const { return read_pending_; }
688 688
689 void CompleteWrite(); 689 void CompleteWrite();
690 int CompleteRead(); 690 int CompleteRead();
691 691
692 // Socket: 692 // Socket:
693 virtual int Write(net::IOBuffer* buf, int buf_len, 693 virtual int Write(net::IOBuffer* buf, int buf_len,
694 net::OldCompletionCallback* callback); 694 net::OldCompletionCallback* callback) OVERRIDE;
695 virtual int Read(net::IOBuffer* buf, int buf_len, 695 virtual int Read(net::IOBuffer* buf, int buf_len,
696 net::OldCompletionCallback* callback); 696 net::OldCompletionCallback* callback) OVERRIDE;
697 697
698 // StreamSocket: 698 // StreamSocket:
699 virtual int Connect(net::OldCompletionCallback* callback); 699 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
700 virtual void Disconnect(); 700 virtual void Disconnect() OVERRIDE;
701 virtual bool IsConnected() const; 701 virtual bool IsConnected() const OVERRIDE;
702 virtual bool IsConnectedAndIdle() const; 702 virtual bool IsConnectedAndIdle() const OVERRIDE;
703 virtual bool WasEverUsed() const; 703 virtual bool WasEverUsed() const OVERRIDE;
704 virtual bool UsingTCPFastOpen() const; 704 virtual bool UsingTCPFastOpen() const OVERRIDE;
705 virtual int64 NumBytesRead() const; 705 virtual int64 NumBytesRead() const OVERRIDE;
706 virtual base::TimeDelta GetConnectTimeMicros() const; 706 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
707 707
708 // AsyncSocket: 708 // AsyncSocket:
709 virtual void OnReadComplete(const MockRead& data); 709 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
710 710
711 private: 711 private:
712 bool write_pending_; 712 bool write_pending_;
713 net::OldCompletionCallback* write_callback_; 713 net::OldCompletionCallback* write_callback_;
714 int write_result_; 714 int write_result_;
715 715
716 net::MockRead read_data_; 716 net::MockRead read_data_;
717 717
718 net::IOBuffer* read_buf_; 718 net::IOBuffer* read_buf_;
719 int read_buf_len_; 719 int read_buf_len_;
720 bool read_pending_; 720 bool read_pending_;
721 net::OldCompletionCallback* read_callback_; 721 net::OldCompletionCallback* read_callback_;
722 net::DeterministicSocketData* data_; 722 net::DeterministicSocketData* data_;
723 bool was_used_to_convey_data_; 723 bool was_used_to_convey_data_;
724 }; 724 };
725 725
726 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { 726 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
727 public: 727 public:
728 MockSSLClientSocket( 728 MockSSLClientSocket(
729 net::ClientSocketHandle* transport_socket, 729 net::ClientSocketHandle* transport_socket,
730 const HostPortPair& host_and_port, 730 const HostPortPair& host_and_port,
731 const net::SSLConfig& ssl_config, 731 const net::SSLConfig& ssl_config,
732 SSLHostInfo* ssl_host_info, 732 SSLHostInfo* ssl_host_info,
733 net::SSLSocketDataProvider* socket); 733 net::SSLSocketDataProvider* socket);
734 virtual ~MockSSLClientSocket(); 734 virtual ~MockSSLClientSocket();
735 735
736 // Socket methods: 736 // Socket methods:
737 virtual int Read(net::IOBuffer* buf, int buf_len, 737 virtual int Read(net::IOBuffer* buf, int buf_len,
738 net::OldCompletionCallback* callback); 738 net::OldCompletionCallback* callback) OVERRIDE;
739 virtual int Write(net::IOBuffer* buf, int buf_len, 739 virtual int Write(net::IOBuffer* buf, int buf_len,
740 net::OldCompletionCallback* callback); 740 net::OldCompletionCallback* callback) OVERRIDE;
741 741
742 // StreamSocket methods: 742 // StreamSocket methods:
743 virtual int Connect(net::OldCompletionCallback* callback); 743 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE;
744 virtual void Disconnect(); 744 virtual void Disconnect() OVERRIDE;
745 virtual bool IsConnected() const; 745 virtual bool IsConnected() const OVERRIDE;
746 virtual bool WasEverUsed() const; 746 virtual bool WasEverUsed() const OVERRIDE;
747 virtual bool UsingTCPFastOpen() const; 747 virtual bool UsingTCPFastOpen() const OVERRIDE;
748 virtual int64 NumBytesRead() const; 748 virtual int64 NumBytesRead() const OVERRIDE;
749 virtual base::TimeDelta GetConnectTimeMicros() const; 749 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
750 750
751 // SSLClientSocket methods: 751 // SSLClientSocket methods:
752 virtual void GetSSLInfo(net::SSLInfo* ssl_info); 752 virtual void GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
753 virtual void GetSSLCertRequestInfo( 753 virtual void GetSSLCertRequestInfo(
754 net::SSLCertRequestInfo* cert_request_info); 754 net::SSLCertRequestInfo* cert_request_info) OVERRIDE;
755 virtual NextProtoStatus GetNextProto(std::string* proto); 755 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE;
756 virtual bool was_npn_negotiated() const; 756 virtual bool was_npn_negotiated() const OVERRIDE;
757 virtual bool set_was_npn_negotiated(bool negotiated); 757 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE;
758 758
759 // This MockSocket does not implement the manual async IO feature. 759 // This MockSocket does not implement the manual async IO feature.
760 virtual void OnReadComplete(const MockRead& data); 760 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
761 761
762 private: 762 private:
763 class ConnectCallback; 763 class ConnectCallback;
764 764
765 scoped_ptr<ClientSocketHandle> transport_; 765 scoped_ptr<ClientSocketHandle> transport_;
766 net::SSLSocketDataProvider* data_; 766 net::SSLSocketDataProvider* data_;
767 bool is_npn_state_set_; 767 bool is_npn_state_set_;
768 bool new_npn_value_; 768 bool new_npn_value_;
769 bool was_used_to_convey_data_; 769 bool was_used_to_convey_data_;
770 }; 770 };
771 771
772 class MockUDPClientSocket : public DatagramClientSocket, 772 class MockUDPClientSocket : public DatagramClientSocket,
773 public AsyncSocket { 773 public AsyncSocket {
774 public: 774 public:
775 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 775 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
776 virtual ~MockUDPClientSocket(); 776 virtual ~MockUDPClientSocket();
777 777
778 // Socket interface 778 // Socket interface
779 virtual int Read(net::IOBuffer* buf, int buf_len, 779 virtual int Read(net::IOBuffer* buf, int buf_len,
780 net::OldCompletionCallback* callback); 780 net::OldCompletionCallback* callback) OVERRIDE;
781 virtual int Write(net::IOBuffer* buf, int buf_len, 781 virtual int Write(net::IOBuffer* buf, int buf_len,
782 net::OldCompletionCallback* callback); 782 net::OldCompletionCallback* callback) OVERRIDE;
783 virtual bool SetReceiveBufferSize(int32 size); 783 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE;
784 virtual bool SetSendBufferSize(int32 size); 784 virtual bool SetSendBufferSize(int32 size) OVERRIDE;
785 785
786 // DatagramSocket interface 786 // DatagramSocket interface
787 virtual void Close(); 787 virtual void Close() OVERRIDE;
788 virtual int GetPeerAddress(IPEndPoint* address) const; 788 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
789 virtual int GetLocalAddress(IPEndPoint* address) const; 789 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
790 virtual const BoundNetLog& NetLog() const; 790 virtual const BoundNetLog& NetLog() const OVERRIDE;
791 791
792 // DatagramClientSocket interface 792 // DatagramClientSocket interface
793 virtual int Connect(const IPEndPoint& address); 793 virtual int Connect(const IPEndPoint& address) OVERRIDE;
794 794
795 // AsyncSocket interface 795 // AsyncSocket interface
796 virtual void OnReadComplete(const MockRead& data); 796 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
797 797
798 private: 798 private:
799 int CompleteRead(); 799 int CompleteRead();
800 800
801 void RunCallbackAsync(net::OldCompletionCallback* callback, int result); 801 void RunCallbackAsync(net::OldCompletionCallback* callback, int result);
802 void RunCallback(net::OldCompletionCallback* callback, int result); 802 void RunCallback(net::OldCompletionCallback* callback, int result);
803 803
804 bool connected_; 804 bool connected_;
805 SocketDataProvider* data_; 805 SocketDataProvider* data_;
806 int read_offset_; 806 int read_offset_;
(...skipping 15 matching lines...) Expand all
822 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { 822 class TestSocketRequest : public CallbackRunner< Tuple1<int> > {
823 public: 823 public:
824 TestSocketRequest( 824 TestSocketRequest(
825 std::vector<TestSocketRequest*>* request_order, 825 std::vector<TestSocketRequest*>* request_order,
826 size_t* completion_count); 826 size_t* completion_count);
827 virtual ~TestSocketRequest(); 827 virtual ~TestSocketRequest();
828 828
829 ClientSocketHandle* handle() { return &handle_; } 829 ClientSocketHandle* handle() { return &handle_; }
830 830
831 int WaitForResult(); 831 int WaitForResult();
832 virtual void RunWithParams(const Tuple1<int>& params); 832 virtual void RunWithParams(const Tuple1<int>& params) OVERRIDE;
833 833
834 private: 834 private:
835 ClientSocketHandle handle_; 835 ClientSocketHandle handle_;
836 std::vector<TestSocketRequest*>* request_order_; 836 std::vector<TestSocketRequest*>* request_order_;
837 size_t* completion_count_; 837 size_t* completion_count_;
838 TestOldCompletionCallback callback_; 838 TestOldCompletionCallback callback_;
839 }; 839 };
840 840
841 class ClientSocketPoolTest { 841 class ClientSocketPoolTest {
842 public: 842 public:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 926
927 int release_count() const { return release_count_; } 927 int release_count() const { return release_count_; }
928 int cancel_count() const { return cancel_count_; } 928 int cancel_count() const { return cancel_count_; }
929 929
930 // TransportClientSocketPool methods. 930 // TransportClientSocketPool methods.
931 virtual int RequestSocket(const std::string& group_name, 931 virtual int RequestSocket(const std::string& group_name,
932 const void* socket_params, 932 const void* socket_params,
933 RequestPriority priority, 933 RequestPriority priority,
934 ClientSocketHandle* handle, 934 ClientSocketHandle* handle,
935 OldCompletionCallback* callback, 935 OldCompletionCallback* callback,
936 const BoundNetLog& net_log); 936 const BoundNetLog& net_log) OVERRIDE;
937 937
938 virtual void CancelRequest(const std::string& group_name, 938 virtual void CancelRequest(const std::string& group_name,
939 ClientSocketHandle* handle); 939 ClientSocketHandle* handle) OVERRIDE;
940 virtual void ReleaseSocket(const std::string& group_name, 940 virtual void ReleaseSocket(const std::string& group_name,
941 StreamSocket* socket, int id); 941 StreamSocket* socket, int id) OVERRIDE;
942 942
943 private: 943 private:
944 ClientSocketFactory* client_socket_factory_; 944 ClientSocketFactory* client_socket_factory_;
945 ScopedVector<MockConnectJob> job_list_; 945 ScopedVector<MockConnectJob> job_list_;
946 int release_count_; 946 int release_count_;
947 int cancel_count_; 947 int cancel_count_;
948 948
949 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool); 949 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool);
950 }; 950 };
951 951
(...skipping 15 matching lines...) Expand all
967 } 967 }
968 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() { 968 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() {
969 return tcp_client_sockets_; 969 return tcp_client_sockets_;
970 } 970 }
971 971
972 // ClientSocketFactory 972 // ClientSocketFactory
973 virtual DatagramClientSocket* CreateDatagramClientSocket( 973 virtual DatagramClientSocket* CreateDatagramClientSocket(
974 DatagramSocket::BindType bind_type, 974 DatagramSocket::BindType bind_type,
975 const RandIntCallback& rand_int_cb, 975 const RandIntCallback& rand_int_cb,
976 NetLog* net_log, 976 NetLog* net_log,
977 const NetLog::Source& source); 977 const NetLog::Source& source) OVERRIDE;
978 virtual StreamSocket* CreateTransportClientSocket( 978 virtual StreamSocket* CreateTransportClientSocket(
979 const AddressList& addresses, 979 const AddressList& addresses,
980 NetLog* net_log, 980 NetLog* net_log,
981 const NetLog::Source& source); 981 const NetLog::Source& source) OVERRIDE;
982 virtual SSLClientSocket* CreateSSLClientSocket( 982 virtual SSLClientSocket* CreateSSLClientSocket(
983 ClientSocketHandle* transport_socket, 983 ClientSocketHandle* transport_socket,
984 const HostPortPair& host_and_port, 984 const HostPortPair& host_and_port,
985 const SSLConfig& ssl_config, 985 const SSLConfig& ssl_config,
986 SSLHostInfo* ssl_host_info, 986 SSLHostInfo* ssl_host_info,
987 const SSLClientSocketContext& context); 987 const SSLClientSocketContext& context) OVERRIDE;
988 virtual void ClearSSLSessionCache(); 988 virtual void ClearSSLSessionCache() OVERRIDE;
989 989
990 private: 990 private:
991 SocketDataProviderArray<DeterministicSocketData> mock_data_; 991 SocketDataProviderArray<DeterministicSocketData> mock_data_;
992 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 992 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
993 993
994 // Store pointers to handed out sockets in case the test wants to get them. 994 // Store pointers to handed out sockets in case the test wants to get them.
995 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_; 995 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_;
996 std::vector<MockSSLClientSocket*> ssl_client_sockets_; 996 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
997 }; 997 };
998 998
999 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { 999 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
1000 public: 1000 public:
1001 MockSOCKSClientSocketPool( 1001 MockSOCKSClientSocketPool(
1002 int max_sockets, 1002 int max_sockets,
1003 int max_sockets_per_group, 1003 int max_sockets_per_group,
1004 ClientSocketPoolHistograms* histograms, 1004 ClientSocketPoolHistograms* histograms,
1005 TransportClientSocketPool* transport_pool); 1005 TransportClientSocketPool* transport_pool);
1006 1006
1007 virtual ~MockSOCKSClientSocketPool(); 1007 virtual ~MockSOCKSClientSocketPool();
1008 1008
1009 // SOCKSClientSocketPool methods. 1009 // SOCKSClientSocketPool methods.
1010 virtual int RequestSocket(const std::string& group_name, 1010 virtual int RequestSocket(const std::string& group_name,
1011 const void* socket_params, 1011 const void* socket_params,
1012 RequestPriority priority, 1012 RequestPriority priority,
1013 ClientSocketHandle* handle, 1013 ClientSocketHandle* handle,
1014 OldCompletionCallback* callback, 1014 OldCompletionCallback* callback,
1015 const BoundNetLog& net_log); 1015 const BoundNetLog& net_log) OVERRIDE;
1016 1016
1017 virtual void CancelRequest(const std::string& group_name, 1017 virtual void CancelRequest(const std::string& group_name,
1018 ClientSocketHandle* handle); 1018 ClientSocketHandle* handle) OVERRIDE;
1019 virtual void ReleaseSocket(const std::string& group_name, 1019 virtual void ReleaseSocket(const std::string& group_name,
1020 StreamSocket* socket, int id); 1020 StreamSocket* socket, int id) OVERRIDE;
1021 1021
1022 private: 1022 private:
1023 TransportClientSocketPool* const transport_pool_; 1023 TransportClientSocketPool* const transport_pool_;
1024 1024
1025 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool); 1025 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool);
1026 }; 1026 };
1027 1027
1028 // Constants for a successful SOCKS v5 handshake. 1028 // Constants for a successful SOCKS v5 handshake.
1029 extern const char kSOCKS5GreetRequest[]; 1029 extern const char kSOCKS5GreetRequest[];
1030 extern const int kSOCKS5GreetRequestLength; 1030 extern const int kSOCKS5GreetRequestLength;
1031 1031
1032 extern const char kSOCKS5GreetResponse[]; 1032 extern const char kSOCKS5GreetResponse[];
1033 extern const int kSOCKS5GreetResponseLength; 1033 extern const int kSOCKS5GreetResponseLength;
1034 1034
1035 extern const char kSOCKS5OkRequest[]; 1035 extern const char kSOCKS5OkRequest[];
1036 extern const int kSOCKS5OkRequestLength; 1036 extern const int kSOCKS5OkRequestLength;
1037 1037
1038 extern const char kSOCKS5OkResponse[]; 1038 extern const char kSOCKS5OkResponse[];
1039 extern const int kSOCKS5OkResponseLength; 1039 extern const int kSOCKS5OkResponseLength;
1040 1040
1041 } // namespace net 1041 } // namespace net
1042 1042
1043 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1043 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_manager.h ('k') | net/socket/socks5_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698