| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 TEST_P(SpdySessionPoolTest, CloseCurrentSessions) { | 89 TEST_P(SpdySessionPoolTest, CloseCurrentSessions) { |
| 90 const char kTestHost[] = "www.foo.com"; | 90 const char kTestHost[] = "www.foo.com"; |
| 91 const int kTestPort = 80; | 91 const int kTestPort = 80; |
| 92 | 92 |
| 93 session_deps_.host_resolver->set_synchronous_mode(true); | 93 session_deps_.host_resolver->set_synchronous_mode(true); |
| 94 | 94 |
| 95 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 95 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 96 SpdySessionKey test_key = | 96 SpdySessionKey test_key = |
| 97 SpdySessionKey( | 97 SpdySessionKey( |
| 98 test_host_port_pair, ProxyServer::Direct(), | 98 test_host_port_pair, ProxyServer::Direct(), |
| 99 PRIVACY_MODE_DISABLED); | 99 kPrivacyModeDisabled); |
| 100 | 100 |
| 101 MockConnect connect_data(SYNCHRONOUS, OK); | 101 MockConnect connect_data(SYNCHRONOUS, OK); |
| 102 MockRead reads[] = { | 102 MockRead reads[] = { |
| 103 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 103 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 106 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 107 data.set_connect_data(connect_data); | 107 data.set_connect_data(connect_data); |
| 108 session_deps_.socket_factory->AddSocketDataProvider(&data); | 108 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 109 | 109 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 151 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 152 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 152 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 153 | 153 |
| 154 CreateNetworkSession(); | 154 CreateNetworkSession(); |
| 155 | 155 |
| 156 // Set up session 1 | 156 // Set up session 1 |
| 157 const std::string kTestHost1("http://www.a.com"); | 157 const std::string kTestHost1("http://www.a.com"); |
| 158 HostPortPair test_host_port_pair1(kTestHost1, 80); | 158 HostPortPair test_host_port_pair1(kTestHost1, 80); |
| 159 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), | 159 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), |
| 160 PRIVACY_MODE_DISABLED); | 160 kPrivacyModeDisabled); |
| 161 base::WeakPtr<SpdySession> session1 = | 161 base::WeakPtr<SpdySession> session1 = |
| 162 CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); | 162 CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); |
| 163 GURL url1(kTestHost1); | 163 GURL url1(kTestHost1); |
| 164 base::WeakPtr<SpdyStream> spdy_stream1 = | 164 base::WeakPtr<SpdyStream> spdy_stream1 = |
| 165 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 165 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, |
| 166 session1, url1, MEDIUM, BoundNetLog()); | 166 session1, url1, MEDIUM, BoundNetLog()); |
| 167 ASSERT_TRUE(spdy_stream1.get() != NULL); | 167 ASSERT_TRUE(spdy_stream1.get() != NULL); |
| 168 | 168 |
| 169 // Set up session 2 | 169 // Set up session 2 |
| 170 session_deps_.socket_factory->AddSocketDataProvider(&data); | 170 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 171 const std::string kTestHost2("http://www.b.com"); | 171 const std::string kTestHost2("http://www.b.com"); |
| 172 HostPortPair test_host_port_pair2(kTestHost2, 80); | 172 HostPortPair test_host_port_pair2(kTestHost2, 80); |
| 173 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), | 173 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), |
| 174 PRIVACY_MODE_DISABLED); | 174 kPrivacyModeDisabled); |
| 175 base::WeakPtr<SpdySession> session2 = | 175 base::WeakPtr<SpdySession> session2 = |
| 176 CreateInsecureSpdySession(http_session_, key2, BoundNetLog()); | 176 CreateInsecureSpdySession(http_session_, key2, BoundNetLog()); |
| 177 GURL url2(kTestHost2); | 177 GURL url2(kTestHost2); |
| 178 base::WeakPtr<SpdyStream> spdy_stream2 = | 178 base::WeakPtr<SpdyStream> spdy_stream2 = |
| 179 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 179 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, |
| 180 session2, url2, MEDIUM, BoundNetLog()); | 180 session2, url2, MEDIUM, BoundNetLog()); |
| 181 ASSERT_TRUE(spdy_stream2.get() != NULL); | 181 ASSERT_TRUE(spdy_stream2.get() != NULL); |
| 182 | 182 |
| 183 // Set up session 3 | 183 // Set up session 3 |
| 184 session_deps_.socket_factory->AddSocketDataProvider(&data); | 184 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 185 const std::string kTestHost3("http://www.c.com"); | 185 const std::string kTestHost3("http://www.c.com"); |
| 186 HostPortPair test_host_port_pair3(kTestHost3, 80); | 186 HostPortPair test_host_port_pair3(kTestHost3, 80); |
| 187 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), | 187 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), |
| 188 PRIVACY_MODE_DISABLED); | 188 kPrivacyModeDisabled); |
| 189 base::WeakPtr<SpdySession> session3 = | 189 base::WeakPtr<SpdySession> session3 = |
| 190 CreateInsecureSpdySession(http_session_, key3, BoundNetLog()); | 190 CreateInsecureSpdySession(http_session_, key3, BoundNetLog()); |
| 191 GURL url3(kTestHost3); | 191 GURL url3(kTestHost3); |
| 192 base::WeakPtr<SpdyStream> spdy_stream3 = | 192 base::WeakPtr<SpdyStream> spdy_stream3 = |
| 193 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 193 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, |
| 194 session3, url3, MEDIUM, BoundNetLog()); | 194 session3, url3, MEDIUM, BoundNetLog()); |
| 195 ASSERT_TRUE(spdy_stream3.get() != NULL); | 195 ASSERT_TRUE(spdy_stream3.get() != NULL); |
| 196 | 196 |
| 197 // All sessions are active and not closed | 197 // All sessions are active and not closed |
| 198 EXPECT_TRUE(session1->is_active()); | 198 EXPECT_TRUE(session1->is_active()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 TEST_P(SpdySessionPoolTest, CloseAllSessions) { | 252 TEST_P(SpdySessionPoolTest, CloseAllSessions) { |
| 253 const char kTestHost[] = "www.foo.com"; | 253 const char kTestHost[] = "www.foo.com"; |
| 254 const int kTestPort = 80; | 254 const int kTestPort = 80; |
| 255 | 255 |
| 256 session_deps_.host_resolver->set_synchronous_mode(true); | 256 session_deps_.host_resolver->set_synchronous_mode(true); |
| 257 | 257 |
| 258 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 258 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 259 SpdySessionKey test_key = | 259 SpdySessionKey test_key = |
| 260 SpdySessionKey( | 260 SpdySessionKey( |
| 261 test_host_port_pair, ProxyServer::Direct(), | 261 test_host_port_pair, ProxyServer::Direct(), |
| 262 PRIVACY_MODE_DISABLED); | 262 kPrivacyModeDisabled); |
| 263 | 263 |
| 264 MockConnect connect_data(SYNCHRONOUS, OK); | 264 MockConnect connect_data(SYNCHRONOUS, OK); |
| 265 MockRead reads[] = { | 265 MockRead reads[] = { |
| 266 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 266 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 269 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 270 data.set_connect_data(connect_data); | 270 data.set_connect_data(connect_data); |
| 271 session_deps_.socket_factory->AddSocketDataProvider(&data); | 271 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 272 | 272 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 session_deps_.host_resolver->Resolve(info, | 341 session_deps_.host_resolver->Resolve(info, |
| 342 DEFAULT_PRIORITY, | 342 DEFAULT_PRIORITY, |
| 343 &test_hosts[i].addresses, | 343 &test_hosts[i].addresses, |
| 344 CompletionCallback(), | 344 CompletionCallback(), |
| 345 NULL, | 345 NULL, |
| 346 BoundNetLog()); | 346 BoundNetLog()); |
| 347 | 347 |
| 348 // Setup a SpdySessionKey | 348 // Setup a SpdySessionKey |
| 349 test_hosts[i].key = SpdySessionKey( | 349 test_hosts[i].key = SpdySessionKey( |
| 350 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct(), | 350 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct(), |
| 351 PRIVACY_MODE_DISABLED); | 351 kPrivacyModeDisabled); |
| 352 } | 352 } |
| 353 | 353 |
| 354 MockConnect connect_data(SYNCHRONOUS, OK); | 354 MockConnect connect_data(SYNCHRONOUS, OK); |
| 355 MockRead reads[] = { | 355 MockRead reads[] = { |
| 356 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 356 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 357 }; | 357 }; |
| 358 | 358 |
| 359 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 359 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 360 data.set_connect_data(connect_data); | 360 data.set_connect_data(connect_data); |
| 361 session_deps_.socket_factory->AddSocketDataProvider(&data); | 361 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 375 | 375 |
| 376 // The third host has no overlap with the first, so it can't pool IPs. | 376 // The third host has no overlap with the first, so it can't pool IPs. |
| 377 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 377 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 378 | 378 |
| 379 // The second host overlaps with the first, and should IP pool. | 379 // The second host overlaps with the first, and should IP pool. |
| 380 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 380 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 381 | 381 |
| 382 // Verify that the second host, through a proxy, won't share the IP. | 382 // Verify that the second host, through a proxy, won't share the IP. |
| 383 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), | 383 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), |
| 384 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), | 384 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), |
| 385 PRIVACY_MODE_DISABLED); | 385 kPrivacyModeDisabled); |
| 386 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); | 386 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); |
| 387 | 387 |
| 388 // Overlap between 2 and 3 does is not transitive to 1. | 388 // Overlap between 2 and 3 does is not transitive to 1. |
| 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 // Create a new session to host 2. | 391 // Create a new session to host 2. |
| 392 session_deps_.socket_factory->AddSocketDataProvider(&data); | 392 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 393 base::WeakPtr<SpdySession> session2 = | 393 base::WeakPtr<SpdySession> session2 = |
| 394 CreateInsecureSpdySession( | 394 CreateInsecureSpdySession( |
| 395 http_session_, test_hosts[2].key, BoundNetLog()); | 395 http_session_, test_hosts[2].key, BoundNetLog()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS); | 489 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS); |
| 490 } | 490 } |
| 491 | 491 |
| 492 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { | 492 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { |
| 493 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); | 493 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); |
| 494 } | 494 } |
| 495 | 495 |
| 496 } // namespace | 496 } // namespace |
| 497 | 497 |
| 498 } // namespace net | 498 } // namespace net |
| OLD | NEW |