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

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

Issue 2870030: Implement SSLClientSocketPool. (Closed)
Patch Set: Rebase and fix mac compile error Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 const scoped_refptr<HttpNetworkSession>& session) 52 const scoped_refptr<HttpNetworkSession>& session)
53 : session_(session) {} 53 : session_(session) {}
54 54
55 void SetTCPSocketPool(const scoped_refptr<TCPClientSocketPool>& pool) { 55 void SetTCPSocketPool(const scoped_refptr<TCPClientSocketPool>& pool) {
56 session_->tcp_socket_pool_ = pool; 56 session_->tcp_socket_pool_ = pool;
57 } 57 }
58 58
59 void SetSocketPoolForSOCKSProxy( 59 void SetSocketPoolForSOCKSProxy(
60 const HostPortPair& socks_proxy, 60 const HostPortPair& socks_proxy,
61 const scoped_refptr<SOCKSClientSocketPool>& pool) { 61 const scoped_refptr<SOCKSClientSocketPool>& pool) {
62 session_->socks_socket_pool_[socks_proxy] = pool; 62 session_->socks_socket_pools_[socks_proxy] = pool;
63 } 63 }
64 64
65 void SetSocketPoolForHTTPProxy( 65 void SetSocketPoolForHTTPProxy(
66 const HostPortPair& http_proxy, 66 const HostPortPair& http_proxy,
67 const scoped_refptr<HttpProxyClientSocketPool>& pool) { 67 const scoped_refptr<HttpProxyClientSocketPool>& pool) {
68 session_->http_proxy_socket_pool_[http_proxy] = pool; 68 session_->http_proxy_socket_pools_[http_proxy] = pool;
69 }
70
71 void SetSSLSocketPool(const scoped_refptr<SSLClientSocketPool>& pool) {
72 session_->ssl_socket_pool_ = pool;
73 }
74
75 void SetSocketPoolForSSLWithProxy(
76 const HostPortPair& proxy_host,
77 const scoped_refptr<SSLClientSocketPool>& pool) {
78 session_->ssl_socket_pools_for_proxies_[proxy_host] = pool;
69 } 79 }
70 80
71 private: 81 private:
72 const scoped_refptr<HttpNetworkSession> session_; 82 const scoped_refptr<HttpNetworkSession> session_;
73 83
74 DISALLOW_COPY_AND_ASSIGN(HttpNetworkSessionPeer); 84 DISALLOW_COPY_AND_ASSIGN(HttpNetworkSessionPeer);
75 }; 85 };
76 86
77 // Helper to manage the lifetimes of the dependencies for a 87 // Helper to manage the lifetimes of the dependencies for a
78 // HttpNetworkTransaction. 88 // HttpNetworkTransaction.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 for (size_t i = 0; i < n; ++i) { 241 for (size_t i = 0; i < n; ++i) {
232 output[i] = bytes[current_byte++]; 242 output[i] = bytes[current_byte++];
233 current_byte %= arraysize(bytes); 243 current_byte %= arraysize(bytes);
234 } 244 }
235 } 245 }
236 246
237 std::string MockGetHostName() { 247 std::string MockGetHostName() {
238 return "WTC-WIN7"; 248 return "WTC-WIN7";
239 } 249 }
240 250
241 template<typename EmulatedClientSocketPool> 251 template<typename ParentPool>
242 class CaptureGroupNameSocketPool : public EmulatedClientSocketPool { 252 class CaptureGroupNameSocketPool : public ParentPool {
243 public: 253 public:
244 explicit CaptureGroupNameSocketPool(HttpNetworkSession* session) 254 explicit CaptureGroupNameSocketPool(HttpNetworkSession* session);
245 : EmulatedClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, 255
246 NULL) {
247 }
248 const std::string last_group_name_received() const { 256 const std::string last_group_name_received() const {
249 return last_group_name_; 257 return last_group_name_;
250 } 258 }
251 259
252 virtual int RequestSocket(const std::string& group_name, 260 virtual int RequestSocket(const std::string& group_name,
253 const void* socket_params, 261 const void* socket_params,
254 RequestPriority priority, 262 RequestPriority priority,
255 ClientSocketHandle* handle, 263 ClientSocketHandle* handle,
256 CompletionCallback* callback, 264 CompletionCallback* callback,
257 const BoundNetLog& net_log) { 265 const BoundNetLog& net_log) {
(...skipping 25 matching lines...) Expand all
283 private: 291 private:
284 std::string last_group_name_; 292 std::string last_group_name_;
285 }; 293 };
286 294
287 typedef CaptureGroupNameSocketPool<TCPClientSocketPool> 295 typedef CaptureGroupNameSocketPool<TCPClientSocketPool>
288 CaptureGroupNameTCPSocketPool; 296 CaptureGroupNameTCPSocketPool;
289 typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> 297 typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool>
290 CaptureGroupNameHttpProxySocketPool; 298 CaptureGroupNameHttpProxySocketPool;
291 typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> 299 typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool>
292 CaptureGroupNameSOCKSSocketPool; 300 CaptureGroupNameSOCKSSocketPool;
301 typedef CaptureGroupNameSocketPool<SSLClientSocketPool>
302 CaptureGroupNameSSLSocketPool;
303
304 template<typename ParentPool>
305 CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool(
306 HttpNetworkSession* session)
307 : ParentPool(0, 0, NULL, session->host_resolver(), NULL, NULL) {}
308
309 template<>
310 CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool(
311 HttpNetworkSession* session)
312 : SSLClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, NULL,
313 NULL, NULL, NULL) {}
293 314
294 //----------------------------------------------------------------------------- 315 //-----------------------------------------------------------------------------
295 316
296 TEST_F(HttpNetworkTransactionTest, Basic) { 317 TEST_F(HttpNetworkTransactionTest, Basic) {
297 SessionDependencies session_deps; 318 SessionDependencies session_deps;
298 scoped_ptr<HttpTransaction> trans( 319 scoped_ptr<HttpTransaction> trans(
299 new HttpNetworkTransaction(CreateSession(&session_deps))); 320 new HttpNetworkTransaction(CreateSession(&session_deps)));
300 } 321 }
301 322
302 TEST_F(HttpNetworkTransactionTest, SimpleGET) { 323 TEST_F(HttpNetworkTransactionTest, SimpleGET) {
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 EXPECT_EQ(10, response->headers->GetContentLength()); 1418 EXPECT_EQ(10, response->headers->GetContentLength());
1398 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 1419 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1399 1420
1400 // The password prompt info should have been set in response->auth_challenge. 1421 // The password prompt info should have been set in response->auth_challenge.
1401 EXPECT_FALSE(response->auth_challenge.get() == NULL); 1422 EXPECT_FALSE(response->auth_challenge.get() == NULL);
1402 1423
1403 EXPECT_EQ(L"myproxy:70", response->auth_challenge->host_and_port); 1424 EXPECT_EQ(L"myproxy:70", response->auth_challenge->host_and_port);
1404 EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); 1425 EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm);
1405 EXPECT_EQ(L"basic", response->auth_challenge->scheme); 1426 EXPECT_EQ(L"basic", response->auth_challenge->scheme);
1406 1427
1407 // Cleanup the transaction so that the sockets are destroyed before the 1428 // Flush the idle socket before the NetLog and HttpNetworkTransaction go
1408 // net log goes out of scope. 1429 // out of scope.
1409 trans.reset(); 1430 session->FlushSocketPools();
1410
1411 // We also need to run the message queue for the socket releases to complete.
1412 MessageLoop::current()->RunAllPending();
1413 } 1431 }
1414 1432
1415 // Test that we don't read the response body when we fail to establish a tunnel, 1433 // Test that we don't read the response body when we fail to establish a tunnel,
1416 // even if the user cancels the proxy's auth attempt. 1434 // even if the user cancels the proxy's auth attempt.
1417 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { 1435 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) {
1418 // Configure against proxy server "myproxy:70". 1436 // Configure against proxy server "myproxy:70".
1419 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); 1437 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
1420 1438
1421 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1439 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1422 1440
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 EXPECT_FALSE(response == NULL); 1476 EXPECT_FALSE(response == NULL);
1459 1477
1460 EXPECT_TRUE(response->headers->IsKeepAlive()); 1478 EXPECT_TRUE(response->headers->IsKeepAlive());
1461 EXPECT_EQ(407, response->headers->response_code()); 1479 EXPECT_EQ(407, response->headers->response_code());
1462 EXPECT_EQ(10, response->headers->GetContentLength()); 1480 EXPECT_EQ(10, response->headers->GetContentLength());
1463 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); 1481 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1464 1482
1465 std::string response_data; 1483 std::string response_data;
1466 rv = ReadTransaction(trans.get(), &response_data); 1484 rv = ReadTransaction(trans.get(), &response_data);
1467 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); 1485 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv);
1486
1487 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
1488 session->FlushSocketPools();
1468 } 1489 }
1469 1490
1470 // Test when a server (non-proxy) returns a 407 (proxy-authenticate). 1491 // Test when a server (non-proxy) returns a 407 (proxy-authenticate).
1471 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. 1492 // The request should fail with ERR_UNEXPECTED_PROXY_AUTH.
1472 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { 1493 TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) {
1473 // We are using a DIRECT connection (i.e. no proxy) for this session. 1494 // We are using a DIRECT connection (i.e. no proxy) for this session.
1474 SessionDependencies session_deps; 1495 SessionDependencies session_deps;
1475 scoped_ptr<HttpTransaction> trans( 1496 scoped_ptr<HttpTransaction> trans(
1476 new HttpNetworkTransaction(CreateSession(&session_deps))); 1497 new HttpNetworkTransaction(CreateSession(&session_deps)));
1477 1498
(...skipping 2492 matching lines...) Expand 10 before | Expand all | Expand 10 after
3970 EXPECT_EQ(OK, rv); 3991 EXPECT_EQ(OK, rv);
3971 EXPECT_EQ("Payload", response_text); 3992 EXPECT_EQ("Payload", response_text);
3972 } 3993 }
3973 3994
3974 // Tests that for connection endpoints the group names are correctly set. 3995 // Tests that for connection endpoints the group names are correctly set.
3975 3996
3976 struct GroupNameTest { 3997 struct GroupNameTest {
3977 std::string proxy_server; 3998 std::string proxy_server;
3978 std::string url; 3999 std::string url;
3979 std::string expected_group_name; 4000 std::string expected_group_name;
4001 bool ssl;
3980 }; 4002 };
3981 4003
3982 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests( 4004 scoped_refptr<HttpNetworkSession> SetupSessionForGroupNameTests(
3983 const std::string& proxy_server) { 4005 const std::string& proxy_server) {
3984 SessionDependencies session_deps(CreateFixedProxyService(proxy_server)); 4006 SessionDependencies session_deps(CreateFixedProxyService(proxy_server));
3985 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 4007 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
3986 4008
3987 HttpAlternateProtocols* alternate_protocols = 4009 HttpAlternateProtocols* alternate_protocols =
3988 session->mutable_alternate_protocols(); 4010 session->mutable_alternate_protocols();
3989 alternate_protocols->SetAlternateProtocolFor( 4011 alternate_protocols->SetAlternateProtocolFor(
(...skipping 18 matching lines...) Expand all
4008 // We do not complete this request, the dtor will clean the transaction up. 4030 // We do not complete this request, the dtor will clean the transaction up.
4009 return trans->Start(&request, &callback, BoundNetLog()); 4031 return trans->Start(&request, &callback, BoundNetLog());
4010 } 4032 }
4011 4033
4012 TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { 4034 TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) {
4013 const GroupNameTest tests[] = { 4035 const GroupNameTest tests[] = {
4014 { 4036 {
4015 "", // unused 4037 "", // unused
4016 "http://www.google.com/direct", 4038 "http://www.google.com/direct",
4017 "www.google.com:80", 4039 "www.google.com:80",
4040 false,
4018 }, 4041 },
4019 { 4042 {
4020 "", // unused 4043 "", // unused
4021 "http://[2001:1418:13:1::25]/direct", 4044 "http://[2001:1418:13:1::25]/direct",
4022 "[2001:1418:13:1::25]:80", 4045 "[2001:1418:13:1::25]:80",
4046 false,
4023 }, 4047 },
4024 4048
4025 // SSL Tests 4049 // SSL Tests
4026 { 4050 {
4027 "", // unused 4051 "", // unused
4028 "https://www.google.com/direct_ssl", 4052 "https://www.google.com/direct_ssl",
4029 "ssl/www.google.com:443", 4053 "ssl/www.google.com:443",
4054 true,
4030 }, 4055 },
4031 { 4056 {
4032 "", // unused 4057 "", // unused
4033 "https://[2001:1418:13:1::25]/direct", 4058 "https://[2001:1418:13:1::25]/direct",
4034 "ssl/[2001:1418:13:1::25]:443", 4059 "ssl/[2001:1418:13:1::25]:443",
4060 true,
4035 }, 4061 },
4036 { 4062 {
4037 "", // unused 4063 "", // unused
4038 "http://host.with.alternate/direct", 4064 "http://host.with.alternate/direct",
4039 "ssl/host.with.alternate:443", 4065 "ssl/host.with.alternate:443",
4066 true,
4040 }, 4067 },
4041 }; 4068 };
4042 4069
4043 HttpNetworkTransaction::SetUseAlternateProtocols(true); 4070 HttpNetworkTransaction::SetUseAlternateProtocols(true);
4044 4071
4045 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 4072 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
4046 scoped_refptr<HttpNetworkSession> session( 4073 scoped_refptr<HttpNetworkSession> session(
4047 SetupSessionForGroupNameTests(tests[i].proxy_server)); 4074 SetupSessionForGroupNameTests(tests[i].proxy_server));
4048 4075
4049 HttpNetworkSessionPeer peer(session); 4076 HttpNetworkSessionPeer peer(session);
4050 scoped_refptr<CaptureGroupNameTCPSocketPool> tcp_conn_pool( 4077 scoped_refptr<CaptureGroupNameTCPSocketPool> tcp_conn_pool(
4051 new CaptureGroupNameTCPSocketPool(session.get())); 4078 new CaptureGroupNameTCPSocketPool(session.get()));
4052 peer.SetTCPSocketPool(tcp_conn_pool); 4079 peer.SetTCPSocketPool(tcp_conn_pool);
4080 scoped_refptr<CaptureGroupNameSSLSocketPool> ssl_conn_pool(
4081 new CaptureGroupNameSSLSocketPool(session.get()));
4082 peer.SetSSLSocketPool(ssl_conn_pool);
4053 4083
4054 EXPECT_EQ(ERR_IO_PENDING, 4084 EXPECT_EQ(ERR_IO_PENDING,
4055 GroupNameTransactionHelper(tests[i].url, session)); 4085 GroupNameTransactionHelper(tests[i].url, session));
4056 EXPECT_EQ(tests[i].expected_group_name, 4086 if (tests[i].ssl)
4057 tcp_conn_pool->last_group_name_received()); 4087 EXPECT_EQ(tests[i].expected_group_name,
4088 ssl_conn_pool->last_group_name_received());
4089 else
4090 EXPECT_EQ(tests[i].expected_group_name,
4091 tcp_conn_pool->last_group_name_received());
4058 } 4092 }
4059 4093
4060 HttpNetworkTransaction::SetUseAlternateProtocols(false); 4094 HttpNetworkTransaction::SetUseAlternateProtocols(false);
4061 } 4095 }
4062 4096
4063 TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { 4097 TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) {
4064 const GroupNameTest tests[] = { 4098 const GroupNameTest tests[] = {
4065 { 4099 {
4066 "http_proxy", 4100 "http_proxy",
4067 "http://www.google.com/http_proxy_normal", 4101 "http://www.google.com/http_proxy_normal",
4068 "www.google.com:80", 4102 "www.google.com:80",
4103 false,
4069 }, 4104 },
4070 4105
4071 // SSL Tests 4106 // SSL Tests
4072 { 4107 {
4073 "http_proxy", 4108 "http_proxy",
4074 "https://www.google.com/http_connect_ssl", 4109 "https://www.google.com/http_connect_ssl",
4075 "ssl/www.google.com:443", 4110 "ssl/www.google.com:443",
4111 true,
4076 }, 4112 },
4077 4113
4078 { 4114 {
4079 "http_proxy", 4115 "http_proxy",
4080 "http://host.with.alternate/direct", 4116 "http://host.with.alternate/direct",
4081 "ssl/host.with.alternate:443", 4117 "ssl/host.with.alternate:443",
4118 true,
4082 }, 4119 },
4083 }; 4120 };
4084 4121
4085 HttpNetworkTransaction::SetUseAlternateProtocols(true); 4122 HttpNetworkTransaction::SetUseAlternateProtocols(true);
4086 4123
4087 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 4124 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
4088 scoped_refptr<HttpNetworkSession> session( 4125 scoped_refptr<HttpNetworkSession> session(
4089 SetupSessionForGroupNameTests(tests[i].proxy_server)); 4126 SetupSessionForGroupNameTests(tests[i].proxy_server));
4090 4127
4091 HttpNetworkSessionPeer peer(session); 4128 HttpNetworkSessionPeer peer(session);
4092 4129
4130 HostPortPair proxy_host("http_proxy", 80);
4093 scoped_refptr<CaptureGroupNameHttpProxySocketPool> http_proxy_pool( 4131 scoped_refptr<CaptureGroupNameHttpProxySocketPool> http_proxy_pool(
4094 new CaptureGroupNameHttpProxySocketPool(session.get())); 4132 new CaptureGroupNameHttpProxySocketPool(session.get()));
4095 peer.SetSocketPoolForHTTPProxy( 4133 peer.SetSocketPoolForHTTPProxy(proxy_host, http_proxy_pool);
4096 HostPortPair("http_proxy", 80), http_proxy_pool); 4134 scoped_refptr<CaptureGroupNameSSLSocketPool> ssl_conn_pool(
4135 new CaptureGroupNameSSLSocketPool(session.get()));
4136 peer.SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
4097 4137
4098 EXPECT_EQ(ERR_IO_PENDING, 4138 EXPECT_EQ(ERR_IO_PENDING,
4099 GroupNameTransactionHelper(tests[i].url, session)); 4139 GroupNameTransactionHelper(tests[i].url, session));
4100 EXPECT_EQ(tests[i].expected_group_name, 4140 if (tests[i].ssl)
4101 http_proxy_pool->last_group_name_received()); 4141 EXPECT_EQ(tests[i].expected_group_name,
4142 ssl_conn_pool->last_group_name_received());
4143 else
4144 EXPECT_EQ(tests[i].expected_group_name,
4145 http_proxy_pool->last_group_name_received());
4102 } 4146 }
4103 4147
4104 HttpNetworkTransaction::SetUseAlternateProtocols(false); 4148 HttpNetworkTransaction::SetUseAlternateProtocols(false);
4105 } 4149 }
4106 4150
4107 TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { 4151 TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) {
4108 const GroupNameTest tests[] = { 4152 const GroupNameTest tests[] = {
4109 { 4153 {
4110 "socks4://socks_proxy:1080", 4154 "socks4://socks_proxy:1080",
4111 "http://www.google.com/socks4_direct", 4155 "http://www.google.com/socks4_direct",
4112 "socks4/www.google.com:80", 4156 "socks4/www.google.com:80",
4157 false,
4113 }, 4158 },
4114 { 4159 {
4115 "socks5://socks_proxy:1080", 4160 "socks5://socks_proxy:1080",
4116 "http://www.google.com/socks5_direct", 4161 "http://www.google.com/socks5_direct",
4117 "socks5/www.google.com:80", 4162 "socks5/www.google.com:80",
4163 false,
4118 }, 4164 },
4119 4165
4120 // SSL Tests 4166 // SSL Tests
4121 { 4167 {
4122 "socks4://socks_proxy:1080", 4168 "socks4://socks_proxy:1080",
4123 "https://www.google.com/socks4_ssl", 4169 "https://www.google.com/socks4_ssl",
4124 "socks4/ssl/www.google.com:443", 4170 "socks4/ssl/www.google.com:443",
4171 true,
4125 }, 4172 },
4126 { 4173 {
4127 "socks5://socks_proxy:1080", 4174 "socks5://socks_proxy:1080",
4128 "https://www.google.com/socks5_ssl", 4175 "https://www.google.com/socks5_ssl",
4129 "socks5/ssl/www.google.com:443", 4176 "socks5/ssl/www.google.com:443",
4177 true,
4130 }, 4178 },
4131 4179
4132 { 4180 {
4133 "socks4://socks_proxy:1080", 4181 "socks4://socks_proxy:1080",
4134 "http://host.with.alternate/direct", 4182 "http://host.with.alternate/direct",
4135 "socks4/ssl/host.with.alternate:443", 4183 "socks4/ssl/host.with.alternate:443",
4184 true,
4136 }, 4185 },
4137 }; 4186 };
4138 4187
4139 HttpNetworkTransaction::SetUseAlternateProtocols(true); 4188 HttpNetworkTransaction::SetUseAlternateProtocols(true);
4140 4189
4141 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 4190 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
4142 scoped_refptr<HttpNetworkSession> session( 4191 scoped_refptr<HttpNetworkSession> session(
4143 SetupSessionForGroupNameTests(tests[i].proxy_server)); 4192 SetupSessionForGroupNameTests(tests[i].proxy_server));
4144 HttpNetworkSessionPeer peer(session); 4193 HttpNetworkSessionPeer peer(session);
4145 4194
4195 HostPortPair proxy_host("socks_proxy", 1080);
4146 scoped_refptr<CaptureGroupNameSOCKSSocketPool> socks_conn_pool( 4196 scoped_refptr<CaptureGroupNameSOCKSSocketPool> socks_conn_pool(
4147 new CaptureGroupNameSOCKSSocketPool(session.get())); 4197 new CaptureGroupNameSOCKSSocketPool(session.get()));
4148 peer.SetSocketPoolForSOCKSProxy( 4198 peer.SetSocketPoolForSOCKSProxy(proxy_host, socks_conn_pool);
4149 HostPortPair("socks_proxy", 1080), socks_conn_pool); 4199 scoped_refptr<CaptureGroupNameSSLSocketPool> ssl_conn_pool(
4200 new CaptureGroupNameSSLSocketPool(session.get()));
4201 peer.SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool);
4150 4202
4151 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 4203 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
4152 4204
4153 EXPECT_EQ(ERR_IO_PENDING, 4205 EXPECT_EQ(ERR_IO_PENDING,
4154 GroupNameTransactionHelper(tests[i].url, session)); 4206 GroupNameTransactionHelper(tests[i].url, session));
4155 EXPECT_EQ(tests[i].expected_group_name, 4207 if (tests[i].ssl)
4156 socks_conn_pool->last_group_name_received()); 4208 EXPECT_EQ(tests[i].expected_group_name,
4209 ssl_conn_pool->last_group_name_received());
4210 else
4211 EXPECT_EQ(tests[i].expected_group_name,
4212 socks_conn_pool->last_group_name_received());
4157 } 4213 }
4158 4214
4159 HttpNetworkTransaction::SetUseAlternateProtocols(false); 4215 HttpNetworkTransaction::SetUseAlternateProtocols(false);
4160 } 4216 }
4161 4217
4162 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { 4218 TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) {
4163 SessionDependencies session_deps( 4219 SessionDependencies session_deps(
4164 CreateFixedProxyService("myproxy:70;foobar:80")); 4220 CreateFixedProxyService("myproxy:70;foobar:80"));
4165 4221
4166 // This simulates failure resolving all hostnames; that means we will fail 4222 // This simulates failure resolving all hostnames; that means we will fail
(...skipping 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after
5862 EXPECT_EQ(round + 1, test_config.num_auth_rounds); 5918 EXPECT_EQ(round + 1, test_config.num_auth_rounds);
5863 continue; 5919 continue;
5864 } 5920 }
5865 if (round + 1 < test_config.num_auth_rounds) { 5921 if (round + 1 < test_config.num_auth_rounds) {
5866 EXPECT_FALSE(response->auth_challenge.get() == NULL); 5922 EXPECT_FALSE(response->auth_challenge.get() == NULL);
5867 } else { 5923 } else {
5868 EXPECT_TRUE(response->auth_challenge.get() == NULL); 5924 EXPECT_TRUE(response->auth_challenge.get() == NULL);
5869 } 5925 }
5870 } 5926 }
5871 } 5927 }
5928
5929 // Flush the idle socket before the HttpNetworkTransaction goes out of scope.
5930 session->FlushSocketPools();
5872 } 5931 }
5873 5932
5874 class TLSDecompressionFailureSocketDataProvider : public SocketDataProvider { 5933 class TLSDecompressionFailureSocketDataProvider : public SocketDataProvider {
5875 public: 5934 public:
5876 explicit TLSDecompressionFailureSocketDataProvider(bool fail_all) 5935 explicit TLSDecompressionFailureSocketDataProvider(bool fail_all)
5877 : fail_all_(fail_all) { 5936 : fail_all_(fail_all) {
5878 } 5937 }
5879 5938
5880 virtual MockRead GetNextRead() { 5939 virtual MockRead GetNextRead() {
5881 if (fail_all_) 5940 if (fail_all_)
(...skipping 30 matching lines...) Expand all
5912 SSLSocketDataProvider ssl_socket_data_provider1( 5971 SSLSocketDataProvider ssl_socket_data_provider1(
5913 false, ERR_SSL_DECOMPRESSION_FAILURE_ALERT); 5972 false, ERR_SSL_DECOMPRESSION_FAILURE_ALERT);
5914 SSLSocketDataProvider ssl_socket_data_provider2(false, OK); 5973 SSLSocketDataProvider ssl_socket_data_provider2(false, OK);
5915 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider1); 5974 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider1);
5916 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider2); 5975 session_deps.socket_factory.AddSocketDataProvider(&socket_data_provider2);
5917 session_deps.socket_factory.AddSSLSocketDataProvider( 5976 session_deps.socket_factory.AddSSLSocketDataProvider(
5918 &ssl_socket_data_provider1); 5977 &ssl_socket_data_provider1);
5919 session_deps.socket_factory.AddSSLSocketDataProvider( 5978 session_deps.socket_factory.AddSSLSocketDataProvider(
5920 &ssl_socket_data_provider2); 5979 &ssl_socket_data_provider2);
5921 5980
5981 // Work around http://crbug.com/37454
5982 StaticSocketDataProvider bug37454_connection;
5983 bug37454_connection.set_connect_data(MockConnect(true, ERR_UNEXPECTED));
5984 session_deps.socket_factory.AddSocketDataProvider(&bug37454_connection);
5985
5922 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 5986 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
5923 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 5987 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
5924 TestCompletionCallback callback; 5988 TestCompletionCallback callback;
5925 5989
5926 int rv = trans->Start(&request, &callback, BoundNetLog()); 5990 int rv = trans->Start(&request, &callback, BoundNetLog());
5927 EXPECT_EQ(ERR_IO_PENDING, rv); 5991 EXPECT_EQ(ERR_IO_PENDING, rv);
5928 EXPECT_EQ(OK, callback.WaitForResult()); 5992 EXPECT_EQ(OK, callback.WaitForResult());
5929 5993
5930 const HttpResponseInfo* response = trans->GetResponseInfo(); 5994 const HttpResponseInfo* response = trans->GetResponseInfo();
5931 ASSERT_TRUE(response != NULL); 5995 ASSERT_TRUE(response != NULL);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
6081 6145
6082 int rv = trans->Start(&request, &callback, BoundNetLog()); 6146 int rv = trans->Start(&request, &callback, BoundNetLog());
6083 EXPECT_EQ(ERR_IO_PENDING, rv); 6147 EXPECT_EQ(ERR_IO_PENDING, rv);
6084 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); 6148 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
6085 6149
6086 HttpNetworkTransaction::SetNextProtos(""); 6150 HttpNetworkTransaction::SetNextProtos("");
6087 HttpNetworkTransaction::SetUseAlternateProtocols(false); 6151 HttpNetworkTransaction::SetUseAlternateProtocols(false);
6088 } 6152 }
6089 6153
6090 } // namespace net 6154 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698