| OLD | NEW |
| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/string16.h" | 20 #include "base/string16.h" |
| 21 #include "net/base/address_list.h" | 21 #include "net/base/address_list.h" |
| 22 #include "net/base/completion_callback.h" | |
| 23 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 24 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_log.h" | 24 #include "net/base/net_log.h" |
| 26 #include "net/base/ssl_config_service.h" | 25 #include "net/base/ssl_config_service.h" |
| 27 #include "net/base/test_completion_callback.h" | 26 #include "net/base/test_completion_callback.h" |
| 28 #include "net/http/http_auth_controller.h" | 27 #include "net/http/http_auth_controller.h" |
| 29 #include "net/http/http_proxy_client_socket_pool.h" | 28 #include "net/http/http_proxy_client_socket_pool.h" |
| 30 #include "net/socket/client_socket_factory.h" | 29 #include "net/socket/client_socket_factory.h" |
| 31 #include "net/socket/client_socket_handle.h" | 30 #include "net/socket/client_socket_handle.h" |
| 32 #include "net/socket/socks_client_socket_pool.h" | 31 #include "net/socket/socks_client_socket_pool.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 struct SSLSocketDataProvider { | 259 struct SSLSocketDataProvider { |
| 261 SSLSocketDataProvider(bool async, int result); | 260 SSLSocketDataProvider(bool async, int result); |
| 262 ~SSLSocketDataProvider(); | 261 ~SSLSocketDataProvider(); |
| 263 | 262 |
| 264 MockConnect connect; | 263 MockConnect connect; |
| 265 SSLClientSocket::NextProtoStatus next_proto_status; | 264 SSLClientSocket::NextProtoStatus next_proto_status; |
| 266 std::string next_proto; | 265 std::string next_proto; |
| 267 std::string server_protos; | 266 std::string server_protos; |
| 268 bool was_npn_negotiated; | 267 bool was_npn_negotiated; |
| 269 bool client_cert_sent; | 268 bool client_cert_sent; |
| 270 net::SSLCertRequestInfo* cert_request_info; | 269 SSLCertRequestInfo* cert_request_info; |
| 271 scoped_refptr<X509Certificate> cert; | 270 scoped_refptr<X509Certificate> cert; |
| 272 }; | 271 }; |
| 273 | 272 |
| 274 // A DataProvider where the client must write a request before the reads (e.g. | 273 // A DataProvider where the client must write a request before the reads (e.g. |
| 275 // the response) will complete. | 274 // the response) will complete. |
| 276 class DelayedSocketData : public StaticSocketDataProvider, | 275 class DelayedSocketData : public StaticSocketDataProvider, |
| 277 public base::RefCounted<DelayedSocketData> { | 276 public base::RefCounted<DelayedSocketData> { |
| 278 public: | 277 public: |
| 279 // |write_delay| the number of MockWrites to complete before allowing | 278 // |write_delay| the number of MockWrites to complete before allowing |
| 280 // a MockRead to complete. | 279 // a MockRead to complete. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 303 void ForceNextRead(); | 302 void ForceNextRead(); |
| 304 | 303 |
| 305 // StaticSocketDataProvider: | 304 // StaticSocketDataProvider: |
| 306 virtual MockRead GetNextRead() OVERRIDE; | 305 virtual MockRead GetNextRead() OVERRIDE; |
| 307 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; | 306 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; |
| 308 virtual void Reset() OVERRIDE; | 307 virtual void Reset() OVERRIDE; |
| 309 virtual void CompleteRead() OVERRIDE; | 308 virtual void CompleteRead() OVERRIDE; |
| 310 | 309 |
| 311 private: | 310 private: |
| 312 int write_delay_; | 311 int write_delay_; |
| 313 ScopedRunnableMethodFactory<DelayedSocketData> factory_; | 312 base::WeakPtrFactory<DelayedSocketData> weak_factory_; |
| 314 }; | 313 }; |
| 315 | 314 |
| 316 // A DataProvider where the reads are ordered. | 315 // A DataProvider where the reads are ordered. |
| 317 // If a read is requested before its sequence number is reached, we return an | 316 // If a read is requested before its sequence number is reached, we return an |
| 318 // ERR_IO_PENDING (that way we don't have to explicitly add a MockRead just to | 317 // ERR_IO_PENDING (that way we don't have to explicitly add a MockRead just to |
| 319 // wait). | 318 // wait). |
| 320 // The sequence number is incremented on every read and write operation. | 319 // The sequence number is incremented on every read and write operation. |
| 321 // The message loop may be interrupted by setting the high bit of the sequence | 320 // The message loop may be interrupted by setting the high bit of the sequence |
| 322 // number in the MockRead's sequence number. When that MockRead is reached, | 321 // number in the MockRead's sequence number. When that MockRead is reached, |
| 323 // we post a Quit message to the loop. This allows us to interrupt the reading | 322 // we post a Quit message to the loop. This allows us to interrupt the reading |
| (...skipping 14 matching lines...) Expand all Loading... |
| 338 // |connect| the result for the connect phase. | 337 // |connect| the result for the connect phase. |
| 339 // |reads| the list of MockRead completions. | 338 // |reads| the list of MockRead completions. |
| 340 // |writes| the list of MockWrite completions. | 339 // |writes| the list of MockWrite completions. |
| 341 // Note: All MockReads and MockWrites must be async. | 340 // Note: All MockReads and MockWrites must be async. |
| 342 // Note: The MockRead and MockWrite lists musts end with a EOF | 341 // Note: The MockRead and MockWrite lists musts end with a EOF |
| 343 // e.g. a MockRead(true, 0, 0); | 342 // e.g. a MockRead(true, 0, 0); |
| 344 OrderedSocketData(const MockConnect& connect, | 343 OrderedSocketData(const MockConnect& connect, |
| 345 MockRead* reads, size_t reads_count, | 344 MockRead* reads, size_t reads_count, |
| 346 MockWrite* writes, size_t writes_count); | 345 MockWrite* writes, size_t writes_count); |
| 347 | 346 |
| 348 void SetOldCompletionCallback(OldCompletionCallback* callback) { | 347 void SetCompletionCallback(const CompletionCallback& callback) { |
| 349 callback_ = callback; | 348 callback_ = callback; |
| 350 } | 349 } |
| 351 | 350 |
| 352 // Posts a quit message to the current message loop, if one is running. | 351 // Posts a quit message to the current message loop, if one is running. |
| 353 void EndLoop(); | 352 void EndLoop(); |
| 354 | 353 |
| 355 // StaticSocketDataProvider: | 354 // StaticSocketDataProvider: |
| 356 virtual MockRead GetNextRead() OVERRIDE; | 355 virtual MockRead GetNextRead() OVERRIDE; |
| 357 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; | 356 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; |
| 358 virtual void Reset() OVERRIDE; | 357 virtual void Reset() OVERRIDE; |
| 359 virtual void CompleteRead() OVERRIDE; | 358 virtual void CompleteRead() OVERRIDE; |
| 360 | 359 |
| 361 private: | 360 private: |
| 362 friend class base::RefCounted<OrderedSocketData>; | 361 friend class base::RefCounted<OrderedSocketData>; |
| 363 virtual ~OrderedSocketData(); | 362 virtual ~OrderedSocketData(); |
| 364 | 363 |
| 365 int sequence_number_; | 364 int sequence_number_; |
| 366 int loop_stop_stage_; | 365 int loop_stop_stage_; |
| 367 OldCompletionCallback* callback_; | 366 CompletionCallback callback_; |
| 368 bool blocked_; | 367 bool blocked_; |
| 369 ScopedRunnableMethodFactory<OrderedSocketData> factory_; | 368 base::WeakPtrFactory<OrderedSocketData> weak_factory_; |
| 370 }; | 369 }; |
| 371 | 370 |
| 372 class DeterministicMockTCPClientSocket; | 371 class DeterministicMockTCPClientSocket; |
| 373 | 372 |
| 374 // This class gives the user full control over the network activity, | 373 // This class gives the user full control over the network activity, |
| 375 // specifically the timing of the COMPLETION of I/O operations. Regardless of | 374 // specifically the timing of the COMPLETION of I/O operations. Regardless of |
| 376 // the order in which I/O operations are initiated, this class ensures that they | 375 // the order in which I/O operations are initiated, this class ensures that they |
| 377 // complete in the correct order. | 376 // complete in the correct order. |
| 378 // | 377 // |
| 379 // Network activity is modeled as a sequence of numbered steps which is | 378 // Network activity is modeled as a sequence of numbered steps which is |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 private: | 573 private: |
| 575 SocketDataProviderArray<SocketDataProvider> mock_data_; | 574 SocketDataProviderArray<SocketDataProvider> mock_data_; |
| 576 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; | 575 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; |
| 577 | 576 |
| 578 // Store pointers to handed out sockets in case the test wants to get them. | 577 // Store pointers to handed out sockets in case the test wants to get them. |
| 579 std::vector<MockUDPClientSocket*> udp_client_sockets_; | 578 std::vector<MockUDPClientSocket*> udp_client_sockets_; |
| 580 std::vector<MockTCPClientSocket*> tcp_client_sockets_; | 579 std::vector<MockTCPClientSocket*> tcp_client_sockets_; |
| 581 std::vector<MockSSLClientSocket*> ssl_client_sockets_; | 580 std::vector<MockSSLClientSocket*> ssl_client_sockets_; |
| 582 }; | 581 }; |
| 583 | 582 |
| 584 class MockClientSocket : public net::SSLClientSocket { | 583 class MockClientSocket : public SSLClientSocket { |
| 585 public: | 584 public: |
| 585 // TODO(ajwong): Why do we need net::NetLog? |
| 586 explicit MockClientSocket(net::NetLog* net_log); | 586 explicit MockClientSocket(net::NetLog* net_log); |
| 587 | 587 |
| 588 // Socket implementation. | 588 // Socket implementation. |
| 589 virtual int Read(net::IOBuffer* buf, int buf_len, | 589 virtual int Read(IOBuffer* buf, int buf_len, |
| 590 net::OldCompletionCallback* callback) = 0; | 590 const CompletionCallback& callback) = 0; |
| 591 virtual int Read(net::IOBuffer* buf, int buf_len, | 591 virtual int Write(IOBuffer* buf, int buf_len, |
| 592 const net::CompletionCallback& callback) = 0; | 592 const CompletionCallback& callback) = 0; |
| 593 virtual int Write(net::IOBuffer* buf, int buf_len, | |
| 594 net::OldCompletionCallback* callback) = 0; | |
| 595 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | 593 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 596 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | 594 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 597 | 595 |
| 598 // StreamSocket implementation. | 596 // StreamSocket implementation. |
| 599 virtual int Connect(net::OldCompletionCallback* callback) = 0; | 597 virtual int Connect(const CompletionCallback& callback) = 0; |
| 600 virtual int Connect(const net::CompletionCallback& callback) = 0; | |
| 601 virtual void Disconnect() OVERRIDE; | 598 virtual void Disconnect() OVERRIDE; |
| 602 virtual bool IsConnected() const OVERRIDE; | 599 virtual bool IsConnected() const OVERRIDE; |
| 603 virtual bool IsConnectedAndIdle() const OVERRIDE; | 600 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 604 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; | 601 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; |
| 605 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 602 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 606 virtual const BoundNetLog& NetLog() const OVERRIDE; | 603 virtual const BoundNetLog& NetLog() const OVERRIDE; |
| 607 virtual void SetSubresourceSpeculation() OVERRIDE {} | 604 virtual void SetSubresourceSpeculation() OVERRIDE {} |
| 608 virtual void SetOmniboxSpeculation() OVERRIDE {} | 605 virtual void SetOmniboxSpeculation() OVERRIDE {} |
| 609 | 606 |
| 610 // SSLClientSocket implementation. | 607 // SSLClientSocket implementation. |
| 611 virtual void GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE; | 608 virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
| 612 virtual void GetSSLCertRequestInfo( | 609 virtual void GetSSLCertRequestInfo( |
| 613 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; | 610 SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 614 virtual int ExportKeyingMaterial(const base::StringPiece& label, | 611 virtual int ExportKeyingMaterial(const base::StringPiece& label, |
| 615 const base::StringPiece& context, | 612 const base::StringPiece& context, |
| 616 unsigned char *out, | 613 unsigned char *out, |
| 617 unsigned int outlen) OVERRIDE; | 614 unsigned int outlen) OVERRIDE; |
| 618 virtual NextProtoStatus GetNextProto(std::string* proto, | 615 virtual NextProtoStatus GetNextProto(std::string* proto, |
| 619 std::string* server_protos) OVERRIDE; | 616 std::string* server_protos) OVERRIDE; |
| 620 | 617 |
| 621 protected: | 618 protected: |
| 622 virtual ~MockClientSocket(); | 619 virtual ~MockClientSocket(); |
| 623 void RunCallbackAsync(net::OldCompletionCallback* callback, int result); | 620 void RunCallbackAsync(const CompletionCallback& callback, int result); |
| 624 void RunCallbackAsync(const net::CompletionCallback& callback, int result); | 621 void RunCallback(const CompletionCallback& callback, int result); |
| 625 void RunOldCallback(net::OldCompletionCallback*, int result); | |
| 626 void RunCallback(const net::CompletionCallback&, int result); | |
| 627 | 622 |
| 628 base::WeakPtrFactory<MockClientSocket> weak_factory_; | 623 base::WeakPtrFactory<MockClientSocket> weak_factory_; |
| 629 | 624 |
| 630 // True if Connect completed successfully and Disconnect hasn't been called. | 625 // True if Connect completed successfully and Disconnect hasn't been called. |
| 631 bool connected_; | 626 bool connected_; |
| 632 | 627 |
| 633 net::BoundNetLog net_log_; | 628 BoundNetLog net_log_; |
| 634 }; | 629 }; |
| 635 | 630 |
| 636 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { | 631 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { |
| 637 public: | 632 public: |
| 638 MockTCPClientSocket(const net::AddressList& addresses, net::NetLog* net_log, | 633 MockTCPClientSocket(const AddressList& addresses, net::NetLog* net_log, |
| 639 net::SocketDataProvider* socket); | 634 SocketDataProvider* socket); |
| 640 virtual ~MockTCPClientSocket(); | 635 virtual ~MockTCPClientSocket(); |
| 641 | 636 |
| 642 net::AddressList addresses() const { return addresses_; } | 637 AddressList addresses() const { return addresses_; } |
| 643 | 638 |
| 644 // Socket implementation. | 639 // Socket implementation. |
| 645 virtual int Read(net::IOBuffer* buf, int buf_len, | 640 virtual int Read(IOBuffer* buf, int buf_len, |
| 646 net::OldCompletionCallback* callback) OVERRIDE; | 641 const CompletionCallback& callback) OVERRIDE; |
| 647 virtual int Read(net::IOBuffer* buf, int buf_len, | 642 virtual int Write(IOBuffer* buf, int buf_len, |
| 648 const net::CompletionCallback& callback) OVERRIDE; | 643 const CompletionCallback& callback) OVERRIDE; |
| 649 virtual int Write(net::IOBuffer* buf, int buf_len, | |
| 650 net::OldCompletionCallback* callback) OVERRIDE; | |
| 651 | 644 |
| 652 // StreamSocket implementation. | 645 // StreamSocket implementation. |
| 653 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; | 646 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
| 654 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; | |
| 655 virtual void Disconnect() OVERRIDE; | 647 virtual void Disconnect() OVERRIDE; |
| 656 virtual bool IsConnected() const OVERRIDE; | 648 virtual bool IsConnected() const OVERRIDE; |
| 657 virtual bool IsConnectedAndIdle() const OVERRIDE; | 649 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 658 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; | 650 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; |
| 659 virtual bool WasEverUsed() const OVERRIDE; | 651 virtual bool WasEverUsed() const OVERRIDE; |
| 660 virtual bool UsingTCPFastOpen() const OVERRIDE; | 652 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 661 virtual int64 NumBytesRead() const OVERRIDE; | 653 virtual int64 NumBytesRead() const OVERRIDE; |
| 662 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; | 654 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 663 | 655 |
| 664 // AsyncSocket: | 656 // AsyncSocket: |
| 665 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 657 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 666 | 658 |
| 667 private: | 659 private: |
| 668 int CompleteRead(); | 660 int CompleteRead(); |
| 669 | 661 |
| 670 net::AddressList addresses_; | 662 AddressList addresses_; |
| 671 | 663 |
| 672 net::SocketDataProvider* data_; | 664 SocketDataProvider* data_; |
| 673 int read_offset_; | 665 int read_offset_; |
| 674 int num_bytes_read_; | 666 int num_bytes_read_; |
| 675 net::MockRead read_data_; | 667 MockRead read_data_; |
| 676 bool need_read_data_; | 668 bool need_read_data_; |
| 677 | 669 |
| 678 // True if the peer has closed the connection. This allows us to simulate | 670 // True if the peer has closed the connection. This allows us to simulate |
| 679 // the recv(..., MSG_PEEK) call in the IsConnectedAndIdle method of the real | 671 // the recv(..., MSG_PEEK) call in the IsConnectedAndIdle method of the real |
| 680 // TCPClientSocket. | 672 // TCPClientSocket. |
| 681 bool peer_closed_connection_; | 673 bool peer_closed_connection_; |
| 682 | 674 |
| 683 // While an asynchronous IO is pending, we save our user-buffer state. | 675 // While an asynchronous IO is pending, we save our user-buffer state. |
| 684 net::IOBuffer* pending_buf_; | 676 IOBuffer* pending_buf_; |
| 685 int pending_buf_len_; | 677 int pending_buf_len_; |
| 686 net::OldCompletionCallback* old_pending_callback_; | 678 CompletionCallback pending_callback_; |
| 687 net::CompletionCallback pending_callback_; | |
| 688 bool was_used_to_convey_data_; | 679 bool was_used_to_convey_data_; |
| 689 }; | 680 }; |
| 690 | 681 |
| 691 class DeterministicMockTCPClientSocket : public MockClientSocket, | 682 class DeterministicMockTCPClientSocket : public MockClientSocket, |
| 692 public AsyncSocket, | 683 public AsyncSocket, |
| 693 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { | 684 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { |
| 694 public: | 685 public: |
| 695 DeterministicMockTCPClientSocket(net::NetLog* net_log, | 686 DeterministicMockTCPClientSocket(net::NetLog* net_log, |
| 696 net::DeterministicSocketData* data); | 687 DeterministicSocketData* data); |
| 697 virtual ~DeterministicMockTCPClientSocket(); | 688 virtual ~DeterministicMockTCPClientSocket(); |
| 698 | 689 |
| 699 bool write_pending() const { return write_pending_; } | 690 bool write_pending() const { return write_pending_; } |
| 700 bool read_pending() const { return read_pending_; } | 691 bool read_pending() const { return read_pending_; } |
| 701 | 692 |
| 702 void CompleteWrite(); | 693 void CompleteWrite(); |
| 703 int CompleteRead(); | 694 int CompleteRead(); |
| 704 | 695 |
| 705 // Socket implementation. | 696 // Socket implementation. |
| 706 virtual int Write(net::IOBuffer* buf, int buf_len, | 697 // Socket: |
| 707 net::OldCompletionCallback* callback) OVERRIDE; | 698 virtual int Write(IOBuffer* buf, int buf_len, |
| 708 virtual int Read(net::IOBuffer* buf, int buf_len, | 699 const CompletionCallback& callback) OVERRIDE; |
| 709 net::OldCompletionCallback* callback) OVERRIDE; | 700 virtual int Read(IOBuffer* buf, int buf_len, |
| 710 virtual int Read(net::IOBuffer* buf, int buf_len, | 701 const CompletionCallback& callback) OVERRIDE; |
| 711 const net::CompletionCallback& callback) OVERRIDE; | |
| 712 | 702 |
| 713 // StreamSocket implementation. | 703 // StreamSocket implementation. |
| 714 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; | 704 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
| 715 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; | |
| 716 virtual void Disconnect() OVERRIDE; | 705 virtual void Disconnect() OVERRIDE; |
| 717 virtual bool IsConnected() const OVERRIDE; | 706 virtual bool IsConnected() const OVERRIDE; |
| 718 virtual bool IsConnectedAndIdle() const OVERRIDE; | 707 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 719 virtual bool WasEverUsed() const OVERRIDE; | 708 virtual bool WasEverUsed() const OVERRIDE; |
| 720 virtual bool UsingTCPFastOpen() const OVERRIDE; | 709 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 721 virtual int64 NumBytesRead() const OVERRIDE; | 710 virtual int64 NumBytesRead() const OVERRIDE; |
| 722 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; | 711 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 723 | 712 |
| 724 // AsyncSocket: | 713 // AsyncSocket: |
| 725 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 714 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 726 | 715 |
| 727 private: | 716 private: |
| 728 bool write_pending_; | 717 bool write_pending_; |
| 729 net::OldCompletionCallback* write_callback_; | 718 CompletionCallback write_callback_; |
| 730 int write_result_; | 719 int write_result_; |
| 731 | 720 |
| 732 net::MockRead read_data_; | 721 MockRead read_data_; |
| 733 | 722 |
| 734 net::IOBuffer* read_buf_; | 723 IOBuffer* read_buf_; |
| 735 int read_buf_len_; | 724 int read_buf_len_; |
| 736 bool read_pending_; | 725 bool read_pending_; |
| 737 net::OldCompletionCallback* old_read_callback_; | 726 CompletionCallback read_callback_; |
| 738 net::CompletionCallback read_callback_; | 727 DeterministicSocketData* data_; |
| 739 net::DeterministicSocketData* data_; | |
| 740 bool was_used_to_convey_data_; | 728 bool was_used_to_convey_data_; |
| 741 }; | 729 }; |
| 742 | 730 |
| 743 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { | 731 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { |
| 744 public: | 732 public: |
| 745 MockSSLClientSocket( | 733 MockSSLClientSocket( |
| 746 net::ClientSocketHandle* transport_socket, | 734 ClientSocketHandle* transport_socket, |
| 747 const HostPortPair& host_and_port, | 735 const HostPortPair& host_and_port, |
| 748 const net::SSLConfig& ssl_config, | 736 const SSLConfig& ssl_config, |
| 749 SSLHostInfo* ssl_host_info, | 737 SSLHostInfo* ssl_host_info, |
| 750 net::SSLSocketDataProvider* socket); | 738 SSLSocketDataProvider* socket); |
| 751 virtual ~MockSSLClientSocket(); | 739 virtual ~MockSSLClientSocket(); |
| 752 | 740 |
| 753 // Socket implementation. | 741 // Socket implementation. |
| 754 virtual int Read(net::IOBuffer* buf, int buf_len, | 742 virtual int Read(IOBuffer* buf, int buf_len, |
| 755 net::OldCompletionCallback* callback) OVERRIDE; | 743 const CompletionCallback& callback) OVERRIDE; |
| 756 virtual int Read(net::IOBuffer* buf, int buf_len, | 744 virtual int Write(IOBuffer* buf, int buf_len, |
| 757 const net::CompletionCallback& callback) OVERRIDE; | 745 const CompletionCallback& callback) OVERRIDE; |
| 758 virtual int Write(net::IOBuffer* buf, int buf_len, | |
| 759 net::OldCompletionCallback* callback) OVERRIDE; | |
| 760 | 746 |
| 761 // StreamSocket implementation. | 747 // StreamSocket implementation. |
| 762 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; | 748 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
| 763 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; | |
| 764 virtual void Disconnect() OVERRIDE; | 749 virtual void Disconnect() OVERRIDE; |
| 765 virtual bool IsConnected() const OVERRIDE; | 750 virtual bool IsConnected() const OVERRIDE; |
| 766 virtual bool WasEverUsed() const OVERRIDE; | 751 virtual bool WasEverUsed() const OVERRIDE; |
| 767 virtual bool UsingTCPFastOpen() const OVERRIDE; | 752 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 768 virtual int64 NumBytesRead() const OVERRIDE; | 753 virtual int64 NumBytesRead() const OVERRIDE; |
| 769 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; | 754 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 770 | 755 |
| 771 // SSLClientSocket implementation. | 756 // SSLClientSocket implementation. |
| 772 virtual void GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE; | 757 virtual void GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
| 773 virtual void GetSSLCertRequestInfo( | 758 virtual void GetSSLCertRequestInfo( |
| 774 net::SSLCertRequestInfo* cert_request_info) OVERRIDE; | 759 SSLCertRequestInfo* cert_request_info) OVERRIDE; |
| 775 virtual NextProtoStatus GetNextProto(std::string* proto, | 760 virtual NextProtoStatus GetNextProto(std::string* proto, |
| 776 std::string* server_protos) OVERRIDE; | 761 std::string* server_protos) OVERRIDE; |
| 777 virtual bool was_npn_negotiated() const OVERRIDE; | 762 virtual bool was_npn_negotiated() const OVERRIDE; |
| 778 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; | 763 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; |
| 779 | 764 |
| 780 // This MockSocket does not implement the manual async IO feature. | 765 // This MockSocket does not implement the manual async IO feature. |
| 781 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 766 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 782 | 767 |
| 783 private: | 768 private: |
| 784 class OldConnectCallback; | 769 static void ConnectCallback(MockSSLClientSocket *ssl_client_socket, |
| 785 class ConnectCallback; | 770 const CompletionCallback& callback, |
| 771 int rv); |
| 786 | 772 |
| 787 scoped_ptr<ClientSocketHandle> transport_; | 773 scoped_ptr<ClientSocketHandle> transport_; |
| 788 net::SSLSocketDataProvider* data_; | 774 SSLSocketDataProvider* data_; |
| 789 bool is_npn_state_set_; | 775 bool is_npn_state_set_; |
| 790 bool new_npn_value_; | 776 bool new_npn_value_; |
| 791 bool was_used_to_convey_data_; | 777 bool was_used_to_convey_data_; |
| 792 }; | 778 }; |
| 793 | 779 |
| 794 class MockUDPClientSocket : public DatagramClientSocket, | 780 class MockUDPClientSocket : public DatagramClientSocket, |
| 795 public AsyncSocket { | 781 public AsyncSocket { |
| 796 public: | 782 public: |
| 797 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); | 783 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); |
| 798 virtual ~MockUDPClientSocket(); | 784 virtual ~MockUDPClientSocket(); |
| 799 | 785 |
| 800 // Socket implementation. | 786 // Socket implementation. |
| 801 virtual int Read(net::IOBuffer* buf, int buf_len, | 787 virtual int Read(IOBuffer* buf, int buf_len, |
| 802 net::OldCompletionCallback* callback) OVERRIDE; | 788 const CompletionCallback& callback) OVERRIDE; |
| 803 virtual int Read(net::IOBuffer* buf, int buf_len, | 789 virtual int Write(IOBuffer* buf, int buf_len, |
| 804 const net::CompletionCallback& callback) OVERRIDE; | 790 const CompletionCallback& callback) OVERRIDE; |
| 805 virtual int Write(net::IOBuffer* buf, int buf_len, | |
| 806 net::OldCompletionCallback* callback) OVERRIDE; | |
| 807 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | 791 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 808 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | 792 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 809 | 793 |
| 810 // DatagramSocket implementation. | 794 // DatagramSocket implementation. |
| 811 virtual void Close() OVERRIDE; | 795 virtual void Close() OVERRIDE; |
| 812 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 796 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
| 813 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 797 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 814 virtual const BoundNetLog& NetLog() const OVERRIDE; | 798 virtual const BoundNetLog& NetLog() const OVERRIDE; |
| 815 | 799 |
| 816 // DatagramClientSocket implementation. | 800 // DatagramClientSocket implementation. |
| 817 virtual int Connect(const IPEndPoint& address) OVERRIDE; | 801 virtual int Connect(const IPEndPoint& address) OVERRIDE; |
| 818 | 802 |
| 819 // AsyncSocket implementation. | 803 // AsyncSocket implementation. |
| 820 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 804 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 821 | 805 |
| 822 private: | 806 private: |
| 823 int CompleteRead(); | 807 int CompleteRead(); |
| 824 | 808 |
| 825 void RunCallbackAsync(net::OldCompletionCallback* callback, int result); | 809 void RunCallbackAsync(const CompletionCallback& callback, int result); |
| 826 void RunCallbackAsync(const net::CompletionCallback& callback, int result); | 810 void RunCallback(const CompletionCallback& callback, int result); |
| 827 void RunOldCallback(net::OldCompletionCallback* callback, int result); | |
| 828 void RunCallback(const net::CompletionCallback& callback, int result); | |
| 829 | 811 |
| 830 bool connected_; | 812 bool connected_; |
| 831 SocketDataProvider* data_; | 813 SocketDataProvider* data_; |
| 832 int read_offset_; | 814 int read_offset_; |
| 833 net::MockRead read_data_; | 815 MockRead read_data_; |
| 834 bool need_read_data_; | 816 bool need_read_data_; |
| 835 | 817 |
| 836 // While an asynchronous IO is pending, we save our user-buffer state. | 818 // While an asynchronous IO is pending, we save our user-buffer state. |
| 837 net::IOBuffer* pending_buf_; | 819 IOBuffer* pending_buf_; |
| 838 int pending_buf_len_; | 820 int pending_buf_len_; |
| 839 net::OldCompletionCallback* old_pending_callback_; | 821 CompletionCallback pending_callback_; |
| 840 net::CompletionCallback pending_callback_; | |
| 841 | 822 |
| 842 BoundNetLog net_log_; | 823 BoundNetLog net_log_; |
| 843 | 824 |
| 844 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; | 825 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; |
| 845 | 826 |
| 846 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); | 827 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); |
| 847 }; | 828 }; |
| 848 | 829 |
| 849 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { | 830 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { |
| 850 public: | 831 public: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 ScopedVector<TestSocketRequest> requests_; | 900 ScopedVector<TestSocketRequest> requests_; |
| 920 std::vector<TestSocketRequest*> request_order_; | 901 std::vector<TestSocketRequest*> request_order_; |
| 921 size_t completion_count_; | 902 size_t completion_count_; |
| 922 }; | 903 }; |
| 923 | 904 |
| 924 class MockTransportClientSocketPool : public TransportClientSocketPool { | 905 class MockTransportClientSocketPool : public TransportClientSocketPool { |
| 925 public: | 906 public: |
| 926 class MockConnectJob { | 907 class MockConnectJob { |
| 927 public: | 908 public: |
| 928 MockConnectJob(StreamSocket* socket, ClientSocketHandle* handle, | 909 MockConnectJob(StreamSocket* socket, ClientSocketHandle* handle, |
| 929 OldCompletionCallback* callback); | 910 const CompletionCallback& callback); |
| 930 ~MockConnectJob(); | 911 ~MockConnectJob(); |
| 931 | 912 |
| 932 int Connect(); | 913 int Connect(); |
| 933 bool CancelHandle(const ClientSocketHandle* handle); | 914 bool CancelHandle(const ClientSocketHandle* handle); |
| 934 | 915 |
| 935 private: | 916 private: |
| 936 void OnConnect(int rv); | 917 void OnConnect(int rv); |
| 937 | 918 |
| 938 scoped_ptr<StreamSocket> socket_; | 919 scoped_ptr<StreamSocket> socket_; |
| 939 ClientSocketHandle* handle_; | 920 ClientSocketHandle* handle_; |
| 940 OldCompletionCallback* user_callback_; | 921 CompletionCallback user_callback_; |
| 941 OldCompletionCallbackImpl<MockConnectJob> connect_callback_; | |
| 942 | 922 |
| 943 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); | 923 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); |
| 944 }; | 924 }; |
| 945 | 925 |
| 946 MockTransportClientSocketPool( | 926 MockTransportClientSocketPool( |
| 947 int max_sockets, | 927 int max_sockets, |
| 948 int max_sockets_per_group, | 928 int max_sockets_per_group, |
| 949 ClientSocketPoolHistograms* histograms, | 929 ClientSocketPoolHistograms* histograms, |
| 950 ClientSocketFactory* socket_factory); | 930 ClientSocketFactory* socket_factory); |
| 951 | 931 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 | 1041 |
| 1062 extern const char kSOCKS5OkRequest[]; | 1042 extern const char kSOCKS5OkRequest[]; |
| 1063 extern const int kSOCKS5OkRequestLength; | 1043 extern const int kSOCKS5OkRequestLength; |
| 1064 | 1044 |
| 1065 extern const char kSOCKS5OkResponse[]; | 1045 extern const char kSOCKS5OkResponse[]; |
| 1066 extern const int kSOCKS5OkResponseLength; | 1046 extern const int kSOCKS5OkResponseLength; |
| 1067 | 1047 |
| 1068 } // namespace net | 1048 } // namespace net |
| 1069 | 1049 |
| 1070 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1050 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |