OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/transport_client_socket_pool_test_util.h" | 5 #include "net/socket/transport_client_socket_pool_test_util.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "net/base/ip_address.h" | 18 #include "net/base/ip_address.h" |
19 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
20 #include "net/base/load_timing_info.h" | 20 #include "net/base/load_timing_info.h" |
21 #include "net/base/load_timing_info_test_util.h" | 21 #include "net/base/load_timing_info_test_util.h" |
| 22 #include "net/log/net_log_source.h" |
22 #include "net/log/net_log_source_type.h" | 23 #include "net/log/net_log_source_type.h" |
| 24 #include "net/log/net_log_with_source.h" |
23 #include "net/socket/client_socket_handle.h" | 25 #include "net/socket/client_socket_handle.h" |
24 #include "net/socket/ssl_client_socket.h" | 26 #include "net/socket/ssl_client_socket.h" |
25 #include "net/udp/datagram_client_socket.h" | 27 #include "net/udp/datagram_client_socket.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
27 | 29 |
28 namespace net { | 30 namespace net { |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 IPAddress ParseIP(const std::string& ip) { | 34 IPAddress ParseIP(const std::string& ip) { |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 312 |
311 } // namespace | 313 } // namespace |
312 | 314 |
313 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { | 315 void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { |
314 LoadTimingInfo load_timing_info; | 316 LoadTimingInfo load_timing_info; |
315 // Only pass true in as |is_reused|, as in general, HttpStream types should | 317 // Only pass true in as |is_reused|, as in general, HttpStream types should |
316 // have stricter concepts of reuse than socket pools. | 318 // have stricter concepts of reuse than socket pools. |
317 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info)); | 319 EXPECT_TRUE(handle.GetLoadTimingInfo(true, &load_timing_info)); |
318 | 320 |
319 EXPECT_TRUE(load_timing_info.socket_reused); | 321 EXPECT_TRUE(load_timing_info.socket_reused); |
320 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 322 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
321 | 323 |
322 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 324 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
323 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 325 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
324 } | 326 } |
325 | 327 |
326 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { | 328 void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { |
327 EXPECT_FALSE(handle.is_reused()); | 329 EXPECT_FALSE(handle.is_reused()); |
328 | 330 |
329 LoadTimingInfo load_timing_info; | 331 LoadTimingInfo load_timing_info; |
330 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info)); | 332 EXPECT_TRUE(handle.GetLoadTimingInfo(false, &load_timing_info)); |
331 | 333 |
332 EXPECT_FALSE(load_timing_info.socket_reused); | 334 EXPECT_FALSE(load_timing_info.socket_reused); |
333 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 335 EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
334 | 336 |
335 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, | 337 ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
336 CONNECT_TIMING_HAS_DNS_TIMES); | 338 CONNECT_TIMING_HAS_DNS_TIMES); |
337 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 339 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
338 | 340 |
339 TestLoadTimingInfoConnectedReused(handle); | 341 TestLoadTimingInfoConnectedReused(handle); |
340 } | 342 } |
341 | 343 |
342 void SetIPv4Address(IPEndPoint* address) { | 344 void SetIPv4Address(IPEndPoint* address) { |
343 *address = IPEndPoint(ParseIP("1.1.1.1"), 80); | 345 *address = IPEndPoint(ParseIP("1.1.1.1"), 80); |
(...skipping 14 matching lines...) Expand all Loading... |
358 delay_(base::TimeDelta::FromMilliseconds( | 360 delay_(base::TimeDelta::FromMilliseconds( |
359 ClientSocketPool::kMaxConnectRetryIntervalMs)) {} | 361 ClientSocketPool::kMaxConnectRetryIntervalMs)) {} |
360 | 362 |
361 MockTransportClientSocketFactory::~MockTransportClientSocketFactory() {} | 363 MockTransportClientSocketFactory::~MockTransportClientSocketFactory() {} |
362 | 364 |
363 std::unique_ptr<DatagramClientSocket> | 365 std::unique_ptr<DatagramClientSocket> |
364 MockTransportClientSocketFactory::CreateDatagramClientSocket( | 366 MockTransportClientSocketFactory::CreateDatagramClientSocket( |
365 DatagramSocket::BindType bind_type, | 367 DatagramSocket::BindType bind_type, |
366 const RandIntCallback& rand_int_cb, | 368 const RandIntCallback& rand_int_cb, |
367 NetLog* net_log, | 369 NetLog* net_log, |
368 const NetLog::Source& source) { | 370 const NetLogSource& source) { |
369 NOTREACHED(); | 371 NOTREACHED(); |
370 return std::unique_ptr<DatagramClientSocket>(); | 372 return std::unique_ptr<DatagramClientSocket>(); |
371 } | 373 } |
372 | 374 |
373 std::unique_ptr<StreamSocket> | 375 std::unique_ptr<StreamSocket> |
374 MockTransportClientSocketFactory::CreateTransportClientSocket( | 376 MockTransportClientSocketFactory::CreateTransportClientSocket( |
375 const AddressList& addresses, | 377 const AddressList& addresses, |
376 std::unique_ptr<SocketPerformanceWatcher> /* socket_performance_watcher */, | 378 std::unique_ptr<SocketPerformanceWatcher> /* socket_performance_watcher */, |
377 NetLog* /* net_log */, | 379 NetLog* /* net_log */, |
378 const NetLog::Source& /* source */) { | 380 const NetLogSource& /* source */) { |
379 allocation_count_++; | 381 allocation_count_++; |
380 | 382 |
381 ClientSocketType type = client_socket_type_; | 383 ClientSocketType type = client_socket_type_; |
382 if (client_socket_types_ && client_socket_index_ < client_socket_index_max_) { | 384 if (client_socket_types_ && client_socket_index_ < client_socket_index_max_) { |
383 type = client_socket_types_[client_socket_index_++]; | 385 type = client_socket_types_[client_socket_index_++]; |
384 } | 386 } |
385 | 387 |
386 switch (type) { | 388 switch (type) { |
387 case MOCK_CLIENT_SOCKET: | 389 case MOCK_CLIENT_SOCKET: |
388 return std::unique_ptr<StreamSocket>( | 390 return std::unique_ptr<StreamSocket>( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 run_loop_quit_closure_ = run_loop.QuitClosure(); | 459 run_loop_quit_closure_ = run_loop.QuitClosure(); |
458 run_loop.Run(); | 460 run_loop.Run(); |
459 run_loop_quit_closure_.Reset(); | 461 run_loop_quit_closure_.Reset(); |
460 } | 462 } |
461 base::Closure trigger = triggerable_sockets_.front(); | 463 base::Closure trigger = triggerable_sockets_.front(); |
462 triggerable_sockets_.pop(); | 464 triggerable_sockets_.pop(); |
463 return trigger; | 465 return trigger; |
464 } | 466 } |
465 | 467 |
466 } // namespace net | 468 } // namespace net |
OLD | NEW |