| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 104 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 105 data.set_connect_data(connect_data); | 105 data.set_connect_data(connect_data); |
| 106 session_deps_.socket_factory->AddSocketDataProvider(&data); | 106 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 107 | 107 |
| 108 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 108 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 109 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 109 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 110 | 110 |
| 111 CreateNetworkSession(); | 111 CreateNetworkSession(); |
| 112 | 112 |
| 113 // Setup the first session to the first host. | 113 // Setup the first session to the first host. |
| 114 base::WeakPtr<SpdySession> session = | 114 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( |
| 115 CreateInsecureSpdySession(http_session_.get(), test_key, BoundNetLog()); | 115 http_session_.get(), test_key, NetLogWithSource()); |
| 116 | 116 |
| 117 // Flush the SpdySession::OnReadComplete() task. | 117 // Flush the SpdySession::OnReadComplete() task. |
| 118 base::RunLoop().RunUntilIdle(); | 118 base::RunLoop().RunUntilIdle(); |
| 119 | 119 |
| 120 // Verify that we have sessions for everything. | 120 // Verify that we have sessions for everything. |
| 121 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 121 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
| 122 | 122 |
| 123 // Set the stream to create a new session when it is closed. | 123 // Set the stream to create a new session when it is closed. |
| 124 base::WeakPtr<SpdyStream> spdy_stream = | 124 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( |
| 125 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 125 SPDY_BIDIRECTIONAL_STREAM, session, GURL("http://www.foo.com"), MEDIUM, |
| 126 session, GURL("http://www.foo.com"), | 126 NetLogWithSource()); |
| 127 MEDIUM, BoundNetLog()); | |
| 128 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); | 127 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); |
| 129 spdy_stream->SetDelegate(&delegate); | 128 spdy_stream->SetDelegate(&delegate); |
| 130 | 129 |
| 131 // Close the current session. | 130 // Close the current session. |
| 132 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); | 131 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); |
| 133 | 132 |
| 134 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 133 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
| 135 } | 134 } |
| 136 | 135 |
| 137 TEST_F(SpdySessionPoolTest, CloseCurrentIdleSessions) { | 136 TEST_F(SpdySessionPoolTest, CloseCurrentIdleSessions) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 149 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 151 | 150 |
| 152 CreateNetworkSession(); | 151 CreateNetworkSession(); |
| 153 | 152 |
| 154 // Set up session 1 | 153 // Set up session 1 |
| 155 const std::string kTestHost1("http://www.a.com"); | 154 const std::string kTestHost1("http://www.a.com"); |
| 156 HostPortPair test_host_port_pair1(kTestHost1, 80); | 155 HostPortPair test_host_port_pair1(kTestHost1, 80); |
| 157 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), | 156 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), |
| 158 PRIVACY_MODE_DISABLED); | 157 PRIVACY_MODE_DISABLED); |
| 159 base::WeakPtr<SpdySession> session1 = | 158 base::WeakPtr<SpdySession> session1 = |
| 160 CreateInsecureSpdySession(http_session_.get(), key1, BoundNetLog()); | 159 CreateInsecureSpdySession(http_session_.get(), key1, NetLogWithSource()); |
| 161 GURL url1(kTestHost1); | 160 GURL url1(kTestHost1); |
| 162 base::WeakPtr<SpdyStream> spdy_stream1 = | 161 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( |
| 163 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 162 SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, NetLogWithSource()); |
| 164 session1, url1, MEDIUM, BoundNetLog()); | |
| 165 ASSERT_TRUE(spdy_stream1); | 163 ASSERT_TRUE(spdy_stream1); |
| 166 | 164 |
| 167 // Set up session 2 | 165 // Set up session 2 |
| 168 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0); | 166 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0); |
| 169 data2.set_connect_data(connect_data); | 167 data2.set_connect_data(connect_data); |
| 170 session_deps_.socket_factory->AddSocketDataProvider(&data2); | 168 session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 171 const std::string kTestHost2("http://www.b.com"); | 169 const std::string kTestHost2("http://www.b.com"); |
| 172 HostPortPair test_host_port_pair2(kTestHost2, 80); | 170 HostPortPair test_host_port_pair2(kTestHost2, 80); |
| 173 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), | 171 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), |
| 174 PRIVACY_MODE_DISABLED); | 172 PRIVACY_MODE_DISABLED); |
| 175 base::WeakPtr<SpdySession> session2 = | 173 base::WeakPtr<SpdySession> session2 = |
| 176 CreateInsecureSpdySession(http_session_.get(), key2, BoundNetLog()); | 174 CreateInsecureSpdySession(http_session_.get(), key2, NetLogWithSource()); |
| 177 GURL url2(kTestHost2); | 175 GURL url2(kTestHost2); |
| 178 base::WeakPtr<SpdyStream> spdy_stream2 = | 176 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously( |
| 179 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 177 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, NetLogWithSource()); |
| 180 session2, url2, MEDIUM, BoundNetLog()); | |
| 181 ASSERT_TRUE(spdy_stream2); | 178 ASSERT_TRUE(spdy_stream2); |
| 182 | 179 |
| 183 // Set up session 3 | 180 // Set up session 3 |
| 184 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0); | 181 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0); |
| 185 data3.set_connect_data(connect_data); | 182 data3.set_connect_data(connect_data); |
| 186 session_deps_.socket_factory->AddSocketDataProvider(&data3); | 183 session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 187 const std::string kTestHost3("http://www.c.com"); | 184 const std::string kTestHost3("http://www.c.com"); |
| 188 HostPortPair test_host_port_pair3(kTestHost3, 80); | 185 HostPortPair test_host_port_pair3(kTestHost3, 80); |
| 189 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), | 186 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), |
| 190 PRIVACY_MODE_DISABLED); | 187 PRIVACY_MODE_DISABLED); |
| 191 base::WeakPtr<SpdySession> session3 = | 188 base::WeakPtr<SpdySession> session3 = |
| 192 CreateInsecureSpdySession(http_session_.get(), key3, BoundNetLog()); | 189 CreateInsecureSpdySession(http_session_.get(), key3, NetLogWithSource()); |
| 193 GURL url3(kTestHost3); | 190 GURL url3(kTestHost3); |
| 194 base::WeakPtr<SpdyStream> spdy_stream3 = | 191 base::WeakPtr<SpdyStream> spdy_stream3 = CreateStreamSynchronously( |
| 195 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 192 SPDY_BIDIRECTIONAL_STREAM, session3, url3, MEDIUM, NetLogWithSource()); |
| 196 session3, url3, MEDIUM, BoundNetLog()); | |
| 197 ASSERT_TRUE(spdy_stream3); | 193 ASSERT_TRUE(spdy_stream3); |
| 198 | 194 |
| 199 // All sessions are active and not closed | 195 // All sessions are active and not closed |
| 200 EXPECT_TRUE(session1->is_active()); | 196 EXPECT_TRUE(session1->is_active()); |
| 201 EXPECT_TRUE(session1->IsAvailable()); | 197 EXPECT_TRUE(session1->IsAvailable()); |
| 202 EXPECT_TRUE(session2->is_active()); | 198 EXPECT_TRUE(session2->is_active()); |
| 203 EXPECT_TRUE(session2->IsAvailable()); | 199 EXPECT_TRUE(session2->IsAvailable()); |
| 204 EXPECT_TRUE(session3->is_active()); | 200 EXPECT_TRUE(session3->is_active()); |
| 205 EXPECT_TRUE(session3->IsAvailable()); | 201 EXPECT_TRUE(session3->IsAvailable()); |
| 206 | 202 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 275 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 280 data.set_connect_data(connect_data); | 276 data.set_connect_data(connect_data); |
| 281 session_deps_.socket_factory->AddSocketDataProvider(&data); | 277 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 282 | 278 |
| 283 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 279 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 284 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 280 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 285 | 281 |
| 286 CreateNetworkSession(); | 282 CreateNetworkSession(); |
| 287 | 283 |
| 288 // Setup the first session to the first host. | 284 // Setup the first session to the first host. |
| 289 base::WeakPtr<SpdySession> session = | 285 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( |
| 290 CreateInsecureSpdySession(http_session_.get(), test_key, BoundNetLog()); | 286 http_session_.get(), test_key, NetLogWithSource()); |
| 291 | 287 |
| 292 // Flush the SpdySession::OnReadComplete() task. | 288 // Flush the SpdySession::OnReadComplete() task. |
| 293 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
| 294 | 290 |
| 295 // Verify that we have sessions for everything. | 291 // Verify that we have sessions for everything. |
| 296 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 292 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
| 297 | 293 |
| 298 // Set the stream to create a new session when it is closed. | 294 // Set the stream to create a new session when it is closed. |
| 299 base::WeakPtr<SpdyStream> spdy_stream = | 295 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( |
| 300 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 296 SPDY_BIDIRECTIONAL_STREAM, session, GURL("http://www.foo.com"), MEDIUM, |
| 301 session, GURL("http://www.foo.com"), | 297 NetLogWithSource()); |
| 302 MEDIUM, BoundNetLog()); | |
| 303 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); | 298 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); |
| 304 spdy_stream->SetDelegate(&delegate); | 299 spdy_stream->SetDelegate(&delegate); |
| 305 | 300 |
| 306 // Close the current session. | 301 // Close the current session. |
| 307 spdy_session_pool_->CloseAllSessions(); | 302 spdy_session_pool_->CloseAllSessions(); |
| 308 | 303 |
| 309 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_key)); | 304 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_key)); |
| 310 } | 305 } |
| 311 | 306 |
| 312 // This test has three variants, one for each style of closing the connection. | 307 // This test has three variants, one for each style of closing the connection. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 std::unique_ptr<HostResolver::Request> request[arraysize(test_hosts)]; | 339 std::unique_ptr<HostResolver::Request> request[arraysize(test_hosts)]; |
| 345 for (size_t i = 0; i < arraysize(test_hosts); i++) { | 340 for (size_t i = 0; i < arraysize(test_hosts); i++) { |
| 346 session_deps_.host_resolver->rules()->AddIPLiteralRule( | 341 session_deps_.host_resolver->rules()->AddIPLiteralRule( |
| 347 test_hosts[i].name, test_hosts[i].iplist, std::string()); | 342 test_hosts[i].name, test_hosts[i].iplist, std::string()); |
| 348 | 343 |
| 349 // This test requires that the HostResolver cache be populated. Normal | 344 // This test requires that the HostResolver cache be populated. Normal |
| 350 // code would have done this already, but we do it manually. | 345 // code would have done this already, but we do it manually. |
| 351 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); | 346 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); |
| 352 session_deps_.host_resolver->Resolve( | 347 session_deps_.host_resolver->Resolve( |
| 353 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(), | 348 info, DEFAULT_PRIORITY, &test_hosts[i].addresses, CompletionCallback(), |
| 354 &request[i], BoundNetLog()); | 349 &request[i], NetLogWithSource()); |
| 355 | 350 |
| 356 // Setup a SpdySessionKey | 351 // Setup a SpdySessionKey |
| 357 test_hosts[i].key = SpdySessionKey( | 352 test_hosts[i].key = SpdySessionKey( |
| 358 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct(), | 353 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct(), |
| 359 PRIVACY_MODE_DISABLED); | 354 PRIVACY_MODE_DISABLED); |
| 360 } | 355 } |
| 361 | 356 |
| 362 MockConnect connect_data(SYNCHRONOUS, OK); | 357 MockConnect connect_data(SYNCHRONOUS, OK); |
| 363 MockRead reads[] = { | 358 MockRead reads[] = { |
| 364 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 359 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 365 }; | 360 }; |
| 366 | 361 |
| 367 StaticSocketDataProvider data1(reads, arraysize(reads), NULL, 0); | 362 StaticSocketDataProvider data1(reads, arraysize(reads), NULL, 0); |
| 368 data1.set_connect_data(connect_data); | 363 data1.set_connect_data(connect_data); |
| 369 session_deps_.socket_factory->AddSocketDataProvider(&data1); | 364 session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 370 | 365 |
| 371 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 366 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 372 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 367 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 373 | 368 |
| 374 CreateNetworkSession(); | 369 CreateNetworkSession(); |
| 375 | 370 |
| 376 // Setup the first session to the first host. | 371 // Setup the first session to the first host. |
| 377 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( | 372 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( |
| 378 http_session_.get(), test_hosts[0].key, BoundNetLog()); | 373 http_session_.get(), test_hosts[0].key, NetLogWithSource()); |
| 379 | 374 |
| 380 // Flush the SpdySession::OnReadComplete() task. | 375 // Flush the SpdySession::OnReadComplete() task. |
| 381 base::RunLoop().RunUntilIdle(); | 376 base::RunLoop().RunUntilIdle(); |
| 382 | 377 |
| 383 // The third host has no overlap with the first, so it can't pool IPs. | 378 // The third host has no overlap with the first, so it can't pool IPs. |
| 384 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 379 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 385 | 380 |
| 386 // The second host overlaps with the first, and should IP pool. | 381 // The second host overlaps with the first, and should IP pool. |
| 387 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 382 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 388 | 383 |
| 389 // Verify that the second host, through a proxy, won't share the IP. | 384 // Verify that the second host, through a proxy, won't share the IP. |
| 390 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), | 385 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), |
| 391 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), | 386 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), |
| 392 PRIVACY_MODE_DISABLED); | 387 PRIVACY_MODE_DISABLED); |
| 393 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); | 388 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); |
| 394 | 389 |
| 395 // Overlap between 2 and 3 does is not transitive to 1. | 390 // Overlap between 2 and 3 does is not transitive to 1. |
| 396 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 391 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 397 | 392 |
| 398 // Create a new session to host 2. | 393 // Create a new session to host 2. |
| 399 StaticSocketDataProvider data2(reads, arraysize(reads), NULL, 0); | 394 StaticSocketDataProvider data2(reads, arraysize(reads), NULL, 0); |
| 400 data2.set_connect_data(connect_data); | 395 data2.set_connect_data(connect_data); |
| 401 session_deps_.socket_factory->AddSocketDataProvider(&data2); | 396 session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 402 base::WeakPtr<SpdySession> session2 = CreateInsecureSpdySession( | 397 base::WeakPtr<SpdySession> session2 = CreateInsecureSpdySession( |
| 403 http_session_.get(), test_hosts[2].key, BoundNetLog()); | 398 http_session_.get(), test_hosts[2].key, NetLogWithSource()); |
| 404 | 399 |
| 405 // Verify that we have sessions for everything. | 400 // Verify that we have sessions for everything. |
| 406 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); | 401 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); |
| 407 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 402 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 408 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 403 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
| 409 | 404 |
| 410 // Grab the session to host 1 and verify that it is the same session | 405 // Grab the session to host 1 and verify that it is the same session |
| 411 // we got with host 0, and that is a different from host 2's session. | 406 // we got with host 0, and that is a different from host 2's session. |
| 412 base::WeakPtr<SpdySession> session1 = | 407 base::WeakPtr<SpdySession> session1 = |
| 413 spdy_session_pool_->FindAvailableSession( | 408 spdy_session_pool_->FindAvailableSession( |
| 414 test_hosts[1].key, GURL(test_hosts[1].url), BoundNetLog()); | 409 test_hosts[1].key, GURL(test_hosts[1].url), NetLogWithSource()); |
| 415 EXPECT_EQ(session.get(), session1.get()); | 410 EXPECT_EQ(session.get(), session1.get()); |
| 416 EXPECT_NE(session2.get(), session1.get()); | 411 EXPECT_NE(session2.get(), session1.get()); |
| 417 | 412 |
| 418 // Remove the aliases and observe that we still have a session for host1. | 413 // Remove the aliases and observe that we still have a session for host1. |
| 419 SpdySessionPoolPeer pool_peer(spdy_session_pool_); | 414 SpdySessionPoolPeer pool_peer(spdy_session_pool_); |
| 420 pool_peer.RemoveAliases(test_hosts[0].key); | 415 pool_peer.RemoveAliases(test_hosts[0].key); |
| 421 pool_peer.RemoveAliases(test_hosts[1].key); | 416 pool_peer.RemoveAliases(test_hosts[1].key); |
| 422 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 417 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 423 | 418 |
| 424 // Expire the host cache | 419 // Expire the host cache |
| 425 session_deps_.host_resolver->GetHostCache()->clear(); | 420 session_deps_.host_resolver->GetHostCache()->clear(); |
| 426 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 421 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
| 427 | 422 |
| 428 // Cleanup the sessions. | 423 // Cleanup the sessions. |
| 429 switch (close_sessions_type) { | 424 switch (close_sessions_type) { |
| 430 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: | 425 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: |
| 431 session->CloseSessionOnError(ERR_ABORTED, std::string()); | 426 session->CloseSessionOnError(ERR_ABORTED, std::string()); |
| 432 session2->CloseSessionOnError(ERR_ABORTED, std::string()); | 427 session2->CloseSessionOnError(ERR_ABORTED, std::string()); |
| 433 base::RunLoop().RunUntilIdle(); | 428 base::RunLoop().RunUntilIdle(); |
| 434 EXPECT_FALSE(session); | 429 EXPECT_FALSE(session); |
| 435 EXPECT_FALSE(session2); | 430 EXPECT_FALSE(session2); |
| 436 break; | 431 break; |
| 437 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: | 432 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: |
| 438 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); | 433 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); |
| 439 break; | 434 break; |
| 440 case SPDY_POOL_CLOSE_IDLE_SESSIONS: | 435 case SPDY_POOL_CLOSE_IDLE_SESSIONS: |
| 441 GURL url(test_hosts[0].url); | 436 GURL url(test_hosts[0].url); |
| 442 base::WeakPtr<SpdyStream> spdy_stream = | 437 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( |
| 443 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 438 SPDY_BIDIRECTIONAL_STREAM, session, url, MEDIUM, NetLogWithSource()); |
| 444 session, url, MEDIUM, BoundNetLog()); | |
| 445 GURL url1(test_hosts[1].url); | 439 GURL url1(test_hosts[1].url); |
| 446 base::WeakPtr<SpdyStream> spdy_stream1 = | 440 base::WeakPtr<SpdyStream> spdy_stream1 = |
| 447 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 441 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, session1, url1, |
| 448 session1, url1, MEDIUM, BoundNetLog()); | 442 MEDIUM, NetLogWithSource()); |
| 449 GURL url2(test_hosts[2].url); | 443 GURL url2(test_hosts[2].url); |
| 450 base::WeakPtr<SpdyStream> spdy_stream2 = | 444 base::WeakPtr<SpdyStream> spdy_stream2 = |
| 451 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 445 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, session2, url2, |
| 452 session2, url2, MEDIUM, BoundNetLog()); | 446 MEDIUM, NetLogWithSource()); |
| 453 | 447 |
| 454 // Close streams to make spdy_session and spdy_session1 inactive. | 448 // Close streams to make spdy_session and spdy_session1 inactive. |
| 455 session->CloseCreatedStream(spdy_stream, OK); | 449 session->CloseCreatedStream(spdy_stream, OK); |
| 456 EXPECT_FALSE(spdy_stream); | 450 EXPECT_FALSE(spdy_stream); |
| 457 session1->CloseCreatedStream(spdy_stream1, OK); | 451 session1->CloseCreatedStream(spdy_stream1, OK); |
| 458 EXPECT_FALSE(spdy_stream1); | 452 EXPECT_FALSE(spdy_stream1); |
| 459 | 453 |
| 460 // Check spdy_session and spdy_session1 are not closed. | 454 // Check spdy_session and spdy_session1 are not closed. |
| 461 EXPECT_FALSE(session->is_active()); | 455 EXPECT_FALSE(session->is_active()); |
| 462 EXPECT_TRUE(session->IsAvailable()); | 456 EXPECT_TRUE(session->IsAvailable()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 528 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 535 | 529 |
| 536 CreateNetworkSession(); | 530 CreateNetworkSession(); |
| 537 | 531 |
| 538 // Set up session A: Going away, but with an active stream. | 532 // Set up session A: Going away, but with an active stream. |
| 539 const std::string kTestHostA("http://www.a.com"); | 533 const std::string kTestHostA("http://www.a.com"); |
| 540 HostPortPair test_host_port_pairA(kTestHostA, 80); | 534 HostPortPair test_host_port_pairA(kTestHostA, 80); |
| 541 SpdySessionKey keyA( | 535 SpdySessionKey keyA( |
| 542 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 536 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 543 base::WeakPtr<SpdySession> sessionA = | 537 base::WeakPtr<SpdySession> sessionA = |
| 544 CreateInsecureSpdySession(http_session_.get(), keyA, BoundNetLog()); | 538 CreateInsecureSpdySession(http_session_.get(), keyA, NetLogWithSource()); |
| 545 | 539 |
| 546 GURL urlA(kTestHostA); | 540 GURL urlA(kTestHostA); |
| 547 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( | 541 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( |
| 548 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, BoundNetLog()); | 542 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, NetLogWithSource()); |
| 549 test::StreamDelegateDoNothing delegateA(spdy_streamA); | 543 test::StreamDelegateDoNothing delegateA(spdy_streamA); |
| 550 spdy_streamA->SetDelegate(&delegateA); | 544 spdy_streamA->SetDelegate(&delegateA); |
| 551 | 545 |
| 552 SpdyHeaderBlock headers(spdy_util.ConstructGetHeaderBlock(urlA.spec())); | 546 SpdyHeaderBlock headers(spdy_util.ConstructGetHeaderBlock(urlA.spec())); |
| 553 spdy_streamA->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); | 547 spdy_streamA->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
| 554 | 548 |
| 555 base::RunLoop().RunUntilIdle(); // Allow headers to write. | 549 base::RunLoop().RunUntilIdle(); // Allow headers to write. |
| 556 EXPECT_TRUE(delegateA.send_headers_completed()); | 550 EXPECT_TRUE(delegateA.send_headers_completed()); |
| 557 | 551 |
| 558 sessionA->MakeUnavailable(); | 552 sessionA->MakeUnavailable(); |
| 559 EXPECT_TRUE(sessionA->IsGoingAway()); | 553 EXPECT_TRUE(sessionA->IsGoingAway()); |
| 560 EXPECT_FALSE(delegateA.StreamIsClosed()); | 554 EXPECT_FALSE(delegateA.StreamIsClosed()); |
| 561 | 555 |
| 562 // Set up session B: Available, with a created stream. | 556 // Set up session B: Available, with a created stream. |
| 563 StaticSocketDataProvider dataB(reads, arraysize(reads), writes, | 557 StaticSocketDataProvider dataB(reads, arraysize(reads), writes, |
| 564 arraysize(writes)); | 558 arraysize(writes)); |
| 565 dataB.set_connect_data(connect_data); | 559 dataB.set_connect_data(connect_data); |
| 566 session_deps_.socket_factory->AddSocketDataProvider(&dataB); | 560 session_deps_.socket_factory->AddSocketDataProvider(&dataB); |
| 567 const std::string kTestHostB("http://www.b.com"); | 561 const std::string kTestHostB("http://www.b.com"); |
| 568 HostPortPair test_host_port_pairB(kTestHostB, 80); | 562 HostPortPair test_host_port_pairB(kTestHostB, 80); |
| 569 SpdySessionKey keyB( | 563 SpdySessionKey keyB( |
| 570 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 564 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 571 base::WeakPtr<SpdySession> sessionB = | 565 base::WeakPtr<SpdySession> sessionB = |
| 572 CreateInsecureSpdySession(http_session_.get(), keyB, BoundNetLog()); | 566 CreateInsecureSpdySession(http_session_.get(), keyB, NetLogWithSource()); |
| 573 EXPECT_TRUE(sessionB->IsAvailable()); | 567 EXPECT_TRUE(sessionB->IsAvailable()); |
| 574 | 568 |
| 575 GURL urlB(kTestHostB); | 569 GURL urlB(kTestHostB); |
| 576 base::WeakPtr<SpdyStream> spdy_streamB = CreateStreamSynchronously( | 570 base::WeakPtr<SpdyStream> spdy_streamB = CreateStreamSynchronously( |
| 577 SPDY_BIDIRECTIONAL_STREAM, sessionB, urlB, MEDIUM, BoundNetLog()); | 571 SPDY_BIDIRECTIONAL_STREAM, sessionB, urlB, MEDIUM, NetLogWithSource()); |
| 578 test::StreamDelegateDoNothing delegateB(spdy_streamB); | 572 test::StreamDelegateDoNothing delegateB(spdy_streamB); |
| 579 spdy_streamB->SetDelegate(&delegateB); | 573 spdy_streamB->SetDelegate(&delegateB); |
| 580 | 574 |
| 581 // Set up session C: Draining. | 575 // Set up session C: Draining. |
| 582 StaticSocketDataProvider dataC(reads, arraysize(reads), writes, | 576 StaticSocketDataProvider dataC(reads, arraysize(reads), writes, |
| 583 arraysize(writes)); | 577 arraysize(writes)); |
| 584 dataC.set_connect_data(connect_data); | 578 dataC.set_connect_data(connect_data); |
| 585 session_deps_.socket_factory->AddSocketDataProvider(&dataC); | 579 session_deps_.socket_factory->AddSocketDataProvider(&dataC); |
| 586 const std::string kTestHostC("http://www.c.com"); | 580 const std::string kTestHostC("http://www.c.com"); |
| 587 HostPortPair test_host_port_pairC(kTestHostC, 80); | 581 HostPortPair test_host_port_pairC(kTestHostC, 80); |
| 588 SpdySessionKey keyC( | 582 SpdySessionKey keyC( |
| 589 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 583 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 590 base::WeakPtr<SpdySession> sessionC = | 584 base::WeakPtr<SpdySession> sessionC = |
| 591 CreateInsecureSpdySession(http_session_.get(), keyC, BoundNetLog()); | 585 CreateInsecureSpdySession(http_session_.get(), keyC, NetLogWithSource()); |
| 592 | 586 |
| 593 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); | 587 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); |
| 594 EXPECT_TRUE(sessionC->IsDraining()); | 588 EXPECT_TRUE(sessionC->IsDraining()); |
| 595 | 589 |
| 596 spdy_session_pool_->OnIPAddressChanged(); | 590 spdy_session_pool_->OnIPAddressChanged(); |
| 597 | 591 |
| 598 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 592 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
| 599 EXPECT_TRUE(sessionA->IsGoingAway()); | 593 EXPECT_TRUE(sessionA->IsGoingAway()); |
| 600 EXPECT_TRUE(sessionB->IsDraining()); | 594 EXPECT_TRUE(sessionB->IsDraining()); |
| 601 EXPECT_TRUE(sessionC->IsDraining()); | 595 EXPECT_TRUE(sessionC->IsDraining()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); | 627 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 634 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 628 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| 635 session_deps_.socket_factory->AddSocketDataProvider(&data); | 629 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 636 | 630 |
| 637 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 631 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 638 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 632 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 639 | 633 |
| 640 CreateNetworkSession(); | 634 CreateNetworkSession(); |
| 641 | 635 |
| 642 base::WeakPtr<SpdySession> session = | 636 base::WeakPtr<SpdySession> session = |
| 643 CreateInsecureSpdySession(http_session_.get(), key, BoundNetLog()); | 637 CreateInsecureSpdySession(http_session_.get(), key, NetLogWithSource()); |
| 644 | 638 |
| 645 // Flush the SpdySession::OnReadComplete() task. | 639 // Flush the SpdySession::OnReadComplete() task. |
| 646 base::RunLoop().RunUntilIdle(); | 640 base::RunLoop().RunUntilIdle(); |
| 647 | 641 |
| 648 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key)); | 642 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key)); |
| 649 | 643 |
| 650 // FindAvailableSession should return |session| if called with empty |url|. | 644 // FindAvailableSession should return |session| if called with empty |url|. |
| 651 base::WeakPtr<SpdySession> session1 = | 645 base::WeakPtr<SpdySession> session1 = |
| 652 spdy_session_pool_->FindAvailableSession(key, GURL(), BoundNetLog()); | 646 spdy_session_pool_->FindAvailableSession(key, GURL(), NetLogWithSource()); |
| 653 EXPECT_EQ(session.get(), session1.get()); | 647 EXPECT_EQ(session.get(), session1.get()); |
| 654 | 648 |
| 655 // FindAvailableSession should return |session| if called with |url| for which | 649 // FindAvailableSession should return |session| if called with |url| for which |
| 656 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. | 650 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. |
| 657 base::WeakPtr<SpdySession> session2 = | 651 base::WeakPtr<SpdySession> session2 = |
| 658 spdy_session_pool_->FindAvailableSession( | 652 spdy_session_pool_->FindAvailableSession( |
| 659 key, GURL("http://news.example.org/foo.html"), BoundNetLog()); | 653 key, GURL("http://news.example.org/foo.html"), NetLogWithSource()); |
| 660 EXPECT_EQ(session.get(), session2.get()); | 654 EXPECT_EQ(session.get(), session2.get()); |
| 661 | 655 |
| 662 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); | 656 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); |
| 663 } | 657 } |
| 664 | 658 |
| 665 } // namespace net | 659 } // namespace net |
| OLD | NEW |