| 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> |
| 11 | 11 |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 14 #include "net/dns/host_cache.h" | 15 #include "net/dns/host_cache.h" |
| 15 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
| 16 #include "net/socket/client_socket_handle.h" | 17 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/transport_client_socket_pool.h" | 18 #include "net/socket/transport_client_socket_pool.h" |
| 18 #include "net/spdy/spdy_session.h" | 19 #include "net/spdy/spdy_session.h" |
| 19 #include "net/spdy/spdy_stream_test_util.h" | 20 #include "net/spdy/spdy_stream_test_util.h" |
| 20 #include "net/spdy/spdy_test_util_common.h" | 21 #include "net/spdy/spdy_test_util_common.h" |
| 22 #include "net/test/cert_test_util.h" |
| 21 #include "net/test/gtest_util.h" | 23 #include "net/test/gtest_util.h" |
| 24 #include "net/test/test_data_directory.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 27 |
| 25 using net::test::IsError; | 28 using net::test::IsError; |
| 26 using net::test::IsOk; | 29 using net::test::IsOk; |
| 27 | 30 |
| 28 namespace net { | 31 namespace net { |
| 29 | 32 |
| 30 class SpdySessionPoolTest : public ::testing::Test { | 33 class SpdySessionPoolTest : public ::testing::Test { |
| 31 protected: | 34 protected: |
| 32 // Used by RunIPPoolingTest(). | 35 // Used by RunIPPoolingTest(). |
| 33 enum SpdyPoolCloseSessionsType { | 36 enum SpdyPoolCloseSessionsType { |
| 34 SPDY_POOL_CLOSE_SESSIONS_MANUALLY, | 37 SPDY_POOL_CLOSE_SESSIONS_MANUALLY, |
| 35 SPDY_POOL_CLOSE_CURRENT_SESSIONS, | 38 SPDY_POOL_CLOSE_CURRENT_SESSIONS, |
| 36 SPDY_POOL_CLOSE_IDLE_SESSIONS, | 39 SPDY_POOL_CLOSE_IDLE_SESSIONS, |
| 37 }; | 40 }; |
| 38 | 41 |
| 39 SpdySessionPoolTest() : spdy_session_pool_(NULL) {} | 42 SpdySessionPoolTest() : spdy_session_pool_(NULL) {} |
| 40 | 43 |
| 41 void CreateNetworkSession() { | 44 void CreateNetworkSession() { |
| 42 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 45 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
| 43 spdy_session_pool_ = http_session_->spdy_session_pool(); | 46 spdy_session_pool_ = http_session_->spdy_session_pool(); |
| 44 } | 47 } |
| 45 | 48 |
| 49 void AddSSLSocketData() { |
| 50 auto ssl = base::MakeUnique<SSLSocketDataProvider>(SYNCHRONOUS, OK); |
| 51 ssl->cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 52 ASSERT_TRUE(ssl->cert); |
| 53 session_deps_.socket_factory->AddSSLSocketDataProvider(ssl.get()); |
| 54 ssl_data_vector_.push_back(std::move(ssl)); |
| 55 } |
| 56 |
| 46 void RunIPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type); | 57 void RunIPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type); |
| 47 | 58 |
| 48 SpdySessionDependencies session_deps_; | 59 SpdySessionDependencies session_deps_; |
| 49 std::unique_ptr<HttpNetworkSession> http_session_; | 60 std::unique_ptr<HttpNetworkSession> http_session_; |
| 50 SpdySessionPool* spdy_session_pool_; | 61 SpdySessionPool* spdy_session_pool_; |
| 62 std::vector<std::unique_ptr<SSLSocketDataProvider>> ssl_data_vector_; |
| 51 }; | 63 }; |
| 52 | 64 |
| 53 // A delegate that opens a new session when it is closed. | 65 // A delegate that opens a new session when it is closed. |
| 54 class SessionOpeningDelegate : public SpdyStream::Delegate { | 66 class SessionOpeningDelegate : public SpdyStream::Delegate { |
| 55 public: | 67 public: |
| 56 SessionOpeningDelegate(SpdySessionPool* spdy_session_pool, | 68 SessionOpeningDelegate(SpdySessionPool* spdy_session_pool, |
| 57 const SpdySessionKey& key) | 69 const SpdySessionKey& key) |
| 58 : spdy_session_pool_(spdy_session_pool), | 70 : spdy_session_pool_(spdy_session_pool), |
| 59 key_(key) {} | 71 key_(key) {} |
| 60 | 72 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 116 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 105 data.set_connect_data(connect_data); | 117 data.set_connect_data(connect_data); |
| 106 session_deps_.socket_factory->AddSocketDataProvider(&data); | 118 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 107 | 119 |
| 108 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 120 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 109 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 121 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 110 | 122 |
| 111 CreateNetworkSession(); | 123 CreateNetworkSession(); |
| 112 | 124 |
| 113 // Setup the first session to the first host. | 125 // Setup the first session to the first host. |
| 114 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( | 126 base::WeakPtr<SpdySession> session = CreateSecureSpdySession( |
| 115 http_session_.get(), test_key, NetLogWithSource()); | 127 http_session_.get(), test_key, NetLogWithSource()); |
| 116 | 128 |
| 117 // Flush the SpdySession::OnReadComplete() task. | 129 // Flush the SpdySession::OnReadComplete() task. |
| 118 base::RunLoop().RunUntilIdle(); | 130 base::RunLoop().RunUntilIdle(); |
| 119 | 131 |
| 120 // Verify that we have sessions for everything. | 132 // Verify that we have sessions for everything. |
| 121 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 133 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
| 122 | 134 |
| 123 // Set the stream to create a new session when it is closed. | 135 // Set the stream to create a new session when it is closed. |
| 124 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( | 136 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 138 MockRead reads[] = { | 150 MockRead reads[] = { |
| 139 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 151 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 140 }; | 152 }; |
| 141 | 153 |
| 142 session_deps_.host_resolver->set_synchronous_mode(true); | 154 session_deps_.host_resolver->set_synchronous_mode(true); |
| 143 | 155 |
| 144 StaticSocketDataProvider data1(reads, arraysize(reads), nullptr, 0); | 156 StaticSocketDataProvider data1(reads, arraysize(reads), nullptr, 0); |
| 145 data1.set_connect_data(connect_data); | 157 data1.set_connect_data(connect_data); |
| 146 session_deps_.socket_factory->AddSocketDataProvider(&data1); | 158 session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 147 | 159 |
| 148 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 160 AddSSLSocketData(); |
| 149 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 161 AddSSLSocketData(); |
| 162 AddSSLSocketData(); |
| 150 | 163 |
| 151 CreateNetworkSession(); | 164 CreateNetworkSession(); |
| 152 | 165 |
| 153 // Set up session 1 | 166 // Set up session 1 |
| 154 const std::string kTestHost1("http://www.a.com"); | 167 const std::string kTestHost1("http://www.example.org"); |
| 155 HostPortPair test_host_port_pair1(kTestHost1, 80); | 168 HostPortPair test_host_port_pair1(kTestHost1, 80); |
| 156 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), | 169 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), |
| 157 PRIVACY_MODE_DISABLED); | 170 PRIVACY_MODE_DISABLED); |
| 158 base::WeakPtr<SpdySession> session1 = | 171 base::WeakPtr<SpdySession> session1 = |
| 159 CreateInsecureSpdySession(http_session_.get(), key1, NetLogWithSource()); | 172 CreateSecureSpdySession(http_session_.get(), key1, NetLogWithSource()); |
| 160 GURL url1(kTestHost1); | 173 GURL url1(kTestHost1); |
| 161 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( | 174 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( |
| 162 SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, NetLogWithSource()); | 175 SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, NetLogWithSource()); |
| 163 ASSERT_TRUE(spdy_stream1); | 176 ASSERT_TRUE(spdy_stream1); |
| 164 | 177 |
| 165 // Set up session 2 | 178 // Set up session 2 |
| 166 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0); | 179 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0); |
| 167 data2.set_connect_data(connect_data); | 180 data2.set_connect_data(connect_data); |
| 168 session_deps_.socket_factory->AddSocketDataProvider(&data2); | 181 session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 169 const std::string kTestHost2("http://www.b.com"); | 182 const std::string kTestHost2("http://mail.example.org"); |
| 170 HostPortPair test_host_port_pair2(kTestHost2, 80); | 183 HostPortPair test_host_port_pair2(kTestHost2, 80); |
| 171 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), | 184 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), |
| 172 PRIVACY_MODE_DISABLED); | 185 PRIVACY_MODE_DISABLED); |
| 173 base::WeakPtr<SpdySession> session2 = | 186 base::WeakPtr<SpdySession> session2 = |
| 174 CreateInsecureSpdySession(http_session_.get(), key2, NetLogWithSource()); | 187 CreateSecureSpdySession(http_session_.get(), key2, NetLogWithSource()); |
| 175 GURL url2(kTestHost2); | 188 GURL url2(kTestHost2); |
| 176 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously( | 189 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously( |
| 177 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, NetLogWithSource()); | 190 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, NetLogWithSource()); |
| 178 ASSERT_TRUE(spdy_stream2); | 191 ASSERT_TRUE(spdy_stream2); |
| 179 | 192 |
| 180 // Set up session 3 | 193 // Set up session 3 |
| 181 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0); | 194 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0); |
| 182 data3.set_connect_data(connect_data); | 195 data3.set_connect_data(connect_data); |
| 183 session_deps_.socket_factory->AddSocketDataProvider(&data3); | 196 session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 184 const std::string kTestHost3("http://www.c.com"); | 197 const std::string kTestHost3("http://mail.example.com"); |
| 185 HostPortPair test_host_port_pair3(kTestHost3, 80); | 198 HostPortPair test_host_port_pair3(kTestHost3, 80); |
| 186 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), | 199 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), |
| 187 PRIVACY_MODE_DISABLED); | 200 PRIVACY_MODE_DISABLED); |
| 188 base::WeakPtr<SpdySession> session3 = | 201 base::WeakPtr<SpdySession> session3 = |
| 189 CreateInsecureSpdySession(http_session_.get(), key3, NetLogWithSource()); | 202 CreateSecureSpdySession(http_session_.get(), key3, NetLogWithSource()); |
| 190 GURL url3(kTestHost3); | 203 GURL url3(kTestHost3); |
| 191 base::WeakPtr<SpdyStream> spdy_stream3 = CreateStreamSynchronously( | 204 base::WeakPtr<SpdyStream> spdy_stream3 = CreateStreamSynchronously( |
| 192 SPDY_BIDIRECTIONAL_STREAM, session3, url3, MEDIUM, NetLogWithSource()); | 205 SPDY_BIDIRECTIONAL_STREAM, session3, url3, MEDIUM, NetLogWithSource()); |
| 193 ASSERT_TRUE(spdy_stream3); | 206 ASSERT_TRUE(spdy_stream3); |
| 194 | 207 |
| 195 // All sessions are active and not closed | 208 // All sessions are active and not closed |
| 196 EXPECT_TRUE(session1->is_active()); | 209 EXPECT_TRUE(session1->is_active()); |
| 197 EXPECT_TRUE(session1->IsAvailable()); | 210 EXPECT_TRUE(session1->IsAvailable()); |
| 198 EXPECT_TRUE(session2->is_active()); | 211 EXPECT_TRUE(session2->is_active()); |
| 199 EXPECT_TRUE(session2->IsAvailable()); | 212 EXPECT_TRUE(session2->IsAvailable()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 288 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 276 data.set_connect_data(connect_data); | 289 data.set_connect_data(connect_data); |
| 277 session_deps_.socket_factory->AddSocketDataProvider(&data); | 290 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 278 | 291 |
| 279 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 292 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 280 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 293 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 281 | 294 |
| 282 CreateNetworkSession(); | 295 CreateNetworkSession(); |
| 283 | 296 |
| 284 // Setup the first session to the first host. | 297 // Setup the first session to the first host. |
| 285 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( | 298 base::WeakPtr<SpdySession> session = CreateSecureSpdySession( |
| 286 http_session_.get(), test_key, NetLogWithSource()); | 299 http_session_.get(), test_key, NetLogWithSource()); |
| 287 | 300 |
| 288 // Flush the SpdySession::OnReadComplete() task. | 301 // Flush the SpdySession::OnReadComplete() task. |
| 289 base::RunLoop().RunUntilIdle(); | 302 base::RunLoop().RunUntilIdle(); |
| 290 | 303 |
| 291 // Verify that we have sessions for everything. | 304 // Verify that we have sessions for everything. |
| 292 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 305 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
| 293 | 306 |
| 294 // Set the stream to create a new session when it is closed. | 307 // Set the stream to create a new session when it is closed. |
| 295 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( | 308 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 314 void SpdySessionPoolTest::RunIPPoolingTest( | 327 void SpdySessionPoolTest::RunIPPoolingTest( |
| 315 SpdyPoolCloseSessionsType close_sessions_type) { | 328 SpdyPoolCloseSessionsType close_sessions_type) { |
| 316 const int kTestPort = 80; | 329 const int kTestPort = 80; |
| 317 struct TestHosts { | 330 struct TestHosts { |
| 318 std::string url; | 331 std::string url; |
| 319 std::string name; | 332 std::string name; |
| 320 std::string iplist; | 333 std::string iplist; |
| 321 SpdySessionKey key; | 334 SpdySessionKey key; |
| 322 AddressList addresses; | 335 AddressList addresses; |
| 323 } test_hosts[] = { | 336 } test_hosts[] = { |
| 324 { "http:://www.foo.com", | 337 {"http:://www.example.org", "www.example.org", |
| 325 "www.foo.com", | 338 "192.0.2.33,192.168.0.1,192.168.0.5"}, |
| 326 "192.0.2.33,192.168.0.1,192.168.0.5" | 339 {"http://mail.example.org", "mail.example.org", |
| 327 }, | 340 "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33"}, |
| 328 { "http://js.foo.com", | 341 {"http://mail.example.com", "mail.example.com", |
| 329 "js.foo.com", | 342 "192.168.0.4,192.168.0.3"}, |
| 330 "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33" | |
| 331 }, | |
| 332 { "http://images.foo.com", | |
| 333 "images.foo.com", | |
| 334 "192.168.0.4,192.168.0.3" | |
| 335 }, | |
| 336 }; | 343 }; |
| 337 | 344 |
| 338 session_deps_.host_resolver->set_synchronous_mode(true); | 345 session_deps_.host_resolver->set_synchronous_mode(true); |
| 339 std::unique_ptr<HostResolver::Request> request[arraysize(test_hosts)]; | 346 std::unique_ptr<HostResolver::Request> request[arraysize(test_hosts)]; |
| 340 for (size_t i = 0; i < arraysize(test_hosts); i++) { | 347 for (size_t i = 0; i < arraysize(test_hosts); i++) { |
| 341 session_deps_.host_resolver->rules()->AddIPLiteralRule( | 348 session_deps_.host_resolver->rules()->AddIPLiteralRule( |
| 342 test_hosts[i].name, test_hosts[i].iplist, std::string()); | 349 test_hosts[i].name, test_hosts[i].iplist, std::string()); |
| 343 | 350 |
| 344 // This test requires that the HostResolver cache be populated. Normal | 351 // This test requires that the HostResolver cache be populated. Normal |
| 345 // code would have done this already, but we do it manually. | 352 // code would have done this already, but we do it manually. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 356 | 363 |
| 357 MockConnect connect_data(SYNCHRONOUS, OK); | 364 MockConnect connect_data(SYNCHRONOUS, OK); |
| 358 MockRead reads[] = { | 365 MockRead reads[] = { |
| 359 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 366 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 360 }; | 367 }; |
| 361 | 368 |
| 362 StaticSocketDataProvider data1(reads, arraysize(reads), NULL, 0); | 369 StaticSocketDataProvider data1(reads, arraysize(reads), NULL, 0); |
| 363 data1.set_connect_data(connect_data); | 370 data1.set_connect_data(connect_data); |
| 364 session_deps_.socket_factory->AddSocketDataProvider(&data1); | 371 session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 365 | 372 |
| 366 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 373 AddSSLSocketData(); |
| 367 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 368 | 374 |
| 369 CreateNetworkSession(); | 375 CreateNetworkSession(); |
| 370 | 376 |
| 371 // Setup the first session to the first host. | 377 // Setup the first session to the first host. |
| 372 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( | 378 base::WeakPtr<SpdySession> session = CreateSecureSpdySession( |
| 373 http_session_.get(), test_hosts[0].key, NetLogWithSource()); | 379 http_session_.get(), test_hosts[0].key, NetLogWithSource()); |
| 374 | 380 |
| 375 // Flush the SpdySession::OnReadComplete() task. | 381 // Flush the SpdySession::OnReadComplete() task. |
| 376 base::RunLoop().RunUntilIdle(); | 382 base::RunLoop().RunUntilIdle(); |
| 377 | 383 |
| 378 // The third host has no overlap with the first, so it can't pool IPs. | 384 // The third host has no overlap with the first, so it can't pool IPs. |
| 379 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 385 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 380 | 386 |
| 381 // The second host overlaps with the first, and should IP pool. | 387 // The second host overlaps with the first, and should IP pool. |
| 382 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 388 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 383 | 389 |
| 384 // Verify that the second host, through a proxy, won't share the IP. | 390 // Verify that the second host, through a proxy, won't share the IP. |
| 385 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), | 391 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), |
| 386 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), | 392 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), |
| 387 PRIVACY_MODE_DISABLED); | 393 PRIVACY_MODE_DISABLED); |
| 388 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); | 394 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); |
| 389 | 395 |
| 390 // Overlap between 2 and 3 does is not transitive to 1. | 396 // Overlap between 2 and 3 does is not transitive to 1. |
| 391 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 397 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 392 | 398 |
| 393 // Create a new session to host 2. | 399 // Create a new session to host 2. |
| 394 StaticSocketDataProvider data2(reads, arraysize(reads), NULL, 0); | 400 StaticSocketDataProvider data2(reads, arraysize(reads), NULL, 0); |
| 395 data2.set_connect_data(connect_data); | 401 data2.set_connect_data(connect_data); |
| 396 session_deps_.socket_factory->AddSocketDataProvider(&data2); | 402 session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 397 base::WeakPtr<SpdySession> session2 = CreateInsecureSpdySession( | 403 |
| 404 AddSSLSocketData(); |
| 405 |
| 406 base::WeakPtr<SpdySession> session2 = CreateSecureSpdySession( |
| 398 http_session_.get(), test_hosts[2].key, NetLogWithSource()); | 407 http_session_.get(), test_hosts[2].key, NetLogWithSource()); |
| 399 | 408 |
| 400 // Verify that we have sessions for everything. | 409 // Verify that we have sessions for everything. |
| 401 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); | 410 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); |
| 402 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 411 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 403 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 412 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 404 | 413 |
| 405 // Grab the session to host 1 and verify that it is the same session | 414 // Grab the session to host 1 and verify that it is the same session |
| 406 // we got with host 0, and that is a different from host 2's session. | 415 // we got with host 0, and that is a different from host 2's session. |
| 407 base::WeakPtr<SpdySession> session1 = | 416 base::WeakPtr<SpdySession> session1 = |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 // This isn't testing anything having to do with SPDY frames; we | 518 // This isn't testing anything having to do with SPDY frames; we |
| 510 // can ignore issues of how dependencies are set. We default to | 519 // can ignore issues of how dependencies are set. We default to |
| 511 // setting them (when doing the appropriate protocol) since that's | 520 // setting them (when doing the appropriate protocol) since that's |
| 512 // where we're eventually headed for all HTTP/2 connections. | 521 // where we're eventually headed for all HTTP/2 connections. |
| 513 SpdyTestUtil spdy_util; | 522 SpdyTestUtil spdy_util; |
| 514 | 523 |
| 515 MockRead reads[] = { | 524 MockRead reads[] = { |
| 516 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 525 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 517 }; | 526 }; |
| 518 SpdySerializedFrame req( | 527 SpdySerializedFrame req( |
| 519 spdy_util.ConstructSpdyGet("http://www.a.com", 1, MEDIUM)); | 528 spdy_util.ConstructSpdyGet("http://www.example.org", 1, MEDIUM)); |
| 520 MockWrite writes[] = {CreateMockWrite(req, 1)}; | 529 MockWrite writes[] = {CreateMockWrite(req, 1)}; |
| 521 | 530 |
| 522 StaticSocketDataProvider dataA(reads, arraysize(reads), writes, | 531 StaticSocketDataProvider dataA(reads, arraysize(reads), writes, |
| 523 arraysize(writes)); | 532 arraysize(writes)); |
| 524 dataA.set_connect_data(connect_data); | 533 dataA.set_connect_data(connect_data); |
| 525 session_deps_.socket_factory->AddSocketDataProvider(&dataA); | 534 session_deps_.socket_factory->AddSocketDataProvider(&dataA); |
| 526 | 535 |
| 527 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 536 AddSSLSocketData(); |
| 528 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 529 | 537 |
| 530 CreateNetworkSession(); | 538 CreateNetworkSession(); |
| 531 | 539 |
| 532 // Set up session A: Going away, but with an active stream. | 540 // Set up session A: Going away, but with an active stream. |
| 533 const std::string kTestHostA("http://www.a.com"); | 541 const std::string kTestHostA("http://www.example.org"); |
| 534 HostPortPair test_host_port_pairA(kTestHostA, 80); | 542 HostPortPair test_host_port_pairA(kTestHostA, 80); |
| 535 SpdySessionKey keyA( | 543 SpdySessionKey keyA( |
| 536 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 544 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 537 base::WeakPtr<SpdySession> sessionA = | 545 base::WeakPtr<SpdySession> sessionA = |
| 538 CreateInsecureSpdySession(http_session_.get(), keyA, NetLogWithSource()); | 546 CreateSecureSpdySession(http_session_.get(), keyA, NetLogWithSource()); |
| 539 | 547 |
| 540 GURL urlA(kTestHostA); | 548 GURL urlA(kTestHostA); |
| 541 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( | 549 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( |
| 542 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, NetLogWithSource()); | 550 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, NetLogWithSource()); |
| 543 test::StreamDelegateDoNothing delegateA(spdy_streamA); | 551 test::StreamDelegateDoNothing delegateA(spdy_streamA); |
| 544 spdy_streamA->SetDelegate(&delegateA); | 552 spdy_streamA->SetDelegate(&delegateA); |
| 545 | 553 |
| 546 SpdyHeaderBlock headers(spdy_util.ConstructGetHeaderBlock(urlA.spec())); | 554 SpdyHeaderBlock headers(spdy_util.ConstructGetHeaderBlock(urlA.spec())); |
| 547 spdy_streamA->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 555 spdy_streamA->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
| 548 | 556 |
| 549 base::RunLoop().RunUntilIdle(); // Allow headers to write. | 557 base::RunLoop().RunUntilIdle(); // Allow headers to write. |
| 550 EXPECT_TRUE(delegateA.send_headers_completed()); | 558 EXPECT_TRUE(delegateA.send_headers_completed()); |
| 551 | 559 |
| 552 sessionA->MakeUnavailable(); | 560 sessionA->MakeUnavailable(); |
| 553 EXPECT_TRUE(sessionA->IsGoingAway()); | 561 EXPECT_TRUE(sessionA->IsGoingAway()); |
| 554 EXPECT_FALSE(delegateA.StreamIsClosed()); | 562 EXPECT_FALSE(delegateA.StreamIsClosed()); |
| 555 | 563 |
| 556 // Set up session B: Available, with a created stream. | 564 // Set up session B: Available, with a created stream. |
| 557 StaticSocketDataProvider dataB(reads, arraysize(reads), writes, | 565 StaticSocketDataProvider dataB(reads, arraysize(reads), writes, |
| 558 arraysize(writes)); | 566 arraysize(writes)); |
| 559 dataB.set_connect_data(connect_data); | 567 dataB.set_connect_data(connect_data); |
| 560 session_deps_.socket_factory->AddSocketDataProvider(&dataB); | 568 session_deps_.socket_factory->AddSocketDataProvider(&dataB); |
| 561 const std::string kTestHostB("http://www.b.com"); | 569 |
| 570 AddSSLSocketData(); |
| 571 |
| 572 const std::string kTestHostB("http://mail.example.org"); |
| 562 HostPortPair test_host_port_pairB(kTestHostB, 80); | 573 HostPortPair test_host_port_pairB(kTestHostB, 80); |
| 563 SpdySessionKey keyB( | 574 SpdySessionKey keyB( |
| 564 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 575 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 565 base::WeakPtr<SpdySession> sessionB = | 576 base::WeakPtr<SpdySession> sessionB = |
| 566 CreateInsecureSpdySession(http_session_.get(), keyB, NetLogWithSource()); | 577 CreateSecureSpdySession(http_session_.get(), keyB, NetLogWithSource()); |
| 567 EXPECT_TRUE(sessionB->IsAvailable()); | 578 EXPECT_TRUE(sessionB->IsAvailable()); |
| 568 | 579 |
| 569 GURL urlB(kTestHostB); | 580 GURL urlB(kTestHostB); |
| 570 base::WeakPtr<SpdyStream> spdy_streamB = CreateStreamSynchronously( | 581 base::WeakPtr<SpdyStream> spdy_streamB = CreateStreamSynchronously( |
| 571 SPDY_BIDIRECTIONAL_STREAM, sessionB, urlB, MEDIUM, NetLogWithSource()); | 582 SPDY_BIDIRECTIONAL_STREAM, sessionB, urlB, MEDIUM, NetLogWithSource()); |
| 572 test::StreamDelegateDoNothing delegateB(spdy_streamB); | 583 test::StreamDelegateDoNothing delegateB(spdy_streamB); |
| 573 spdy_streamB->SetDelegate(&delegateB); | 584 spdy_streamB->SetDelegate(&delegateB); |
| 574 | 585 |
| 575 // Set up session C: Draining. | 586 // Set up session C: Draining. |
| 576 StaticSocketDataProvider dataC(reads, arraysize(reads), writes, | 587 StaticSocketDataProvider dataC(reads, arraysize(reads), writes, |
| 577 arraysize(writes)); | 588 arraysize(writes)); |
| 578 dataC.set_connect_data(connect_data); | 589 dataC.set_connect_data(connect_data); |
| 579 session_deps_.socket_factory->AddSocketDataProvider(&dataC); | 590 session_deps_.socket_factory->AddSocketDataProvider(&dataC); |
| 580 const std::string kTestHostC("http://www.c.com"); | 591 |
| 592 AddSSLSocketData(); |
| 593 |
| 594 const std::string kTestHostC("http://mail.example.com"); |
| 581 HostPortPair test_host_port_pairC(kTestHostC, 80); | 595 HostPortPair test_host_port_pairC(kTestHostC, 80); |
| 582 SpdySessionKey keyC( | 596 SpdySessionKey keyC( |
| 583 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 597 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 584 base::WeakPtr<SpdySession> sessionC = | 598 base::WeakPtr<SpdySession> sessionC = |
| 585 CreateInsecureSpdySession(http_session_.get(), keyC, NetLogWithSource()); | 599 CreateSecureSpdySession(http_session_.get(), keyC, NetLogWithSource()); |
| 586 | 600 |
| 587 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); | 601 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); |
| 588 EXPECT_TRUE(sessionC->IsDraining()); | 602 EXPECT_TRUE(sessionC->IsDraining()); |
| 589 | 603 |
| 590 spdy_session_pool_->OnIPAddressChanged(); | 604 spdy_session_pool_->OnIPAddressChanged(); |
| 591 | 605 |
| 592 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 606 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
| 593 EXPECT_TRUE(sessionA->IsGoingAway()); | 607 EXPECT_TRUE(sessionA->IsGoingAway()); |
| 594 EXPECT_TRUE(sessionB->IsDraining()); | 608 EXPECT_TRUE(sessionB->IsDraining()); |
| 595 EXPECT_TRUE(sessionC->IsDraining()); | 609 EXPECT_TRUE(sessionC->IsDraining()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); | 641 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 628 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 642 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 629 session_deps_.socket_factory->AddSocketDataProvider(&data); | 643 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 630 | 644 |
| 631 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 645 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 632 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 646 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 633 | 647 |
| 634 CreateNetworkSession(); | 648 CreateNetworkSession(); |
| 635 | 649 |
| 636 base::WeakPtr<SpdySession> session = | 650 base::WeakPtr<SpdySession> session = |
| 637 CreateInsecureSpdySession(http_session_.get(), key, NetLogWithSource()); | 651 CreateSecureSpdySession(http_session_.get(), key, NetLogWithSource()); |
| 638 | 652 |
| 639 // Flush the SpdySession::OnReadComplete() task. | 653 // Flush the SpdySession::OnReadComplete() task. |
| 640 base::RunLoop().RunUntilIdle(); | 654 base::RunLoop().RunUntilIdle(); |
| 641 | 655 |
| 642 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key)); | 656 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key)); |
| 643 | 657 |
| 644 // FindAvailableSession should return |session| if called with empty |url|. | 658 // FindAvailableSession should return |session| if called with empty |url|. |
| 645 base::WeakPtr<SpdySession> session1 = | 659 base::WeakPtr<SpdySession> session1 = |
| 646 spdy_session_pool_->FindAvailableSession(key, GURL(), NetLogWithSource()); | 660 spdy_session_pool_->FindAvailableSession(key, GURL(), NetLogWithSource()); |
| 647 EXPECT_EQ(session.get(), session1.get()); | 661 EXPECT_EQ(session.get(), session1.get()); |
| 648 | 662 |
| 649 // FindAvailableSession should return |session| if called with |url| for which | 663 // FindAvailableSession should return |session| if called with |url| for which |
| 650 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. | 664 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. |
| 651 base::WeakPtr<SpdySession> session2 = | 665 base::WeakPtr<SpdySession> session2 = |
| 652 spdy_session_pool_->FindAvailableSession( | 666 spdy_session_pool_->FindAvailableSession( |
| 653 key, GURL("http://news.example.org/foo.html"), NetLogWithSource()); | 667 key, GURL("http://news.example.org/foo.html"), NetLogWithSource()); |
| 654 EXPECT_EQ(session.get(), session2.get()); | 668 EXPECT_EQ(session.get(), session2.get()); |
| 655 | 669 |
| 656 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); | 670 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); |
| 657 } | 671 } |
| 658 | 672 |
| 659 } // namespace net | 673 } // namespace net |
| OLD | NEW |