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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/spdy/spdy_session_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 8684 matching lines...) Expand 10 before | Expand all | Expand 10 after
8695 8695
8696 // Now that the new handshake has failed, ensure that the client 8696 // Now that the new handshake has failed, ensure that the client
8697 // certificate was removed from the client auth cache. 8697 // certificate was removed from the client auth cache.
8698 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70", 8698 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("proxy:70",
8699 &client_cert)); 8699 &client_cert));
8700 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443", 8700 ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup("www.example.com:443",
8701 &client_cert)); 8701 &client_cert));
8702 } 8702 }
8703 } 8703 }
8704 8704
8705 void IPPoolingPreloadHostCache(MockCachingHostResolver* host_resolver, 8705 void IPPoolingAddAlias(MockCachingHostResolver* host_resolver,
8706 SpdySessionPoolPeer* pool_peer) { 8706 SpdySessionPoolPeer* pool_peer,
8707 const int kTestPort = 443; 8707 std::string host,
8708 struct TestHosts { 8708 int port,
8709 std::string name; 8709 std::string iplist) {
8710 std::string iplist; 8710 // Create a host resolver dependency that returns address |iplist| for
8711 } test_hosts[] = { 8711 // resolutions of |host|.
8712 { "www.google.com", "127.0.0.1"}, 8712 host_resolver->rules()->AddIPLiteralRule(host, iplist, "");
8713 };
8714 8713
8715 // Preload cache entries into HostCache. 8714 // Setup a HostPortProxyPair.
8716 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { 8715 HostPortPair host_port_pair(host, port);
8717 host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name, 8716 HostPortProxyPair pair = HostPortProxyPair(host_port_pair,
8718 test_hosts[i].iplist, ""); 8717 ProxyServer::Direct());
8719 8718
8720 AddressList addresses; 8719 // Resolve the host and port.
8721 // This test requires that the HostResolver cache be populated. Normal 8720 AddressList addresses;
8722 // code would have done this already, but we do it manually. 8721 HostResolver::RequestInfo info(host_port_pair);
8723 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); 8722 host_resolver->Resolve(info, &addresses, NULL, NULL, BoundNetLog());
8724 host_resolver->Resolve(
8725 info, &addresses, NULL, NULL, BoundNetLog());
8726 8723
8727 // Setup a HostPortProxyPair 8724 // Add the first address as an alias. It would have been better to call
8728 HostPortProxyPair pair = HostPortProxyPair( 8725 // MockClientSocket::GetPeerAddress but that returns 192.0.2.33 whereas
8729 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); 8726 // MockHostResolver returns 127.0.0.1 (MockHostResolverBase::Reset). So we use
8730 8727 // the first address (127.0.0.1) returned by MockHostResolver as an alias for
8731 const addrinfo* address = addresses.head(); 8728 // the |pair|.
8732 pool_peer->AddAlias(address, pair); 8729 const addrinfo* address = addresses.head();
8733 } 8730 pool_peer->AddAlias(address, pair);
8734 } 8731 }
8735 8732
8736 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { 8733 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) {
8737 HttpStreamFactory::set_use_alternate_protocols(true); 8734 HttpStreamFactory::set_use_alternate_protocols(true);
8738 HttpStreamFactory::set_next_protos(kExpectedNPNString); 8735 HttpStreamFactory::set_next_protos(kExpectedNPNString);
8739 8736
8740 // Set up a special HttpNetworkSession with a MockCachingHostResolver. 8737 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
8741 SessionDependencies session_deps; 8738 SessionDependencies session_deps;
8742 MockCachingHostResolver host_resolver; 8739 MockCachingHostResolver host_resolver;
8743 net::HttpNetworkSession::Params params; 8740 net::HttpNetworkSession::Params params;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
8804 std::string response_data; 8801 std::string response_data;
8805 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); 8802 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
8806 EXPECT_EQ("hello!", response_data); 8803 EXPECT_EQ("hello!", response_data);
8807 8804
8808 // Preload www.gmail.com into HostCache. 8805 // Preload www.gmail.com into HostCache.
8809 HostPortPair host_port("www.gmail.com", 443); 8806 HostPortPair host_port("www.gmail.com", 443);
8810 HostResolver::RequestInfo resolve_info(host_port); 8807 HostResolver::RequestInfo resolve_info(host_port);
8811 AddressList ignored; 8808 AddressList ignored;
8812 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog()); 8809 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog());
8813 8810
8814 IPPoolingPreloadHostCache(&host_resolver, &pool_peer); 8811 // MockHostResolver returns 127.0.0.1, port 443 for https://www.google.com/
8812 // and https://www.gmail.com/. Add 127.0.0.1 as alias for host_port_pair:
8813 // (www.google.com, 443).
8814 IPPoolingAddAlias(&host_resolver, &pool_peer, "www.google.com", 443,
8815 "127.0.0.1");
8815 8816
8816 HttpRequestInfo request2; 8817 HttpRequestInfo request2;
8817 request2.method = "GET"; 8818 request2.method = "GET";
8818 request2.url = GURL("https://www.gmail.com/"); 8819 request2.url = GURL("https://www.gmail.com/");
8819 request2.load_flags = 0; 8820 request2.load_flags = 0;
8820 HttpNetworkTransaction trans2(session); 8821 HttpNetworkTransaction trans2(session);
8821 8822
8822 rv = trans2.Start(&request2, &callback, BoundNetLog()); 8823 rv = trans2.Start(&request2, &callback, BoundNetLog());
8823 EXPECT_EQ(ERR_IO_PENDING, rv); 8824 EXPECT_EQ(ERR_IO_PENDING, rv);
8824 EXPECT_EQ(OK, callback.WaitForResult()); 8825 EXPECT_EQ(OK, callback.WaitForResult());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
8958 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); 8959 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443));
8959 AddressList ignored; 8960 AddressList ignored;
8960 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog()); 8961 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog());
8961 8962
8962 HttpRequestInfo request2; 8963 HttpRequestInfo request2;
8963 request2.method = "GET"; 8964 request2.method = "GET";
8964 request2.url = GURL("https://www.gmail.com/"); 8965 request2.url = GURL("https://www.gmail.com/");
8965 request2.load_flags = 0; 8966 request2.load_flags = 0;
8966 HttpNetworkTransaction trans2(session); 8967 HttpNetworkTransaction trans2(session);
8967 8968
8968 IPPoolingPreloadHostCache(host_resolver.GetMockHostResolver(), &pool_peer); 8969 // MockHostResolver returns 127.0.0.1, port 443 for https://www.google.com/
8970 // and https://www.gmail.com/. Add 127.0.0.1 as alias for host_port_pair:
8971 // (www.google.com, 443).
8972 IPPoolingAddAlias(host_resolver.GetMockHostResolver(), &pool_peer,
8973 "www.google.com", 443, "127.0.0.1");
8969 8974
8970 rv = trans2.Start(&request2, &callback, BoundNetLog()); 8975 rv = trans2.Start(&request2, &callback, BoundNetLog());
8971 EXPECT_EQ(ERR_IO_PENDING, rv); 8976 EXPECT_EQ(ERR_IO_PENDING, rv);
8972 EXPECT_EQ(OK, callback.WaitForResult()); 8977 EXPECT_EQ(OK, callback.WaitForResult());
8973 8978
8974 response = trans2.GetResponseInfo(); 8979 response = trans2.GetResponseInfo();
8975 ASSERT_TRUE(response != NULL); 8980 ASSERT_TRUE(response != NULL);
8976 ASSERT_TRUE(response->headers != NULL); 8981 ASSERT_TRUE(response->headers != NULL);
8977 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8982 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8978 EXPECT_TRUE(response->was_fetched_via_spdy); 8983 EXPECT_TRUE(response->was_fetched_via_spdy);
8979 EXPECT_TRUE(response->was_npn_negotiated); 8984 EXPECT_TRUE(response->was_npn_negotiated);
8980 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); 8985 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
8981 EXPECT_EQ("hello!", response_data); 8986 EXPECT_EQ("hello!", response_data);
8982 8987
8983 HttpStreamFactory::set_next_protos(""); 8988 HttpStreamFactory::set_next_protos("");
8984 HttpStreamFactory::set_use_alternate_protocols(false); 8989 HttpStreamFactory::set_use_alternate_protocols(false);
8985 } 8990 }
8986 8991
8987 } // namespace net 8992 } // namespace net
OLDNEW
« 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