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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "net/base/port_util.h" | 14 #include "net/base/port_util.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
16 #include "net/cert/mock_cert_verifier.h" | 16 #include "net/cert/mock_cert_verifier.h" |
17 #include "net/dns/mock_host_resolver.h" | 17 #include "net/dns/mock_host_resolver.h" |
18 #include "net/http/http_auth_handler_factory.h" | 18 #include "net/http/http_auth_handler_factory.h" |
19 #include "net/http/http_network_session.h" | 19 #include "net/http/http_network_session.h" |
20 #include "net/http/http_network_session_peer.h" | 20 #include "net/http/http_network_session_peer.h" |
21 #include "net/http/http_network_transaction.h" | 21 #include "net/http/http_network_transaction.h" |
22 #include "net/http/http_request_info.h" | 22 #include "net/http/http_request_info.h" |
23 #include "net/http/http_server_properties.h" | 23 #include "net/http/http_server_properties.h" |
24 #include "net/http/http_server_properties_impl.h" | 24 #include "net/http/http_server_properties_impl.h" |
25 #include "net/http/http_stream.h" | 25 #include "net/http/http_stream.h" |
26 #include "net/http/transport_security_state.h" | 26 #include "net/http/transport_security_state.h" |
27 #include "net/log/net_log.h" | 27 #include "net/log/net_log.h" |
28 #include "net/proxy/proxy_info.h" | 28 #include "net/proxy/proxy_info.h" |
29 #include "net/proxy/proxy_service.h" | 29 #include "net/proxy/proxy_service.h" |
30 #include "net/quic/test_tools/quic_stream_factory_peer.h" | |
30 #include "net/socket/client_socket_handle.h" | 31 #include "net/socket/client_socket_handle.h" |
31 #include "net/socket/mock_client_socket_pool_manager.h" | 32 #include "net/socket/mock_client_socket_pool_manager.h" |
32 #include "net/socket/next_proto.h" | 33 #include "net/socket/next_proto.h" |
33 #include "net/socket/socket_test_util.h" | 34 #include "net/socket/socket_test_util.h" |
34 #include "net/spdy/spdy_session.h" | 35 #include "net/spdy/spdy_session.h" |
35 #include "net/spdy/spdy_session_pool.h" | 36 #include "net/spdy/spdy_session_pool.h" |
36 #include "net/spdy/spdy_test_util_common.h" | 37 #include "net/spdy/spdy_test_util_common.h" |
37 #include "net/ssl/ssl_config_service.h" | 38 #include "net/ssl/ssl_config_service.h" |
38 #include "net/ssl/ssl_config_service_defaults.h" | 39 #include "net/ssl/ssl_config_service_defaults.h" |
39 // This file can be included from net/http even though | 40 // This file can be included from net/http even though |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 | 110 |
110 // HttpStreamFactoryImpl subclass that can wait until a preconnect is complete. | 111 // HttpStreamFactoryImpl subclass that can wait until a preconnect is complete. |
111 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { | 112 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { |
112 public: | 113 public: |
113 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, | 114 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, |
114 bool for_websockets) | 115 bool for_websockets) |
115 : HttpStreamFactoryImpl(session, for_websockets), | 116 : HttpStreamFactoryImpl(session, for_websockets), |
116 preconnect_done_(false), | 117 preconnect_done_(false), |
117 waiting_for_preconnect_(false) {} | 118 waiting_for_preconnect_(false) {} |
118 | 119 |
119 | |
120 void WaitForPreconnects() { | 120 void WaitForPreconnects() { |
121 while (!preconnect_done_) { | 121 while (!preconnect_done_) { |
122 waiting_for_preconnect_ = true; | 122 waiting_for_preconnect_ = true; |
123 base::MessageLoop::current()->Run(); | 123 base::MessageLoop::current()->Run(); |
124 waiting_for_preconnect_ = false; | 124 waiting_for_preconnect_ = false; |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 private: | 128 private: |
129 // HttpStreamFactoryImpl methods. | 129 // HttpStreamFactoryImpl methods. |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 ERR_QUIC_HANDSHAKE_FAILED, | 632 ERR_QUIC_HANDSHAKE_FAILED, |
633 ERR_SSL_PROTOCOL_ERROR, | 633 ERR_SSL_PROTOCOL_ERROR, |
634 ERR_MSG_TOO_BIG}; | 634 ERR_MSG_TOO_BIG}; |
635 for (size_t i = 0; i < arraysize(mock_error); ++i) { | 635 for (size_t i = 0; i < arraysize(mock_error); ++i) { |
636 scoped_ptr<ProxyService> proxy_service; | 636 scoped_ptr<ProxyService> proxy_service; |
637 proxy_service = | 637 proxy_service = |
638 ProxyService::CreateFixedFromPacResult("QUIC bad:99; DIRECT"); | 638 ProxyService::CreateFixedFromPacResult("QUIC bad:99; DIRECT"); |
639 | 639 |
640 HttpNetworkSession::Params params; | 640 HttpNetworkSession::Params params; |
641 params.enable_quic = true; | 641 params.enable_quic = true; |
642 params.disable_preconnects = false; | |
642 params.enable_quic_for_proxies = true; | 643 params.enable_quic_for_proxies = true; |
643 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service( | 644 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service( |
644 new SSLConfigServiceDefaults); | 645 new SSLConfigServiceDefaults); |
645 HttpServerPropertiesImpl http_server_properties; | 646 HttpServerPropertiesImpl http_server_properties; |
646 MockClientSocketFactory socket_factory; | 647 MockClientSocketFactory socket_factory; |
647 params.client_socket_factory = &socket_factory; | 648 params.client_socket_factory = &socket_factory; |
648 MockHostResolver host_resolver; | 649 MockHostResolver host_resolver; |
649 params.host_resolver = &host_resolver; | 650 params.host_resolver = &host_resolver; |
650 TransportSecurityState transport_security_state; | 651 TransportSecurityState transport_security_state; |
651 params.transport_security_state = &transport_security_state; | 652 params.transport_security_state = &transport_security_state; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 } // namespace | 694 } // namespace |
694 | 695 |
695 TEST_P(HttpStreamFactoryTest, QuicLossyProxyMarkedAsBad) { | 696 TEST_P(HttpStreamFactoryTest, QuicLossyProxyMarkedAsBad) { |
696 // Checks if a | 697 // Checks if a |
697 scoped_ptr<ProxyService> proxy_service; | 698 scoped_ptr<ProxyService> proxy_service; |
698 proxy_service = ProxyService::CreateFixedFromPacResult("QUIC bad:99; DIRECT"); | 699 proxy_service = ProxyService::CreateFixedFromPacResult("QUIC bad:99; DIRECT"); |
699 | 700 |
700 HttpNetworkSession::Params params; | 701 HttpNetworkSession::Params params; |
701 params.enable_quic = true; | 702 params.enable_quic = true; |
702 params.enable_quic_for_proxies = true; | 703 params.enable_quic_for_proxies = true; |
704 params.disable_preconnects = false; | |
703 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service( | 705 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service( |
704 new SSLConfigServiceDefaults); | 706 new SSLConfigServiceDefaults); |
705 HttpServerPropertiesImpl http_server_properties; | 707 HttpServerPropertiesImpl http_server_properties; |
706 MockClientSocketFactory socket_factory; | 708 MockClientSocketFactory socket_factory; |
707 params.client_socket_factory = &socket_factory; | 709 params.client_socket_factory = &socket_factory; |
708 MockHostResolver host_resolver; | 710 MockHostResolver host_resolver; |
709 params.host_resolver = &host_resolver; | 711 params.host_resolver = &host_resolver; |
710 TransportSecurityState transport_security_state; | 712 TransportSecurityState transport_security_state; |
711 params.transport_security_state = &transport_security_state; | 713 params.transport_security_state = &transport_security_state; |
712 params.proxy_service = proxy_service.get(); | 714 params.proxy_service = proxy_service.get(); |
(...skipping 28 matching lines...) Expand all Loading... | |
741 // The proxy that failed should now be known to the proxy_service as bad. | 743 // The proxy that failed should now be known to the proxy_service as bad. |
742 const ProxyRetryInfoMap& retry_info = | 744 const ProxyRetryInfoMap& retry_info = |
743 session->proxy_service()->proxy_retry_info(); | 745 session->proxy_service()->proxy_retry_info(); |
744 EXPECT_EQ(1u, retry_info.size()); | 746 EXPECT_EQ(1u, retry_info.size()); |
745 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 747 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
746 | 748 |
747 ProxyRetryInfoMap::const_iterator iter = retry_info.find("quic://bad:99"); | 749 ProxyRetryInfoMap::const_iterator iter = retry_info.find("quic://bad:99"); |
748 EXPECT_TRUE(iter != retry_info.end()); | 750 EXPECT_TRUE(iter != retry_info.end()); |
749 } | 751 } |
750 | 752 |
753 TEST_P(HttpStreamFactoryTest, PreconnectDisabled) { | |
Ryan Hamilton
2015/12/05 04:16:17
It'd be good to have a test where preconnect works
ramant (doing other things)
2015/12/07 20:05:39
Done.
| |
754 // Set up QUIC as alternative_service. | |
755 HttpServerPropertiesImpl http_server_properties; | |
756 const AlternativeService alternative_service1(QUIC, "www.google.com", 443); | |
757 AlternativeServiceInfoVector alternative_service_info_vector; | |
758 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | |
759 alternative_service_info_vector.push_back( | |
760 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); | |
761 HostPortPair host_port_pair(alternative_service1.host_port_pair()); | |
762 http_server_properties.SetAlternativeServices( | |
763 host_port_pair, alternative_service_info_vector); | |
764 | |
765 SpdySessionDependencies session_deps(GetParam()); | |
766 | |
767 // Setup params. | |
768 HttpNetworkSession::Params params = | |
769 SpdySessionDependencies::CreateSessionParams(&session_deps); | |
770 params.enable_quic = true; | |
771 params.disable_preconnects = true; | |
772 params.http_server_properties = http_server_properties.GetWeakPtr(); | |
773 | |
774 scoped_ptr<HttpNetworkSession> session(new HttpNetworkSession(params)); | |
775 | |
776 // Setup 0RTT for QUIC. | |
777 QuicStreamFactory* factory = session->quic_stream_factory(); | |
778 factory->set_require_confirmation(false); | |
779 test::QuicStreamFactoryPeer::CacheDummyServerConfig(factory, host_port_pair, | |
780 PRIVACY_MODE_DISABLED); | |
781 | |
782 HttpNetworkSessionPeer peer(session.get()); | |
783 CapturePreconnectsTransportSocketPool* transport_conn_pool = | |
784 new CapturePreconnectsTransportSocketPool( | |
785 session_deps.host_resolver.get(), session_deps.cert_verifier.get()); | |
786 scoped_ptr<MockClientSocketPoolManager> mock_pool_manager( | |
787 new MockClientSocketPoolManager); | |
788 mock_pool_manager->SetTransportSocketPool(transport_conn_pool); | |
789 peer.SetClientSocketPoolManager(mock_pool_manager.Pass()); | |
790 | |
791 HttpRequestInfo request; | |
792 request.method = "GET"; | |
793 request.url = GURL("https://www.google.com:443"); | |
Ryan Hamilton
2015/12/05 04:16:17
nit: do you need :443?
ramant (doing other things)
2015/12/07 20:05:39
Done.
| |
794 request.load_flags = 0; | |
795 | |
796 SSLConfig ssl_config; | |
797 session->ssl_config_service()->GetSSLConfig(&ssl_config); | |
798 session->http_stream_factory()->PreconnectStreams(1, request, ssl_config, | |
799 ssl_config); | |
800 EXPECT_EQ(-1, transport_conn_pool->last_num_streams()); | |
801 } | |
802 | |
751 namespace { | 803 namespace { |
752 | 804 |
753 TEST_P(HttpStreamFactoryTest, PrivacyModeDisablesChannelId) { | 805 TEST_P(HttpStreamFactoryTest, PrivacyModeDisablesChannelId) { |
754 SpdySessionDependencies session_deps( | 806 SpdySessionDependencies session_deps( |
755 GetParam(), ProxyService::CreateDirect()); | 807 GetParam(), ProxyService::CreateDirect()); |
756 | 808 |
757 StaticSocketDataProvider socket_data; | 809 StaticSocketDataProvider socket_data; |
758 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | 810 socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
759 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | 811 session_deps.socket_factory->AddSocketDataProvider(&socket_data); |
760 | 812 |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1440 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 1492 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
1441 | 1493 |
1442 // Make sure there is no orphaned job. it is already canceled. | 1494 // Make sure there is no orphaned job. it is already canceled. |
1443 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( | 1495 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( |
1444 session->http_stream_factory_for_websocket())->num_orphaned_jobs()); | 1496 session->http_stream_factory_for_websocket())->num_orphaned_jobs()); |
1445 } | 1497 } |
1446 | 1498 |
1447 } // namespace | 1499 } // namespace |
1448 | 1500 |
1449 } // namespace net | 1501 } // namespace net |
OLD | NEW |