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

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

Issue 1824903002: Change the AlternativeServiceMap with SchemeOriginPair key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests Created 4 years, 9 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 <vector> 5 #include <vector>
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 void SendRequestAndExpectQuicResponseFromProxyOnPort( 526 void SendRequestAndExpectQuicResponseFromProxyOnPort(
527 const std::string& expected, 527 const std::string& expected,
528 uint16_t port) { 528 uint16_t port) {
529 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); 529 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port);
530 } 530 }
531 531
532 void AddQuicAlternateProtocolMapping( 532 void AddQuicAlternateProtocolMapping(
533 MockCryptoClientStream::HandshakeMode handshake_mode) { 533 MockCryptoClientStream::HandshakeMode handshake_mode) {
534 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); 534 crypto_client_stream_factory_.set_handshake_mode(handshake_mode);
535 HostPortPair host_port_pair = HostPortPair::FromURL(request_.url); 535 HostPortPair host_port_pair = HostPortPair::FromURL(request_.url);
536 SchemeOriginPair scheme_origin_pair =
537 SchemeOriginPair::FromURL(request_.url);
536 AlternativeService alternative_service(QUIC, host_port_pair.host(), 443); 538 AlternativeService alternative_service(QUIC, host_port_pair.host(), 443);
537 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 539 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
538 http_server_properties_.SetAlternativeService( 540 http_server_properties_.SetAlternativeService(
539 host_port_pair, alternative_service, 1.0, expiration); 541 scheme_origin_pair, alternative_service, 1.0, expiration);
540 } 542 }
541 543
542 void AddQuicRemoteAlternativeServiceMapping( 544 void AddQuicRemoteAlternativeServiceMapping(
543 MockCryptoClientStream::HandshakeMode handshake_mode, 545 MockCryptoClientStream::HandshakeMode handshake_mode,
544 const HostPortPair& alternative) { 546 const HostPortPair& alternative) {
545 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); 547 crypto_client_stream_factory_.set_handshake_mode(handshake_mode);
546 HostPortPair host_port_pair = HostPortPair::FromURL(request_.url); 548 HostPortPair host_port_pair = HostPortPair::FromURL(request_.url);
549 SchemeOriginPair scheme_origin_pair =
550 SchemeOriginPair::FromURL(request_.url);
547 AlternativeService alternative_service(QUIC, alternative.host(), 551 AlternativeService alternative_service(QUIC, alternative.host(),
548 alternative.port()); 552 alternative.port());
549 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 553 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
550 http_server_properties_.SetAlternativeService( 554 http_server_properties_.SetAlternativeService(
551 host_port_pair, alternative_service, 1.0, expiration); 555 scheme_origin_pair, alternative_service, 1.0, expiration);
552 } 556 }
553 557
554 void ExpectBrokenAlternateProtocolMapping() { 558 void ExpectBrokenAlternateProtocolMapping() {
555 const HostPortPair origin = HostPortPair::FromURL(request_.url); 559 SchemeOriginPair scheme_origin = SchemeOriginPair::FromURL(request_.url);
556 const AlternativeServiceVector alternative_service_vector = 560 const AlternativeServiceVector alternative_service_vector =
557 http_server_properties_.GetAlternativeServices(origin); 561 http_server_properties_.GetAlternativeServices(scheme_origin);
558 EXPECT_EQ(1u, alternative_service_vector.size()); 562 EXPECT_EQ(1u, alternative_service_vector.size());
559 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( 563 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken(
560 alternative_service_vector[0])); 564 alternative_service_vector[0]));
561 } 565 }
562 566
563 void ExpectQuicAlternateProtocolMapping() { 567 void ExpectQuicAlternateProtocolMapping() {
564 const HostPortPair origin = HostPortPair::FromURL(request_.url); 568 SchemeOriginPair scheme_origin = SchemeOriginPair::FromURL(request_.url);
565 const AlternativeServiceVector alternative_service_vector = 569 const AlternativeServiceVector alternative_service_vector =
566 http_server_properties_.GetAlternativeServices(origin); 570 http_server_properties_.GetAlternativeServices(scheme_origin);
567 EXPECT_EQ(1u, alternative_service_vector.size()); 571 EXPECT_EQ(1u, alternative_service_vector.size());
568 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); 572 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
569 } 573 }
570 574
571 void AddHangingNonAlternateProtocolSocketData() { 575 void AddHangingNonAlternateProtocolSocketData() {
572 scoped_ptr<StaticSocketDataProvider> hanging_data; 576 scoped_ptr<StaticSocketDataProvider> hanging_data;
573 hanging_data.reset(new StaticSocketDataProvider()); 577 hanging_data.reset(new StaticSocketDataProvider());
574 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); 578 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING);
575 hanging_data->set_connect_data(hanging_connect); 579 hanging_data->set_connect_data(hanging_connect);
576 hanging_data_.push_back(std::move(hanging_data)); 580 hanging_data_.push_back(std::move(hanging_data));
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 896
893 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 897 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
894 898
895 AddHangingNonAlternateProtocolSocketData(); 899 AddHangingNonAlternateProtocolSocketData();
896 CreateSession(); 900 CreateSession();
897 901
898 SendRequestAndExpectHttpResponse("hello world"); 902 SendRequestAndExpectHttpResponse("hello world");
899 SendRequestAndExpectQuicResponse("hello!"); 903 SendRequestAndExpectQuicResponse("hello!");
900 } 904 }
901 905
906 TEST_P(QuicNetworkTransactionTest, SetAlternativeServiceForOriginWithScheme) {
907 MockRead http_reads[] = {
908 MockRead("HTTP/1.1 200 OK\r\n"),
909 MockRead("Alt-Svc: quic=\"foo.example.org:443\", quic=\":444\"\r\n\r\n"),
910 MockRead("hello world"),
911 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
912 MockRead(ASYNC, OK)};
913
914 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
915 0);
916 socket_factory_.AddSocketDataProvider(&http_data);
917 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
918
919 CreateSession();
920 // Send http request, ignore alternative service advertising if response
921 // header advertises alternative service for mail.example.org.
922 request_.url = GURL("http://mail.example.org:443");
923 SendRequestAndExpectHttpResponse("hello world");
924 base::WeakPtr<HttpServerProperties> http_server_properties =
925 session_->http_server_properties();
926 SchemeOriginPair http_origin = SchemeOriginPair::FromURL(request_.url);
927 SchemeOriginPair https_origin("https", HostPortPair::FromURL(request_.url));
928 // Check alternative service is set for the correct origin.
929 EXPECT_EQ(2u,
930 http_server_properties->GetAlternativeServices(http_origin).size());
931 EXPECT_EQ(
932 0u, http_server_properties->GetAlternativeServices(https_origin).size());
933 }
934
935 TEST_P(QuicNetworkTransactionTest, DoNotGetAltSvcForDifferentOrigin) {
936 MockRead http_reads[] = {
937 MockRead("HTTP/1.1 200 OK\r\n"),
938 MockRead("Alt-Svc: quic=\"foo.example.org:443\", quic=\":444\"\r\n\r\n"),
939 MockRead("hello world"),
940 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
941 MockRead(ASYNC, OK)};
942
943 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
944 0);
945 socket_factory_.AddSocketDataProvider(&http_data);
946 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
947 socket_factory_.AddSocketDataProvider(&http_data);
948 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
949 CreateSession();
950
951 // Send https request and set alternative services if response header
952 // advertises alternative service for mail.example.org.
953 request_.url = GURL("https://mail.example.org:443");
954 SendRequestAndExpectHttpResponse("hello world");
955 base::WeakPtr<HttpServerProperties> http_server_properties =
956 session_->http_server_properties();
957
958 const SchemeOriginPair https_origin = SchemeOriginPair::FromURL(request_.url);
959 // Check alternative service is set.
960 AlternativeServiceVector alternative_service_vector =
961 http_server_properties->GetAlternativeServices(https_origin);
962 EXPECT_EQ(2u, alternative_service_vector.size());
963
964 // Send http request to the same origin, should not use QUIC.
965 request_.url = GURL("http://mail.example.org:443");
966 SendRequestAndExpectHttpResponse("hello world");
967 }
968
902 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceQuicSupportedVersion) { 969 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceQuicSupportedVersion) {
903 std::string altsvc_header = base::StringPrintf( 970 std::string altsvc_header = base::StringPrintf(
904 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", GetParam()); 971 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", GetParam());
905 MockRead http_reads[] = { 972 MockRead http_reads[] = {
906 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), 973 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()),
907 MockRead("hello world"), 974 MockRead("hello world"),
908 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 975 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
909 MockRead(ASYNC, OK)}; 976 MockRead(ASYNC, OK)};
910 977
911 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, 978 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 // connection to |alternate| only. 1897 // connection to |alternate| only.
1831 MockConnect refused_connect(ASYNC, ERR_CONNECTION_REFUSED); 1898 MockConnect refused_connect(ASYNC, ERR_CONNECTION_REFUSED);
1832 StaticSocketDataProvider refused_data; 1899 StaticSocketDataProvider refused_data;
1833 refused_data.set_connect_data(refused_connect); 1900 refused_data.set_connect_data(refused_connect);
1834 socket_factory_.AddSocketDataProvider(&refused_data); 1901 socket_factory_.AddSocketDataProvider(&refused_data);
1835 1902
1836 CreateSession(); 1903 CreateSession();
1837 AlternativeService alternative_service(QUIC, alternative); 1904 AlternativeService alternative_service(QUIC, alternative);
1838 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 1905 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
1839 session_->http_server_properties()->SetAlternativeService( 1906 session_->http_server_properties()->SetAlternativeService(
1840 origin, alternative_service, 1.0, expiration); 1907 SchemeOriginPair("https", origin), alternative_service, 1.0,
1908 expiration);
1841 scoped_ptr<HttpNetworkTransaction> trans( 1909 scoped_ptr<HttpNetworkTransaction> trans(
1842 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1910 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1843 TestCompletionCallback callback; 1911 TestCompletionCallback callback;
1844 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1912 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1845 EXPECT_EQ(ERR_IO_PENDING, rv); 1913 EXPECT_EQ(ERR_IO_PENDING, rv);
1846 rv = callback.WaitForResult(); 1914 rv = callback.WaitForResult();
1847 if (valid) { 1915 if (valid) {
1848 EXPECT_EQ(OK, rv); 1916 EXPECT_EQ(OK, rv);
1849 CheckWasQuicResponse(trans); 1917 CheckWasQuicResponse(trans);
1850 CheckResponsePort(trans, 443); 1918 CheckResponsePort(trans, 443);
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 scoped_ptr<HttpNetworkTransaction> trans( 2495 scoped_ptr<HttpNetworkTransaction> trans(
2428 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 2496 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
2429 TestCompletionCallback callback; 2497 TestCompletionCallback callback;
2430 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 2498 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
2431 EXPECT_EQ(ERR_IO_PENDING, rv); 2499 EXPECT_EQ(ERR_IO_PENDING, rv);
2432 EXPECT_NE(OK, callback.WaitForResult()); 2500 EXPECT_NE(OK, callback.WaitForResult());
2433 } 2501 }
2434 2502
2435 } // namespace test 2503 } // namespace test
2436 } // namespace net 2504 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698