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

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

Issue 2768173002: Record the time duration for establishing proxy connection (Closed)
Patch Set: Created 3 years, 9 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/test/histogram_tester.h"
13 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
14 #include "net/base/proxy_delegate.h" 15 #include "net/base/proxy_delegate.h"
15 #include "net/base/test_completion_callback.h" 16 #include "net/base/test_completion_callback.h"
16 #include "net/base/test_proxy_delegate.h" 17 #include "net/base/test_proxy_delegate.h"
17 #include "net/http/http_network_session.h" 18 #include "net/http/http_network_session.h"
18 #include "net/http/http_proxy_client_socket.h" 19 #include "net/http/http_proxy_client_socket.h"
19 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
20 #include "net/log/net_log_with_source.h" 21 #include "net/log/net_log_with_source.h"
21 #include "net/socket/client_socket_handle.h" 22 #include "net/socket/client_socket_handle.h"
22 #include "net/socket/next_proto.h" 23 #include "net/socket/next_proto.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 void InitializeSpdySsl() { ssl_data_->next_proto = kProtoHTTP2; } 185 void InitializeSpdySsl() { ssl_data_->next_proto = kProtoHTTP2; }
185 186
186 std::unique_ptr<HttpNetworkSession> CreateNetworkSession() { 187 std::unique_ptr<HttpNetworkSession> CreateNetworkSession() {
187 return SpdySessionDependencies::SpdyCreateSession(&session_deps_); 188 return SpdySessionDependencies::SpdyCreateSession(&session_deps_);
188 } 189 }
189 190
190 RequestPriority GetLastTransportRequestPriority() const { 191 RequestPriority GetLastTransportRequestPriority() const {
191 return transport_socket_pool_.last_request_priority(); 192 return transport_socket_pool_.last_request_priority();
192 } 193 }
193 194
195 const base::HistogramTester& histogram_tester() { return histogram_tester_; }
196
194 private: 197 private:
195 SpdySessionDependencies session_deps_; 198 SpdySessionDependencies session_deps_;
196 199
197 MockTransportClientSocketPool transport_socket_pool_; 200 MockTransportClientSocketPool transport_socket_pool_;
198 MockHostResolver host_resolver_; 201 MockHostResolver host_resolver_;
199 std::unique_ptr<CertVerifier> cert_verifier_; 202 std::unique_ptr<CertVerifier> cert_verifier_;
200 SSLClientSocketPool ssl_socket_pool_; 203 SSLClientSocketPool ssl_socket_pool_;
201 204
202 std::unique_ptr<HttpNetworkSession> session_; 205 std::unique_ptr<HttpNetworkSession> session_;
203 206
207 base::HistogramTester histogram_tester_;
208
204 protected: 209 protected:
205 SpdyTestUtil spdy_util_; 210 SpdyTestUtil spdy_util_;
206 std::unique_ptr<SSLSocketDataProvider> ssl_data_; 211 std::unique_ptr<SSLSocketDataProvider> ssl_data_;
207 std::unique_ptr<SequencedSocketData> data_; 212 std::unique_ptr<SequencedSocketData> data_;
208 HttpProxyClientSocketPool pool_; 213 HttpProxyClientSocketPool pool_;
209 ClientSocketHandle handle_; 214 ClientSocketHandle handle_;
210 TestCompletionCallback callback_; 215 TestCompletionCallback callback_;
211 }; 216 };
212 217
213 // All tests are run with three different proxy types: HTTP, HTTPS (non-SPDY) 218 // All tests are run with three different proxy types: HTTP, HTTPS (non-SPDY)
214 // and SPDY. 219 // and SPDY.
215 INSTANTIATE_TEST_CASE_P(HttpProxyType, 220 INSTANTIATE_TEST_CASE_P(HttpProxyType,
216 HttpProxyClientSocketPoolTest, 221 HttpProxyClientSocketPoolTest,
217 ::testing::Values(HTTP, HTTPS, SPDY)); 222 ::testing::Values(HTTP, HTTPS, SPDY));
218 223
219 TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) { 224 TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) {
220 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); 225 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0);
221 226
222 std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); 227 std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate());
223 int rv = handle_.Init("a", CreateNoTunnelParams(proxy_delegate.get()), LOW, 228 int rv = handle_.Init("a", CreateNoTunnelParams(proxy_delegate.get()), LOW,
224 ClientSocketPool::RespectLimits::ENABLED, 229 ClientSocketPool::RespectLimits::ENABLED,
225 CompletionCallback(), &pool_, NetLogWithSource()); 230 CompletionCallback(), &pool_, NetLogWithSource());
226 EXPECT_THAT(rv, IsOk()); 231 EXPECT_THAT(rv, IsOk());
227 EXPECT_TRUE(handle_.is_initialized()); 232 EXPECT_TRUE(handle_.is_initialized());
228 ASSERT_TRUE(handle_.socket()); 233 ASSERT_TRUE(handle_.socket());
229 EXPECT_TRUE(handle_.socket()->IsConnected()); 234 EXPECT_TRUE(handle_.socket()->IsConnected());
230 EXPECT_FALSE(proxy_delegate->on_before_tunnel_request_called()); 235 EXPECT_FALSE(proxy_delegate->on_before_tunnel_request_called());
231 EXPECT_FALSE(proxy_delegate->on_tunnel_headers_received_called()); 236 EXPECT_FALSE(proxy_delegate->on_tunnel_headers_received_called());
232 EXPECT_TRUE(proxy_delegate->on_tunnel_request_completed_called()); 237 EXPECT_TRUE(proxy_delegate->on_tunnel_request_completed_called());
238
239 bool is_secure_proxy = GetParam() == HTTPS || GetParam() == SPDY;
240 histogram_tester().ExpectTotalCount(
241 "Net.Proxy.ConnectLatency.Insecure.Success", is_secure_proxy ? 0 : 1);
242 histogram_tester().ExpectTotalCount("Net.Proxy.ConnectLatency.Secure.Success",
243 is_secure_proxy ? 1 : 0);
233 } 244 }
234 245
235 // Make sure that HttpProxyConnectJob passes on its priority to its 246 // Make sure that HttpProxyConnectJob passes on its priority to its
236 // (non-SSL) socket request on Init. 247 // (non-SSL) socket request on Init.
237 TEST_P(HttpProxyClientSocketPoolTest, SetSocketRequestPriorityOnInit) { 248 TEST_P(HttpProxyClientSocketPoolTest, SetSocketRequestPriorityOnInit) {
238 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); 249 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0);
239 EXPECT_EQ(OK, handle_.Init("a", CreateNoTunnelParams(NULL), HIGHEST, 250 EXPECT_EQ(OK, handle_.Init("a", CreateNoTunnelParams(NULL), HIGHEST,
240 ClientSocketPool::RespectLimits::ENABLED, 251 ClientSocketPool::RespectLimits::ENABLED,
241 CompletionCallback(), &pool_, NetLogWithSource())); 252 CompletionCallback(), &pool_, NetLogWithSource()));
242 EXPECT_EQ(HIGHEST, GetLastTransportRequestPriority()); 253 EXPECT_EQ(HIGHEST, GetLastTransportRequestPriority());
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // Make sure Location header was included and correct. 704 // Make sure Location header was included and correct.
694 std::string location; 705 std::string location;
695 EXPECT_TRUE(headers->IsRedirect(&location)); 706 EXPECT_TRUE(headers->IsRedirect(&location));
696 EXPECT_EQ(location, redirectTarget); 707 EXPECT_EQ(location, redirectTarget);
697 } 708 }
698 } 709 }
699 710
700 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. 711 // It would be nice to also test the timeouts in HttpProxyClientSocketPool.
701 712
702 } // namespace net 713 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_proxy_client_socket_wrapper.h » ('j') | net/http/http_proxy_client_socket_wrapper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698