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

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

Issue 2964603002: JobController: do not create alternative job for those AlternativeServiceInfo (Closed)
Patch Set: Always initialize local variable to fix windows compile issue Created 3 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) 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
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 that the controller does not create alternative job when the advertised
710 // versions in AlternativeServiceInfo do not contain any version that is
711 // supported.
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 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 Preconnect(kNumPreconects); 2103 Preconnect(kNumPreconects);
2075 // If experiment is enabled, only 1 stream is requested. 2104 // If experiment is enabled, only 1 stream is requested.
2076 EXPECT_EQ( 2105 EXPECT_EQ(
2077 (int)actual_num_connects, 2106 (int)actual_num_connects,
2078 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job())); 2107 HttpStreamFactoryImplJobPeer::GetNumStreams(job_controller_->main_job()));
2079 base::RunLoop().RunUntilIdle(); 2108 base::RunLoop().RunUntilIdle();
2080 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_)); 2109 EXPECT_TRUE(HttpStreamFactoryImplPeer::IsJobControllerDeleted(factory_));
2081 } 2110 }
2082 2111
2083 // Test that GetAlternativeServiceInfoFor will include a list of advertised 2112 // Test that GetAlternativeServiceInfoFor will include a list of advertised
2084 // versions. Returns an empty list if advertised versions are missing in 2113 // versions, which contains a version that is supported. Returns an empty list
2085 // HttpServerProperties. 2114 // if advertised versions are missing in HttpServerProperties.
2086 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) { 2115 TEST_F(HttpStreamFactoryImplJobControllerTest, GetAlternativeServiceInfoFor) {
2087 HttpRequestInfo request_info; 2116 HttpRequestInfo request_info;
2088 request_info.method = "GET"; 2117 request_info.method = "GET";
2089 request_info.url = GURL("https://www.google.com"); 2118 request_info.url = GURL("https://www.google.com");
2090 2119
2091 Initialize(request_info); 2120 Initialize(request_info);
2092 url::SchemeHostPort server(request_info.url); 2121 url::SchemeHostPort server(request_info.url);
2093 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); 2122 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
2094 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url); 2123 HostPortPair host_port_pair = HostPortPair::FromURL(request_info.url);
2095 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 2124 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
2096 2125
2097 // Set alternative service with no advertised version. 2126 // Set alternative service with no advertised version.
2098 session_->http_server_properties()->SetQuicAlternativeService( 2127 session_->http_server_properties()->SetQuicAlternativeService(
2099 server, alternative_service, expiration, QuicVersionVector()); 2128 server, alternative_service, expiration, QuicVersionVector());
2100 2129
2101 AlternativeServiceInfo alt_svc_info = 2130 AlternativeServiceInfo alt_svc_info =
2102 JobControllerPeer::GetAlternativeServiceInfoFor( 2131 JobControllerPeer::GetAlternativeServiceInfoFor(
2103 job_controller_, request_info, &request_delegate_, 2132 job_controller_, request_info, &request_delegate_,
2104 HttpStreamRequest::HTTP_STREAM); 2133 HttpStreamRequest::HTTP_STREAM);
2105 // Verify that JobController get an empty list of supported QUIC versions. 2134 // Verify that JobController get an empty list of supported QUIC versions.
2106 EXPECT_TRUE(alt_svc_info.advertised_versions().empty()); 2135 EXPECT_TRUE(alt_svc_info.advertised_versions().empty());
2107 2136
2108 // Set alternative service for the same server with QUIC_VERSION_39 specified. 2137 // Set alternative service for the same server with the same list of versions
2138 // that is supported.
2139 QuicVersionVector supported_versions =
2140 session_->params().quic_supported_versions;
2109 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( 2141 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService(
2110 server, alternative_service, expiration, {QUIC_VERSION_39})); 2142 server, alternative_service, expiration, supported_versions));
2111 2143
2112 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( 2144 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor(
2113 job_controller_, request_info, &request_delegate_, 2145 job_controller_, request_info, &request_delegate_,
2114 HttpStreamRequest::HTTP_STREAM); 2146 HttpStreamRequest::HTTP_STREAM);
2115 EXPECT_EQ(1u, alt_svc_info.advertised_versions().size()); 2147 std::sort(supported_versions.begin(), supported_versions.end());
2116 // Verify that JobController returns the single version specified in set. 2148 EXPECT_EQ(supported_versions, alt_svc_info.advertised_versions());
2117 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[0]); 2149
2150 QuicVersion unsupported_version_1(QUIC_VERSION_UNSUPPORTED);
2151 QuicVersion unsupported_version_2(QUIC_VERSION_UNSUPPORTED);
2152 for (const QuicVersion& version : AllSupportedVersions()) {
2153 if (std::find(supported_versions.begin(), supported_versions.end(),
2154 version) != supported_versions.end())
2155 continue;
2156 if (unsupported_version_1 == QUIC_VERSION_UNSUPPORTED) {
2157 unsupported_version_1 = version;
2158 continue;
2159 }
2160 unsupported_version_2 = version;
2161 break;
2162 }
2118 2163
2119 // Set alternative service for the same server with two QUIC versions: 2164 // Set alternative service for the same server with two QUIC versions:
2120 // QUIC_VERSION_35, QUIC_VERSION_39. 2165 // - one unsupported version: |unsupported_version_1|,
2166 // - one supported version: session_->params().quic_supported_versions[0].
2167 QuicVersionVector mixed_quic_versions = {
2168 unsupported_version_1, session_->params().quic_supported_versions[0]};
2121 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService( 2169 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService(
2122 server, alternative_service, expiration, 2170 server, alternative_service, expiration, mixed_quic_versions));
2123 {QUIC_VERSION_35, QUIC_VERSION_39}));
2124 2171
2125 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor( 2172 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor(
2126 job_controller_, request_info, &request_delegate_, 2173 job_controller_, request_info, &request_delegate_,
2127 HttpStreamRequest::HTTP_STREAM); 2174 HttpStreamRequest::HTTP_STREAM);
2128 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size()); 2175 EXPECT_EQ(2u, alt_svc_info.advertised_versions().size());
2129 // Verify that JobController returns the list of versions specified in set. 2176 // Verify that JobController returns the list of versions specified in set.
2130 EXPECT_EQ(QUIC_VERSION_35, alt_svc_info.advertised_versions()[0]); 2177 std::sort(mixed_quic_versions.begin(), mixed_quic_versions.end());
2131 EXPECT_EQ(QUIC_VERSION_39, alt_svc_info.advertised_versions()[1]); 2178 EXPECT_EQ(mixed_quic_versions, alt_svc_info.advertised_versions());
2179
2180 // Set alternative service for the same server with two unsupported QUIC
2181 // versions: |unsupported_version_1|, |unsupported_version_2|.
2182 ASSERT_TRUE(session_->http_server_properties()->SetQuicAlternativeService(
2183 server, alternative_service, expiration,
2184 {unsupported_version_1, unsupported_version_2}));
2185
2186 alt_svc_info = JobControllerPeer::GetAlternativeServiceInfoFor(
2187 job_controller_, request_info, &request_delegate_,
2188 HttpStreamRequest::HTTP_STREAM);
2189 // Verify that JobController returns no valid alternative service.
2190 EXPECT_EQ(kProtoUnknown, alt_svc_info.alternative_service().protocol);
2191 EXPECT_EQ(0u, alt_svc_info.advertised_versions().size());
2132 } 2192 }
2133 2193
2134 } // namespace test 2194 } // namespace test
2135 2195
2136 } // namespace net 2196 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_job_controller.cc ('k') | net/quic/chromium/quic_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698