| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_stream_factory_impl.h" | 5 #include "net/http/http_stream_factory_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/field_trial.h" | |
| 18 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 19 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 20 #include "net/base/port_util.h" | 19 #include "net/base/port_util.h" |
| 21 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 22 #include "net/base/test_proxy_delegate.h" | 21 #include "net/base/test_proxy_delegate.h" |
| 23 #include "net/cert/ct_policy_enforcer.h" | 22 #include "net/cert/ct_policy_enforcer.h" |
| 24 #include "net/cert/mock_cert_verifier.h" | 23 #include "net/cert/mock_cert_verifier.h" |
| 25 #include "net/cert/multi_log_ct_verifier.h" | 24 #include "net/cert/multi_log_ct_verifier.h" |
| 26 #include "net/dns/mock_host_resolver.h" | 25 #include "net/dns/mock_host_resolver.h" |
| 27 #include "net/http/bidirectional_stream_impl.h" | 26 #include "net/http/bidirectional_stream_impl.h" |
| (...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 HttpRequestInfo request; | 1210 HttpRequestInfo request; |
| 1212 request.method = "GET"; | 1211 request.method = "GET"; |
| 1213 request.url = url; | 1212 request.url = url; |
| 1214 request.load_flags = 0; | 1213 request.load_flags = 0; |
| 1215 | 1214 |
| 1216 session->http_stream_factory()->PreconnectStreams(num_streams, request); | 1215 session->http_stream_factory()->PreconnectStreams(num_streams, request); |
| 1217 EXPECT_EQ(-1, transport_conn_pool->last_num_streams()); | 1216 EXPECT_EQ(-1, transport_conn_pool->last_num_streams()); |
| 1218 } | 1217 } |
| 1219 } | 1218 } |
| 1220 | 1219 |
| 1221 // Verify that the proxy delegate can disable preconnect jobs to only the proxy | 1220 // Verify that only one preconnect job succeeds to a proxy server that supports |
| 1222 // servers that support request priorities. | 1221 // request priorities. |
| 1223 TEST_F(HttpStreamFactoryTest, ProxyDelegateDisablesPreconnect) { | 1222 TEST_F(HttpStreamFactoryTest, OnlyOnePreconnectToProxyServer) { |
| 1224 base::FieldTrialList field_trial_list(nullptr); | |
| 1225 base::FieldTrialList::CreateFieldTrial( | |
| 1226 "NetAllowOnlyOnePreconnectToProxyServers", "Enabled"); | |
| 1227 | |
| 1228 for (bool set_http_server_properties : {false, true}) { | 1223 for (bool set_http_server_properties : {false, true}) { |
| 1229 for (int num_streams = 1; num_streams < 3; ++num_streams) { | 1224 for (int num_streams = 1; num_streams < 3; ++num_streams) { |
| 1230 base::HistogramTester histogram_tester; | 1225 base::HistogramTester histogram_tester; |
| 1231 GURL url = GURL("http://www.google.com"); | 1226 GURL url = GURL("http://www.google.com"); |
| 1232 std::unique_ptr<ProxyService> proxy_service = | 1227 std::unique_ptr<ProxyService> proxy_service = |
| 1233 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | 1228 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); |
| 1234 | 1229 |
| 1235 // Set up the proxy server as a server that supports request priorities. | 1230 // Set up the proxy server as a server that supports request priorities. |
| 1236 HttpServerPropertiesImpl http_server_properties; | 1231 HttpServerPropertiesImpl http_server_properties; |
| 1237 if (set_http_server_properties) { | 1232 if (set_http_server_properties) { |
| 1238 url::SchemeHostPort spdy_server("https", "myproxy.org", 443); | 1233 url::SchemeHostPort spdy_server("https", "myproxy.org", 443); |
| 1239 http_server_properties.SetSupportsSpdy(spdy_server, true); | 1234 http_server_properties.SetSupportsSpdy(spdy_server, true); |
| 1240 } | 1235 } |
| 1241 | 1236 |
| 1242 SpdySessionDependencies session_deps; | 1237 SpdySessionDependencies session_deps; |
| 1243 HttpNetworkSession::Params params = | 1238 HttpNetworkSession::Params params = |
| 1244 SpdySessionDependencies::CreateSessionParams(&session_deps); | 1239 SpdySessionDependencies::CreateSessionParams(&session_deps); |
| 1245 params.enable_quic = true; | 1240 params.enable_quic = true; |
| 1246 params.proxy_service = proxy_service.get(); | 1241 params.proxy_service = proxy_service.get(); |
| 1247 params.http_server_properties = &http_server_properties; | 1242 params.http_server_properties = &http_server_properties; |
| 1243 ASSERT_TRUE(params.restrict_to_one_preconnect_for_proxies); |
| 1248 | 1244 |
| 1249 std::unique_ptr<HttpNetworkSession> session( | 1245 std::unique_ptr<HttpNetworkSession> session( |
| 1250 new HttpNetworkSession(params)); | 1246 new HttpNetworkSession(params)); |
| 1251 | 1247 |
| 1252 HttpNetworkSessionPeer peer(session.get()); | 1248 HttpNetworkSessionPeer peer(session.get()); |
| 1253 HostPortPair proxy_host("myproxy.org", 443); | 1249 HostPortPair proxy_host("myproxy.org", 443); |
| 1254 | 1250 |
| 1255 for (int preconnect_request = 0; preconnect_request < 2; | 1251 for (int preconnect_request = 0; preconnect_request < 2; |
| 1256 ++preconnect_request) { | 1252 ++preconnect_request) { |
| 1257 CapturePreconnectsHttpProxySocketPool* http_proxy_pool = | 1253 CapturePreconnectsHttpProxySocketPool* http_proxy_pool = |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 HostPortPair("myproxy", 8888)))); | 1599 HostPortPair("myproxy", 8888)))); |
| 1604 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( | 1600 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( |
| 1605 HttpNetworkSession::WEBSOCKET_SOCKET_POOL, | 1601 HttpNetworkSession::WEBSOCKET_SOCKET_POOL, |
| 1606 HostPortPair("myproxy", 8888)))); | 1602 HostPortPair("myproxy", 8888)))); |
| 1607 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); | 1603 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); |
| 1608 } | 1604 } |
| 1609 | 1605 |
| 1610 // Verifies that once a stream has been created to a proxy server (that supports | 1606 // Verifies that once a stream has been created to a proxy server (that supports |
| 1611 // request priorities) the next preconnect job can again open new sockets. | 1607 // request priorities) the next preconnect job can again open new sockets. |
| 1612 TEST_F(HttpStreamFactoryTest, RequestHttpStreamOverProxyWithPreconnects) { | 1608 TEST_F(HttpStreamFactoryTest, RequestHttpStreamOverProxyWithPreconnects) { |
| 1613 base::FieldTrialList field_trial_list(nullptr); | |
| 1614 base::FieldTrialList::CreateFieldTrial( | |
| 1615 "NetAllowOnlyOnePreconnectToProxyServers", "Enabled"); | |
| 1616 | |
| 1617 SpdySessionDependencies session_deps( | 1609 SpdySessionDependencies session_deps( |
| 1618 ProxyService::CreateFixed("https://myproxy.org:443")); | 1610 ProxyService::CreateFixed("https://myproxy.org:443")); |
| 1619 | 1611 |
| 1620 // Set up the proxy server as a server that supports request priorities. | 1612 // Set up the proxy server as a server that supports request priorities. |
| 1621 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties( | 1613 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties( |
| 1622 new HttpServerPropertiesImpl()); | 1614 new HttpServerPropertiesImpl()); |
| 1623 url::SchemeHostPort spdy_server("https", "myproxy.org", 443); | 1615 url::SchemeHostPort spdy_server("https", "myproxy.org", 443); |
| 1624 http_server_properties->SetSupportsSpdy(spdy_server, true); | 1616 http_server_properties->SetSupportsSpdy(spdy_server, true); |
| 1625 session_deps.http_server_properties = std::move(http_server_properties); | 1617 session_deps.http_server_properties = std::move(http_server_properties); |
| 1626 | 1618 |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2512 session->GetTransportSocketPool( | 2504 session->GetTransportSocketPool( |
| 2513 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 2505 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 2514 EXPECT_EQ(1, GetSocketPoolGroupCount( | 2506 EXPECT_EQ(1, GetSocketPoolGroupCount( |
| 2515 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 2507 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 2516 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 2508 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 2517 } | 2509 } |
| 2518 | 2510 |
| 2519 } // namespace | 2511 } // namespace |
| 2520 | 2512 |
| 2521 } // namespace net | 2513 } // namespace net |
| OLD | NEW |