OLD | NEW |
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 #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 12 matching lines...) Expand all Loading... |
23 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
24 #include "net/base/net_log.h" | 24 #include "net/base/net_log.h" |
25 #include "net/base/ssl_config_service.h" | 25 #include "net/base/ssl_config_service.h" |
26 #include "net/base/test_completion_callback.h" | 26 #include "net/base/test_completion_callback.h" |
27 #include "net/http/http_auth_controller.h" | 27 #include "net/http/http_auth_controller.h" |
28 #include "net/http/http_proxy_client_socket_pool.h" | 28 #include "net/http/http_proxy_client_socket_pool.h" |
29 #include "net/socket/client_socket_factory.h" | 29 #include "net/socket/client_socket_factory.h" |
30 #include "net/socket/client_socket_handle.h" | 30 #include "net/socket/client_socket_handle.h" |
31 #include "net/socket/socks_client_socket_pool.h" | 31 #include "net/socket/socks_client_socket_pool.h" |
32 #include "net/socket/ssl_client_socket.h" | 32 #include "net/socket/ssl_client_socket.h" |
| 33 #include "net/socket/ssl_client_socket_pool.h" |
33 #include "net/socket/tcp_client_socket_pool.h" | 34 #include "net/socket/tcp_client_socket_pool.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
35 | 36 |
36 namespace net { | 37 namespace net { |
37 | 38 |
38 enum { | 39 enum { |
39 // A private network error code used by the socket test utility classes. | 40 // A private network error code used by the socket test utility classes. |
40 // If the |result| member of a MockRead is | 41 // If the |result| member of a MockRead is |
41 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a | 42 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a |
42 // marker that indicates the peer will close the connection after the next | 43 // marker that indicates the peer will close the connection after the next |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 | 864 |
864 extern const char kSOCKS5GreetResponse[]; | 865 extern const char kSOCKS5GreetResponse[]; |
865 extern const int kSOCKS5GreetResponseLength; | 866 extern const int kSOCKS5GreetResponseLength; |
866 | 867 |
867 extern const char kSOCKS5OkRequest[]; | 868 extern const char kSOCKS5OkRequest[]; |
868 extern const int kSOCKS5OkRequestLength; | 869 extern const int kSOCKS5OkRequestLength; |
869 | 870 |
870 extern const char kSOCKS5OkResponse[]; | 871 extern const char kSOCKS5OkResponse[]; |
871 extern const int kSOCKS5OkResponseLength; | 872 extern const int kSOCKS5OkResponseLength; |
872 | 873 |
| 874 class MockSSLClientSocketPool : public SSLClientSocketPool { |
| 875 public: |
| 876 class MockConnectJob { |
| 877 public: |
| 878 MockConnectJob(ClientSocket* socket, ClientSocketHandle* handle, |
| 879 CompletionCallback* callback); |
| 880 |
| 881 int Connect(); |
| 882 bool CancelHandle(const ClientSocketHandle* handle); |
| 883 |
| 884 private: |
| 885 void OnConnect(int rv); |
| 886 |
| 887 scoped_ptr<ClientSocket> socket_; |
| 888 ClientSocketHandle* handle_; |
| 889 CompletionCallback* user_callback_; |
| 890 CompletionCallbackImpl<MockConnectJob> connect_callback_; |
| 891 |
| 892 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); |
| 893 }; |
| 894 |
| 895 MockSSLClientSocketPool( |
| 896 int max_sockets, |
| 897 int max_sockets_per_group, |
| 898 const scoped_refptr<ClientSocketPoolHistograms>& histograms, |
| 899 ClientSocketFactory* socket_factory); |
| 900 |
| 901 int release_count() const { return release_count_; } |
| 902 int cancel_count() const { return cancel_count_; } |
| 903 |
| 904 // SSLClientSocketPool methods. |
| 905 virtual int RequestSocket(const std::string& group_name, |
| 906 const void* socket_params, |
| 907 RequestPriority priority, |
| 908 ClientSocketHandle* handle, |
| 909 CompletionCallback* callback, |
| 910 const BoundNetLog& net_log); |
| 911 |
| 912 virtual void CancelRequest(const std::string& group_name, |
| 913 ClientSocketHandle* handle); |
| 914 virtual void ReleaseSocket(const std::string& group_name, |
| 915 ClientSocket* socket, int id); |
| 916 |
| 917 protected: |
| 918 virtual ~MockSSLClientSocketPool(); |
| 919 |
| 920 private: |
| 921 ClientSocketFactory* client_socket_factory_; |
| 922 int release_count_; |
| 923 int cancel_count_; |
| 924 ScopedVector<MockConnectJob> job_list_; |
| 925 |
| 926 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocketPool); |
| 927 }; |
| 928 |
| 929 |
873 } // namespace net | 930 } // namespace net |
874 | 931 |
875 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 932 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
OLD | NEW |