OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 2282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2293 base::RunLoop().RunUntilIdle(); | 2293 base::RunLoop().RunUntilIdle(); |
2294 EXPECT_TRUE(pool->IsStalled()); | 2294 EXPECT_TRUE(pool->IsStalled()); |
2295 EXPECT_FALSE(callback2.have_result()); | 2295 EXPECT_FALSE(callback2.have_result()); |
2296 | 2296 |
2297 // Release the pointer to the session so it can be closed. | 2297 // Release the pointer to the session so it can be closed. |
2298 session1 = NULL; | 2298 session1 = NULL; |
2299 EXPECT_EQ(OK, callback2.WaitForResult()); | 2299 EXPECT_EQ(OK, callback2.WaitForResult()); |
2300 EXPECT_FALSE(pool->IsStalled()); | 2300 EXPECT_FALSE(pool->IsStalled()); |
2301 } | 2301 } |
2302 | 2302 |
2303 // Tests that a non-SPDY request can't close a SPDY session that's currently in | 2303 // Tests that when a SPDY session becomes idle, it closes itself if there is |
2304 // use. | 2304 // a lower layer pool stalled on the per-pool socket limit. |
2305 TEST_P(SpdySessionTest, CloseOneIdleConnectionFailsWhenSessionInUse) { | 2305 TEST_P(SpdySessionTest, CloseSessionOnIdleWhenPoolStalled) { |
2306 ClientSocketPoolManager::set_max_sockets_per_group( | 2306 ClientSocketPoolManager::set_max_sockets_per_group( |
2307 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 2307 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
2308 ClientSocketPoolManager::set_max_sockets_per_pool( | 2308 ClientSocketPoolManager::set_max_sockets_per_pool( |
2309 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | 2309 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
2310 | 2310 |
2311 MockConnect connect_data(SYNCHRONOUS, OK); | 2311 MockConnect connect_data(SYNCHRONOUS, OK); |
2312 MockRead reads[] = { | 2312 MockRead reads[] = { |
2313 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 2313 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
2314 }; | 2314 }; |
2315 scoped_ptr<SpdyFrame> req1( | 2315 scoped_ptr<SpdyFrame> req1( |
2316 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2316 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
2317 scoped_ptr<SpdyFrame> cancel1( | 2317 scoped_ptr<SpdyFrame> cancel1( |
2318 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 2318 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
2319 MockWrite writes[] = { | 2319 MockWrite writes[] = { |
2320 CreateMockWrite(*req1, 1), | 2320 CreateMockWrite(*req1, 1), |
2321 CreateMockWrite(*cancel1, 1), | 2321 CreateMockWrite(*cancel1, 1), |
2322 }; | 2322 }; |
2323 StaticSocketDataProvider data(reads, arraysize(reads), | 2323 StaticSocketDataProvider data(reads, arraysize(reads), |
2324 writes, arraysize(writes)); | 2324 writes, arraysize(writes)); |
2325 data.set_connect_data(connect_data); | 2325 data.set_connect_data(connect_data); |
2326 session_deps_.socket_factory->AddSocketDataProvider(&data); | 2326 session_deps_.socket_factory->AddSocketDataProvider(&data); |
2327 | 2327 |
| 2328 MockRead http_reads[] = { |
| 2329 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 2330 }; |
| 2331 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 2332 NULL, 0); |
| 2333 http_data.set_connect_data(connect_data); |
| 2334 session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 2335 |
| 2336 |
2328 CreateNetworkSession(); | 2337 CreateNetworkSession(); |
2329 | 2338 |
2330 TransportClientSocketPool* pool = | 2339 TransportClientSocketPool* pool = |
2331 http_session_->GetTransportSocketPool( | 2340 http_session_->GetTransportSocketPool( |
2332 HttpNetworkSession::NORMAL_SOCKET_POOL); | 2341 HttpNetworkSession::NORMAL_SOCKET_POOL); |
2333 | 2342 |
2334 // Create a SPDY session. | 2343 // Create a SPDY session. |
2335 GURL url1("http://www.google.com"); | 2344 GURL url1("http://www.google.com"); |
2336 SpdySessionKey key1(HostPortPair(url1.host(), 80), | 2345 SpdySessionKey key1(HostPortPair(url1.host(), 80), |
2337 ProxyServer::Direct(), kPrivacyModeDisabled); | 2346 ProxyServer::Direct(), kPrivacyModeDisabled); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2376 callback2.callback(), pool, BoundNetLog())); | 2385 callback2.callback(), pool, BoundNetLog())); |
2377 EXPECT_TRUE(pool->IsStalled()); | 2386 EXPECT_TRUE(pool->IsStalled()); |
2378 | 2387 |
2379 // Running the message loop should cause the socket pool to ask the SPDY | 2388 // Running the message loop should cause the socket pool to ask the SPDY |
2380 // session to close an idle socket, but since the socket is in use, nothing | 2389 // session to close an idle socket, but since the socket is in use, nothing |
2381 // happens. | 2390 // happens. |
2382 base::RunLoop().RunUntilIdle(); | 2391 base::RunLoop().RunUntilIdle(); |
2383 EXPECT_TRUE(pool->IsStalled()); | 2392 EXPECT_TRUE(pool->IsStalled()); |
2384 EXPECT_FALSE(callback2.have_result()); | 2393 EXPECT_FALSE(callback2.have_result()); |
2385 | 2394 |
2386 // Cancelling the request should still not release the session's socket, | 2395 // Cancelling the request should result in the session's socket being |
2387 // since the session is still kept alive by the SpdySessionPool. | 2396 // closed, since the pool is stalled. |
2388 ASSERT_TRUE(spdy_stream1.get()); | 2397 ASSERT_TRUE(spdy_stream1.get()); |
2389 spdy_stream1->Cancel(); | 2398 spdy_stream1->Cancel(); |
2390 base::RunLoop().RunUntilIdle(); | 2399 base::RunLoop().RunUntilIdle(); |
2391 EXPECT_TRUE(pool->IsStalled()); | 2400 ASSERT_FALSE(pool->IsStalled()); |
2392 EXPECT_FALSE(callback2.have_result()); | 2401 EXPECT_EQ(OK, callback2.WaitForResult()); |
2393 } | 2402 } |
2394 | 2403 |
2395 // Verify that SpdySessionKey and therefore SpdySession is different when | 2404 // Verify that SpdySessionKey and therefore SpdySession is different when |
2396 // privacy mode is enabled or disabled. | 2405 // privacy mode is enabled or disabled. |
2397 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) { | 2406 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) { |
2398 CreateDeterministicNetworkSession(); | 2407 CreateDeterministicNetworkSession(); |
2399 | 2408 |
2400 HostPortPair host_port_pair("www.google.com", 443); | 2409 HostPortPair host_port_pair("www.google.com", 443); |
2401 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), | 2410 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), |
2402 kPrivacyModeEnabled); | 2411 kPrivacyModeEnabled); |
(...skipping 1155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3558 EXPECT_TRUE(delegate1.send_headers_completed()); | 3567 EXPECT_TRUE(delegate1.send_headers_completed()); |
3559 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 3568 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
3560 | 3569 |
3561 EXPECT_TRUE(delegate2.send_headers_completed()); | 3570 EXPECT_TRUE(delegate2.send_headers_completed()); |
3562 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 3571 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
3563 | 3572 |
3564 EXPECT_TRUE(data.at_write_eof()); | 3573 EXPECT_TRUE(data.at_write_eof()); |
3565 } | 3574 } |
3566 | 3575 |
3567 } // namespace net | 3576 } // namespace net |
OLD | NEW |