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

Side by Side Diff: net/socket/socks_client_socket_pool_unittest.cc

Issue 11428150: LoadTiming implementation in net, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix a header or two Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | net/socket/ssl_client_socket_pool.h » ('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/socket/socks_client_socket_pool.h" 5 #include "net/socket/socks_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/time.h" 9 #include "base/time.h"
10 #include "net/base/load_timing_info.h"
10 #include "net/base/mock_host_resolver.h" 11 #include "net/base/mock_host_resolver.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
13 #include "net/socket/client_socket_factory.h" 14 #include "net/socket/client_socket_factory.h"
14 #include "net/socket/client_socket_handle.h" 15 #include "net/socket/client_socket_handle.h"
15 #include "net/socket/client_socket_pool_histograms.h" 16 #include "net/socket/client_socket_pool_histograms.h"
16 #include "net/socket/socket_test_util.h" 17 #include "net/socket/socket_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace net { 20 namespace net {
20 21
21 namespace { 22 namespace {
22 23
23 const int kMaxSockets = 32; 24 const int kMaxSockets = 32;
24 const int kMaxSocketsPerGroup = 6; 25 const int kMaxSocketsPerGroup = 6;
25 26
27 // Make sure |handle|'s load times are set correctly. Only connect times should
28 // be set.
29 void TestLoadTimingInfo(const ClientSocketHandle& handle) {
30 LoadTimingInfo load_timing_info;
31 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info));
32
33 // None of these tests use a NetLog.
34 EXPECT_EQ(NetLog::Source::kInvalidId, load_timing_info.socket_log_id);
35
36 EXPECT_FALSE(load_timing_info.socket_reused);
37
38 EXPECT_FALSE(load_timing_info.connect_timing.connect_start.is_null());
39 EXPECT_LE(load_timing_info.connect_timing.connect_start,
40 load_timing_info.connect_timing.connect_end);
41
42 // None of these should be set by the socket handle.
43 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null());
44 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null());
45 EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null());
46 EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null());
47 EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null());
48 EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null());
49 EXPECT_TRUE(load_timing_info.send_start.is_null());
50 EXPECT_TRUE(load_timing_info.send_end.is_null());
51 EXPECT_TRUE(load_timing_info.receive_headers_end.is_null());
52 }
53
26 class SOCKSClientSocketPoolTest : public testing::Test { 54 class SOCKSClientSocketPoolTest : public testing::Test {
27 protected: 55 protected:
28 class SOCKS5MockData { 56 class SOCKS5MockData {
29 public: 57 public:
30 explicit SOCKS5MockData(IoMode mode) { 58 explicit SOCKS5MockData(IoMode mode) {
31 writes_.reset(new MockWrite[3]); 59 writes_.reset(new MockWrite[3]);
32 writes_[0] = MockWrite(mode, kSOCKS5GreetRequest, 60 writes_[0] = MockWrite(mode, kSOCKS5GreetRequest,
33 kSOCKS5GreetRequestLength); 61 kSOCKS5GreetRequestLength);
34 writes_[1] = MockWrite(mode, kSOCKS5OkRequest, kSOCKS5OkRequestLength); 62 writes_[1] = MockWrite(mode, kSOCKS5OkRequest, kSOCKS5OkRequestLength);
35 writes_[2] = MockWrite(mode, 0); 63 writes_[2] = MockWrite(mode, 0);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 SOCKS5MockData data(SYNCHRONOUS); 128 SOCKS5MockData data(SYNCHRONOUS);
101 data.data_provider()->set_connect_data(MockConnect(SYNCHRONOUS, OK)); 129 data.data_provider()->set_connect_data(MockConnect(SYNCHRONOUS, OK));
102 transport_client_socket_factory_.AddSocketDataProvider(data.data_provider()); 130 transport_client_socket_factory_.AddSocketDataProvider(data.data_provider());
103 131
104 ClientSocketHandle handle; 132 ClientSocketHandle handle;
105 int rv = handle.Init("a", ignored_socket_params_, LOW, CompletionCallback(), 133 int rv = handle.Init("a", ignored_socket_params_, LOW, CompletionCallback(),
106 &pool_, BoundNetLog()); 134 &pool_, BoundNetLog());
107 EXPECT_EQ(OK, rv); 135 EXPECT_EQ(OK, rv);
108 EXPECT_TRUE(handle.is_initialized()); 136 EXPECT_TRUE(handle.is_initialized());
109 EXPECT_TRUE(handle.socket()); 137 EXPECT_TRUE(handle.socket());
138 TestLoadTimingInfo(handle);
110 } 139 }
111 140
112 TEST_F(SOCKSClientSocketPoolTest, Async) { 141 TEST_F(SOCKSClientSocketPoolTest, Async) {
113 SOCKS5MockData data(ASYNC); 142 SOCKS5MockData data(ASYNC);
114 transport_client_socket_factory_.AddSocketDataProvider(data.data_provider()); 143 transport_client_socket_factory_.AddSocketDataProvider(data.data_provider());
115 144
116 TestCompletionCallback callback; 145 TestCompletionCallback callback;
117 ClientSocketHandle handle; 146 ClientSocketHandle handle;
118 int rv = handle.Init("a", ignored_socket_params_, LOW, callback.callback(), 147 int rv = handle.Init("a", ignored_socket_params_, LOW, callback.callback(),
119 &pool_, BoundNetLog()); 148 &pool_, BoundNetLog());
120 EXPECT_EQ(ERR_IO_PENDING, rv); 149 EXPECT_EQ(ERR_IO_PENDING, rv);
121 EXPECT_FALSE(handle.is_initialized()); 150 EXPECT_FALSE(handle.is_initialized());
122 EXPECT_FALSE(handle.socket()); 151 EXPECT_FALSE(handle.socket());
123 152
124 EXPECT_EQ(OK, callback.WaitForResult()); 153 EXPECT_EQ(OK, callback.WaitForResult());
125 EXPECT_TRUE(handle.is_initialized()); 154 EXPECT_TRUE(handle.is_initialized());
126 EXPECT_TRUE(handle.socket()); 155 EXPECT_TRUE(handle.socket());
156 TestLoadTimingInfo(handle);
127 } 157 }
128 158
129 TEST_F(SOCKSClientSocketPoolTest, TransportConnectError) { 159 TEST_F(SOCKSClientSocketPoolTest, TransportConnectError) {
130 StaticSocketDataProvider socket_data; 160 StaticSocketDataProvider socket_data;
131 socket_data.set_connect_data(MockConnect(SYNCHRONOUS, 161 socket_data.set_connect_data(MockConnect(SYNCHRONOUS,
132 ERR_CONNECTION_REFUSED)); 162 ERR_CONNECTION_REFUSED));
133 transport_client_socket_factory_.AddSocketDataProvider(&socket_data); 163 transport_client_socket_factory_.AddSocketDataProvider(&socket_data);
134 164
135 ClientSocketHandle handle; 165 ClientSocketHandle handle;
136 int rv = handle.Init("a", ignored_socket_params_, LOW, CompletionCallback(), 166 int rv = handle.Init("a", ignored_socket_params_, LOW, CompletionCallback(),
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 298
269 (*requests())[0]->handle()->Reset(); 299 (*requests())[0]->handle()->Reset();
270 (*requests())[1]->handle()->Reset(); 300 (*requests())[1]->handle()->Reset();
271 } 301 }
272 302
273 // It would be nice to also test the timeouts in SOCKSClientSocketPool. 303 // It would be nice to also test the timeouts in SOCKSClientSocketPool.
274 304
275 } // namespace 305 } // namespace
276 306
277 } // namespace net 307 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/socket_test_util.cc ('k') | net/socket/ssl_client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698