| OLD | NEW |
| 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/time.h" | 9 #include "base/time/time.h" |
| 10 #include "net/base/load_timing_info.h" | 10 #include "net/base/load_timing_info.h" |
| 11 #include "net/base/load_timing_info_test_util.h" | 11 #include "net/base/load_timing_info_test_util.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "net/dns/mock_host_resolver.h" | 14 #include "net/dns/mock_host_resolver.h" |
| 15 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
| 16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/client_socket_pool_histograms.h" | |
| 18 #include "net/socket/socket_test_util.h" | 17 #include "net/socket/socket_test_util.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 19 |
| 21 namespace net { | 20 namespace net { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 const int kMaxSockets = 32; | 24 const int kMaxSockets = 32; |
| 26 const int kMaxSocketsPerGroup = 6; | 25 const int kMaxSocketsPerGroup = 6; |
| 27 | 26 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 82 |
| 84 SocketDataProvider* data_provider() { return data_.get(); } | 83 SocketDataProvider* data_provider() { return data_.get(); } |
| 85 | 84 |
| 86 private: | 85 private: |
| 87 scoped_ptr<StaticSocketDataProvider> data_; | 86 scoped_ptr<StaticSocketDataProvider> data_; |
| 88 scoped_ptr<MockWrite[]> writes_; | 87 scoped_ptr<MockWrite[]> writes_; |
| 89 scoped_ptr<MockRead[]> reads_; | 88 scoped_ptr<MockRead[]> reads_; |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 SOCKSClientSocketPoolTest() | 91 SOCKSClientSocketPoolTest() |
| 93 : transport_histograms_("MockTCP"), | 92 : transport_socket_pool_(kMaxSockets, |
| 94 transport_socket_pool_( | 93 kMaxSocketsPerGroup, |
| 95 kMaxSockets, kMaxSocketsPerGroup, | 94 &transport_client_socket_factory_), |
| 96 &transport_histograms_, | 95 pool_(kMaxSockets, |
| 97 &transport_client_socket_factory_), | 96 kMaxSocketsPerGroup, |
| 98 socks_histograms_("SOCKSUnitTest"), | |
| 99 pool_(kMaxSockets, kMaxSocketsPerGroup, | |
| 100 &socks_histograms_, | |
| 101 &host_resolver_, | 97 &host_resolver_, |
| 102 &transport_socket_pool_, | 98 &transport_socket_pool_, |
| 103 NULL) { | 99 NULL) {} |
| 104 } | |
| 105 | 100 |
| 106 ~SOCKSClientSocketPoolTest() override {} | 101 ~SOCKSClientSocketPoolTest() override {} |
| 107 | 102 |
| 108 int StartRequestV5(const std::string& group_name, RequestPriority priority) { | 103 int StartRequestV5(const std::string& group_name, RequestPriority priority) { |
| 109 return test_base_.StartRequestUsingPool( | 104 return test_base_.StartRequestUsingPool( |
| 110 &pool_, group_name, priority, CreateSOCKSv5Params()); | 105 &pool_, group_name, priority, CreateSOCKSv5Params()); |
| 111 } | 106 } |
| 112 | 107 |
| 113 int GetOrderOfRequest(size_t index) const { | 108 int GetOrderOfRequest(size_t index) const { |
| 114 return test_base_.GetOrderOfRequest(index); | 109 return test_base_.GetOrderOfRequest(index); |
| 115 } | 110 } |
| 116 | 111 |
| 117 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } | 112 ScopedVector<TestSocketRequest>* requests() { return test_base_.requests(); } |
| 118 | 113 |
| 119 ClientSocketPoolHistograms transport_histograms_; | |
| 120 MockClientSocketFactory transport_client_socket_factory_; | 114 MockClientSocketFactory transport_client_socket_factory_; |
| 121 MockTransportClientSocketPool transport_socket_pool_; | 115 MockTransportClientSocketPool transport_socket_pool_; |
| 122 | 116 |
| 123 ClientSocketPoolHistograms socks_histograms_; | |
| 124 MockHostResolver host_resolver_; | 117 MockHostResolver host_resolver_; |
| 125 SOCKSClientSocketPool pool_; | 118 SOCKSClientSocketPool pool_; |
| 126 ClientSocketPoolTest test_base_; | 119 ClientSocketPoolTest test_base_; |
| 127 }; | 120 }; |
| 128 | 121 |
| 129 TEST_F(SOCKSClientSocketPoolTest, Simple) { | 122 TEST_F(SOCKSClientSocketPoolTest, Simple) { |
| 130 SOCKS5MockData data(SYNCHRONOUS); | 123 SOCKS5MockData data(SYNCHRONOUS); |
| 131 data.data_provider()->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 124 data.data_provider()->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 132 transport_client_socket_factory_.AddSocketDataProvider(data.data_provider()); | 125 transport_client_socket_factory_.AddSocketDataProvider(data.data_provider()); |
| 133 | 126 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 332 |
| 340 (*requests())[0]->handle()->Reset(); | 333 (*requests())[0]->handle()->Reset(); |
| 341 (*requests())[1]->handle()->Reset(); | 334 (*requests())[1]->handle()->Reset(); |
| 342 } | 335 } |
| 343 | 336 |
| 344 // It would be nice to also test the timeouts in SOCKSClientSocketPool. | 337 // It would be nice to also test the timeouts in SOCKSClientSocketPool. |
| 345 | 338 |
| 346 } // namespace | 339 } // namespace |
| 347 | 340 |
| 348 } // namespace net | 341 } // namespace net |
| OLD | NEW |