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

Side by Side Diff: net/quic/chromium/quic_network_transaction_unittest.cc

Issue 2964603002: JobController: do not create alternative job for those AlternativeServiceInfo (Closed)
Patch Set: 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) 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 <algorithm> 5 #include <algorithm>
6 #include <memory> 6 #include <memory>
7 #include <ostream> 7 #include <ostream>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 1183
1184 request_.url = GURL("https://" + origin.host()); 1184 request_.url = GURL("https://" + origin.host());
1185 AddQuicRemoteAlternativeServiceMapping( 1185 AddQuicRemoteAlternativeServiceMapping(
1186 MockCryptoClientStream::CONFIRM_HANDSHAKE, alternative); 1186 MockCryptoClientStream::CONFIRM_HANDSHAKE, alternative);
1187 AddHangingNonAlternateProtocolSocketData(); 1187 AddHangingNonAlternateProtocolSocketData();
1188 CreateSession(); 1188 CreateSession();
1189 1189
1190 SendRequestAndExpectQuicResponse("hello!"); 1190 SendRequestAndExpectQuicResponse("hello!");
1191 } 1191 }
1192 1192
1193 TEST_P(QuicNetworkTransactionTest, DoNotUseQuicForUnsupportedVersion) {
1194 // Add support for another QUIC version besides |version_|.
1195 // Client supported versions: {version_, QUIC_VERSION_40/QUIC_VERSION_37}.
1196 if (version_ != QUIC_VERSION_40) {
1197 supported_versions_.push_back(QUIC_VERSION_40);
1198 } else {
1199 supported_versions_.push_back(QUIC_VERSION_37);
1200 }
Ryan Hamilton 2017/06/30 02:45:11 Can you do the same trick as in your previous CL?
Zhongyi Shi 2017/06/30 21:08:43 Done.
1201
1202 // Set up alternative service to use QUIC with a version that is not supported
1203 // by the net stack: QUIC_VERSION_35/QUIC_VERSION_39.
1204 QuicVersion unsupported_version(QUIC_VERSION_35);
1205 if (version_ == QUIC_VERSION_35)
1206 unsupported_version = QUIC_VERSION_39;
Ryan Hamilton 2017/06/30 02:45:11 ditto
Zhongyi Shi 2017/06/30 21:08:43 Done.
1207
1208 url::SchemeHostPort server(request_.url);
1209 AlternativeService alternative_service(kProtoQUIC, kDefaultServerHostName,
1210 443);
1211 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
1212 http_server_properties_.SetQuicAlternativeService(
1213 server, alternative_service, expiration, {unsupported_version});
1214
1215 AlternativeServiceInfoVector alt_svc_info_vector =
1216 http_server_properties_.GetAlternativeServiceInfos(server);
1217 EXPECT_EQ(1u, alt_svc_info_vector.size());
1218 EXPECT_EQ(kProtoQUIC, alt_svc_info_vector[0].alternative_service().protocol);
1219 EXPECT_EQ(1u, alt_svc_info_vector[0].advertised_versions().size());
1220 EXPECT_EQ(unsupported_version,
1221 alt_svc_info_vector[0].advertised_versions()[0]);
1222
1223 // First request should still be sent via TCP as the QUIC version advertised
1224 // in the stored AlternativeService is not supported by the client. However,
1225 // the response from the server will advertise new Alt-Svc with supported
1226 // versions.
1227 std::string advertised_versions_list_str =
1228 GenerateQuicVersionsListForAltSvcHeader(AllSupportedVersions());
1229 std::string altsvc_header =
1230 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%s\"\r\n\r\n",
1231 advertised_versions_list_str.c_str());
1232 MockRead http_reads[] = {
1233 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()),
1234 MockRead("hello world"),
1235 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
1236 MockRead(ASYNC, OK)};
1237
1238 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
1239 0);
1240 socket_factory_.AddSocketDataProvider(&http_data);
1241 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
1242
1243 // Second request should be sent via QUIC as a new list of verions supported
1244 // by the client has been advertised by the server.
1245 MockQuicData mock_quic_data;
1246 QuicStreamOffset header_stream_offset = 0;
1247 mock_quic_data.AddWrite(
1248 ConstructInitialSettingsPacket(1, &header_stream_offset));
1249 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
1250 2, GetNthClientInitiatedStreamId(0), true, true,
1251 GetRequestHeaders("GET", "https", "/"), &header_stream_offset));
1252 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
1253 1, GetNthClientInitiatedStreamId(0), false, false,
1254 GetResponseHeaders("200 OK")));
1255 mock_quic_data.AddRead(ConstructServerDataPacket(
1256 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!"));
1257 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1));
1258 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
1259 mock_quic_data.AddRead(ASYNC, 0); // EOF
1260
1261 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
1262
1263 AddHangingNonAlternateProtocolSocketData();
1264
1265 CreateSession(supported_versions_);
1266
1267 SendRequestAndExpectHttpResponse("hello world");
1268 SendRequestAndExpectQuicResponse("hello!");
1269
1270 // Check alternative service list is updated with new versions.
1271 alt_svc_info_vector =
1272 session_->http_server_properties()->GetAlternativeServiceInfos(server);
1273 EXPECT_EQ(1u, alt_svc_info_vector.size());
1274 EXPECT_EQ(kProtoQUIC, alt_svc_info_vector[0].alternative_service().protocol);
1275 EXPECT_EQ(2u, alt_svc_info_vector[0].advertised_versions().size());
1276 // Advertised versions will be lised in a sorted order.
1277 std::sort(supported_versions_.begin(), supported_versions_.end());
1278 EXPECT_EQ(supported_versions_[0],
1279 alt_svc_info_vector[0].advertised_versions()[0]);
1280 EXPECT_EQ(supported_versions_[1],
1281 alt_svc_info_vector[0].advertised_versions()[1]);
1282 }
1283
1193 // Regression test for https://crbug.com/546991. 1284 // Regression test for https://crbug.com/546991.
1194 // The server might not be able to serve a request on an alternative connection, 1285 // The server might not be able to serve a request on an alternative connection,
1195 // and might send a 421 Misdirected Request response status to indicate this. 1286 // and might send a 421 Misdirected Request response status to indicate this.
1196 // HttpNetworkTransaction should reset the request and retry without using 1287 // HttpNetworkTransaction should reset the request and retry without using
1197 // alternative services. 1288 // alternative services.
1198 TEST_P(QuicNetworkTransactionTest, RetryMisdirectedRequest) { 1289 TEST_P(QuicNetworkTransactionTest, RetryMisdirectedRequest) {
1199 // Set up alternative service to use QUIC. 1290 // Set up alternative service to use QUIC.
1200 // Note that |origins_to_force_quic_on| cannot be used in this test, because 1291 // Note that |origins_to_force_quic_on| cannot be used in this test, because
1201 // that overrides |enable_alternative_services|. 1292 // that overrides |enable_alternative_services|.
1202 url::SchemeHostPort server(request_.url); 1293 url::SchemeHostPort server(request_.url);
(...skipping 3986 matching lines...) Expand 10 before | Expand all | Expand 10 after
5189 5280
5190 request_.url = GURL("https://mail.example.org/pushed.jpg"); 5281 request_.url = GURL("https://mail.example.org/pushed.jpg");
5191 ChunkedUploadDataStream upload_data(0); 5282 ChunkedUploadDataStream upload_data(0);
5192 upload_data.AppendData("1", 1, true); 5283 upload_data.AppendData("1", 1, true);
5193 request_.upload_data_stream = &upload_data; 5284 request_.upload_data_stream = &upload_data;
5194 SendRequestAndExpectQuicResponse("and hello!"); 5285 SendRequestAndExpectQuicResponse("and hello!");
5195 } 5286 }
5196 5287
5197 } // namespace test 5288 } // namespace test
5198 } // namespace net 5289 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698