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

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

Issue 2333923004: Extracting NetLog inner classes into their own classes. (Closed)
Patch Set: Some nit fixes and better, impl-agnostic naming of net_log_parameters_callback_typedef.h -> net/log… Created 4 years, 2 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/socket/client_socket_pool_base.h" 5 #include "net/socket/client_socket_pool_base.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/values.h" 27 #include "base/values.h"
28 #include "net/base/load_timing_info.h" 28 #include "net/base/load_timing_info.h"
29 #include "net/base/load_timing_info_test_util.h" 29 #include "net/base/load_timing_info_test_util.h"
30 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
31 #include "net/base/request_priority.h" 31 #include "net/base/request_priority.h"
32 #include "net/base/test_completion_callback.h" 32 #include "net/base/test_completion_callback.h"
33 #include "net/http/http_response_headers.h" 33 #include "net/http/http_response_headers.h"
34 #include "net/log/net_log.h" 34 #include "net/log/net_log.h"
35 #include "net/log/net_log_event_type.h" 35 #include "net/log/net_log_event_type.h"
36 #include "net/log/net_log_source.h"
36 #include "net/log/net_log_source_type.h" 37 #include "net/log/net_log_source_type.h"
37 #include "net/log/test_net_log.h" 38 #include "net/log/test_net_log.h"
38 #include "net/log/test_net_log_entry.h" 39 #include "net/log/test_net_log_entry.h"
39 #include "net/log/test_net_log_util.h" 40 #include "net/log/test_net_log_util.h"
40 #include "net/socket/client_socket_factory.h" 41 #include "net/socket/client_socket_factory.h"
41 #include "net/socket/client_socket_handle.h" 42 #include "net/socket/client_socket_handle.h"
42 #include "net/socket/socket_performance_watcher.h" 43 #include "net/socket/socket_performance_watcher.h"
43 #include "net/socket/socket_test_util.h" 44 #include "net/socket/socket_test_util.h"
44 #include "net/socket/ssl_client_socket.h" 45 #include "net/socket/ssl_client_socket.h"
45 #include "net/socket/stream_socket.h" 46 #include "net/socket/stream_socket.h"
(...skipping 17 matching lines...) Expand all
63 64
64 // Make sure |handle| sets load times correctly when it has been assigned a 65 // Make sure |handle| sets load times correctly when it has been assigned a
65 // reused socket. 66 // reused socket.
66 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { 67 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) {
67 LoadTimingInfo load_timing_info; 68 LoadTimingInfo load_timing_info;
68 // Only pass true in as |is_reused|, as in general, HttpStream types should 69 // Only pass true in as |is_reused|, as in general, HttpStream types should
69 // have stricter concepts of reuse than socket pools. 70 // have stricter concepts of reuse than socket pools.
70 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info)); 71 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info));
71 72
72 EXPECT_EQ(true, load_timing_info.socket_reused); 73 EXPECT_EQ(true, load_timing_info.socket_reused);
73 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); 74 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id);
74 75
75 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); 76 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
76 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); 77 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info);
77 } 78 }
78 79
79 // Make sure |handle| sets load times correctly when it has been assigned a 80 // Make sure |handle| sets load times correctly when it has been assigned a
80 // fresh socket. Also runs TestLoadTimingInfoConnectedReused, since the owner 81 // fresh socket. Also runs TestLoadTimingInfoConnectedReused, since the owner
81 // of a connection where |is_reused| is false may consider the connection 82 // of a connection where |is_reused| is false may consider the connection
82 // reused. 83 // reused.
83 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { 84 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) {
84 EXPECT_FALSE(handle.is_reused()); 85 EXPECT_FALSE(handle.is_reused());
85 86
86 LoadTimingInfo load_timing_info; 87 LoadTimingInfo load_timing_info;
87 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info)); 88 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info));
88 89
89 EXPECT_FALSE(load_timing_info.socket_reused); 90 EXPECT_FALSE(load_timing_info.socket_reused);
90 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); 91 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id);
91 92
92 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, 93 ExpectConnectTimingHasTimes(load_timing_info.connect_timing,
93 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); 94 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
94 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); 95 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info);
95 96
96 TestLoadTimingInfoConnectedReused(handle); 97 TestLoadTimingInfoConnectedReused(handle);
97 } 98 }
98 99
99 // Make sure |handle| sets load times correctly, in the case that it does not 100 // Make sure |handle| sets load times correctly, in the case that it does not
100 // currently have a socket. 101 // currently have a socket.
101 void TestLoadTimingInfoNotConnected(const ClientSocketHandle& handle) { 102 void TestLoadTimingInfoNotConnected(const ClientSocketHandle& handle) {
102 // Should only be set to true once a socket is assigned, if at all. 103 // Should only be set to true once a socket is assigned, if at all.
103 EXPECT_FALSE(handle.is_reused()); 104 EXPECT_FALSE(handle.is_reused());
104 105
105 LoadTimingInfo load_timing_info; 106 LoadTimingInfo load_timing_info;
106 EXPECT_FALSE(handle.GetLoadTimingInfo(false, &load_timing_info)); 107 EXPECT_FALSE(handle.GetLoadTimingInfo(false, &load_timing_info));
107 108
108 EXPECT_FALSE(load_timing_info.socket_reused); 109 EXPECT_FALSE(load_timing_info.socket_reused);
109 EXPECT_EQ(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); 110 EXPECT_EQ(NetLogSource::kInvalidId, load_timing_info.socket_log_id);
110 111
111 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); 112 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing);
112 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); 113 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info);
113 } 114 }
114 115
115 class TestSocketParams : public base::RefCounted<TestSocketParams> { 116 class TestSocketParams : public base::RefCounted<TestSocketParams> {
116 public: 117 public:
117 explicit TestSocketParams() {} 118 explicit TestSocketParams() {}
118 119
119 private: 120 private:
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 class TestConnectJob; 208 class TestConnectJob;
208 209
209 class MockClientSocketFactory : public ClientSocketFactory { 210 class MockClientSocketFactory : public ClientSocketFactory {
210 public: 211 public:
211 MockClientSocketFactory() : allocation_count_(0) {} 212 MockClientSocketFactory() : allocation_count_(0) {}
212 213
213 std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( 214 std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
214 DatagramSocket::BindType bind_type, 215 DatagramSocket::BindType bind_type,
215 const RandIntCallback& rand_int_cb, 216 const RandIntCallback& rand_int_cb,
216 NetLog* net_log, 217 NetLog* net_log,
217 const NetLog::Source& source) override { 218 const NetLogSource& source) override {
218 NOTREACHED(); 219 NOTREACHED();
219 return std::unique_ptr<DatagramClientSocket>(); 220 return std::unique_ptr<DatagramClientSocket>();
220 } 221 }
221 222
222 std::unique_ptr<StreamSocket> CreateTransportClientSocket( 223 std::unique_ptr<StreamSocket> CreateTransportClientSocket(
223 const AddressList& addresses, 224 const AddressList& addresses,
224 std::unique_ptr< 225 std::unique_ptr<
225 SocketPerformanceWatcher> /* socket_performance_watcher */, 226 SocketPerformanceWatcher> /* socket_performance_watcher */,
226 NetLog* /* net_log */, 227 NetLog* /* net_log */,
227 const NetLog::Source& /*source*/) override { 228 const NetLogSource& /*source*/) override {
228 allocation_count_++; 229 allocation_count_++;
229 return std::unique_ptr<StreamSocket>(); 230 return std::unique_ptr<StreamSocket>();
230 } 231 }
231 232
232 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket( 233 std::unique_ptr<SSLClientSocket> CreateSSLClientSocket(
233 std::unique_ptr<ClientSocketHandle> transport_socket, 234 std::unique_ptr<ClientSocketHandle> transport_socket,
234 const HostPortPair& host_and_port, 235 const HostPortPair& host_and_port,
235 const SSLConfig& ssl_config, 236 const SSLConfig& ssl_config,
236 const SSLClientSocketContext& context) override { 237 const SSLClientSocketContext& context) override {
237 NOTIMPLEMENTED(); 238 NOTIMPLEMENTED();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 handle->set_ssl_error_response_info(info); 314 handle->set_ssl_error_response_info(info);
314 } 315 }
315 } 316 }
316 317
317 private: 318 private:
318 // From ConnectJob: 319 // From ConnectJob:
319 320
320 int ConnectInternal() override { 321 int ConnectInternal() override {
321 AddressList ignored; 322 AddressList ignored;
322 client_socket_factory_->CreateTransportClientSocket(ignored, NULL, NULL, 323 client_socket_factory_->CreateTransportClientSocket(ignored, NULL, NULL,
323 NetLog::Source()); 324 NetLogSource());
324 SetSocket(std::unique_ptr<StreamSocket>( 325 SetSocket(std::unique_ptr<StreamSocket>(
325 new MockClientSocket(net_log().net_log()))); 326 new MockClientSocket(net_log().net_log())));
326 switch (job_type_) { 327 switch (job_type_) {
327 case kMockJob: 328 case kMockJob:
328 return DoConnect(true /* successful */, false /* sync */, 329 return DoConnect(true /* successful */, false /* sync */,
329 false /* recoverable */); 330 false /* recoverable */);
330 case kMockFailingJob: 331 case kMockFailingJob:
331 return DoConnect(false /* error */, false /* sync */, 332 return DoConnect(false /* error */, false /* sync */,
332 false /* recoverable */); 333 false /* recoverable */);
333 case kMockPendingJob: 334 case kMockPendingJob:
(...skipping 3465 matching lines...) Expand 10 before | Expand all | Expand 10 after
3799 request(1)->handle()->Reset(); 3800 request(1)->handle()->Reset();
3800 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a")); 3801 ASSERT_EQ(1, pool_->NumConnectJobsInGroup("a"));
3801 3802
3802 EXPECT_THAT(request(2)->WaitForResult(), IsOk()); 3803 EXPECT_THAT(request(2)->WaitForResult(), IsOk());
3803 EXPECT_FALSE(request(1)->have_result()); 3804 EXPECT_FALSE(request(1)->have_result());
3804 } 3805 }
3805 3806
3806 } // namespace 3807 } // namespace
3807 3808
3808 } // namespace net 3809 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698