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

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

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 3 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 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 private: 121 private:
122 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportClientSocketPoolTest); 122 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportClientSocketPoolTest);
123 }; 123 };
124 124
125 TEST_F(WebSocketTransportClientSocketPoolTest, Basic) { 125 TEST_F(WebSocketTransportClientSocketPoolTest, Basic) {
126 TestCompletionCallback callback; 126 TestCompletionCallback callback;
127 ClientSocketHandle handle; 127 ClientSocketHandle handle;
128 int rv = 128 int rv =
129 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 129 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
130 callback.callback(), &pool_, BoundNetLog()); 130 callback.callback(), &pool_, NetLogWithSource());
131 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 131 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
132 EXPECT_FALSE(handle.is_initialized()); 132 EXPECT_FALSE(handle.is_initialized());
133 EXPECT_FALSE(handle.socket()); 133 EXPECT_FALSE(handle.socket());
134 134
135 EXPECT_THAT(callback.WaitForResult(), IsOk()); 135 EXPECT_THAT(callback.WaitForResult(), IsOk());
136 EXPECT_TRUE(handle.is_initialized()); 136 EXPECT_TRUE(handle.is_initialized());
137 EXPECT_TRUE(handle.socket()); 137 EXPECT_TRUE(handle.socket());
138 TestLoadTimingInfoConnectedNotReused(handle); 138 TestLoadTimingInfoConnectedNotReused(handle);
139 } 139 }
140 140
141 // Make sure that WebSocketTransportConnectJob passes on its priority to its 141 // Make sure that WebSocketTransportConnectJob passes on its priority to its
142 // HostResolver request on Init. 142 // HostResolver request on Init.
143 TEST_F(WebSocketTransportClientSocketPoolTest, SetResolvePriorityOnInit) { 143 TEST_F(WebSocketTransportClientSocketPoolTest, SetResolvePriorityOnInit) {
144 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) { 144 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) {
145 RequestPriority priority = static_cast<RequestPriority>(i); 145 RequestPriority priority = static_cast<RequestPriority>(i);
146 TestCompletionCallback callback; 146 TestCompletionCallback callback;
147 ClientSocketHandle handle; 147 ClientSocketHandle handle;
148 EXPECT_EQ(ERR_IO_PENDING, 148 EXPECT_EQ(ERR_IO_PENDING,
149 handle.Init("a", params_, priority, 149 handle.Init("a", params_, priority,
150 ClientSocketPool::RespectLimits::ENABLED, 150 ClientSocketPool::RespectLimits::ENABLED,
151 callback.callback(), &pool_, BoundNetLog())); 151 callback.callback(), &pool_, NetLogWithSource()));
152 EXPECT_EQ(priority, host_resolver_->last_request_priority()); 152 EXPECT_EQ(priority, host_resolver_->last_request_priority());
153 } 153 }
154 } 154 }
155 155
156 TEST_F(WebSocketTransportClientSocketPoolTest, InitHostResolutionFailure) { 156 TEST_F(WebSocketTransportClientSocketPoolTest, InitHostResolutionFailure) {
157 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); 157 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name");
158 TestCompletionCallback callback; 158 TestCompletionCallback callback;
159 ClientSocketHandle handle; 159 ClientSocketHandle handle;
160 HostPortPair host_port_pair("unresolvable.host.name", 80); 160 HostPortPair host_port_pair("unresolvable.host.name", 80);
161 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( 161 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams(
162 host_port_pair, false, OnHostResolutionCallback(), 162 host_port_pair, false, OnHostResolutionCallback(),
163 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); 163 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
164 EXPECT_EQ(ERR_IO_PENDING, 164 EXPECT_EQ(ERR_IO_PENDING,
165 handle.Init("a", dest, kDefaultPriority, 165 handle.Init("a", dest, kDefaultPriority,
166 ClientSocketPool::RespectLimits::ENABLED, 166 ClientSocketPool::RespectLimits::ENABLED,
167 callback.callback(), &pool_, BoundNetLog())); 167 callback.callback(), &pool_, NetLogWithSource()));
168 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); 168 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED));
169 } 169 }
170 170
171 TEST_F(WebSocketTransportClientSocketPoolTest, InitConnectionFailure) { 171 TEST_F(WebSocketTransportClientSocketPoolTest, InitConnectionFailure) {
172 client_socket_factory_.set_default_client_socket_type( 172 client_socket_factory_.set_default_client_socket_type(
173 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); 173 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET);
174 TestCompletionCallback callback; 174 TestCompletionCallback callback;
175 ClientSocketHandle handle; 175 ClientSocketHandle handle;
176 EXPECT_EQ(ERR_IO_PENDING, 176 EXPECT_EQ(ERR_IO_PENDING,
177 handle.Init("a", params_, kDefaultPriority, 177 handle.Init("a", params_, kDefaultPriority,
178 ClientSocketPool::RespectLimits::ENABLED, 178 ClientSocketPool::RespectLimits::ENABLED,
179 callback.callback(), &pool_, BoundNetLog())); 179 callback.callback(), &pool_, NetLogWithSource()));
180 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); 180 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED));
181 181
182 // Make the host resolutions complete synchronously this time. 182 // Make the host resolutions complete synchronously this time.
183 host_resolver_->set_synchronous_mode(true); 183 host_resolver_->set_synchronous_mode(true);
184 EXPECT_EQ(ERR_CONNECTION_FAILED, 184 EXPECT_EQ(ERR_CONNECTION_FAILED,
185 handle.Init("a", params_, kDefaultPriority, 185 handle.Init("a", params_, kDefaultPriority,
186 ClientSocketPool::RespectLimits::ENABLED, 186 ClientSocketPool::RespectLimits::ENABLED,
187 callback.callback(), &pool_, BoundNetLog())); 187 callback.callback(), &pool_, NetLogWithSource()));
188 } 188 }
189 189
190 TEST_F(WebSocketTransportClientSocketPoolTest, PendingRequestsFinishFifo) { 190 TEST_F(WebSocketTransportClientSocketPoolTest, PendingRequestsFinishFifo) {
191 // First request finishes asynchronously. 191 // First request finishes asynchronously.
192 EXPECT_THAT(StartRequest("a", kDefaultPriority), IsError(ERR_IO_PENDING)); 192 EXPECT_THAT(StartRequest("a", kDefaultPriority), IsError(ERR_IO_PENDING));
193 EXPECT_THAT(request(0)->WaitForResult(), IsOk()); 193 EXPECT_THAT(request(0)->WaitForResult(), IsOk());
194 194
195 // Make all subsequent host resolutions complete synchronously. 195 // Make all subsequent host resolutions complete synchronously.
196 host_resolver_->set_synchronous_mode(true); 196 host_resolver_->set_synchronous_mode(true);
197 197
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 // This test will start up a RequestSocket() and then immediately Cancel() it. 255 // This test will start up a RequestSocket() and then immediately Cancel() it.
256 // The pending host resolution will eventually complete, and destroy the 256 // The pending host resolution will eventually complete, and destroy the
257 // ClientSocketPool which will crash if the group was not cleared properly. 257 // ClientSocketPool which will crash if the group was not cleared properly.
258 TEST_F(WebSocketTransportClientSocketPoolTest, CancelRequestClearGroup) { 258 TEST_F(WebSocketTransportClientSocketPoolTest, CancelRequestClearGroup) {
259 TestCompletionCallback callback; 259 TestCompletionCallback callback;
260 ClientSocketHandle handle; 260 ClientSocketHandle handle;
261 EXPECT_EQ(ERR_IO_PENDING, 261 EXPECT_EQ(ERR_IO_PENDING,
262 handle.Init("a", params_, kDefaultPriority, 262 handle.Init("a", params_, kDefaultPriority,
263 ClientSocketPool::RespectLimits::ENABLED, 263 ClientSocketPool::RespectLimits::ENABLED,
264 callback.callback(), &pool_, BoundNetLog())); 264 callback.callback(), &pool_, NetLogWithSource()));
265 handle.Reset(); 265 handle.Reset();
266 } 266 }
267 267
268 TEST_F(WebSocketTransportClientSocketPoolTest, TwoRequestsCancelOne) { 268 TEST_F(WebSocketTransportClientSocketPoolTest, TwoRequestsCancelOne) {
269 ClientSocketHandle handle; 269 ClientSocketHandle handle;
270 TestCompletionCallback callback; 270 TestCompletionCallback callback;
271 ClientSocketHandle handle2; 271 ClientSocketHandle handle2;
272 TestCompletionCallback callback2; 272 TestCompletionCallback callback2;
273 273
274 EXPECT_EQ(ERR_IO_PENDING, 274 EXPECT_EQ(ERR_IO_PENDING,
275 handle.Init("a", params_, kDefaultPriority, 275 handle.Init("a", params_, kDefaultPriority,
276 ClientSocketPool::RespectLimits::ENABLED, 276 ClientSocketPool::RespectLimits::ENABLED,
277 callback.callback(), &pool_, BoundNetLog())); 277 callback.callback(), &pool_, NetLogWithSource()));
278 EXPECT_EQ(ERR_IO_PENDING, 278 EXPECT_EQ(ERR_IO_PENDING,
279 handle2.Init("a", params_, kDefaultPriority, 279 handle2.Init("a", params_, kDefaultPriority,
280 ClientSocketPool::RespectLimits::ENABLED, 280 ClientSocketPool::RespectLimits::ENABLED,
281 callback2.callback(), &pool_, BoundNetLog())); 281 callback2.callback(), &pool_, NetLogWithSource()));
282 282
283 handle.Reset(); 283 handle.Reset();
284 284
285 EXPECT_THAT(callback2.WaitForResult(), IsOk()); 285 EXPECT_THAT(callback2.WaitForResult(), IsOk());
286 handle2.Reset(); 286 handle2.Reset();
287 } 287 }
288 288
289 TEST_F(WebSocketTransportClientSocketPoolTest, ConnectCancelConnect) { 289 TEST_F(WebSocketTransportClientSocketPoolTest, ConnectCancelConnect) {
290 client_socket_factory_.set_default_client_socket_type( 290 client_socket_factory_.set_default_client_socket_type(
291 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); 291 MockTransportClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET);
292 ClientSocketHandle handle; 292 ClientSocketHandle handle;
293 TestCompletionCallback callback; 293 TestCompletionCallback callback;
294 EXPECT_EQ(ERR_IO_PENDING, 294 EXPECT_EQ(ERR_IO_PENDING,
295 handle.Init("a", params_, kDefaultPriority, 295 handle.Init("a", params_, kDefaultPriority,
296 ClientSocketPool::RespectLimits::ENABLED, 296 ClientSocketPool::RespectLimits::ENABLED,
297 callback.callback(), &pool_, BoundNetLog())); 297 callback.callback(), &pool_, NetLogWithSource()));
298 298
299 handle.Reset(); 299 handle.Reset();
300 300
301 TestCompletionCallback callback2; 301 TestCompletionCallback callback2;
302 EXPECT_EQ(ERR_IO_PENDING, 302 EXPECT_EQ(ERR_IO_PENDING,
303 handle.Init("a", params_, kDefaultPriority, 303 handle.Init("a", params_, kDefaultPriority,
304 ClientSocketPool::RespectLimits::ENABLED, 304 ClientSocketPool::RespectLimits::ENABLED,
305 callback2.callback(), &pool_, BoundNetLog())); 305 callback2.callback(), &pool_, NetLogWithSource()));
306 306
307 host_resolver_->set_synchronous_mode(true); 307 host_resolver_->set_synchronous_mode(true);
308 // At this point, handle has two ConnectingSockets out for it. Due to the 308 // At this point, handle has two ConnectingSockets out for it. Due to the
309 // setting the mock resolver into synchronous mode, the host resolution for 309 // setting the mock resolver into synchronous mode, the host resolution for
310 // both will return in the same loop of the MessageLoop. The client socket 310 // both will return in the same loop of the MessageLoop. The client socket
311 // is a pending socket, so the Connect() will asynchronously complete on the 311 // is a pending socket, so the Connect() will asynchronously complete on the
312 // next loop of the MessageLoop. That means that the first 312 // next loop of the MessageLoop. That means that the first
313 // ConnectingSocket will enter OnIOComplete, and then the second one will. 313 // ConnectingSocket will enter OnIOComplete, and then the second one will.
314 // If the first one is not cancelled, it will advance the load state, and 314 // If the first one is not cancelled, it will advance the load state, and
315 // then the second one will crash. 315 // then the second one will crash.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 // Don't allow reuse of the socket. Disconnect it and then release it. 370 // Don't allow reuse of the socket. Disconnect it and then release it.
371 handle->socket()->Disconnect(); 371 handle->socket()->Disconnect();
372 handle->Reset(); 372 handle->Reset();
373 373
374 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( 374 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams(
375 HostPortPair("www.google.com", 80), false, OnHostResolutionCallback(), 375 HostPortPair("www.google.com", 80), false, OnHostResolutionCallback(),
376 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); 376 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
377 int rv = 377 int rv =
378 handle->Init("a", dest, LOWEST, ClientSocketPool::RespectLimits::ENABLED, 378 handle->Init("a", dest, LOWEST, ClientSocketPool::RespectLimits::ENABLED,
379 nested_callback, pool, BoundNetLog()); 379 nested_callback, pool, NetLogWithSource());
380 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 380 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
381 if (ERR_IO_PENDING != rv) 381 if (ERR_IO_PENDING != rv)
382 nested_callback.Run(rv); 382 nested_callback.Run(rv);
383 } 383 }
384 384
385 // Tests the case where a second socket is requested in a completion callback, 385 // Tests the case where a second socket is requested in a completion callback,
386 // and the second socket connects asynchronously. Reuses the same 386 // and the second socket connects asynchronously. Reuses the same
387 // ClientSocketHandle for the second socket, after disconnecting the first. 387 // ClientSocketHandle for the second socket, after disconnecting the first.
388 TEST_F(WebSocketTransportClientSocketPoolTest, RequestTwice) { 388 TEST_F(WebSocketTransportClientSocketPoolTest, RequestTwice) {
389 ClientSocketHandle handle; 389 ClientSocketHandle handle;
390 scoped_refptr<TransportSocketParams> dest( 390 scoped_refptr<TransportSocketParams> dest(
391 new TransportSocketParams( 391 new TransportSocketParams(
392 HostPortPair("www.google.com", 80), 392 HostPortPair("www.google.com", 80),
393 false, 393 false,
394 OnHostResolutionCallback(), 394 OnHostResolutionCallback(),
395 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); 395 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
396 TestCompletionCallback second_result_callback; 396 TestCompletionCallback second_result_callback;
397 int rv = 397 int rv =
398 handle.Init("a", dest, LOWEST, ClientSocketPool::RespectLimits::ENABLED, 398 handle.Init("a", dest, LOWEST, ClientSocketPool::RespectLimits::ENABLED,
399 base::Bind(&RequestSocketOnComplete, &handle, &pool_, 399 base::Bind(&RequestSocketOnComplete, &handle, &pool_,
400 second_result_callback.callback()), 400 second_result_callback.callback()),
401 &pool_, BoundNetLog()); 401 &pool_, NetLogWithSource());
402 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); 402 ASSERT_THAT(rv, IsError(ERR_IO_PENDING));
403 EXPECT_THAT(second_result_callback.WaitForResult(), IsOk()); 403 EXPECT_THAT(second_result_callback.WaitForResult(), IsOk());
404 404
405 handle.Reset(); 405 handle.Reset();
406 } 406 }
407 407
408 // Make sure that pending requests get serviced after active requests get 408 // Make sure that pending requests get serviced after active requests get
409 // cancelled. 409 // cancelled.
410 TEST_F(WebSocketTransportClientSocketPoolTest, 410 TEST_F(WebSocketTransportClientSocketPoolTest,
411 CancelActiveRequestWithPendingRequests) { 411 CancelActiveRequestWithPendingRequests) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 RunUntilIdle(); 464 RunUntilIdle();
465 EXPECT_TRUE(request(1)->handle()->is_initialized()); 465 EXPECT_TRUE(request(1)->handle()->is_initialized());
466 } 466 }
467 467
468 // The lock on the endpoint is released when a ClientSocketHandle is deleted. 468 // The lock on the endpoint is released when a ClientSocketHandle is deleted.
469 TEST_F(WebSocketTransportClientSocketPoolTest, LockReleasedOnHandleDelete) { 469 TEST_F(WebSocketTransportClientSocketPoolTest, LockReleasedOnHandleDelete) {
470 TestCompletionCallback callback; 470 TestCompletionCallback callback;
471 std::unique_ptr<ClientSocketHandle> handle(new ClientSocketHandle); 471 std::unique_ptr<ClientSocketHandle> handle(new ClientSocketHandle);
472 int rv = 472 int rv =
473 handle->Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 473 handle->Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
474 callback.callback(), &pool_, BoundNetLog()); 474 callback.callback(), &pool_, NetLogWithSource());
475 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 475 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
476 476
477 EXPECT_THAT(StartRequest("a", kDefaultPriority), IsError(ERR_IO_PENDING)); 477 EXPECT_THAT(StartRequest("a", kDefaultPriority), IsError(ERR_IO_PENDING));
478 EXPECT_THAT(callback.WaitForResult(), IsOk()); 478 EXPECT_THAT(callback.WaitForResult(), IsOk());
479 EXPECT_FALSE(request(0)->handle()->is_initialized()); 479 EXPECT_FALSE(request(0)->handle()->is_initialized());
480 handle.reset(); 480 handle.reset();
481 RunUntilIdle(); 481 RunUntilIdle();
482 EXPECT_TRUE(request(0)->handle()->is_initialized()); 482 EXPECT_TRUE(request(0)->handle()->is_initialized());
483 } 483 }
484 484
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 client_socket_factory_.set_client_socket_types(case_types, 2); 532 client_socket_factory_.set_client_socket_types(case_types, 2);
533 533
534 // Resolve an AddressList with an IPv6 address first and then an IPv4 address. 534 // Resolve an AddressList with an IPv6 address first and then an IPv4 address.
535 host_resolver_->rules()->AddIPLiteralRule( 535 host_resolver_->rules()->AddIPLiteralRule(
536 "*", "2:abcd::3:4:ff,2.2.2.2", std::string()); 536 "*", "2:abcd::3:4:ff,2.2.2.2", std::string());
537 537
538 TestCompletionCallback callback; 538 TestCompletionCallback callback;
539 ClientSocketHandle handle; 539 ClientSocketHandle handle;
540 int rv = 540 int rv =
541 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 541 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
542 callback.callback(), &pool, BoundNetLog()); 542 callback.callback(), &pool, NetLogWithSource());
543 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 543 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
544 EXPECT_FALSE(handle.is_initialized()); 544 EXPECT_FALSE(handle.is_initialized());
545 EXPECT_FALSE(handle.socket()); 545 EXPECT_FALSE(handle.socket());
546 546
547 EXPECT_THAT(callback.WaitForResult(), IsOk()); 547 EXPECT_THAT(callback.WaitForResult(), IsOk());
548 EXPECT_TRUE(handle.is_initialized()); 548 EXPECT_TRUE(handle.is_initialized());
549 EXPECT_TRUE(handle.socket()); 549 EXPECT_TRUE(handle.socket());
550 IPEndPoint endpoint; 550 IPEndPoint endpoint;
551 handle.socket()->GetLocalAddress(&endpoint); 551 handle.socket()->GetLocalAddress(&endpoint);
552 EXPECT_TRUE(endpoint.address().IsIPv4()); 552 EXPECT_TRUE(endpoint.address().IsIPv4());
(...skipping 22 matching lines...) Expand all
575 TransportConnectJob::kIPv6FallbackTimerInMs + 50)); 575 TransportConnectJob::kIPv6FallbackTimerInMs + 50));
576 576
577 // Resolve an AddressList with an IPv6 address first and then an IPv4 address. 577 // Resolve an AddressList with an IPv6 address first and then an IPv4 address.
578 host_resolver_->rules()->AddIPLiteralRule( 578 host_resolver_->rules()->AddIPLiteralRule(
579 "*", "2:abcd::3:4:ff,2.2.2.2", std::string()); 579 "*", "2:abcd::3:4:ff,2.2.2.2", std::string());
580 580
581 TestCompletionCallback callback; 581 TestCompletionCallback callback;
582 ClientSocketHandle handle; 582 ClientSocketHandle handle;
583 int rv = 583 int rv =
584 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 584 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
585 callback.callback(), &pool, BoundNetLog()); 585 callback.callback(), &pool, NetLogWithSource());
586 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 586 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
587 EXPECT_FALSE(handle.is_initialized()); 587 EXPECT_FALSE(handle.is_initialized());
588 EXPECT_FALSE(handle.socket()); 588 EXPECT_FALSE(handle.socket());
589 589
590 EXPECT_THAT(callback.WaitForResult(), IsOk()); 590 EXPECT_THAT(callback.WaitForResult(), IsOk());
591 EXPECT_TRUE(handle.is_initialized()); 591 EXPECT_TRUE(handle.is_initialized());
592 EXPECT_TRUE(handle.socket()); 592 EXPECT_TRUE(handle.socket());
593 IPEndPoint endpoint; 593 IPEndPoint endpoint;
594 handle.socket()->GetLocalAddress(&endpoint); 594 handle.socket()->GetLocalAddress(&endpoint);
595 EXPECT_TRUE(endpoint.address().IsIPv6()); 595 EXPECT_TRUE(endpoint.address().IsIPv6());
(...skipping 12 matching lines...) Expand all
608 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); 608 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET);
609 609
610 // Resolve an AddressList with only IPv6 addresses. 610 // Resolve an AddressList with only IPv6 addresses.
611 host_resolver_->rules()->AddIPLiteralRule( 611 host_resolver_->rules()->AddIPLiteralRule(
612 "*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string()); 612 "*", "2:abcd::3:4:ff,3:abcd::3:4:ff", std::string());
613 613
614 TestCompletionCallback callback; 614 TestCompletionCallback callback;
615 ClientSocketHandle handle; 615 ClientSocketHandle handle;
616 int rv = 616 int rv =
617 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 617 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
618 callback.callback(), &pool, BoundNetLog()); 618 callback.callback(), &pool, NetLogWithSource());
619 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 619 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
620 EXPECT_FALSE(handle.is_initialized()); 620 EXPECT_FALSE(handle.is_initialized());
621 EXPECT_FALSE(handle.socket()); 621 EXPECT_FALSE(handle.socket());
622 622
623 EXPECT_THAT(callback.WaitForResult(), IsOk()); 623 EXPECT_THAT(callback.WaitForResult(), IsOk());
624 EXPECT_TRUE(handle.is_initialized()); 624 EXPECT_TRUE(handle.is_initialized());
625 EXPECT_TRUE(handle.socket()); 625 EXPECT_TRUE(handle.socket());
626 IPEndPoint endpoint; 626 IPEndPoint endpoint;
627 handle.socket()->GetLocalAddress(&endpoint); 627 handle.socket()->GetLocalAddress(&endpoint);
628 EXPECT_TRUE(endpoint.address().IsIPv6()); 628 EXPECT_TRUE(endpoint.address().IsIPv6());
(...skipping 10 matching lines...) Expand all
639 client_socket_factory_.set_default_client_socket_type( 639 client_socket_factory_.set_default_client_socket_type(
640 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET); 640 MockTransportClientSocketFactory::MOCK_DELAYED_CLIENT_SOCKET);
641 641
642 // Resolve an AddressList with only IPv4 addresses. 642 // Resolve an AddressList with only IPv4 addresses.
643 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string()); 643 host_resolver_->rules()->AddIPLiteralRule("*", "1.1.1.1", std::string());
644 644
645 TestCompletionCallback callback; 645 TestCompletionCallback callback;
646 ClientSocketHandle handle; 646 ClientSocketHandle handle;
647 int rv = 647 int rv =
648 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 648 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
649 callback.callback(), &pool, BoundNetLog()); 649 callback.callback(), &pool, NetLogWithSource());
650 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 650 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
651 EXPECT_FALSE(handle.is_initialized()); 651 EXPECT_FALSE(handle.is_initialized());
652 EXPECT_FALSE(handle.socket()); 652 EXPECT_FALSE(handle.socket());
653 653
654 EXPECT_THAT(callback.WaitForResult(), IsOk()); 654 EXPECT_THAT(callback.WaitForResult(), IsOk());
655 EXPECT_TRUE(handle.is_initialized()); 655 EXPECT_TRUE(handle.is_initialized());
656 EXPECT_TRUE(handle.socket()); 656 EXPECT_TRUE(handle.socket());
657 IPEndPoint endpoint; 657 IPEndPoint endpoint;
658 handle.socket()->GetLocalAddress(&endpoint); 658 handle.socket()->GetLocalAddress(&endpoint);
659 EXPECT_TRUE(endpoint.address().IsIPv4()); 659 EXPECT_TRUE(endpoint.address().IsIPv4());
(...skipping 21 matching lines...) Expand all
681 arraysize(case_types)); 681 arraysize(case_types));
682 682
683 // Resolve an AddressList with two IPv6 addresses and then an IPv4 address. 683 // Resolve an AddressList with two IPv6 addresses and then an IPv4 address.
684 host_resolver_->rules()->AddIPLiteralRule( 684 host_resolver_->rules()->AddIPLiteralRule(
685 "*", "2:abcd::3:4:ff,2:abcd::3:5:ff,2.2.2.2", std::string()); 685 "*", "2:abcd::3:4:ff,2:abcd::3:5:ff,2.2.2.2", std::string());
686 host_resolver_->set_synchronous_mode(true); 686 host_resolver_->set_synchronous_mode(true);
687 TestCompletionCallback callback; 687 TestCompletionCallback callback;
688 ClientSocketHandle handle; 688 ClientSocketHandle handle;
689 int rv = 689 int rv =
690 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 690 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
691 callback.callback(), &pool, BoundNetLog()); 691 callback.callback(), &pool, NetLogWithSource());
692 EXPECT_THAT(rv, IsOk()); 692 EXPECT_THAT(rv, IsOk());
693 ASSERT_TRUE(handle.socket()); 693 ASSERT_TRUE(handle.socket());
694 694
695 IPEndPoint endpoint; 695 IPEndPoint endpoint;
696 handle.socket()->GetPeerAddress(&endpoint); 696 handle.socket()->GetPeerAddress(&endpoint);
697 EXPECT_EQ("2.2.2.2", endpoint.ToStringWithoutPort()); 697 EXPECT_EQ("2.2.2.2", endpoint.ToStringWithoutPort());
698 } 698 }
699 699
700 // If all IPv6 addresses fail before the IPv4 fallback timeout, then the IPv4 700 // If all IPv6 addresses fail before the IPv4 fallback timeout, then the IPv4
701 // connections proceed immediately. 701 // connections proceed immediately.
(...skipping 16 matching lines...) Expand all
718 arraysize(case_types)); 718 arraysize(case_types));
719 719
720 // Resolve an AddressList with two IPv6 addresses and then an IPv4 address. 720 // Resolve an AddressList with two IPv6 addresses and then an IPv4 address.
721 host_resolver_->rules()->AddIPLiteralRule( 721 host_resolver_->rules()->AddIPLiteralRule(
722 "*", "2:abcd::3:4:ff,2:abcd::3:5:ff,2.2.2.2", std::string()); 722 "*", "2:abcd::3:4:ff,2:abcd::3:5:ff,2.2.2.2", std::string());
723 723
724 TestCompletionCallback callback; 724 TestCompletionCallback callback;
725 ClientSocketHandle handle; 725 ClientSocketHandle handle;
726 int rv = 726 int rv =
727 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 727 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
728 callback.callback(), &pool, BoundNetLog()); 728 callback.callback(), &pool, NetLogWithSource());
729 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 729 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
730 EXPECT_FALSE(handle.socket()); 730 EXPECT_FALSE(handle.socket());
731 731
732 base::TimeTicks start(base::TimeTicks::Now()); 732 base::TimeTicks start(base::TimeTicks::Now());
733 EXPECT_THAT(callback.WaitForResult(), IsOk()); 733 EXPECT_THAT(callback.WaitForResult(), IsOk());
734 EXPECT_LT(base::TimeTicks::Now() - start, 734 EXPECT_LT(base::TimeTicks::Now() - start,
735 base::TimeDelta::FromMilliseconds( 735 base::TimeDelta::FromMilliseconds(
736 TransportConnectJob::kIPv6FallbackTimerInMs)); 736 TransportConnectJob::kIPv6FallbackTimerInMs));
737 ASSERT_TRUE(handle.socket()); 737 ASSERT_TRUE(handle.socket());
738 738
(...skipping 16 matching lines...) Expand all
755 MockTransportClientSocketFactory::MOCK_TRIGGERABLE_CLIENT_SOCKET); 755 MockTransportClientSocketFactory::MOCK_TRIGGERABLE_CLIENT_SOCKET);
756 756
757 // Resolve an AddressList with an IPv6 addresses and an IPv4 address. 757 // Resolve an AddressList with an IPv6 addresses and an IPv4 address.
758 host_resolver_->rules()->AddIPLiteralRule( 758 host_resolver_->rules()->AddIPLiteralRule(
759 "*", "2:abcd::3:4:ff,2.2.2.2", std::string()); 759 "*", "2:abcd::3:4:ff,2.2.2.2", std::string());
760 760
761 TestCompletionCallback callback; 761 TestCompletionCallback callback;
762 ClientSocketHandle handle; 762 ClientSocketHandle handle;
763 int rv = 763 int rv =
764 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 764 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
765 callback.callback(), &pool, BoundNetLog()); 765 callback.callback(), &pool, NetLogWithSource());
766 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 766 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
767 ASSERT_FALSE(handle.socket()); 767 ASSERT_FALSE(handle.socket());
768 768
769 base::Closure ipv6_connect_trigger = 769 base::Closure ipv6_connect_trigger =
770 client_socket_factory_.WaitForTriggerableSocketCreation(); 770 client_socket_factory_.WaitForTriggerableSocketCreation();
771 base::Closure ipv4_connect_trigger = 771 base::Closure ipv4_connect_trigger =
772 client_socket_factory_.WaitForTriggerableSocketCreation(); 772 client_socket_factory_.WaitForTriggerableSocketCreation();
773 773
774 ipv4_connect_trigger.Run(); 774 ipv4_connect_trigger.Run();
775 ipv6_connect_trigger.Run(); 775 ipv6_connect_trigger.Run();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 // After 200ms: Connect to 2:abcd::3:4:ff times out 808 // After 200ms: Connect to 2:abcd::3:4:ff times out
809 // After 300ms: Connect to 3:abcd::3:4:ff times out, IPv4 fallback starts 809 // After 300ms: Connect to 3:abcd::3:4:ff times out, IPv4 fallback starts
810 // After 400ms: Connect to 4:abcd::3:4:ff and 1.1.1.1 time out 810 // After 400ms: Connect to 4:abcd::3:4:ff and 1.1.1.1 time out
811 // After 500ms: Connect to 2.2.2.2 times out 811 // After 500ms: Connect to 2.2.2.2 times out
812 812
813 TestCompletionCallback callback; 813 TestCompletionCallback callback;
814 ClientSocketHandle handle; 814 ClientSocketHandle handle;
815 base::TimeTicks start(base::TimeTicks::Now()); 815 base::TimeTicks start(base::TimeTicks::Now());
816 int rv = 816 int rv =
817 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 817 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
818 callback.callback(), &pool, BoundNetLog()); 818 callback.callback(), &pool, NetLogWithSource());
819 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 819 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
820 820
821 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED)); 821 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_FAILED));
822 822
823 EXPECT_GE(base::TimeTicks::Now() - start, delay * 5); 823 EXPECT_GE(base::TimeTicks::Now() - start, delay * 5);
824 } 824 }
825 825
826 // Global timeout for all connects applies. This test is disabled by default 826 // Global timeout for all connects applies. This test is disabled by default
827 // because it takes 4 minutes. Run with --gtest_also_run_disabled_tests if you 827 // because it takes 4 minutes. Run with --gtest_also_run_disabled_tests if you
828 // want to run it. 828 // want to run it.
(...skipping 17 matching lines...) Expand all
846 "5:abcd::3:4:ff,6:abcd::3:4:ff," 846 "5:abcd::3:4:ff,6:abcd::3:4:ff,"
847 "1.1.1.1,2.2.2.2,3.3.3.3," 847 "1.1.1.1,2.2.2.2,3.3.3.3,"
848 "4.4.4.4,5.5.5.5,6.6.6.6", 848 "4.4.4.4,5.5.5.5,6.6.6.6",
849 std::string()); 849 std::string());
850 850
851 TestCompletionCallback callback; 851 TestCompletionCallback callback;
852 ClientSocketHandle handle; 852 ClientSocketHandle handle;
853 853
854 int rv = 854 int rv =
855 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED, 855 handle.Init("a", params_, LOW, ClientSocketPool::RespectLimits::ENABLED,
856 callback.callback(), &pool, BoundNetLog()); 856 callback.callback(), &pool, NetLogWithSource());
857 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 857 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
858 858
859 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_TIMED_OUT)); 859 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_TIMED_OUT));
860 } 860 }
861 861
862 TEST_F(WebSocketTransportClientSocketPoolTest, MaxSocketsEnforced) { 862 TEST_F(WebSocketTransportClientSocketPoolTest, MaxSocketsEnforced) {
863 host_resolver_->set_synchronous_mode(true); 863 host_resolver_->set_synchronous_mode(true);
864 for (int i = 0; i < kMaxSockets; ++i) { 864 for (int i = 0; i < kMaxSockets; ++i) {
865 ASSERT_THAT(StartRequest("a", kDefaultPriority), IsOk()); 865 ASSERT_THAT(StartRequest("a", kDefaultPriority), IsOk());
866 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle()); 866 WebSocketTransportClientSocketPool::UnlockEndpoint(request(i)->handle());
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 EXPECT_THAT(request(1)->WaitForResult(), IsOk()); 1099 EXPECT_THAT(request(1)->WaitForResult(), IsOk());
1100 // Third socket should still be waiting for endpoint. 1100 // Third socket should still be waiting for endpoint.
1101 ASSERT_FALSE(request(2)->handle()->is_initialized()); 1101 ASSERT_FALSE(request(2)->handle()->is_initialized());
1102 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET, 1102 EXPECT_EQ(LOAD_STATE_WAITING_FOR_AVAILABLE_SOCKET,
1103 request(2)->handle()->GetLoadState()); 1103 request(2)->handle()->GetLoadState());
1104 } 1104 }
1105 1105
1106 } // namespace 1106 } // namespace
1107 1107
1108 } // namespace net 1108 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698