| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const char kHttpProxyHost[] = "httpproxy.example.com"; | 59 const char kHttpProxyHost[] = "httpproxy.example.com"; |
| 60 const char kHttpsProxyHost[] = "httpsproxy.example.com"; | 60 const char kHttpsProxyHost[] = "httpsproxy.example.com"; |
| 61 | 61 |
| 62 class TestProxyDelegate : public ProxyDelegate { | 62 class TestProxyDelegate : public ProxyDelegate { |
| 63 public: | 63 public: |
| 64 TestProxyDelegate() | 64 TestProxyDelegate() |
| 65 : on_before_tunnel_request_called_(false), | 65 : on_before_tunnel_request_called_(false), |
| 66 on_tunnel_headers_received_called_(false) { | 66 on_tunnel_headers_received_called_(false) { |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual ~TestProxyDelegate() override { | 69 ~TestProxyDelegate() override {} |
| 70 } | |
| 71 | 70 |
| 72 bool on_before_tunnel_request_called() const { | 71 bool on_before_tunnel_request_called() const { |
| 73 return on_before_tunnel_request_called_; | 72 return on_before_tunnel_request_called_; |
| 74 } | 73 } |
| 75 | 74 |
| 76 bool on_tunnel_headers_received_called() const { | 75 bool on_tunnel_headers_received_called() const { |
| 77 return on_tunnel_headers_received_called_; | 76 return on_tunnel_headers_received_called_; |
| 78 } | 77 } |
| 79 | 78 |
| 80 void VerifyOnTunnelHeadersReceived(const std::string& origin, | 79 void VerifyOnTunnelHeadersReceived(const std::string& origin, |
| 81 const std::string& proxy_server, | 80 const std::string& proxy_server, |
| 82 const std::string& status_line) const { | 81 const std::string& status_line) const { |
| 83 EXPECT_TRUE(on_tunnel_headers_received_called_); | 82 EXPECT_TRUE(on_tunnel_headers_received_called_); |
| 84 EXPECT_TRUE(HostPortPair::FromString(origin).Equals( | 83 EXPECT_TRUE(HostPortPair::FromString(origin).Equals( |
| 85 on_tunnel_headers_received_origin_)); | 84 on_tunnel_headers_received_origin_)); |
| 86 EXPECT_TRUE(HostPortPair::FromString(proxy_server).Equals( | 85 EXPECT_TRUE(HostPortPair::FromString(proxy_server).Equals( |
| 87 on_tunnel_headers_received_proxy_server_)); | 86 on_tunnel_headers_received_proxy_server_)); |
| 88 EXPECT_EQ(status_line, on_tunnel_headers_received_status_line_); | 87 EXPECT_EQ(status_line, on_tunnel_headers_received_status_line_); |
| 89 } | 88 } |
| 90 | 89 |
| 91 // ProxyDelegate: | 90 // ProxyDelegate: |
| 92 virtual void OnResolveProxy(const GURL& url, | 91 void OnResolveProxy(const GURL& url, |
| 93 int load_flags, | 92 int load_flags, |
| 94 const ProxyService& proxy_service, | 93 const ProxyService& proxy_service, |
| 95 ProxyInfo* result) override { | 94 ProxyInfo* result) override {} |
| 96 } | |
| 97 | 95 |
| 98 virtual void OnFallback(const ProxyServer& bad_proxy, | 96 void OnFallback(const ProxyServer& bad_proxy, int net_error) override {} |
| 99 int net_error) override { | |
| 100 } | |
| 101 | 97 |
| 102 virtual void OnBeforeSendHeaders(URLRequest* request, | 98 void OnBeforeSendHeaders(URLRequest* request, |
| 103 const ProxyInfo& proxy_info, | 99 const ProxyInfo& proxy_info, |
| 104 HttpRequestHeaders* headers) override { | 100 HttpRequestHeaders* headers) override {} |
| 105 } | |
| 106 | 101 |
| 107 virtual void OnBeforeTunnelRequest( | 102 void OnBeforeTunnelRequest(const net::HostPortPair& proxy_server, |
| 108 const net::HostPortPair& proxy_server, | 103 net::HttpRequestHeaders* extra_headers) override { |
| 109 net::HttpRequestHeaders* extra_headers) override { | |
| 110 on_before_tunnel_request_called_ = true; | 104 on_before_tunnel_request_called_ = true; |
| 111 if (extra_headers) { | 105 if (extra_headers) { |
| 112 extra_headers->SetHeader("Foo", proxy_server.ToString()); | 106 extra_headers->SetHeader("Foo", proxy_server.ToString()); |
| 113 } | 107 } |
| 114 } | 108 } |
| 115 | 109 |
| 116 virtual void OnTunnelHeadersReceived( | 110 void OnTunnelHeadersReceived( |
| 117 const net::HostPortPair& origin, | 111 const net::HostPortPair& origin, |
| 118 const net::HostPortPair& proxy_server, | 112 const net::HostPortPair& proxy_server, |
| 119 const net::HttpResponseHeaders& response_headers) override { | 113 const net::HttpResponseHeaders& response_headers) override { |
| 120 on_tunnel_headers_received_called_ = true; | 114 on_tunnel_headers_received_called_ = true; |
| 121 on_tunnel_headers_received_origin_ = origin; | 115 on_tunnel_headers_received_origin_ = origin; |
| 122 on_tunnel_headers_received_proxy_server_ = proxy_server; | 116 on_tunnel_headers_received_proxy_server_ = proxy_server; |
| 123 on_tunnel_headers_received_status_line_ = response_headers.GetStatusLine(); | 117 on_tunnel_headers_received_status_line_ = response_headers.GetStatusLine(); |
| 124 } | 118 } |
| 125 | 119 |
| 126 private: | 120 private: |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 EXPECT_TRUE(headers->IsRedirect(&location)); | 804 EXPECT_TRUE(headers->IsRedirect(&location)); |
| 811 EXPECT_EQ(location, redirectTarget); | 805 EXPECT_EQ(location, redirectTarget); |
| 812 } | 806 } |
| 813 } | 807 } |
| 814 | 808 |
| 815 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 809 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
| 816 | 810 |
| 817 } // namespace | 811 } // namespace |
| 818 | 812 |
| 819 } // namespace net | 813 } // namespace net |
| OLD | NEW |