1 // Copyright 2016 The Chromium Authors
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/base/net_errors.h"
8 #include "net/base/proxy_server.h"
9 #include "net/base/proxy_string_util.h"
10 #include "net/http/http_request_headers.h"
11 #include "net/http/http_response_headers.h"
12 #include "net/proxy_resolution/proxy_info.h"
13 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace net {
17
18 TestProxyDelegate::TestProxyDelegate() = default;
19
20 TestProxyDelegate::~TestProxyDelegate() = default;
21
VerifyOnTunnelHeadersReceived(const ProxyChain & proxy_chain,size_t chain_index,const std::string & response_header_name,const std::string & response_header_value,size_t call_index) const22 void TestProxyDelegate::VerifyOnTunnelHeadersReceived(
23 const ProxyChain& proxy_chain,
24 size_t chain_index,
25 const std::string& response_header_name,
26 const std::string& response_header_value,
27 size_t call_index) const {
28 ASSERT_LT(call_index, on_tunnel_headers_received_proxy_chains_.size());
29 ASSERT_LT(call_index, on_tunnel_headers_received_chain_indices_.size());
30 ASSERT_LT(call_index, on_tunnel_headers_received_headers_.size());
31
32 EXPECT_EQ(proxy_chain,
33 on_tunnel_headers_received_proxy_chains_.at(call_index));
34 EXPECT_EQ(chain_index,
35 on_tunnel_headers_received_chain_indices_.at(call_index));
36
37 scoped_refptr<HttpResponseHeaders> response_headers =
38 on_tunnel_headers_received_headers_.at(call_index);
39 ASSERT_NE(response_headers.get(), nullptr);
40 EXPECT_TRUE(response_headers->HasHeaderValue(response_header_name,
41 response_header_value));
42 }
43
OnResolveProxy(const GURL & url,const NetworkAnonymizationKey & network_anonymization_key,const std::string & method,const ProxyRetryInfoMap & proxy_retry_info,ProxyInfo * result)44 void TestProxyDelegate::OnResolveProxy(
45 const GURL& url,
46 const NetworkAnonymizationKey& network_anonymization_key,
47 const std::string& method,
48 const ProxyRetryInfoMap& proxy_retry_info,
49 ProxyInfo* result) {}
50
OnFallback(const ProxyChain & bad_chain,int net_error)51 void TestProxyDelegate::OnFallback(const ProxyChain& bad_chain, int net_error) {
52 }
53
OnBeforeTunnelRequest(const ProxyChain & proxy_chain,size_t chain_index,HttpRequestHeaders * extra_headers)54 void TestProxyDelegate::OnBeforeTunnelRequest(
55 const ProxyChain& proxy_chain,
56 size_t chain_index,
57 HttpRequestHeaders* extra_headers) {
58 on_before_tunnel_request_called_ = true;
59 if (extra_headers) {
60 extra_headers->SetHeader(
61 kTestHeaderName,
62 ProxyServerToProxyUri(proxy_chain.GetProxyServer(chain_index)));
63 }
64 }
65
OnTunnelHeadersReceived(const ProxyChain & proxy_chain,size_t chain_index,const HttpResponseHeaders & response_headers)66 Error TestProxyDelegate::OnTunnelHeadersReceived(
67 const ProxyChain& proxy_chain,
68 size_t chain_index,
69 const HttpResponseHeaders& response_headers) {
70 on_tunnel_headers_received_headers_.push_back(
71 base::MakeRefCounted<HttpResponseHeaders>(
72 response_headers.raw_headers()));
73
74 on_tunnel_headers_received_proxy_chains_.push_back(proxy_chain);
75 on_tunnel_headers_received_chain_indices_.push_back(chain_index);
76 return OK;
77 }
78
79 } // namespace net
80