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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 7349023: Changed SPDY's ip connection pooling logic to only add the used IP, (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 unified diff | Download patch | Annotate | Revision Log
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,
8706 SpdySessionPoolPeer* pool_peer) {
8707 const int kTestPort = 443;
8708 struct TestHosts {
8709 std::string name;
8710 std::string iplist;
8711 } test_hosts[] = {
8712 { "www.google.com", "127.0.0.1"},
8713 };
wtc 2011/07/19 22:12:36 The need to preload this entry, with the magic hos
ramant (doing other things) 2011/07/25 23:36:06 Done.
8714
8715 // Preload cache entries into HostCache.
8716 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) {
8717 host_resolver->rules()->AddIPLiteralRule(test_hosts[i].name,
8718 test_hosts[i].iplist, "");
wtc 2011/07/19 22:12:36 Align this line with the argument on the previous
ramant (doing other things) 2011/07/25 23:36:06 Done.
8719
8720 AddressList addresses;
8721 // This test requires that the HostResolver cache be populated. Normal
wtc 2011/07/19 22:12:36 By "This test", which test are you referring to?
ramant (doing other things) 2011/07/25 23:36:06 Done.
8722 // code would have done this already, but we do it manually.
8723 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
8724 host_resolver->Resolve(
8725 info, &addresses, NULL, NULL, BoundNetLog());
8726
8727 // Setup a HostPortProxyPair
8728 HostPortProxyPair pair = HostPortProxyPair(
8729 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct());
8730
8731 const addrinfo* address = addresses.head();
8732 pool_peer->AddAlias(address, pair);
8733 }
8734 }
8735
8705 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { 8736 TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) {
8706 HttpStreamFactory::set_use_alternate_protocols(true); 8737 HttpStreamFactory::set_use_alternate_protocols(true);
8707 HttpStreamFactory::set_next_protos(kExpectedNPNString); 8738 HttpStreamFactory::set_next_protos(kExpectedNPNString);
8708 8739
8709 // Set up a special HttpNetworkSession with a MockCachingHostResolver. 8740 // Set up a special HttpNetworkSession with a MockCachingHostResolver.
8710 SessionDependencies session_deps; 8741 SessionDependencies session_deps;
8711 MockCachingHostResolver host_resolver; 8742 MockCachingHostResolver host_resolver;
8712 net::HttpNetworkSession::Params params; 8743 net::HttpNetworkSession::Params params;
8713 params.client_socket_factory = &session_deps.socket_factory; 8744 params.client_socket_factory = &session_deps.socket_factory;
8714 params.host_resolver = &host_resolver; 8745 params.host_resolver = &host_resolver;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
8773 std::string response_data; 8804 std::string response_data;
8774 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data)); 8805 ASSERT_EQ(OK, ReadTransaction(&trans1, &response_data));
8775 EXPECT_EQ("hello!", response_data); 8806 EXPECT_EQ("hello!", response_data);
8776 8807
8777 // Preload www.gmail.com into HostCache. 8808 // Preload www.gmail.com into HostCache.
8778 HostPortPair host_port("www.gmail.com", 443); 8809 HostPortPair host_port("www.gmail.com", 443);
8779 HostResolver::RequestInfo resolve_info(host_port); 8810 HostResolver::RequestInfo resolve_info(host_port);
8780 AddressList ignored; 8811 AddressList ignored;
8781 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog()); 8812 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog());
8782 8813
8814 IPPoolingPreloadHostCache(&host_resolver, &pool_peer);
8815
8783 HttpRequestInfo request2; 8816 HttpRequestInfo request2;
8784 request2.method = "GET"; 8817 request2.method = "GET";
8785 request2.url = GURL("https://www.gmail.com/"); 8818 request2.url = GURL("https://www.gmail.com/");
8786 request2.load_flags = 0; 8819 request2.load_flags = 0;
8787 HttpNetworkTransaction trans2(session); 8820 HttpNetworkTransaction trans2(session);
8788 8821
8789 rv = trans2.Start(&request2, &callback, BoundNetLog()); 8822 rv = trans2.Start(&request2, &callback, BoundNetLog());
8790 EXPECT_EQ(ERR_IO_PENDING, rv); 8823 EXPECT_EQ(ERR_IO_PENDING, rv);
8791 EXPECT_EQ(OK, callback.WaitForResult()); 8824 EXPECT_EQ(OK, callback.WaitForResult());
8792 8825
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
8832 } 8865 }
8833 8866
8834 virtual void AddObserver(Observer* observer) { 8867 virtual void AddObserver(Observer* observer) {
8835 return host_resolver_.AddObserver(observer); 8868 return host_resolver_.AddObserver(observer);
8836 } 8869 }
8837 8870
8838 virtual void RemoveObserver(Observer* observer) { 8871 virtual void RemoveObserver(Observer* observer) {
8839 return host_resolver_.RemoveObserver(observer); 8872 return host_resolver_.RemoveObserver(observer);
8840 } 8873 }
8841 8874
8875 MockCachingHostResolver* GetMockHostResolver() {
8876 return &host_resolver_;
8877 }
8878
8842 private: 8879 private:
8843 MockCachingHostResolver host_resolver_; 8880 MockCachingHostResolver host_resolver_;
8844 const HostPortPair host_port_; 8881 const HostPortPair host_port_;
8845 }; 8882 };
8846 8883
8847 TEST_F(HttpNetworkTransactionTest, 8884 TEST_F(HttpNetworkTransactionTest,
8848 UseIPConnectionPoolingWithHostCacheExpiration) { 8885 UseIPConnectionPoolingWithHostCacheExpiration) {
8849 HttpStreamFactory::set_use_alternate_protocols(true); 8886 HttpStreamFactory::set_use_alternate_protocols(true);
8850 HttpStreamFactory::set_next_protos(kExpectedNPNString); 8887 HttpStreamFactory::set_next_protos(kExpectedNPNString);
8851 8888
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
8921 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443)); 8958 HostResolver::RequestInfo resolve_info(HostPortPair("www.gmail.com", 443));
8922 AddressList ignored; 8959 AddressList ignored;
8923 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog()); 8960 host_resolver.Resolve(resolve_info, &ignored, NULL, NULL, BoundNetLog());
8924 8961
8925 HttpRequestInfo request2; 8962 HttpRequestInfo request2;
8926 request2.method = "GET"; 8963 request2.method = "GET";
8927 request2.url = GURL("https://www.gmail.com/"); 8964 request2.url = GURL("https://www.gmail.com/");
8928 request2.load_flags = 0; 8965 request2.load_flags = 0;
8929 HttpNetworkTransaction trans2(session); 8966 HttpNetworkTransaction trans2(session);
8930 8967
8968 IPPoolingPreloadHostCache(host_resolver.GetMockHostResolver(), &pool_peer);
8969
8931 rv = trans2.Start(&request2, &callback, BoundNetLog()); 8970 rv = trans2.Start(&request2, &callback, BoundNetLog());
8932 EXPECT_EQ(ERR_IO_PENDING, rv); 8971 EXPECT_EQ(ERR_IO_PENDING, rv);
8933 EXPECT_EQ(OK, callback.WaitForResult()); 8972 EXPECT_EQ(OK, callback.WaitForResult());
8934 8973
8935 response = trans2.GetResponseInfo(); 8974 response = trans2.GetResponseInfo();
8936 ASSERT_TRUE(response != NULL); 8975 ASSERT_TRUE(response != NULL);
8937 ASSERT_TRUE(response->headers != NULL); 8976 ASSERT_TRUE(response->headers != NULL);
8938 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8977 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8939 EXPECT_TRUE(response->was_fetched_via_spdy); 8978 EXPECT_TRUE(response->was_fetched_via_spdy);
8940 EXPECT_TRUE(response->was_npn_negotiated); 8979 EXPECT_TRUE(response->was_npn_negotiated);
8941 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data)); 8980 ASSERT_EQ(OK, ReadTransaction(&trans2, &response_data));
8942 EXPECT_EQ("hello!", response_data); 8981 EXPECT_EQ("hello!", response_data);
8943 8982
8944 HttpStreamFactory::set_next_protos(""); 8983 HttpStreamFactory::set_next_protos("");
8945 HttpStreamFactory::set_use_alternate_protocols(false); 8984 HttpStreamFactory::set_use_alternate_protocols(false);
8946 } 8985 }
8947 8986
8948 } // namespace net 8987 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/socket/ssl_client_socket_pool_unittest.cc » ('j') | net/spdy/spdy_session_pool.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698