OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/test_proxy_delegate.h" |
| 6 |
| 7 #include "net/http/http_request_headers.h" |
| 8 #include "net/http/http_response_headers.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace net { |
| 12 |
| 13 TestProxyDelegate::TestProxyDelegate() |
| 14 : on_before_tunnel_request_called_(false), |
| 15 on_tunnel_request_completed_called_(false), |
| 16 on_tunnel_headers_received_called_(false) {} |
| 17 |
| 18 TestProxyDelegate::~TestProxyDelegate() {} |
| 19 |
| 20 void TestProxyDelegate::VerifyOnTunnelRequestCompleted( |
| 21 const std::string& endpoint, |
| 22 const std::string& proxy_server) const { |
| 23 EXPECT_TRUE(on_tunnel_request_completed_called_); |
| 24 EXPECT_TRUE(HostPortPair::FromString(endpoint).Equals( |
| 25 on_tunnel_request_completed_endpoint_)); |
| 26 EXPECT_TRUE(HostPortPair::FromString(proxy_server) |
| 27 .Equals(on_tunnel_request_completed_proxy_server_)); |
| 28 } |
| 29 |
| 30 void TestProxyDelegate::VerifyOnTunnelHeadersReceived( |
| 31 const std::string& origin, |
| 32 const std::string& proxy_server, |
| 33 const std::string& status_line) const { |
| 34 EXPECT_TRUE(on_tunnel_headers_received_called_); |
| 35 EXPECT_TRUE(HostPortPair::FromString(origin).Equals( |
| 36 on_tunnel_headers_received_origin_)); |
| 37 EXPECT_TRUE(HostPortPair::FromString(proxy_server) |
| 38 .Equals(on_tunnel_headers_received_proxy_server_)); |
| 39 EXPECT_EQ(status_line, on_tunnel_headers_received_status_line_); |
| 40 } |
| 41 |
| 42 void TestProxyDelegate::OnResolveProxy(const GURL& url, |
| 43 int load_flags, |
| 44 const ProxyService& proxy_service, |
| 45 ProxyInfo* result) {} |
| 46 |
| 47 void TestProxyDelegate::OnTunnelConnectCompleted( |
| 48 const HostPortPair& endpoint, |
| 49 const HostPortPair& proxy_server, |
| 50 int net_error) { |
| 51 on_tunnel_request_completed_called_ = true; |
| 52 on_tunnel_request_completed_endpoint_ = endpoint; |
| 53 on_tunnel_request_completed_proxy_server_ = proxy_server; |
| 54 } |
| 55 |
| 56 void TestProxyDelegate::OnFallback(const ProxyServer& bad_proxy, |
| 57 int net_error) {} |
| 58 |
| 59 void TestProxyDelegate::OnBeforeSendHeaders(URLRequest* request, |
| 60 const ProxyInfo& proxy_info, |
| 61 HttpRequestHeaders* headers) {} |
| 62 |
| 63 void TestProxyDelegate::OnBeforeTunnelRequest( |
| 64 const HostPortPair& proxy_server, |
| 65 HttpRequestHeaders* extra_headers) { |
| 66 on_before_tunnel_request_called_ = true; |
| 67 if (extra_headers) |
| 68 extra_headers->SetHeader("Foo", proxy_server.ToString()); |
| 69 } |
| 70 |
| 71 void TestProxyDelegate::OnTunnelHeadersReceived( |
| 72 const HostPortPair& origin, |
| 73 const HostPortPair& proxy_server, |
| 74 const HttpResponseHeaders& response_headers) { |
| 75 on_tunnel_headers_received_called_ = true; |
| 76 on_tunnel_headers_received_origin_ = origin; |
| 77 on_tunnel_headers_received_proxy_server_ = proxy_server; |
| 78 on_tunnel_headers_received_status_line_ = response_headers.GetStatusLine(); |
| 79 } |
| 80 |
| 81 bool TestProxyDelegate::IsTrustedSpdyProxy( |
| 82 const net::ProxyServer& proxy_server) { |
| 83 return proxy_server.is_valid() && trusted_spdy_proxy_ == proxy_server; |
| 84 } |
| 85 |
| 86 } // namespace net |
OLD | NEW |