Index: net/spdy/spdy_session_unittest.cc |
=================================================================== |
--- net/spdy/spdy_session_unittest.cc (revision 92397) |
+++ net/spdy/spdy_session_unittest.cc (working copy) |
@@ -19,10 +19,125 @@ |
static void TurnOffCompression() { |
spdy::SpdyFramer::set_enable_compression_default(false); |
} |
+ |
+ // This test has two variants, one for each style of closing the connection. |
willchan no longer on Chromium
2011/07/17 01:23:45
Did you just move this to gain the friend access?
ramant (doing other things)
2011/07/17 08:12:30
Done.
|
+ // If |clean_via_close_current_sessions| is false, the sessions are closed |
+ // manually, calling SpdySessionPool::Remove() directly. If it is true, |
+ // sessions are closed with SpdySessionPool::CloseCurrentSessions(). |
+ static void IPPoolingTest(bool clean_via_close_current_sessions) { |
+ const int kTestPort = 80; |
+ struct TestHosts { |
+ std::string name; |
+ std::string iplist; |
+ HostPortProxyPair pair; |
+ } test_hosts[] = { |
+ { "www.foo.com", "192.168.0.1,192.168.0.5" }, |
+ { "images.foo.com", "192.168.0.1,192.168.0.2,192.168.0.3" }, |
+ { "js.foo.com", "192.168.0.4,192.168.0.3" }, |
+ }; |
+ |
+ SpdySessionDependencies session_deps; |
+ session_deps.host_resolver->set_synchronous_mode(true); |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { |
+ session_deps.host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name, |
+ test_hosts[i].iplist, ""); |
+ |
+ // This test requires that the HostResolver cache be populated. Normal |
+ // code would have done this already, but we do it manually. |
+ HostResolver::RequestInfo info( |
+ HostPortPair(test_hosts[i].name, kTestPort)); |
+ AddressList result; |
+ session_deps.host_resolver->Resolve( |
+ info, &result, NULL, NULL, BoundNetLog()); |
+ |
+ // Setup a HostPortProxyPair |
+ test_hosts[i].pair = HostPortProxyPair( |
+ HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); |
+ } |
+ |
+ MockConnect connect_data(false, OK); |
+ MockRead reads[] = { |
+ MockRead(false, ERR_IO_PENDING) // Stall forever. |
+ }; |
+ |
+ StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
+ data.set_connect_data(connect_data); |
+ session_deps.socket_factory->AddSocketDataProvider(&data); |
+ |
+ SSLSocketDataProvider ssl(false, OK); |
+ session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
+ |
+ scoped_refptr<HttpNetworkSession> http_session( |
+ SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
+ |
+ // Setup the first session to the first host. |
+ SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
+ EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
+ scoped_refptr<SpdySession> session = |
+ spdy_session_pool->Get(test_hosts[0].pair, BoundNetLog()); |
+ EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
+ |
+ HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); |
+ scoped_refptr<TransportSocketParams> transport_params( |
+ new TransportSocketParams(test_host_port_pair, |
+ MEDIUM, |
+ GURL(), |
+ false, |
+ false)); |
+ scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
+ EXPECT_EQ(OK, |
+ connection->Init(test_host_port_pair.ToString(), |
+ transport_params, MEDIUM, |
+ NULL, http_session->transport_socket_pool(), |
+ BoundNetLog())); |
+ spdy_session_pool->AddAliases(test_hosts[0].pair); |
+ EXPECT_EQ(OK, |
+ session->InitializeWithSocket(connection.release(), false, OK)); |
+ |
+ // Flush the SpdySession::OnReadComplete() task. |
+ MessageLoop::current()->RunAllPending(); |
+ |
+ // The third host has no overlap with the first, so it can't pool IPs. |
+ EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
+ |
+ // The second host overlaps with the first, and should IP pool. |
+ EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); |
+ |
+ // Verify that the second host, through a proxy, won't share the IP. |
+ HostPortProxyPair proxy_pair(test_hosts[1].pair.first, |
+ ProxyServer::FromPacString("HTTP http://proxy.foo.com/")); |
+ EXPECT_FALSE(spdy_session_pool->HasSession(proxy_pair)); |
+ |
+ // Overlap between 2 and 3 does is not transitive to 1. |
+ EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
+ |
+ // Create a new session to host 2. |
+ scoped_refptr<SpdySession> session2 = |
+ spdy_session_pool->Get(test_hosts[2].pair, BoundNetLog()); |
+ |
+ // Verify that we have sessions for everything. |
+ EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
+ EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); |
+ EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
+ |
+ // Cleanup the sessions. |
+ if (!clean_via_close_current_sessions) { |
+ spdy_session_pool->Remove(session); |
+ session = NULL; |
+ spdy_session_pool->Remove(session2); |
+ session2 = NULL; |
+ } else { |
+ spdy_session_pool->CloseCurrentSessions(); |
+ } |
+ |
+ // Verify that the map is all cleaned up. |
+ EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
+ EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[1].pair)); |
+ EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
+ } |
+ |
}; |
-namespace { |
- |
// Test the SpdyIOBuffer class. |
TEST_F(SpdySessionTest, SpdyIOBuffer) { |
std::priority_queue<SpdyIOBuffer> queue_; |
@@ -103,6 +218,7 @@ |
transport_params, MEDIUM, |
NULL, http_session->transport_socket_pool(), |
BoundNetLog())); |
+ spdy_session_pool->AddAliases(pair); |
willchan no longer on Chromium
2011/07/17 01:23:45
Why is this necessary?
ramant (doing other things)
2011/07/17 08:12:30
Done.
|
EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
// Flush the SpdySession::OnReadComplete() task. |
@@ -215,6 +331,7 @@ |
transport_params, MEDIUM, |
NULL, http_session->transport_socket_pool(), |
BoundNetLog())); |
+ spdy_session_pool->AddAliases(pair); |
willchan no longer on Chromium
2011/07/17 01:23:45
Why is this necessary?
ramant (doing other things)
2011/07/17 08:12:30
Done.
|
EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
// Create 2 streams. First will succeed. Second will be pending. |
@@ -301,6 +418,7 @@ |
transport_params, MEDIUM, |
NULL, http_session->transport_socket_pool(), |
BoundNetLog())); |
+ spdy_session_pool->AddAliases(pair); |
willchan no longer on Chromium
2011/07/17 01:23:45
Why is this necessary?
ramant (doing other things)
2011/07/17 08:12:30
Done.
|
EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
// Use scoped_ptr to let us invalidate the memory when we want to, to trigger |
@@ -401,130 +519,18 @@ |
transport_params, MEDIUM, |
NULL, http_session->transport_socket_pool(), |
BoundNetLog())); |
+ spdy_session_pool->AddAliases(pair); |
willchan no longer on Chromium
2011/07/17 01:23:45
Ditto
ramant (doing other things)
2011/07/17 08:12:30
Done.
|
EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
MessageLoop::current()->RunAllPending(); |
EXPECT_TRUE(data.at_write_eof()); |
} |
-// This test has two variants, one for each style of closing the connection. |
-// If |clean_via_close_current_sessions| is false, the sessions are closed |
-// manually, calling SpdySessionPool::Remove() directly. If it is true, |
-// sessions are closed with SpdySessionPool::CloseCurrentSessions(). |
-void IPPoolingTest(bool clean_via_close_current_sessions) { |
- const int kTestPort = 80; |
- struct TestHosts { |
- std::string name; |
- std::string iplist; |
- HostPortProxyPair pair; |
- } test_hosts[] = { |
- { "www.foo.com", "192.168.0.1,192.168.0.5" }, |
- { "images.foo.com", "192.168.0.2,192.168.0.3,192.168.0.5" }, |
- { "js.foo.com", "192.168.0.4,192.168.0.3" }, |
- }; |
- |
- SpdySessionDependencies session_deps; |
- session_deps.host_resolver->set_synchronous_mode(true); |
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { |
- session_deps.host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name, |
- test_hosts[i].iplist, ""); |
- |
- // This test requires that the HostResolver cache be populated. Normal |
- // code would have done this already, but we do it manually. |
- HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); |
- AddressList result; |
- session_deps.host_resolver->Resolve( |
- info, &result, NULL, NULL, BoundNetLog()); |
- |
- // Setup a HostPortProxyPair |
- test_hosts[i].pair = HostPortProxyPair( |
- HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); |
- } |
- |
- MockConnect connect_data(false, OK); |
- MockRead reads[] = { |
- MockRead(false, ERR_IO_PENDING) // Stall forever. |
- }; |
- |
- StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
- data.set_connect_data(connect_data); |
- session_deps.socket_factory->AddSocketDataProvider(&data); |
- |
- SSLSocketDataProvider ssl(false, OK); |
- session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
- |
- scoped_refptr<HttpNetworkSession> http_session( |
- SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
- |
- // Setup the first session to the first host. |
- SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
- EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
- scoped_refptr<SpdySession> session = |
- spdy_session_pool->Get(test_hosts[0].pair, BoundNetLog()); |
- EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
- |
- HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); |
- scoped_refptr<TransportSocketParams> transport_params( |
- new TransportSocketParams(test_host_port_pair, |
- MEDIUM, |
- GURL(), |
- false, |
- false)); |
- scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
- EXPECT_EQ(OK, |
- connection->Init(test_host_port_pair.ToString(), |
- transport_params, MEDIUM, |
- NULL, http_session->transport_socket_pool(), |
- BoundNetLog())); |
- EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
- |
- // Flush the SpdySession::OnReadComplete() task. |
- MessageLoop::current()->RunAllPending(); |
- |
- // The third host has no overlap with the first, so it can't pool IPs. |
- EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
- |
- // The second host overlaps with the first, and should IP pool. |
- EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); |
- |
- // Verify that the second host, through a proxy, won't share the IP. |
- HostPortProxyPair proxy_pair(test_hosts[1].pair.first, |
- ProxyServer::FromPacString("HTTP http://proxy.foo.com/")); |
- EXPECT_FALSE(spdy_session_pool->HasSession(proxy_pair)); |
- |
- // Overlap between 2 and 3 does is not transitive to 1. |
- EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
- |
- // Create a new session to host 2. |
- scoped_refptr<SpdySession> session2 = |
- spdy_session_pool->Get(test_hosts[2].pair, BoundNetLog()); |
- |
- // Verify that we have sessions for everything. |
- EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
- EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[1].pair)); |
- EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
- |
- // Cleanup the sessions. |
- if (!clean_via_close_current_sessions) { |
- spdy_session_pool->Remove(session); |
- session = NULL; |
- spdy_session_pool->Remove(session2); |
- session2 = NULL; |
- } else { |
- spdy_session_pool->CloseCurrentSessions(); |
- } |
- |
- // Verify that the map is all cleaned up. |
- EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
- EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[1].pair)); |
- EXPECT_FALSE(spdy_session_pool->HasSession(test_hosts[2].pair)); |
-} |
- |
TEST_F(SpdySessionTest, IPPooling) { |
- IPPoolingTest(false); |
+ SpdySessionTest::IPPoolingTest(false); |
} |
TEST_F(SpdySessionTest, IPPoolingCloseCurrentSessions) { |
- IPPoolingTest(true); |
+ SpdySessionTest::IPPoolingTest(true); |
} |
TEST_F(SpdySessionTest, ClearSettingsStorage) { |
@@ -570,6 +576,4 @@ |
EXPECT_EQ(0u, test_settings_storage->Get(test_host_port_pair).size()); |
} |
-} // namespace |
- |
} // namespace net |