Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: net/http/http_proxy_client_socket_pool_unittest.cc

Issue 1547273003: Set trusted SPDY proxy dynamically on per-profile basis (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added net/base/test_proxy_delegate.{h,cc} Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/net.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/base/proxy_delegate.h" 12 #include "net/base/proxy_delegate.h"
13 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
14 #include "net/base/test_proxy_delegate.h"
14 #include "net/http/http_network_session.h" 15 #include "net/http/http_network_session.h"
15 #include "net/http/http_proxy_client_socket.h" 16 #include "net/http/http_proxy_client_socket.h"
16 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
17 #include "net/socket/client_socket_handle.h" 18 #include "net/socket/client_socket_handle.h"
18 #include "net/socket/next_proto.h" 19 #include "net/socket/next_proto.h"
19 #include "net/socket/socket_test_util.h" 20 #include "net/socket/socket_test_util.h"
20 #include "net/spdy/spdy_protocol.h" 21 #include "net/spdy/spdy_protocol.h"
21 #include "net/spdy/spdy_test_util_common.h" 22 #include "net/spdy/spdy_test_util_common.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
(...skipping 30 matching lines...) Expand all
54 HttpProxyType proxy_type; 55 HttpProxyType proxy_type;
55 NextProto protocol; 56 NextProto protocol;
56 bool priority_to_dependency; 57 bool priority_to_dependency;
57 }; 58 };
58 59
59 typedef ::testing::TestWithParam<HttpProxyType> TestWithHttpParam; 60 typedef ::testing::TestWithParam<HttpProxyType> TestWithHttpParam;
60 61
61 const char kHttpProxyHost[] = "httpproxy.example.com"; 62 const char kHttpProxyHost[] = "httpproxy.example.com";
62 const char kHttpsProxyHost[] = "httpsproxy.example.com"; 63 const char kHttpsProxyHost[] = "httpsproxy.example.com";
63 64
64 class TestProxyDelegate : public ProxyDelegate {
65 public:
66 TestProxyDelegate()
67 : on_before_tunnel_request_called_(false),
68 on_tunnel_request_completed_called_(false),
69 on_tunnel_headers_received_called_(false) {
70 }
71
72 ~TestProxyDelegate() override {}
73
74 bool on_before_tunnel_request_called() const {
75 return on_before_tunnel_request_called_;
76 }
77
78 bool on_tunnel_request_completed_called() const {
79 return on_tunnel_request_completed_called_;
80 }
81
82 bool on_tunnel_headers_received_called() const {
83 return on_tunnel_headers_received_called_;
84 }
85
86 void VerifyOnTunnelRequestCompleted(const std::string& endpoint,
87 const std::string& proxy_server) const {
88 EXPECT_TRUE(on_tunnel_request_completed_called_);
89 EXPECT_TRUE(HostPortPair::FromString(endpoint).Equals(
90 on_tunnel_request_completed_endpoint_));
91 EXPECT_TRUE(HostPortPair::FromString(proxy_server).Equals(
92 on_tunnel_request_completed_proxy_server_));
93 }
94
95 void VerifyOnTunnelHeadersReceived(const std::string& origin,
96 const std::string& proxy_server,
97 const std::string& status_line) const {
98 EXPECT_TRUE(on_tunnel_headers_received_called_);
99 EXPECT_TRUE(HostPortPair::FromString(origin).Equals(
100 on_tunnel_headers_received_origin_));
101 EXPECT_TRUE(HostPortPair::FromString(proxy_server).Equals(
102 on_tunnel_headers_received_proxy_server_));
103 EXPECT_EQ(status_line, on_tunnel_headers_received_status_line_);
104 }
105
106 // ProxyDelegate:
107 void OnResolveProxy(const GURL& url,
108 int load_flags,
109 const ProxyService& proxy_service,
110 ProxyInfo* result) override {}
111
112 void OnTunnelConnectCompleted(const HostPortPair& endpoint,
113 const HostPortPair& proxy_server,
114 int net_error) override {
115 on_tunnel_request_completed_called_ = true;
116 on_tunnel_request_completed_endpoint_ = endpoint;
117 on_tunnel_request_completed_proxy_server_ = proxy_server;
118 }
119
120 void OnFallback(const ProxyServer& bad_proxy, int net_error) override {}
121
122 void OnBeforeSendHeaders(URLRequest* request,
123 const ProxyInfo& proxy_info,
124 HttpRequestHeaders* headers) override {}
125
126 void OnBeforeTunnelRequest(const HostPortPair& proxy_server,
127 HttpRequestHeaders* extra_headers) override {
128 on_before_tunnel_request_called_ = true;
129 if (extra_headers) {
130 extra_headers->SetHeader("Foo", proxy_server.ToString());
131 }
132 }
133
134 void OnTunnelHeadersReceived(
135 const HostPortPair& origin,
136 const HostPortPair& proxy_server,
137 const HttpResponseHeaders& response_headers) override {
138 on_tunnel_headers_received_called_ = true;
139 on_tunnel_headers_received_origin_ = origin;
140 on_tunnel_headers_received_proxy_server_ = proxy_server;
141 on_tunnel_headers_received_status_line_ = response_headers.GetStatusLine();
142 }
143
144 private:
145 bool on_before_tunnel_request_called_;
146 bool on_tunnel_request_completed_called_;
147 bool on_tunnel_headers_received_called_;
148 HostPortPair on_tunnel_request_completed_endpoint_;
149 HostPortPair on_tunnel_request_completed_proxy_server_;
150 HostPortPair on_tunnel_headers_received_origin_;
151 HostPortPair on_tunnel_headers_received_proxy_server_;
152 std::string on_tunnel_headers_received_status_line_;
153 };
154
155 } // namespace 65 } // namespace
156 66
157 class HttpProxyClientSocketPoolTest 67 class HttpProxyClientSocketPoolTest
158 : public ::testing::TestWithParam<HttpProxyClientSocketPoolTestParams> { 68 : public ::testing::TestWithParam<HttpProxyClientSocketPoolTestParams> {
159 protected: 69 protected:
160 HttpProxyClientSocketPoolTest() 70 HttpProxyClientSocketPoolTest()
161 : session_deps_(GetParam().protocol), 71 : session_deps_(GetParam().protocol),
162 transport_socket_pool_(kMaxSockets, 72 transport_socket_pool_(kMaxSockets,
163 kMaxSocketsPerGroup, 73 kMaxSocketsPerGroup,
164 session_deps_.socket_factory.get()), 74 session_deps_.socket_factory.get()),
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // Make sure Location header was included and correct. 741 // Make sure Location header was included and correct.
832 std::string location; 742 std::string location;
833 EXPECT_TRUE(headers->IsRedirect(&location)); 743 EXPECT_TRUE(headers->IsRedirect(&location));
834 EXPECT_EQ(location, redirectTarget); 744 EXPECT_EQ(location, redirectTarget);
835 } 745 }
836 } 746 }
837 747
838 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. 748 // It would be nice to also test the timeouts in HttpProxyClientSocketPool.
839 749
840 } // namespace net 750 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/net.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698