| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/spdy/spdy_session_pool.h" | 5 #include "net/spdy/spdy_session_pool.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 384 |
| 385 // Flush the SpdySession::OnReadComplete() task. | 385 // Flush the SpdySession::OnReadComplete() task. |
| 386 base::RunLoop().RunUntilIdle(); | 386 base::RunLoop().RunUntilIdle(); |
| 387 | 387 |
| 388 // The third host has no overlap with the first, so it can't pool IPs. | 388 // The third host has no overlap with the first, so it can't pool IPs. |
| 389 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 389 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 390 | 390 |
| 391 // The second host overlaps with the first, and should IP pool. | 391 // The second host overlaps with the first, and should IP pool. |
| 392 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 392 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 393 | 393 |
| 394 // However, if IP pooling is disabled, FindAvailableSession() should not find |
| 395 // |session| for the second host. |
| 396 base::WeakPtr<SpdySession> session1 = |
| 397 spdy_session_pool_->FindAvailableSession( |
| 398 test_hosts[1].key, GURL(test_hosts[1].url), |
| 399 /* enable_ip_based_pooling = */ false, NetLogWithSource()); |
| 400 EXPECT_FALSE(session1); |
| 401 |
| 394 // Verify that the second host, through a proxy, won't share the IP. | 402 // Verify that the second host, through a proxy, won't share the IP. |
| 395 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), | 403 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), |
| 396 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), | 404 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), |
| 397 PRIVACY_MODE_DISABLED); | 405 PRIVACY_MODE_DISABLED); |
| 398 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); | 406 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); |
| 399 | 407 |
| 400 // Overlap between 2 and 3 does is not transitive to 1. | 408 // Overlap between 2 and 3 does is not transitive to 1. |
| 401 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 409 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 402 | 410 |
| 403 // Create a new session to host 2. | 411 // Create a new session to host 2. |
| 404 StaticSocketDataProvider data2(reads, arraysize(reads), NULL, 0); | 412 StaticSocketDataProvider data2(reads, arraysize(reads), NULL, 0); |
| 405 data2.set_connect_data(connect_data); | 413 data2.set_connect_data(connect_data); |
| 406 session_deps_.socket_factory->AddSocketDataProvider(&data2); | 414 session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 407 | 415 |
| 408 AddSSLSocketData(); | 416 AddSSLSocketData(); |
| 409 | 417 |
| 410 base::WeakPtr<SpdySession> session2 = CreateSecureSpdySession( | 418 base::WeakPtr<SpdySession> session2 = CreateSecureSpdySession( |
| 411 http_session_.get(), test_hosts[2].key, NetLogWithSource()); | 419 http_session_.get(), test_hosts[2].key, NetLogWithSource()); |
| 412 | 420 |
| 413 // Verify that we have sessions for everything. | 421 // Verify that we have sessions for everything. |
| 414 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); | 422 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); |
| 415 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 423 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 416 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 424 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 417 | 425 |
| 418 // Grab the session to host 1 and verify that it is the same session | 426 // Grab the session to host 1 and verify that it is the same session |
| 419 // we got with host 0, and that is a different from host 2's session. | 427 // we got with host 0, and that is a different from host 2's session. |
| 420 base::WeakPtr<SpdySession> session1 = | 428 session1 = spdy_session_pool_->FindAvailableSession( |
| 421 spdy_session_pool_->FindAvailableSession( | 429 test_hosts[1].key, GURL(test_hosts[1].url), |
| 422 test_hosts[1].key, GURL(test_hosts[1].url), | 430 /* enable_ip_based_pooling = */ true, NetLogWithSource()); |
| 423 /* enable_ip_based_pooling = */ true, NetLogWithSource()); | |
| 424 EXPECT_EQ(session.get(), session1.get()); | 431 EXPECT_EQ(session.get(), session1.get()); |
| 425 EXPECT_NE(session2.get(), session1.get()); | 432 EXPECT_NE(session2.get(), session1.get()); |
| 426 | 433 |
| 427 // Remove the aliases and observe that we still have a session for host1. | 434 // Remove the aliases and observe that we still have a session for host1. |
| 428 SpdySessionPoolPeer pool_peer(spdy_session_pool_); | 435 SpdySessionPoolPeer pool_peer(spdy_session_pool_); |
| 429 pool_peer.RemoveAliases(test_hosts[0].key); | 436 pool_peer.RemoveAliases(test_hosts[0].key); |
| 430 pool_peer.RemoveAliases(test_hosts[1].key); | 437 pool_peer.RemoveAliases(test_hosts[1].key); |
| 431 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 438 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 432 | 439 |
| 433 // Expire the host cache | 440 // Expire the host cache |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 active_session_count_attr->GetString("value", &active_session_count)); | 899 active_session_count_attr->GetString("value", &active_session_count)); |
| 893 // No created stream so the session should be idle. | 900 // No created stream so the session should be idle. |
| 894 ASSERT_EQ("0", active_session_count); | 901 ASSERT_EQ("0", active_session_count); |
| 895 did_dump = true; | 902 did_dump = true; |
| 896 } | 903 } |
| 897 EXPECT_TRUE(did_dump); | 904 EXPECT_TRUE(did_dump); |
| 898 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); | 905 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); |
| 899 } | 906 } |
| 900 | 907 |
| 901 } // namespace net | 908 } // namespace net |
| OLD | NEW |