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

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

Issue 15070: Split ProxyResolver into two interfaces:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 | « net/http/http_network_layer_unittest.cc ('k') | net/http/http_transaction_winhttp_unittest.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <math.h> // ceil 5 #include <math.h> // ceil
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "net/base/client_socket_factory.h" 8 #include "net/base/client_socket_factory.h"
9 #include "net/base/test_completion_callback.h" 9 #include "net/base/test_completion_callback.h"
10 #include "net/base/upload_data.h" 10 #include "net/base/upload_data.h"
11 #include "net/http/http_network_session.h" 11 #include "net/http/http_network_session.h"
12 #include "net/http/http_network_transaction.h" 12 #include "net/http/http_network_transaction.h"
13 #include "net/http/http_transaction_unittest.h" 13 #include "net/http/http_transaction_unittest.h"
14 #include "net/proxy/proxy_resolver_fixed.h" 14 #include "net/proxy/proxy_config_service_fixed.h"
15 #include "net/proxy/proxy_resolver_null.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
18 17
19 //----------------------------------------------------------------------------- 18 //-----------------------------------------------------------------------------
20 19
21 20
22 struct MockConnect { 21 struct MockConnect {
23 // Asynchronous connection success. 22 // Asynchronous connection success.
24 MockConnect() : async(true), result(net::OK) { } 23 MockConnect() : async(true), result(net::OK) { }
25 24
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 const std::string& hostname, 194 const std::string& hostname,
196 const net::SSLConfig& ssl_config) { 195 const net::SSLConfig& ssl_config) {
197 return NULL; 196 return NULL;
198 } 197 }
199 }; 198 };
200 199
201 MockClientSocketFactory mock_socket_factory; 200 MockClientSocketFactory mock_socket_factory;
202 201
203 // Create a proxy service which fails on all requests (falls back to direct). 202 // Create a proxy service which fails on all requests (falls back to direct).
204 net::ProxyService* CreateNullProxyService() { 203 net::ProxyService* CreateNullProxyService() {
205 return new net::ProxyService(new net::ProxyResolverNull); 204 return net::ProxyService::CreateNull();
206 } 205 }
207 206
207 net::ProxyService* CreateFixedProxyService(const std::string& proxy) {
208 net::ProxyInfo proxy_info;
209 proxy_info.UseNamedProxy(proxy);
210 return new net::ProxyService(
211 new net::ProxyConfigServiceFixed(proxy_info), NULL);
212 }
213
214
208 net::HttpNetworkSession* CreateSession(net::ProxyService* proxy_service) { 215 net::HttpNetworkSession* CreateSession(net::ProxyService* proxy_service) {
209 return new net::HttpNetworkSession(proxy_service); 216 return new net::HttpNetworkSession(proxy_service);
210 } 217 }
211 218
212 class HttpNetworkTransactionTest : public PlatformTest { 219 class HttpNetworkTransactionTest : public PlatformTest {
213 public: 220 public:
214 virtual void SetUp() { 221 virtual void SetUp() {
215 PlatformTest::SetUp(); 222 PlatformTest::SetUp();
216 mock_sockets[0] = NULL; 223 mock_sockets[0] = NULL;
217 mock_sockets_index = 0; 224 mock_sockets_index = 0;
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 response = trans->GetResponseInfo(); 709 response = trans->GetResponseInfo();
703 EXPECT_FALSE(response == NULL); 710 EXPECT_FALSE(response == NULL);
704 EXPECT_TRUE(response->auth_challenge.get() == NULL); 711 EXPECT_TRUE(response->auth_challenge.get() == NULL);
705 EXPECT_EQ(100, response->headers->GetContentLength()); 712 EXPECT_EQ(100, response->headers->GetContentLength());
706 } 713 }
707 714
708 // Test the flow when both the proxy server AND origin server require 715 // Test the flow when both the proxy server AND origin server require
709 // authentication. Again, this uses basic auth for both since that is 716 // authentication. Again, this uses basic auth for both since that is
710 // the simplest to mock. 717 // the simplest to mock.
711 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { 718 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) {
712 net::ProxyInfo proxy_info; 719 scoped_ptr<net::ProxyService> proxy_service(
713 proxy_info.UseNamedProxy("myproxy:70"); 720 CreateFixedProxyService("myproxy:70"));
714 net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info));
715 721
716 // Configure against proxy server "myproxy:70". 722 // Configure against proxy server "myproxy:70".
717 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 723 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
718 CreateSession(&proxy_service), 724 CreateSession(proxy_service.get()),
719 &mock_socket_factory)); 725 &mock_socket_factory));
720 726
721 net::HttpRequestInfo request; 727 net::HttpRequestInfo request;
722 request.method = "GET"; 728 request.method = "GET";
723 request.url = GURL("http://www.google.com/"); 729 request.url = GURL("http://www.google.com/");
724 request.load_flags = 0; 730 request.load_flags = 0;
725 731
726 MockWrite data_writes1[] = { 732 MockWrite data_writes1[] = {
727 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n" 733 MockWrite("GET http://www.google.com/ HTTP/1.1\r\n"
728 "Host: www.google.com\r\n" 734 "Host: www.google.com\r\n"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 888
883 const net::HttpResponseInfo* response = trans->GetResponseInfo(); 889 const net::HttpResponseInfo* response = trans->GetResponseInfo();
884 EXPECT_TRUE(response == NULL); 890 EXPECT_TRUE(response == NULL);
885 } 891 }
886 892
887 // Make sure that we don't try to reuse a TCPClientSocket when failing to 893 // Make sure that we don't try to reuse a TCPClientSocket when failing to
888 // establish tunnel. 894 // establish tunnel.
889 // http://code.google.com/p/chromium/issues/detail?id=3772 895 // http://code.google.com/p/chromium/issues/detail?id=3772
890 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { 896 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) {
891 // Configure against proxy server "myproxy:70". 897 // Configure against proxy server "myproxy:70".
892 net::ProxyInfo proxy_info; 898 scoped_ptr<net::ProxyService> proxy_service(
893 proxy_info.UseNamedProxy("myproxy:70"); 899 CreateFixedProxyService("myproxy:70"));
894 net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info));
895 900
896 scoped_refptr<net::HttpNetworkSession> session( 901 scoped_refptr<net::HttpNetworkSession> session(
897 CreateSession(&proxy_service)); 902 CreateSession(proxy_service.get()));
898 903
899 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 904 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
900 session.get(), &mock_socket_factory)); 905 session.get(), &mock_socket_factory));
901 906
902 net::HttpRequestInfo request; 907 net::HttpRequestInfo request;
903 request.method = "GET"; 908 request.method = "GET";
904 request.url = GURL("https://www.google.com/"); 909 request.url = GURL("https://www.google.com/");
905 request.load_flags = 0; 910 request.load_flags = 0;
906 911
907 // Since we have proxy, should try to establish tunnel. 912 // Since we have proxy, should try to establish tunnel.
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 1519
1515 rv = callback2.WaitForResult(); 1520 rv = callback2.WaitForResult();
1516 EXPECT_EQ(net::OK, rv); 1521 EXPECT_EQ(net::OK, rv);
1517 1522
1518 response = trans->GetResponseInfo(); 1523 response = trans->GetResponseInfo();
1519 EXPECT_FALSE(response == NULL); 1524 EXPECT_FALSE(response == NULL);
1520 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1525 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1521 EXPECT_EQ(100, response->headers->GetContentLength()); 1526 EXPECT_EQ(100, response->headers->GetContentLength());
1522 } 1527 }
1523 } 1528 }
OLDNEW
« no previous file with comments | « net/http/http_network_layer_unittest.cc ('k') | net/http/http_transaction_winhttp_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698