Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_job_controller.h" | 5 #include "net/http/http_stream_factory_impl_job_controller.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 EXPECT_TRUE(job_controller_->alternative_job()); | 699 EXPECT_TRUE(job_controller_->alternative_job()); |
| 700 | 700 |
| 701 // Reset the Request will cancel all the Jobs since there's no Job determined | 701 // Reset the Request will cancel all the Jobs since there's no Job determined |
| 702 // to serve Request yet and JobController will notify the factory to delete | 702 // to serve Request yet and JobController will notify the factory to delete |
| 703 // itself upon completion. | 703 // itself upon completion. |
| 704 request_.reset(); | 704 request_.reset(); |
| 705 VerifyBrokenAlternateProtocolMapping(request_info, false); | 705 VerifyBrokenAlternateProtocolMapping(request_info, false); |
| 706 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 706 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 707 } | 707 } |
| 708 | 708 |
| 709 // Test we do not create alternative job when the advertised versions in | |
|
Ryan Hamilton
2017/06/30 02:45:11
nit: avoid first person. "Test that the controller
Zhongyi Shi
2017/06/30 21:08:43
Done.
| |
| 710 // AlternativeServiceInfo do not contain any version supported by the net | |
| 711 // stack. | |
| 712 TEST_F(HttpStreamFactoryImplJobControllerTest, | |
| 713 DoNotCreateAltJobIfQuicVersionsUnsupported) { | |
| 714 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | |
| 715 tcp_data_->set_connect_data(MockConnect(ASYNC, OK)); | |
| 716 HttpRequestInfo request_info; | |
| 717 request_info.method = "GET"; | |
| 718 request_info.url = GURL("https://www.google.com"); | |
| 719 | |
| 720 Initialize(request_info); | |
| 721 url::SchemeHostPort server(request_info.url); | |
| 722 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | |
| 723 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | |
| 724 session_->http_server_properties()->SetQuicAlternativeService( | |
| 725 server, alternative_service, expiration, {QUIC_VERSION_UNSUPPORTED}); | |
| 726 | |
| 727 request_ = | |
| 728 job_controller_->Start(&request_delegate_, nullptr, net_log_.bound(), | |
| 729 HttpStreamRequest::HTTP_STREAM, DEFAULT_PRIORITY); | |
| 730 EXPECT_TRUE(job_controller_->main_job()); | |
| 731 EXPECT_FALSE(job_controller_->alternative_job()); | |
| 732 | |
| 733 request_.reset(); | |
| 734 VerifyBrokenAlternateProtocolMapping(request_info, false); | |
| 735 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | |
| 736 } | |
| 737 | |
| 709 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { | 738 TEST_F(HttpStreamFactoryImplJobControllerTest, OnStreamFailedForBothJobs) { |
| 710 quic_data_ = base::MakeUnique<MockQuicData>(); | 739 quic_data_ = base::MakeUnique<MockQuicData>(); |
| 711 quic_data_->AddConnect(ASYNC, ERR_FAILED); | 740 quic_data_->AddConnect(ASYNC, ERR_FAILED); |
| 712 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); | 741 tcp_data_ = base::MakeUnique<SequencedSocketData>(nullptr, 0, nullptr, 0); |
| 713 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); | 742 tcp_data_->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
| 714 | 743 |
| 715 HttpRequestInfo request_info; | 744 HttpRequestInfo request_info; |
| 716 request_info.method = "GET"; | 745 request_info.method = "GET"; |
| 717 request_info.url = GURL("https://www.google.com"); | 746 request_info.url = GURL("https://www.google.com"); |
| 718 | 747 |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2079 Preconnect(kNumPreconects); | 2108 Preconnect(kNumPreconects); |
| 2080 // If experiment is enabled, only 1 stream is requested. | 2109 // If experiment is enabled, only 1 stream is requested. |
| 2081 EXPECT_EQ( | 2110 EXPECT_EQ( |
| 2082 (int)actual_num_connects, | 2111 (int)actual_num_connects, |
| 2083 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); | 2112 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); |
| 2084 base::RunLoop().RunUntilIdle(); | 2113 base::RunLoop().RunUntilIdle(); |
| 2085 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); | 2114 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); |
| 2086 } | 2115 } |
| 2087 | 2116 |
| 2088 // Test that GetAlternativeServiceInfoFor will include a list of advertised | 2117 // Test that GetAlternativeServiceInfoFor will include a list of advertised |
| 2089 // versions. Returns an empty list if advertised versions are missing in | 2118 // versions, which contains a version that is supported by the net stack. |
| 2119 // Returns an empty list if advertised versions are missing in | |
| 2090 // HttpServerProperties. | 2120 // HttpServerProperties. |
| 2091 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { | 2121 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { |
| 2092 HttpRequestInfo request_info; | 2122 HttpRequestInfo request_info; |
| 2093 request_info.method = "GET"; | 2123 request_info.method = "GET"; |
| 2094 request_info.url = GURL("https://www.google.com"); | 2124 request_info.url = GURL("https://www.google.com"); |
| 2095 | 2125 |
| 2096 Initialize(request_info); | 2126 Initialize(request_info); |
| 2097 url::SchemeHostPort server(request_info.url); | 2127 url::SchemeHostPort server(request_info.url); |
| 2098 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 2128 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 2099 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); | 2129 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); |
| 2100 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 2130 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 2101 | 2131 |
| 2102 // Set alternative service with no advertised version. | 2132 // Set alternative service with no advertised version. |
| 2103 session_->http_server_properties()->SetQuicAlternativeService( | 2133 session_->http_server_properties()->SetQuicAlternativeService( |
| 2104 server, alternative_service, expiration, QuicVersionVector()); | 2134 server, alternative_service, expiration, QuicVersionVector()); |
| 2105 | 2135 |
| 2106 AlternativeServiceInfo alt_svc_info = | 2136 AlternativeServiceInfo alt_svc_info = |
| 2107 JobControllerPeer::GetAlternativeServiceInfoFor( | 2137 JobControllerPeer::GetAlternativeServiceInfoFor( |
| 2108 job_controller_, request_info, &request_delegate_, | 2138 job_controller_, request_info, &request_delegate_, |
| 2109 HttpStreamRequest::HTTP_STREAM); | 2139 HttpStreamRequest::HTTP_STREAM); |
| 2110 // Verify that JobController get an empty list of supported QUIC versions. | 2140 // Verify that JobController get an empty list of supported QUIC versions. |
| 2111 EXPECT_TRUE(alt_svc_info.advertised_versions().empty()); | 2141 EXPECT_TRUE(alt_svc_info.advertised_versions().empty()); |
| 2112 | 2142 |
| 2113 // Set alternative service for the same server with QUIC_VERSION_39 specified. | 2143 // Set alternative service for the same server with the same list of versions |
| 2144 // that is supported by the net stack. | |
| 2145 QuicVersionVector supported_versions = | |
| 2146 session_->params().quic_supported_versions; | |
| 2114 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( | 2147 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( |
| 2115 server, alternative_service, expiration, {QUIC_VERSION_39})); | 2148 server, alternative_service, expiration, supported_versions)); |
| 2116 | 2149 |
| 2117 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( | 2150 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
| 2118 job_controller_, request_info, &request_delegate_, | 2151 job_controller_, request_info, &request_delegate_, |
| 2119 HttpStreamRequest::HTTP_STREAM); | 2152 HttpStreamRequest::HTTP_STREAM); |
| 2120 EXPECT_EQ(1u, alt_svc_info.advertised_versions().size()); | 2153 std::sort(supported_versions.begin(), supported_versions.end()); |
| 2121 // Verify that JobController returns the single version specified in set. | 2154 EXPECT_EQ(supported_versions, alt_svc_info.advertised_versions()); |
| 2122 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[0]); | |
| 2123 | 2155 |
| 2124 // Set alternative service for the same server with two QUIC versions: | 2156 // Set alternative service for the same server with two QUIC versions: |
| 2125 // QUIC_VERSION_35, QUIC_VERSION_39. | 2157 // - one unsupported version: QUIC_VERSION_35, |
| 2158 // - one supported version: session_->params().quic_supported_versions[0]. | |
| 2126 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( | 2159 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( |
| 2127 server, alternative_service, expiration, | 2160 server, alternative_service, expiration, |
| 2128 {QUIC_VERSION_35, QUIC_VERSION_39})); | 2161 {QUIC_VERSION_35, session_->params().quic_supported_versions[0]})); |
| 2129 | 2162 |
| 2130 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( | 2163 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( |
| 2131 job_controller_, request_info, &request_delegate_, | 2164 job_controller_, request_info, &request_delegate_, |
| 2132 HttpStreamRequest::HTTP_STREAM); | 2165 HttpStreamRequest::HTTP_STREAM); |
| 2133 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); | 2166 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); |
| 2134 // Verify that JobController returns the list of versions specified in set. | 2167 // Verify that JobController returns the list of versions specified in set. |
| 2135 EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); | 2168 EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); |
| 2136 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[1]); | 2169 EXPECT_EQ(session_->params().quic_supported_versions[0], |
| 2170 alt_svc_info.advertised_versions()[1]); | |
| 2171 | |
| 2172 // Set alternative service for the same server with two unsupported QUIC | |
| 2173 // versions: QUIC_VERSION_35, QUIC_VERSION_36. | |
| 2174 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( | |
| 2175 server, alternative_service, expiration, | |
| 2176 {QUIC_VERSION_35, QUIC_VERSION_36})); | |
| 2177 | |
| 2178 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( | |
| 2179 job_controller_, request_info, &request_delegate_, | |
| 2180 HttpStreamRequest::HTTP_STREAM); | |
| 2181 // Verify that JobController returns no valid alternative service. | |
| 2182 EXPECT_EQ(kProtoUnknown, alt_svc_info.alternative_service().protocol); | |
| 2183 EXPECT_EQ(0u, alt_svc_info.advertised_versions().size()); | |
| 2137 } | 2184 } |
| 2138 | 2185 |
| 2139 } // namespace test | 2186 } // namespace test |
| 2140 | 2187 |
| 2141 } // namespace net | 2188 } // namespace net |
| OLD | NEW |