Chromium Code Reviews| 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/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
| 19 #include "net/base/port_util.h" | 19 #include "net/base/port_util.h" |
| 20 #include "net/base/privacy_mode.h" | |
| 20 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
| 21 #include "net/base/test_proxy_delegate.h" | 22 #include "net/base/test_proxy_delegate.h" |
| 22 #include "net/cert/ct_policy_enforcer.h" | 23 #include "net/cert/ct_policy_enforcer.h" |
| 23 #include "net/cert/mock_cert_verifier.h" | 24 #include "net/cert/mock_cert_verifier.h" |
| 24 #include "net/cert/multi_log_ct_verifier.h" | 25 #include "net/cert/multi_log_ct_verifier.h" |
| 25 #include "net/dns/mock_host_resolver.h" | 26 #include "net/dns/mock_host_resolver.h" |
| 26 #include "net/http/bidirectional_stream_impl.h" | 27 #include "net/http/bidirectional_stream_impl.h" |
| 27 #include "net/http/bidirectional_stream_request_info.h" | 28 #include "net/http/bidirectional_stream_request_info.h" |
| 28 #include "net/http/http_auth_handler_factory.h" | 29 #include "net/http/http_auth_handler_factory.h" |
| 29 #include "net/http/http_network_session.h" | 30 #include "net/http/http_network_session.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 CapturePreconnectsSocketPool(HostResolver* host_resolver, | 382 CapturePreconnectsSocketPool(HostResolver* host_resolver, |
| 382 CertVerifier* cert_verifier, | 383 CertVerifier* cert_verifier, |
| 383 TransportSecurityState* transport_security_state, | 384 TransportSecurityState* transport_security_state, |
| 384 CTVerifier* cert_transparency_verifier, | 385 CTVerifier* cert_transparency_verifier, |
| 385 CTPolicyEnforcer* ct_policy_enforcer); | 386 CTPolicyEnforcer* ct_policy_enforcer); |
| 386 | 387 |
| 387 int last_num_streams() const { | 388 int last_num_streams() const { |
| 388 return last_num_streams_; | 389 return last_num_streams_; |
| 389 } | 390 } |
| 390 | 391 |
| 392 // Resets |last_num_streams_| to its default value. | |
| 393 void reset_last_num_streams() { last_num_streams_ = -1; } | |
| 394 | |
| 391 int RequestSocket(const std::string& group_name, | 395 int RequestSocket(const std::string& group_name, |
| 392 const void* socket_params, | 396 const void* socket_params, |
| 393 RequestPriority priority, | 397 RequestPriority priority, |
| 394 ClientSocketPool::RespectLimits respect_limits, | 398 ClientSocketPool::RespectLimits respect_limits, |
| 395 ClientSocketHandle* handle, | 399 ClientSocketHandle* handle, |
| 396 const CompletionCallback& callback, | 400 const CompletionCallback& callback, |
| 397 const NetLogWithSource& net_log) override { | 401 const NetLogWithSource& net_log) override { |
| 398 ADD_FAILURE(); | 402 ADD_FAILURE(); |
| 399 return ERR_UNEXPECTED; | 403 return ERR_UNEXPECTED; |
| 400 } | 404 } |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1302 histogram_tester.ExpectUniqueSample( | 1306 histogram_tester.ExpectUniqueSample( |
| 1303 "Net.PreconnectSkippedToProxyServers", 1, 1); | 1307 "Net.PreconnectSkippedToProxyServers", 1, 1); |
| 1304 } else { | 1308 } else { |
| 1305 histogram_tester.ExpectTotalCount("Net.PreconnectSkippedToProxyServers", | 1309 histogram_tester.ExpectTotalCount("Net.PreconnectSkippedToProxyServers", |
| 1306 0); | 1310 0); |
| 1307 } | 1311 } |
| 1308 } | 1312 } |
| 1309 } | 1313 } |
| 1310 } | 1314 } |
| 1311 | 1315 |
| 1316 // Verify that preconnect to a HTTP2 proxy server with a privacy mode different | |
| 1317 // than that of the in-flight preconnect job succeeds. | |
|
Ryan Hamilton
2017/01/22 16:22:34
Presumably, the existing tests cover the case of t
tbansal1
2017/01/23 01:37:50
Yes, they do. Additionally, in this new test, I cr
| |
| 1318 TEST_F(HttpStreamFactoryTest, ProxyServerPreconnectDifferentPrivacyModes) { | |
| 1319 int num_streams = 1; | |
| 1320 base::HistogramTester histogram_tester; | |
| 1321 GURL url = GURL("http://www.google.com"); | |
| 1322 std::unique_ptr<ProxyService> proxy_service = | |
| 1323 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443"); | |
| 1324 | |
| 1325 // Set up the proxy server as a server that supports request priorities. | |
| 1326 HttpServerPropertiesImpl http_server_properties; | |
| 1327 | |
| 1328 url::SchemeHostPort spdy_server("https", "myproxy.org", 443); | |
| 1329 http_server_properties.SetSupportsSpdy(spdy_server, true); | |
| 1330 | |
| 1331 SpdySessionDependencies session_deps; | |
| 1332 HttpNetworkSession::Params params = | |
| 1333 SpdySessionDependencies::CreateSessionParams(&session_deps); | |
| 1334 params.enable_quic = true; | |
| 1335 params.proxy_service = proxy_service.get(); | |
| 1336 params.http_server_properties = &http_server_properties; | |
| 1337 ASSERT_TRUE(params.restrict_to_one_preconnect_for_proxies); | |
| 1338 | |
| 1339 std::unique_ptr<HttpNetworkSession> session(new HttpNetworkSession(params)); | |
| 1340 | |
| 1341 HttpNetworkSessionPeer peer(session.get()); | |
| 1342 HostPortPair proxy_host("myproxy.org", 443); | |
| 1343 | |
| 1344 CapturePreconnectsHttpProxySocketPool* http_proxy_pool = | |
| 1345 new CapturePreconnectsHttpProxySocketPool( | |
| 1346 session_deps.host_resolver.get(), session_deps.cert_verifier.get(), | |
| 1347 session_deps.transport_security_state.get(), | |
| 1348 session_deps.cert_transparency_verifier.get(), | |
| 1349 session_deps.ct_policy_enforcer.get()); | |
| 1350 CapturePreconnectsSSLSocketPool* ssl_conn_pool = | |
| 1351 new CapturePreconnectsSSLSocketPool( | |
| 1352 session_deps.host_resolver.get(), session_deps.cert_verifier.get(), | |
| 1353 session_deps.transport_security_state.get(), | |
| 1354 session_deps.cert_transparency_verifier.get(), | |
| 1355 session_deps.ct_policy_enforcer.get()); | |
| 1356 | |
| 1357 std::unique_ptr<MockClientSocketPoolManager> mock_pool_manager( | |
| 1358 new MockClientSocketPoolManager); | |
| 1359 mock_pool_manager->SetSocketPoolForHTTPProxy( | |
| 1360 proxy_host, base::WrapUnique(http_proxy_pool)); | |
| 1361 mock_pool_manager->SetSocketPoolForSSLWithProxy( | |
| 1362 proxy_host, base::WrapUnique(ssl_conn_pool)); | |
| 1363 peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); | |
| 1364 | |
| 1365 HttpRequestInfo request_privacy_mode_disabled; | |
| 1366 request_privacy_mode_disabled.method = "GET"; | |
| 1367 request_privacy_mode_disabled.url = url; | |
| 1368 request_privacy_mode_disabled.load_flags = 0; | |
| 1369 | |
| 1370 // First preconnect job should succeed. | |
| 1371 session->http_stream_factory()->PreconnectStreams( | |
| 1372 num_streams, request_privacy_mode_disabled); | |
| 1373 EXPECT_EQ(-1, ssl_conn_pool->last_num_streams()); | |
| 1374 EXPECT_EQ(num_streams, http_proxy_pool->last_num_streams()); | |
| 1375 http_proxy_pool->reset_last_num_streams(); | |
| 1376 | |
| 1377 // Second preconnect job with same privacy mode should not succeed. | |
| 1378 session->http_stream_factory()->PreconnectStreams( | |
| 1379 num_streams + 1, request_privacy_mode_disabled); | |
| 1380 EXPECT_EQ(-1, ssl_conn_pool->last_num_streams()); | |
| 1381 EXPECT_EQ(-1, http_proxy_pool->last_num_streams()); | |
| 1382 | |
| 1383 // Next request with a different privacy mode should succeed. | |
| 1384 HttpRequestInfo request_privacy_mode_enabled; | |
| 1385 request_privacy_mode_enabled.method = "GET"; | |
| 1386 request_privacy_mode_enabled.url = url; | |
| 1387 request_privacy_mode_enabled.load_flags = 0; | |
| 1388 request_privacy_mode_enabled.privacy_mode = PRIVACY_MODE_ENABLED; | |
| 1389 | |
| 1390 // Request with a different privacy mode should succeed. | |
| 1391 session->http_stream_factory()->PreconnectStreams( | |
| 1392 num_streams, request_privacy_mode_enabled); | |
| 1393 EXPECT_EQ(-1, ssl_conn_pool->last_num_streams()); | |
| 1394 EXPECT_EQ(num_streams, http_proxy_pool->last_num_streams()); | |
| 1395 } | |
| 1396 | |
| 1312 namespace { | 1397 namespace { |
| 1313 | 1398 |
| 1314 TEST_F(HttpStreamFactoryTest, PrivacyModeDisablesChannelId) { | 1399 TEST_F(HttpStreamFactoryTest, PrivacyModeDisablesChannelId) { |
| 1315 SpdySessionDependencies session_deps(ProxyService::CreateDirect()); | 1400 SpdySessionDependencies session_deps(ProxyService::CreateDirect()); |
| 1316 | 1401 |
| 1317 StaticSocketDataProvider socket_data; | 1402 StaticSocketDataProvider socket_data; |
| 1318 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | 1403 socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| 1319 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | 1404 session_deps.socket_factory->AddSocketDataProvider(&socket_data); |
| 1320 | 1405 |
| 1321 SSLSocketDataProvider ssl(ASYNC, OK); | 1406 SSLSocketDataProvider ssl(ASYNC, OK); |
| (...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2504 session->GetTransportSocketPool( | 2589 session->GetTransportSocketPool( |
| 2505 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 2590 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 2506 EXPECT_EQ(1, GetSocketPoolGroupCount( | 2591 EXPECT_EQ(1, GetSocketPoolGroupCount( |
| 2507 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 2592 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 2508 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 2593 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 2509 } | 2594 } |
| 2510 | 2595 |
| 2511 } // namespace | 2596 } // namespace |
| 2512 | 2597 |
| 2513 } // namespace net | 2598 } // namespace net |
| OLD | NEW |