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 <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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 | 232 |
| 233 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory); | 233 DISALLOW_COPY_AND_ASSIGN(TestSocketPerformanceWatcherFactory); |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 class QuicNetworkTransactionTest | 236 class QuicNetworkTransactionTest |
| 237 : public PlatformTest, | 237 : public PlatformTest, |
| 238 public ::testing::WithParamInterface<QuicVersion> { | 238 public ::testing::WithParamInterface<QuicVersion> { |
| 239 protected: | 239 protected: |
| 240 QuicNetworkTransactionTest() | 240 QuicNetworkTransactionTest() |
| 241 : version_(GetParam()), | 241 : version_(GetParam()), |
| 242 supported_versions_(SupportedVersions(version_)), | |
| 242 client_maker_(version_, | 243 client_maker_(version_, |
| 243 0, | 244 0, |
| 244 &clock_, | 245 &clock_, |
| 245 kDefaultServerHostName, | 246 kDefaultServerHostName, |
| 246 Perspective::IS_CLIENT), | 247 Perspective::IS_CLIENT), |
| 247 server_maker_(version_, | 248 server_maker_(version_, |
| 248 0, | 249 0, |
| 249 &clock_, | 250 &clock_, |
| 250 kDefaultServerHostName, | 251 kDefaultServerHostName, |
| 251 Perspective::IS_SERVER), | 252 Perspective::IS_SERVER), |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 session_context_.proxy_service = proxy_service_.get(); | 532 session_context_.proxy_service = proxy_service_.get(); |
| 532 session_context_.ssl_config_service = ssl_config_service_.get(); | 533 session_context_.ssl_config_service = ssl_config_service_.get(); |
| 533 session_context_.http_auth_handler_factory = auth_handler_factory_.get(); | 534 session_context_.http_auth_handler_factory = auth_handler_factory_.get(); |
| 534 session_context_.http_server_properties = &http_server_properties_; | 535 session_context_.http_server_properties = &http_server_properties_; |
| 535 session_context_.net_log = net_log_.bound().net_log(); | 536 session_context_.net_log = net_log_.bound().net_log(); |
| 536 | 537 |
| 537 session_.reset(new HttpNetworkSession(session_params_, session_context_)); | 538 session_.reset(new HttpNetworkSession(session_params_, session_context_)); |
| 538 session_->quic_stream_factory()->set_require_confirmation(false); | 539 session_->quic_stream_factory()->set_require_confirmation(false); |
| 539 } | 540 } |
| 540 | 541 |
| 541 void CreateSession() { return CreateSession(SupportedVersions(version_)); } | 542 void CreateSession() { return CreateSession(supported_versions_); } |
| 542 | 543 |
| 543 void CheckWasQuicResponse(HttpNetworkTransaction* trans) { | 544 void CheckWasQuicResponse(HttpNetworkTransaction* trans) { |
| 544 const HttpResponseInfo* response = trans->GetResponseInfo(); | 545 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 545 ASSERT_TRUE(response != nullptr); | 546 ASSERT_TRUE(response != nullptr); |
| 546 ASSERT_TRUE(response->headers.get() != nullptr); | 547 ASSERT_TRUE(response->headers.get() != nullptr); |
| 547 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 548 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 548 EXPECT_TRUE(response->was_fetched_via_spdy); | 549 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 549 EXPECT_TRUE(response->was_alpn_negotiated); | 550 EXPECT_TRUE(response->was_alpn_negotiated); |
| 550 EXPECT_EQ(QuicHttpStream::ConnectionInfoFromQuicVersion(version_), | 551 EXPECT_EQ(QuicHttpStream::ConnectionInfoFromQuicVersion(version_), |
| 551 response->connection_info); | 552 response->connection_info); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); | 620 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); |
| 620 } | 621 } |
| 621 | 622 |
| 622 void AddQuicAlternateProtocolMapping( | 623 void AddQuicAlternateProtocolMapping( |
| 623 MockCryptoClientStream::HandshakeMode handshake_mode) { | 624 MockCryptoClientStream::HandshakeMode handshake_mode) { |
| 624 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); | 625 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
| 625 url::SchemeHostPort server(request_.url); | 626 url::SchemeHostPort server(request_.url); |
| 626 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); | 627 AlternativeService alternative_service(kProtoQUIC, server.host(), 443); |
| 627 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 628 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 628 http_server_properties_.SetQuicAlternativeService( | 629 http_server_properties_.SetQuicAlternativeService( |
| 629 server, alternative_service, expiration, | 630 server, alternative_service, expiration, supported_versions_); |
| 630 HttpNetworkSession::Params().quic_supported_versions); | |
| 631 } | 631 } |
| 632 | 632 |
| 633 void AddQuicRemoteAlternativeServiceMapping( | 633 void AddQuicRemoteAlternativeServiceMapping( |
| 634 MockCryptoClientStream::HandshakeMode handshake_mode, | 634 MockCryptoClientStream::HandshakeMode handshake_mode, |
| 635 const HostPortPair& alternative) { | 635 const HostPortPair& alternative) { |
| 636 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); | 636 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
| 637 url::SchemeHostPort server(request_.url); | 637 url::SchemeHostPort server(request_.url); |
| 638 AlternativeService alternative_service(kProtoQUIC, alternative.host(), | 638 AlternativeService alternative_service(kProtoQUIC, alternative.host(), |
| 639 alternative.port()); | 639 alternative.port()); |
| 640 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 640 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 641 http_server_properties_.SetQuicAlternativeService( | 641 http_server_properties_.SetQuicAlternativeService( |
| 642 server, alternative_service, expiration, | 642 server, alternative_service, expiration, supported_versions_); |
| 643 HttpNetworkSession::Params().quic_supported_versions); | |
| 644 } | 643 } |
| 645 | 644 |
| 646 void ExpectBrokenAlternateProtocolMapping() { | 645 void ExpectBrokenAlternateProtocolMapping() { |
| 647 const url::SchemeHostPort server(request_.url); | 646 const url::SchemeHostPort server(request_.url); |
| 648 const AlternativeServiceInfoVector alternative_service_info_vector = | 647 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 649 http_server_properties_.GetAlternativeServiceInfos(server); | 648 http_server_properties_.GetAlternativeServiceInfos(server); |
| 650 EXPECT_EQ(1u, alternative_service_info_vector.size()); | 649 EXPECT_EQ(1u, alternative_service_info_vector.size()); |
| 651 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( | 650 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( |
| 652 alternative_service_info_vector[0].alternative_service())); | 651 alternative_service_info_vector[0].alternative_service())); |
| 653 } | 652 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 | 740 |
| 742 QuicStreamId GetNthClientInitiatedStreamId(int n) { | 741 QuicStreamId GetNthClientInitiatedStreamId(int n) { |
| 743 return test::GetNthClientInitiatedStreamId(version_, n); | 742 return test::GetNthClientInitiatedStreamId(version_, n); |
| 744 } | 743 } |
| 745 | 744 |
| 746 QuicStreamId GetNthServerInitiatedStreamId(int n) { | 745 QuicStreamId GetNthServerInitiatedStreamId(int n) { |
| 747 return test::GetNthServerInitiatedStreamId(version_, n); | 746 return test::GetNthServerInitiatedStreamId(version_, n); |
| 748 } | 747 } |
| 749 | 748 |
| 750 const QuicVersion version_; | 749 const QuicVersion version_; |
| 750 QuicVersionVector supported_versions_; | |
| 751 QuicFlagSaver flags_; // Save/restore all QUIC flag values. | 751 QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
| 752 MockClock clock_; | 752 MockClock clock_; |
| 753 QuicTestPacketMaker client_maker_; | 753 QuicTestPacketMaker client_maker_; |
| 754 QuicTestPacketMaker server_maker_; | 754 QuicTestPacketMaker server_maker_; |
| 755 std::unique_ptr<HttpNetworkSession> session_; | 755 std::unique_ptr<HttpNetworkSession> session_; |
| 756 MockClientSocketFactory socket_factory_; | 756 MockClientSocketFactory socket_factory_; |
| 757 ProofVerifyDetailsChromium verify_details_; | 757 ProofVerifyDetailsChromium verify_details_; |
| 758 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 758 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 759 MockHostResolver host_resolver_; | 759 MockHostResolver host_resolver_; |
| 760 MockCertVerifier cert_verifier_; | 760 MockCertVerifier cert_verifier_; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 // alternative services. | 1197 // alternative services. |
| 1198 TEST_P(QuicNetworkTransactionTest, RetryMisdirectedRequest) { | 1198 TEST_P(QuicNetworkTransactionTest, RetryMisdirectedRequest) { |
| 1199 // Set up alternative service to use QUIC. | 1199 // Set up alternative service to use QUIC. |
| 1200 // Note that |origins_to_force_quic_on| cannot be used in this test, because | 1200 // Note that |origins_to_force_quic_on| cannot be used in this test, because |
| 1201 // that overrides |enable_alternative_services|. | 1201 // that overrides |enable_alternative_services|. |
| 1202 url::SchemeHostPort server(request_.url); | 1202 url::SchemeHostPort server(request_.url); |
| 1203 AlternativeService alternative_service(kProtoQUIC, kDefaultServerHostName, | 1203 AlternativeService alternative_service(kProtoQUIC, kDefaultServerHostName, |
| 1204 443); | 1204 443); |
| 1205 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 1205 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 1206 http_server_properties_.SetQuicAlternativeService( | 1206 http_server_properties_.SetQuicAlternativeService( |
| 1207 server, alternative_service, expiration, | 1207 server, alternative_service, expiration, supported_versions_); |
| 1208 HttpNetworkSession::Params().quic_supported_versions); | |
| 1209 | 1208 |
| 1210 // First try: The alternative job uses QUIC and reports an HTTP 421 | 1209 // First try: The alternative job uses QUIC and reports an HTTP 421 |
| 1211 // Misdirected Request error. The main job uses TCP, but |http_data| below is | 1210 // Misdirected Request error. The main job uses TCP, but |http_data| below is |
| 1212 // paused at Connect(), so it will never exit the socket pool. This ensures | 1211 // paused at Connect(), so it will never exit the socket pool. This ensures |
| 1213 // that the alternate job always wins the race and keeps whether the | 1212 // that the alternate job always wins the race and keeps whether the |
| 1214 // |http_data| exits the socket pool before the main job is aborted | 1213 // |http_data| exits the socket pool before the main job is aborted |
| 1215 // deterministic. The first main job gets aborted without the socket pool ever | 1214 // deterministic. The first main job gets aborted without the socket pool ever |
| 1216 // dispensing the socket, making it available for the second try. | 1215 // dispensing the socket, making it available for the second try. |
| 1217 MockQuicData mock_quic_data; | 1216 MockQuicData mock_quic_data; |
| 1218 QuicStreamOffset request_header_offset = 0; | 1217 QuicStreamOffset request_header_offset = 0; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1460 http_server_properties->GetAlternativeServiceInfos(https_server).size()); | 1459 http_server_properties->GetAlternativeServiceInfos(https_server).size()); |
| 1461 | 1460 |
| 1462 // Send http request to the same origin but with diffrent scheme, should not | 1461 // Send http request to the same origin but with diffrent scheme, should not |
| 1463 // use QUIC. | 1462 // use QUIC. |
| 1464 request_.url = GURL("http://mail.example.org:443"); | 1463 request_.url = GURL("http://mail.example.org:443"); |
| 1465 SendRequestAndExpectHttpResponse("hello world"); | 1464 SendRequestAndExpectHttpResponse("hello world"); |
| 1466 } | 1465 } |
| 1467 | 1466 |
| 1468 TEST_P(QuicNetworkTransactionTest, | 1467 TEST_P(QuicNetworkTransactionTest, |
| 1469 StoreMutuallySupportedVersionsWhenProcessAltSvc) { | 1468 StoreMutuallySupportedVersionsWhenProcessAltSvc) { |
| 1469 // Add support for another QUIC version besides |version_|. | |
| 1470 if (version_ != QUIC_VERSION_40) { | |
| 1471 supported_versions_.push_back(QUIC_VERSION_40); | |
| 1472 } else { | |
| 1473 supported_versions_.push_back(QUIC_VERSION_37); | |
| 1474 } | |
|
Ryan Hamilton
2017/06/29 22:50:10
You might consider doing something which avoids ha
Zhongyi Shi
2017/06/29 23:56:29
Good point! Thanks for the suggestion!
| |
| 1475 | |
| 1470 std::string advertised_versions_list_str = | 1476 std::string advertised_versions_list_str = |
| 1471 GenerateQuicVersionsListForAltSvcHeader(AllSupportedVersions()); | 1477 GenerateQuicVersionsListForAltSvcHeader(AllSupportedVersions()); |
| 1472 std::string altsvc_header = | 1478 std::string altsvc_header = |
| 1473 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%s\"\r\n\r\n", | 1479 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%s\"\r\n\r\n", |
| 1474 advertised_versions_list_str.c_str()); | 1480 advertised_versions_list_str.c_str()); |
| 1475 MockRead http_reads[] = { | 1481 MockRead http_reads[] = { |
| 1476 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), | 1482 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), |
| 1477 MockRead("hello world"), | 1483 MockRead("hello world"), |
| 1478 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 1484 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1479 MockRead(ASYNC, OK)}; | 1485 MockRead(ASYNC, OK)}; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1496 mock_quic_data.AddRead(ConstructServerDataPacket( | 1502 mock_quic_data.AddRead(ConstructServerDataPacket( |
| 1497 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!")); | 1503 2, GetNthClientInitiatedStreamId(0), false, true, 0, "hello!")); |
| 1498 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1)); | 1504 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1, 1)); |
| 1499 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | 1505 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 1500 mock_quic_data.AddRead(ASYNC, 0); // EOF | 1506 mock_quic_data.AddRead(ASYNC, 0); // EOF |
| 1501 | 1507 |
| 1502 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 1508 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1503 | 1509 |
| 1504 AddHangingNonAlternateProtocolSocketData(); | 1510 AddHangingNonAlternateProtocolSocketData(); |
| 1505 | 1511 |
| 1506 // Generate a list of QUIC versions suppored by netstack. | 1512 CreateSession(supported_versions_); |
| 1507 QuicVersionVector current_supported_versions = SupportedVersions(version_); | |
| 1508 if (version_ != QUIC_VERSION_40) { | |
| 1509 current_supported_versions.push_back(QUIC_VERSION_40); | |
| 1510 } else { | |
| 1511 current_supported_versions.push_back(QUIC_VERSION_37); | |
| 1512 } | |
| 1513 | |
| 1514 CreateSession(current_supported_versions); | |
| 1515 | 1513 |
| 1516 SendRequestAndExpectHttpResponse("hello world"); | 1514 SendRequestAndExpectHttpResponse("hello world"); |
| 1517 SendRequestAndExpectQuicResponse("hello!"); | 1515 SendRequestAndExpectQuicResponse("hello!"); |
| 1518 | 1516 |
| 1519 // Check alternative service is set with only mutually supported versions. | 1517 // Check alternative service is set with only mutually supported versions. |
| 1520 const url::SchemeHostPort https_server(request_.url); | 1518 const url::SchemeHostPort https_server(request_.url); |
| 1521 const AlternativeServiceInfoVector alt_svc_info_vector = | 1519 const AlternativeServiceInfoVector alt_svc_info_vector = |
| 1522 session_->http_server_properties()->GetAlternativeServiceInfos( | 1520 session_->http_server_properties()->GetAlternativeServiceInfos( |
| 1523 https_server); | 1521 https_server); |
| 1524 EXPECT_EQ(1u, alt_svc_info_vector.size()); | 1522 EXPECT_EQ(1u, alt_svc_info_vector.size()); |
| 1525 EXPECT_EQ(kProtoQUIC, alt_svc_info_vector[0].alternative_service().protocol); | 1523 EXPECT_EQ(kProtoQUIC, alt_svc_info_vector[0].alternative_service().protocol); |
| 1526 EXPECT_EQ(2u, alt_svc_info_vector[0].advertised_versions().size()); | 1524 EXPECT_EQ(2u, alt_svc_info_vector[0].advertised_versions().size()); |
| 1527 // Advertised versions will be lised in a sorted order. | 1525 // Advertised versions will be lised in a sorted order. |
| 1528 std::sort(current_supported_versions.begin(), | 1526 std::sort(supported_versions_.begin(), supported_versions_.end()); |
| 1529 current_supported_versions.end()); | 1527 EXPECT_EQ(supported_versions_[0], |
| 1530 EXPECT_EQ(current_supported_versions[0], | |
| 1531 alt_svc_info_vector[0].advertised_versions()[0]); | 1528 alt_svc_info_vector[0].advertised_versions()[0]); |
| 1532 EXPECT_EQ(current_supported_versions[1], | 1529 EXPECT_EQ(supported_versions_[1], |
| 1533 alt_svc_info_vector[0].advertised_versions()[1]); | 1530 alt_svc_info_vector[0].advertised_versions()[1]); |
| 1534 } | 1531 } |
| 1535 | 1532 |
| 1536 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceAllSupportedVersion) { | 1533 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceAllSupportedVersion) { |
| 1537 std::string altsvc_header = | 1534 std::string altsvc_header = |
| 1538 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", version_); | 1535 base::StringPrintf("Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", version_); |
| 1539 MockRead http_reads[] = { | 1536 MockRead http_reads[] = { |
| 1540 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), | 1537 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), |
| 1541 MockRead("hello world"), | 1538 MockRead("hello world"), |
| 1542 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 1539 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| (...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2858 | 2855 |
| 2859 mock_quic_data2.AddSocketDataToFactory(&socket_factory_); | 2856 mock_quic_data2.AddSocketDataToFactory(&socket_factory_); |
| 2860 | 2857 |
| 2861 CreateSession(); | 2858 CreateSession(); |
| 2862 | 2859 |
| 2863 // Set up alternative service for |origin1|. | 2860 // Set up alternative service for |origin1|. |
| 2864 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 2861 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 2865 http_server_properties_.SetQuicAlternativeService( | 2862 http_server_properties_.SetQuicAlternativeService( |
| 2866 url::SchemeHostPort(origin1), | 2863 url::SchemeHostPort(origin1), |
| 2867 AlternativeService(kProtoQUIC, "mail.example.com", 443), expiration, | 2864 AlternativeService(kProtoQUIC, "mail.example.com", 443), expiration, |
| 2868 HttpNetworkSession::Params().quic_supported_versions); | 2865 supported_versions_); |
| 2869 | 2866 |
| 2870 // Set up alternative service for |origin2|. | 2867 // Set up alternative service for |origin2|. |
| 2871 AlternativeServiceInfoVector alternative_services; | 2868 AlternativeServiceInfoVector alternative_services; |
| 2872 http_server_properties_.SetQuicAlternativeService( | 2869 http_server_properties_.SetQuicAlternativeService( |
| 2873 url::SchemeHostPort(origin2), | 2870 url::SchemeHostPort(origin2), |
| 2874 AlternativeService(kProtoQUIC, "www.example.com", 443), expiration, | 2871 AlternativeService(kProtoQUIC, "www.example.com", 443), expiration, |
| 2875 HttpNetworkSession::Params().quic_supported_versions); | 2872 supported_versions_); |
| 2876 // First request opens connection to |destination1| | 2873 // First request opens connection to |destination1| |
| 2877 // with QuicServerId.host() == origin1.host(). | 2874 // with QuicServerId.host() == origin1.host(). |
| 2878 SendRequestAndExpectQuicResponse("hello!"); | 2875 SendRequestAndExpectQuicResponse("hello!"); |
| 2879 | 2876 |
| 2880 // Second request pools to existing connection with same destination, | 2877 // Second request pools to existing connection with same destination, |
| 2881 // because certificate matches, even though QuicServerId is different. | 2878 // because certificate matches, even though QuicServerId is different. |
| 2882 // After it is reset, it will fail back to QUIC and mark QUIC as broken. | 2879 // After it is reset, it will fail back to QUIC and mark QUIC as broken. |
| 2883 request_.url = origin2; | 2880 request_.url = origin2; |
| 2884 SendRequestAndExpectHttpResponse("hello world"); | 2881 SendRequestAndExpectHttpResponse("hello world"); |
| 2885 | 2882 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3089 CreateSession(); | 3086 CreateSession(); |
| 3090 | 3087 |
| 3091 const char destination1[] = "first.example.com"; | 3088 const char destination1[] = "first.example.com"; |
| 3092 const char destination2[] = "second.example.com"; | 3089 const char destination2[] = "second.example.com"; |
| 3093 | 3090 |
| 3094 // Set up alternative service entry to destination1. | 3091 // Set up alternative service entry to destination1. |
| 3095 url::SchemeHostPort server(request_.url); | 3092 url::SchemeHostPort server(request_.url); |
| 3096 AlternativeService alternative_service(kProtoQUIC, destination1, 443); | 3093 AlternativeService alternative_service(kProtoQUIC, destination1, 443); |
| 3097 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 3094 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 3098 http_server_properties_.SetQuicAlternativeService( | 3095 http_server_properties_.SetQuicAlternativeService( |
| 3099 server, alternative_service, expiration, | 3096 server, alternative_service, expiration, supported_versions_); |
| 3100 HttpNetworkSession::Params().quic_supported_versions); | |
| 3101 // First request opens connection to |destination1| | 3097 // First request opens connection to |destination1| |
| 3102 // with QuicServerId.host() == kDefaultServerHostName. | 3098 // with QuicServerId.host() == kDefaultServerHostName. |
| 3103 SendRequestAndExpectQuicResponse("hello!"); | 3099 SendRequestAndExpectQuicResponse("hello!"); |
| 3104 | 3100 |
| 3105 // Set up alternative service entry to a different destination. | 3101 // Set up alternative service entry to a different destination. |
| 3106 alternative_service = AlternativeService(kProtoQUIC, destination2, 443); | 3102 alternative_service = AlternativeService(kProtoQUIC, destination2, 443); |
| 3107 http_server_properties_.SetQuicAlternativeService( | 3103 http_server_properties_.SetQuicAlternativeService( |
| 3108 server, alternative_service, expiration, | 3104 server, alternative_service, expiration, supported_versions_); |
| 3109 HttpNetworkSession::Params().quic_supported_versions); | |
| 3110 // Second request pools to existing connection with same QuicServerId, | 3105 // Second request pools to existing connection with same QuicServerId, |
| 3111 // even though alternative service destination is different. | 3106 // even though alternative service destination is different. |
| 3112 SendRequestAndExpectQuicResponse("hello!"); | 3107 SendRequestAndExpectQuicResponse("hello!"); |
| 3113 } | 3108 } |
| 3114 | 3109 |
| 3115 // Pool to existing session with matching destination and matching certificate | 3110 // Pool to existing session with matching destination and matching certificate |
| 3116 // even if origin is different, and even if the alternative service with | 3111 // even if origin is different, and even if the alternative service with |
| 3117 // matching destination is not the first one on the list. | 3112 // matching destination is not the first one on the list. |
| 3118 TEST_P(QuicNetworkTransactionTest, PoolByDestination) { | 3113 TEST_P(QuicNetworkTransactionTest, PoolByDestination) { |
| 3119 GURL origin1 = request_.url; | 3114 GURL origin1 = request_.url; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3164 CreateSession(); | 3159 CreateSession(); |
| 3165 | 3160 |
| 3166 const char destination1[] = "first.example.com"; | 3161 const char destination1[] = "first.example.com"; |
| 3167 const char destination2[] = "second.example.com"; | 3162 const char destination2[] = "second.example.com"; |
| 3168 | 3163 |
| 3169 // Set up alternative service for |origin1|. | 3164 // Set up alternative service for |origin1|. |
| 3170 AlternativeService alternative_service1(kProtoQUIC, destination1, 443); | 3165 AlternativeService alternative_service1(kProtoQUIC, destination1, 443); |
| 3171 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 3166 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 3172 http_server_properties_.SetQuicAlternativeService( | 3167 http_server_properties_.SetQuicAlternativeService( |
| 3173 url::SchemeHostPort(origin1), alternative_service1, expiration, | 3168 url::SchemeHostPort(origin1), alternative_service1, expiration, |
| 3174 HttpNetworkSession::Params().quic_supported_versions); | 3169 supported_versions_); |
| 3175 | 3170 |
| 3176 // Set up multiple alternative service entries for |origin2|, | 3171 // Set up multiple alternative service entries for |origin2|, |
| 3177 // the first one with a different destination as for |origin1|, | 3172 // the first one with a different destination as for |origin1|, |
| 3178 // the second one with the same. The second one should be used, | 3173 // the second one with the same. The second one should be used, |
| 3179 // because the request can be pooled to that one. | 3174 // because the request can be pooled to that one. |
| 3180 AlternativeService alternative_service2(kProtoQUIC, destination2, 443); | 3175 AlternativeService alternative_service2(kProtoQUIC, destination2, 443); |
| 3181 AlternativeServiceInfoVector alternative_services; | 3176 AlternativeServiceInfoVector alternative_services; |
| 3182 alternative_services.push_back( | 3177 alternative_services.push_back( |
| 3183 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( | 3178 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 3184 alternative_service2, expiration, | 3179 alternative_service2, expiration, |
| (...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4684 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed()); | 4679 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed()); |
| 4685 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed()); | 4680 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed()); |
| 4686 } | 4681 } |
| 4687 | 4682 |
| 4688 class QuicNetworkTransactionWithDestinationTest | 4683 class QuicNetworkTransactionWithDestinationTest |
| 4689 : public PlatformTest, | 4684 : public PlatformTest, |
| 4690 public ::testing::WithParamInterface<PoolingTestParams> { | 4685 public ::testing::WithParamInterface<PoolingTestParams> { |
| 4691 protected: | 4686 protected: |
| 4692 QuicNetworkTransactionWithDestinationTest() | 4687 QuicNetworkTransactionWithDestinationTest() |
| 4693 : version_(GetParam().version), | 4688 : version_(GetParam().version), |
| 4689 supported_versions_(SupportedVersions(version_)), | |
| 4694 destination_type_(GetParam().destination_type), | 4690 destination_type_(GetParam().destination_type), |
| 4695 cert_transparency_verifier_(new MultiLogCTVerifier()), | 4691 cert_transparency_verifier_(new MultiLogCTVerifier()), |
| 4696 ssl_config_service_(new SSLConfigServiceDefaults), | 4692 ssl_config_service_(new SSLConfigServiceDefaults), |
| 4697 proxy_service_(ProxyService::CreateDirect()), | 4693 proxy_service_(ProxyService::CreateDirect()), |
| 4698 auth_handler_factory_( | 4694 auth_handler_factory_( |
| 4699 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), | 4695 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
| 4700 random_generator_(0), | 4696 random_generator_(0), |
| 4701 ssl_data_(ASYNC, OK) {} | 4697 ssl_data_(ASYNC, OK) {} |
| 4702 | 4698 |
| 4703 void SetUp() override { | 4699 void SetUp() override { |
| 4704 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 4700 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 4705 base::RunLoop().RunUntilIdle(); | 4701 base::RunLoop().RunUntilIdle(); |
| 4706 | 4702 |
| 4707 HttpNetworkSession::Params session_params; | 4703 HttpNetworkSession::Params session_params; |
| 4708 session_params.enable_quic = true; | 4704 session_params.enable_quic = true; |
| 4709 session_params.quic_supported_versions = SupportedVersions(version_); | 4705 session_params.quic_supported_versions = supported_versions_; |
| 4710 | 4706 |
| 4711 HttpNetworkSession::Context session_context; | 4707 HttpNetworkSession::Context session_context; |
| 4712 | 4708 |
| 4713 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); | 4709 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
| 4714 session_context.quic_clock = &clock_; | 4710 session_context.quic_clock = &clock_; |
| 4715 | 4711 |
| 4716 crypto_client_stream_factory_.set_handshake_mode( | 4712 crypto_client_stream_factory_.set_handshake_mode( |
| 4717 MockCryptoClientStream::CONFIRM_HANDSHAKE); | 4713 MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 4718 session_context.quic_crypto_client_stream_factory = | 4714 session_context.quic_crypto_client_stream_factory = |
| 4719 &crypto_client_stream_factory_; | 4715 &crypto_client_stream_factory_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 4732 session_context.proxy_service = proxy_service_.get(); | 4728 session_context.proxy_service = proxy_service_.get(); |
| 4733 session_context.http_auth_handler_factory = auth_handler_factory_.get(); | 4729 session_context.http_auth_handler_factory = auth_handler_factory_.get(); |
| 4734 session_context.http_server_properties = &http_server_properties_; | 4730 session_context.http_server_properties = &http_server_properties_; |
| 4735 | 4731 |
| 4736 session_.reset(new HttpNetworkSession(session_params, session_context)); | 4732 session_.reset(new HttpNetworkSession(session_params, session_context)); |
| 4737 session_->quic_stream_factory()->set_require_confirmation(true); | 4733 session_->quic_stream_factory()->set_require_confirmation(true); |
| 4738 } | 4734 } |
| 4739 | 4735 |
| 4740 void TearDown() override { | 4736 void TearDown() override { |
| 4741 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 4737 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 4742 // Empty the current queue. | 4738 // Empty the _current queue. |
|
Ryan Hamilton
2017/06/29 22:50:10
typo?
Zhongyi Shi
2017/06/29 23:56:29
whoops, fixed.
| |
| 4743 base::RunLoop().RunUntilIdle(); | 4739 base::RunLoop().RunUntilIdle(); |
| 4744 PlatformTest::TearDown(); | 4740 PlatformTest::TearDown(); |
| 4745 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 4741 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 4746 base::RunLoop().RunUntilIdle(); | 4742 base::RunLoop().RunUntilIdle(); |
| 4747 session_.reset(); | 4743 session_.reset(); |
| 4748 } | 4744 } |
| 4749 | 4745 |
| 4750 void SetQuicAlternativeService(const std::string& origin) { | 4746 void SetQuicAlternativeService(const std::string& origin) { |
| 4751 HostPortPair destination; | 4747 HostPortPair destination; |
| 4752 switch (destination_type_) { | 4748 switch (destination_type_) { |
| 4753 case SAME_AS_FIRST: | 4749 case SAME_AS_FIRST: |
| 4754 destination = HostPortPair(origin1_, 443); | 4750 destination = HostPortPair(origin1_, 443); |
| 4755 break; | 4751 break; |
| 4756 case SAME_AS_SECOND: | 4752 case SAME_AS_SECOND: |
| 4757 destination = HostPortPair(origin2_, 443); | 4753 destination = HostPortPair(origin2_, 443); |
| 4758 break; | 4754 break; |
| 4759 case DIFFERENT: | 4755 case DIFFERENT: |
| 4760 destination = HostPortPair(kDifferentHostname, 443); | 4756 destination = HostPortPair(kDifferentHostname, 443); |
| 4761 break; | 4757 break; |
| 4762 } | 4758 } |
| 4763 AlternativeService alternative_service(kProtoQUIC, destination); | 4759 AlternativeService alternative_service(kProtoQUIC, destination); |
| 4764 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 4760 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 4765 http_server_properties_.SetQuicAlternativeService( | 4761 http_server_properties_.SetQuicAlternativeService( |
| 4766 url::SchemeHostPort("https", origin, 443), alternative_service, | 4762 url::SchemeHostPort("https", origin, 443), alternative_service, |
| 4767 expiration, session_->params().quic_supported_versions); | 4763 expiration, supported_versions_); |
| 4768 } | 4764 } |
| 4769 | 4765 |
| 4770 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket( | 4766 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket( |
| 4771 QuicPacketNumber packet_number, | 4767 QuicPacketNumber packet_number, |
| 4772 QuicStreamId stream_id, | 4768 QuicStreamId stream_id, |
| 4773 bool should_include_version, | 4769 bool should_include_version, |
| 4774 QuicStreamOffset* offset, | 4770 QuicStreamOffset* offset, |
| 4775 QuicTestPacketMaker* maker) { | 4771 QuicTestPacketMaker* maker) { |
| 4776 SpdyPriority priority = | 4772 SpdyPriority priority = |
| 4777 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); | 4773 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4888 response->connection_info); | 4884 response->connection_info); |
| 4889 EXPECT_EQ(443, response->socket_address.port()); | 4885 EXPECT_EQ(443, response->socket_address.port()); |
| 4890 } | 4886 } |
| 4891 | 4887 |
| 4892 QuicStreamId GetNthClientInitiatedStreamId(int n) { | 4888 QuicStreamId GetNthClientInitiatedStreamId(int n) { |
| 4893 return test::GetNthClientInitiatedStreamId(version_, n); | 4889 return test::GetNthClientInitiatedStreamId(version_, n); |
| 4894 } | 4890 } |
| 4895 | 4891 |
| 4896 MockClock clock_; | 4892 MockClock clock_; |
| 4897 QuicVersion version_; | 4893 QuicVersion version_; |
| 4894 QuicVersionVector supported_versions_; | |
| 4898 DestinationType destination_type_; | 4895 DestinationType destination_type_; |
| 4899 std::string origin1_; | 4896 std::string origin1_; |
| 4900 std::string origin2_; | 4897 std::string origin2_; |
| 4901 std::unique_ptr<HttpNetworkSession> session_; | 4898 std::unique_ptr<HttpNetworkSession> session_; |
| 4902 MockClientSocketFactory socket_factory_; | 4899 MockClientSocketFactory socket_factory_; |
| 4903 MockHostResolver host_resolver_; | 4900 MockHostResolver host_resolver_; |
| 4904 MockCertVerifier cert_verifier_; | 4901 MockCertVerifier cert_verifier_; |
| 4905 TransportSecurityState transport_security_state_; | 4902 TransportSecurityState transport_security_state_; |
| 4906 std::unique_ptr<CTVerifier> cert_transparency_verifier_; | 4903 std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
| 4907 CTPolicyEnforcer ct_policy_enforcer_; | 4904 CTPolicyEnforcer ct_policy_enforcer_; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5192 | 5189 |
| 5193 request_.url = GURL("https://mail.example.org/pushed.jpg"); | 5190 request_.url = GURL("https://mail.example.org/pushed.jpg"); |
| 5194 ChunkedUploadDataStream upload_data(0); | 5191 ChunkedUploadDataStream upload_data(0); |
| 5195 upload_data.AppendData("1", 1, true); | 5192 upload_data.AppendData("1", 1, true); |
| 5196 request_.upload_data_stream = &upload_data; | 5193 request_.upload_data_stream = &upload_data; |
| 5197 SendRequestAndExpectQuicResponse("and hello!"); | 5194 SendRequestAndExpectQuicResponse("and hello!"); |
| 5198 } | 5195 } |
| 5199 | 5196 |
| 5200 } // namespace test | 5197 } // namespace test |
| 5201 } // namespace net | 5198 } // namespace net |
| OLD | NEW |