Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1934)

Unified Diff: net/http/http_network_transaction_unittest.cc

Issue 7471056: Minor cleanup of unit tests for spdy_session_ool. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/spdy/spdy_session_pool.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_network_transaction_unittest.cc
===================================================================
--- net/http/http_network_transaction_unittest.cc (revision 93322)
+++ net/http/http_network_transaction_unittest.cc (working copy)
@@ -8702,35 +8702,32 @@
}
}
-void IPPoolingPreloadHostCache(MockCachingHostResolver* host_resolver,
- SpdySessionPoolPeer* pool_peer) {
- const int kTestPort = 443;
- struct TestHosts {
- std::string name;
- std::string iplist;
- } test_hosts[] = {
- { "www.google.com", "127.0.0.1"},
- };
+void IPPoolingAddAlias(MockCachingHostResolver* host_resolver,
+ SpdySessionPoolPeer* pool_peer,
+ std::string host,
+ int port,
+ std::string iplist) {
+ // Create a host resolver dependency that returns address |iplist| for
+ // resolutions of |host|.
+ host_resolver->rules()->AddIPLiteralRule(host, iplist, "");
- // Preload cache entries into HostCache.
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) {
- host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name,
- test_hosts[i].iplist, "");
+ // Setup a HostPortProxyPair.
+ HostPortPair host_port_pair(host, port);
+ HostPortProxyPair pair = HostPortProxyPair(host_port_pair,
+ ProxyServer::Direct());
- AddressList addresses;
- // 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));
- host_resolver->Resolve(
- info, &addresses, NULL, NULL, BoundNetLog());
+ // Resolve the host and port.
+ AddressList addresses;
+ HostResolver::RequestInfo info(host_port_pair);
+ host_resolver->Resolve(info, &addresses, NULL, NULL, BoundNetLog());
- // Setup a HostPortProxyPair
- HostPortProxyPair pair = HostPortProxyPair(
- HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct());
-
- const addrinfo* address = addresses.head();
- pool_peer->AddAlias(address, pair);
- }
+ // Add the first address as an alias. It would have been better to call
+ // MockClientSocket::GetPeerAddress but that returns 192.0.2.33 whereas
+ // MockHostResolver returns 127.0.0.1 (MockHostResolverBase::Reset). So we use
+ // the first address (127.0.0.1) returned by MockHostResolver as an alias for
+ // the |pair|.
+ const addrinfo* address = addresses.head();
+ pool_peer->AddAlias(address, pair);
}
TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) {
@@ -8811,7 +8808,11 @@
AddressList ignored;
host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog());
- IPPoolingPreloadHostCache(&host_resolver, &pool_peer);
+ // MockHostResolver returns 127.0.0.1, port 443 for https://www.google.com/
+ // and https://www.gmail.com/. Add 127.0.0.1 as alias for host_port_pair:
+ // (www.google.com, 443).
+ IPPoolingAddAlias(&host_resolver, &pool_peer, "www.google.com", 443,
+ "127.0.0.1");
HttpRequestInfo request2;
request2.method = "GET";
@@ -8965,7 +8966,11 @@
request2.load_flags = 0;
HttpNetworkTransaction trans2(session);
- IPPoolingPreloadHostCache(host_resolver.GetMockHostResolver(), &pool_peer);
+ // MockHostResolver returns 127.0.0.1, port 443 for https://www.google.com/
+ // and https://www.gmail.com/. Add 127.0.0.1 as alias for host_port_pair:
+ // (www.google.com, 443).
+ IPPoolingAddAlias(host_resolver.GetMockHostResolver(), &pool_peer,
+ "www.google.com", 443, "127.0.0.1");
rv = trans2.Start(&request2, &callback, BoundNetLog());
EXPECT_EQ(ERR_IO_PENDING, rv);
« no previous file with comments | « no previous file | net/spdy/spdy_session_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698