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/websocket_transport_client_socket_pool.h" | 5 #include "net/socket/websocket_transport_client_socket_pool.h" |
6 | 6 |
7 #include <queue> | 7 #include <queue> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 FROM_HERE, quit_closure, period); | 47 FROM_HERE, quit_closure, period); |
48 run_loop.Run(); | 48 run_loop.Run(); |
49 } | 49 } |
50 | 50 |
51 class WebSocketTransportClientSocketPoolTest : public testing::Test { | 51 class WebSocketTransportClientSocketPoolTest : public testing::Test { |
52 protected: | 52 protected: |
53 WebSocketTransportClientSocketPoolTest() | 53 WebSocketTransportClientSocketPoolTest() |
54 : params_(new TransportSocketParams(HostPortPair("www.google.com", 80), | 54 : params_(new TransportSocketParams(HostPortPair("www.google.com", 80), |
55 false, | 55 false, |
56 false, | 56 false, |
57 OnHostResolutionCallback())), | 57 OnHostResolutionCallback(), |
| 58 AUTO_CONNECT_USE_DEFAULT)), |
58 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), | 59 histograms_(new ClientSocketPoolHistograms("TCPUnitTest")), |
59 host_resolver_(new MockHostResolver), | 60 host_resolver_(new MockHostResolver), |
60 client_socket_factory_(&net_log_), | 61 client_socket_factory_(&net_log_), |
61 pool_(kMaxSockets, | 62 pool_(kMaxSockets, |
62 kMaxSocketsPerGroup, | 63 kMaxSocketsPerGroup, |
63 histograms_.get(), | 64 histograms_.get(), |
64 host_resolver_.get(), | 65 host_resolver_.get(), |
65 &client_socket_factory_, | 66 &client_socket_factory_, |
66 NULL) {} | 67 NULL) {} |
67 | 68 |
68 virtual ~WebSocketTransportClientSocketPoolTest() { | 69 virtual ~WebSocketTransportClientSocketPoolTest() { |
69 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); | 70 ReleaseAllConnections(ClientSocketPoolTest::NO_KEEP_ALIVE); |
70 EXPECT_TRUE(WebSocketEndpointLockManager::GetInstance()->IsEmpty()); | 71 EXPECT_TRUE(WebSocketEndpointLockManager::GetInstance()->IsEmpty()); |
71 } | 72 } |
72 | 73 |
73 int StartRequest(const std::string& group_name, RequestPriority priority) { | 74 int StartRequest(const std::string& group_name, RequestPriority priority) { |
74 scoped_refptr<TransportSocketParams> params( | 75 scoped_refptr<TransportSocketParams> params( |
75 new TransportSocketParams(HostPortPair("www.google.com", 80), | 76 new TransportSocketParams(HostPortPair("www.google.com", 80), |
76 false, | 77 false, |
77 false, | 78 false, |
78 OnHostResolutionCallback())); | 79 OnHostResolutionCallback(), |
| 80 AUTO_CONNECT_USE_DEFAULT)); |
79 return test_base_.StartRequestUsingPool( | 81 return test_base_.StartRequestUsingPool( |
80 &pool_, group_name, priority, params); | 82 &pool_, group_name, priority, params); |
81 } | 83 } |
82 | 84 |
83 int GetOrderOfRequest(size_t index) { | 85 int GetOrderOfRequest(size_t index) { |
84 return test_base_.GetOrderOfRequest(index); | 86 return test_base_.GetOrderOfRequest(index); |
85 } | 87 } |
86 | 88 |
87 bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) { | 89 bool ReleaseOneConnection(ClientSocketPoolTest::KeepAlive keep_alive) { |
88 return test_base_.ReleaseOneConnection(keep_alive); | 90 return test_base_.ReleaseOneConnection(keep_alive); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 EXPECT_EQ(priority, host_resolver_->last_request_priority()); | 143 EXPECT_EQ(priority, host_resolver_->last_request_priority()); |
142 } | 144 } |
143 } | 145 } |
144 | 146 |
145 TEST_F(WebSocketTransportClientSocketPoolTest, InitHostResolutionFailure) { | 147 TEST_F(WebSocketTransportClientSocketPoolTest, InitHostResolutionFailure) { |
146 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); | 148 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); |
147 TestCompletionCallback callback; | 149 TestCompletionCallback callback; |
148 ClientSocketHandle handle; | 150 ClientSocketHandle handle; |
149 HostPortPair host_port_pair("unresolvable.host.name", 80); | 151 HostPortPair host_port_pair("unresolvable.host.name", 80); |
150 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( | 152 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( |
151 host_port_pair, false, false, OnHostResolutionCallback())); | 153 host_port_pair, false, false, OnHostResolutionCallback(), |
| 154 AUTO_CONNECT_USE_DEFAULT)); |
152 EXPECT_EQ(ERR_IO_PENDING, | 155 EXPECT_EQ(ERR_IO_PENDING, |
153 handle.Init("a", | 156 handle.Init("a", |
154 dest, | 157 dest, |
155 kDefaultPriority, | 158 kDefaultPriority, |
156 callback.callback(), | 159 callback.callback(), |
157 &pool_, | 160 &pool_, |
158 BoundNetLog())); | 161 BoundNetLog())); |
159 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult()); | 162 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult()); |
160 } | 163 } |
161 | 164 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 { | 397 { |
395 base::MessageLoop::ScopedNestableTaskAllower allow( | 398 base::MessageLoop::ScopedNestableTaskAllower allow( |
396 base::MessageLoop::current()); | 399 base::MessageLoop::current()); |
397 base::MessageLoop::current()->RunUntilIdle(); | 400 base::MessageLoop::current()->RunUntilIdle(); |
398 } | 401 } |
399 within_callback_ = true; | 402 within_callback_ = true; |
400 scoped_refptr<TransportSocketParams> dest( | 403 scoped_refptr<TransportSocketParams> dest( |
401 new TransportSocketParams(HostPortPair("www.google.com", 80), | 404 new TransportSocketParams(HostPortPair("www.google.com", 80), |
402 false, | 405 false, |
403 false, | 406 false, |
404 OnHostResolutionCallback())); | 407 OnHostResolutionCallback(), |
| 408 AUTO_CONNECT_USE_DEFAULT)); |
405 int rv = | 409 int rv = |
406 handle_->Init("a", dest, LOWEST, callback(), pool_, BoundNetLog()); | 410 handle_->Init("a", dest, LOWEST, callback(), pool_, BoundNetLog()); |
407 EXPECT_EQ(OK, rv); | 411 EXPECT_EQ(OK, rv); |
408 } | 412 } |
409 } | 413 } |
410 | 414 |
411 ClientSocketHandle* const handle_; | 415 ClientSocketHandle* const handle_; |
412 WebSocketTransportClientSocketPool* const pool_; | 416 WebSocketTransportClientSocketPool* const pool_; |
413 bool within_callback_; | 417 bool within_callback_; |
414 CompletionCallback callback_; | 418 CompletionCallback callback_; |
415 | 419 |
416 DISALLOW_COPY_AND_ASSIGN(RequestSocketCallback); | 420 DISALLOW_COPY_AND_ASSIGN(RequestSocketCallback); |
417 }; | 421 }; |
418 | 422 |
419 TEST_F(WebSocketTransportClientSocketPoolTest, RequestTwice) { | 423 TEST_F(WebSocketTransportClientSocketPoolTest, RequestTwice) { |
420 ClientSocketHandle handle; | 424 ClientSocketHandle handle; |
421 RequestSocketCallback callback(&handle, &pool_); | 425 RequestSocketCallback callback(&handle, &pool_); |
422 scoped_refptr<TransportSocketParams> dest( | 426 scoped_refptr<TransportSocketParams> dest( |
423 new TransportSocketParams(HostPortPair("www.google.com", 80), | 427 new TransportSocketParams(HostPortPair("www.google.com", 80), |
424 false, | 428 false, |
425 false, | 429 false, |
426 OnHostResolutionCallback())); | 430 OnHostResolutionCallback(), |
| 431 AUTO_CONNECT_USE_DEFAULT)); |
427 int rv = handle.Init( | 432 int rv = handle.Init( |
428 "a", dest, LOWEST, callback.callback(), &pool_, BoundNetLog()); | 433 "a", dest, LOWEST, callback.callback(), &pool_, BoundNetLog()); |
429 ASSERT_EQ(ERR_IO_PENDING, rv); | 434 ASSERT_EQ(ERR_IO_PENDING, rv); |
430 | 435 |
431 // The callback is going to request "www.google.com". We want it to complete | 436 // The callback is going to request "www.google.com". We want it to complete |
432 // synchronously this time. | 437 // synchronously this time. |
433 host_resolver_->set_synchronous_mode(true); | 438 host_resolver_->set_synchronous_mode(true); |
434 | 439 |
435 EXPECT_EQ(OK, callback.WaitForResult()); | 440 EXPECT_EQ(OK, callback.WaitForResult()); |
436 | 441 |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 EXPECT_EQ(OK, request(1)->WaitForResult()); | 1130 EXPECT_EQ(OK, request(1)->WaitForResult()); |
1126 // Third socket should still be waiting for endpoint. | 1131 // Third socket should still be waiting for endpoint. |
1127 ASSERT_FALSE(request(2)->handle()->is_initialized()); | 1132 ASSERT_FALSE(request(2)->handle()->is_initialized()); |
1128 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, | 1133 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, |
1129 request(2)->handle()->GetLoadState()); | 1134 request(2)->handle()->GetLoadState()); |
1130 } | 1135 } |
1131 | 1136 |
1132 } // namespace | 1137 } // namespace |
1133 | 1138 |
1134 } // namespace net | 1139 } // namespace net |
OLD | NEW |