| 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 #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 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_util.h" |
| 14 #include "base/time.h" | 15 #include "base/time.h" |
| 15 #include "net/base/address_family.h" | 16 #include "net/base/address_family.h" |
| 16 #include "net/base/auth.h" | 17 #include "net/base/auth.h" |
| 17 #include "net/base/host_resolver_proc.h" | 18 #include "net/base/host_resolver_proc.h" |
| 18 #include "net/base/ssl_info.h" | 19 #include "net/base/ssl_info.h" |
| 19 #include "net/http/http_network_session.h" | 20 #include "net/http/http_network_session.h" |
| 20 #include "net/http/http_request_headers.h" | 21 #include "net/http/http_request_headers.h" |
| 21 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 22 #include "net/socket/client_socket_pool_histograms.h" | 23 #include "net/socket/client_socket_pool_histograms.h" |
| 23 #include "net/socket/socket.h" | 24 #include "net/socket/socket.h" |
| (...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 return tcp_pool_->ReleaseSocket(group_name, socket, id); | 885 return tcp_pool_->ReleaseSocket(group_name, socket, id); |
| 885 } | 886 } |
| 886 | 887 |
| 887 MockSOCKSClientSocketPool::~MockSOCKSClientSocketPool() {} | 888 MockSOCKSClientSocketPool::~MockSOCKSClientSocketPool() {} |
| 888 | 889 |
| 889 MockHttpAuthController::MockHttpAuthController() | 890 MockHttpAuthController::MockHttpAuthController() |
| 890 : HttpAuthController(HttpAuth::AUTH_PROXY, GURL(), | 891 : HttpAuthController(HttpAuth::AUTH_PROXY, GURL(), |
| 891 scoped_refptr<HttpNetworkSession>(NULL)), | 892 scoped_refptr<HttpNetworkSession>(NULL)), |
| 892 data_(NULL), | 893 data_(NULL), |
| 893 data_index_(0), | 894 data_index_(0), |
| 894 data_count_(0) { | 895 data_count_(0), |
| 896 next_index_(0) { |
| 895 } | 897 } |
| 896 | 898 |
| 897 void MockHttpAuthController::SetMockAuthControllerData( | 899 void MockHttpAuthController::SetMockAuthControllerData( |
| 898 struct MockHttpAuthControllerData* data, size_t count) { | 900 struct MockHttpAuthControllerData* data, size_t count) { |
| 899 data_ = data; | 901 data_ = data; |
| 900 data_count_ = count; | 902 data_count_ = count; |
| 901 } | 903 } |
| 902 | 904 |
| 903 int MockHttpAuthController::MaybeGenerateAuthToken( | 905 int MockHttpAuthController::MaybeGenerateAuthToken( |
| 904 const HttpRequestInfo* request, | 906 const HttpRequestInfo* request, |
| 905 CompletionCallback* callback, | 907 CompletionCallback* callback, |
| 906 const BoundNetLog& net_log) { | 908 const BoundNetLog& net_log) { |
| 907 return OK; | 909 return OK; |
| 908 } | 910 } |
| 909 | 911 |
| 910 void MockHttpAuthController::AddAuthorizationHeader( | 912 void MockHttpAuthController::AddAuthorizationHeader( |
| 911 HttpRequestHeaders* authorization_headers) { | 913 HttpRequestHeaders* authorization_headers) { |
| 912 authorization_headers->AddHeadersFromString(CurrentData().auth_header); | 914 authorization_headers->AddHeadersFromString(CurrentData().auth_header); |
| 913 } | 915 } |
| 914 | 916 |
| 915 int MockHttpAuthController::HandleAuthChallenge( | 917 int MockHttpAuthController::HandleAuthChallenge( |
| 916 scoped_refptr<HttpResponseHeaders> headers, | 918 scoped_refptr<HttpResponseHeaders> headers, |
| 917 bool do_not_send_server_auth, | 919 bool do_not_send_server_auth, |
| 918 bool establishing_tunnel, | 920 bool establishing_tunnel, |
| 919 const BoundNetLog& net_log) { | 921 const BoundNetLog& net_log) { |
| 920 return OK; | 922 return OK; |
| 921 } | 923 } |
| 922 | 924 |
| 923 void MockHttpAuthController::ResetAuth(const std::wstring& username, | 925 void MockHttpAuthController::SetCredentials(const std::wstring& username, |
| 924 const std::wstring& password) { | 926 const std::wstring& password) { |
| 925 data_index_++; | 927 EXPECT_EQ(ASCIIToWide(CurrentData().username), username); |
| 928 EXPECT_EQ(ASCIIToWide(CurrentData().password), password); |
| 929 next_index_ = data_index_ + 1; |
| 930 data_index_ = data_count_; |
| 931 } |
| 932 |
| 933 void MockHttpAuthController::PrepareForAuthRestart() { |
| 934 data_index_ = next_index_; |
| 926 } | 935 } |
| 927 | 936 |
| 928 bool MockHttpAuthController::HaveAuth() const { | 937 bool MockHttpAuthController::HaveAuth() const { |
| 929 return CurrentData().auth_header.size() != 0; | 938 return CurrentData().auth_header.size() != 0; |
| 930 } | 939 } |
| 931 | 940 |
| 932 bool MockHttpAuthController::HaveAuthHandler() const { | 941 bool MockHttpAuthController::HaveAuthHandler() const { |
| 933 return HaveAuth(); | 942 return HaveAuth(); |
| 934 } | 943 } |
| 935 | 944 |
| 945 HttpAuth::Identity MockHttpAuthController::AuthIdentity() { |
| 946 HttpAuth::Identity identity; |
| 947 identity.source = HttpAuth::IDENT_SRC_EXTERNAL; |
| 948 identity.invalid = false; |
| 949 identity.username = ASCIIToWide(CurrentData().username); |
| 950 identity.password = ASCIIToWide(CurrentData().password); |
| 951 data_index_++; |
| 952 return identity; |
| 953 } |
| 954 |
| 936 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; | 955 const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 937 const int kSOCKS5GreetRequestLength = arraysize(kSOCKS5GreetRequest); | 956 const int kSOCKS5GreetRequestLength = arraysize(kSOCKS5GreetRequest); |
| 938 | 957 |
| 939 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; | 958 const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
| 940 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse); | 959 const int kSOCKS5GreetResponseLength = arraysize(kSOCKS5GreetResponse); |
| 941 | 960 |
| 942 const char kSOCKS5OkRequest[] = | 961 const char kSOCKS5OkRequest[] = |
| 943 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 962 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
| 944 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 963 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
| 945 | 964 |
| 946 const char kSOCKS5OkResponse[] = | 965 const char kSOCKS5OkResponse[] = |
| 947 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 966 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 948 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 967 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
| 949 | 968 |
| 950 } // namespace net | 969 } // namespace net |
| OLD | NEW |