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

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: Created 4 years, 8 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
« no previous file with comments | « net/http/http_stream_factory_impl_unittest.cc ('k') | net/quic/quic_stream_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 url::SchemeHostPort scheme_origin_pair(request_.url);
536 AlternativeService alternative_service(QUIC, host_port_pair.host(), 443); 537 AlternativeService alternative_service(QUIC, host_port_pair.host(), 443);
537 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 538 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
538 http_server_properties_.SetAlternativeService( 539 http_server_properties_.SetAlternativeService(
539 host_port_pair, alternative_service, expiration); 540 scheme_origin_pair, alternative_service, expiration);
540 } 541 }
541 542
542 void AddQuicRemoteAlternativeServiceMapping( 543 void AddQuicRemoteAlternativeServiceMapping(
543 MockCryptoClientStream::HandshakeMode handshake_mode, 544 MockCryptoClientStream::HandshakeMode handshake_mode,
544 const HostPortPair& alternative) { 545 const HostPortPair& alternative) {
545 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); 546 crypto_client_stream_factory_.set_handshake_mode(handshake_mode);
546 HostPortPair host_port_pair = HostPortPair::FromURL(request_.url); 547 HostPortPair host_port_pair = HostPortPair::FromURL(request_.url);
548 url::SchemeHostPort scheme_origin_pair(request_.url);
547 AlternativeService alternative_service(QUIC, alternative.host(), 549 AlternativeService alternative_service(QUIC, alternative.host(),
548 alternative.port()); 550 alternative.port());
549 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 551 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
550 http_server_properties_.SetAlternativeService( 552 http_server_properties_.SetAlternativeService(
551 host_port_pair, alternative_service, expiration); 553 scheme_origin_pair, alternative_service, expiration);
552 } 554 }
553 555
554 void ExpectBrokenAlternateProtocolMapping() { 556 void ExpectBrokenAlternateProtocolMapping() {
555 const HostPortPair origin = HostPortPair::FromURL(request_.url); 557 url::SchemeHostPort scheme_origin(request_.url);
556 const AlternativeServiceVector alternative_service_vector = 558 const AlternativeServiceVector alternative_service_vector =
557 http_server_properties_.GetAlternativeServices(origin); 559 http_server_properties_.GetAlternativeServices(scheme_origin);
558 EXPECT_EQ(1u, alternative_service_vector.size()); 560 EXPECT_EQ(1u, alternative_service_vector.size());
559 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( 561 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken(
560 alternative_service_vector[0])); 562 alternative_service_vector[0]));
561 } 563 }
562 564
563 void ExpectQuicAlternateProtocolMapping() { 565 void ExpectQuicAlternateProtocolMapping() {
564 const HostPortPair origin = HostPortPair::FromURL(request_.url); 566 url::SchemeHostPort scheme_origin(request_.url);
565 const AlternativeServiceVector alternative_service_vector = 567 const AlternativeServiceVector alternative_service_vector =
566 http_server_properties_.GetAlternativeServices(origin); 568 http_server_properties_.GetAlternativeServices(scheme_origin);
567 EXPECT_EQ(1u, alternative_service_vector.size()); 569 EXPECT_EQ(1u, alternative_service_vector.size());
568 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); 570 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
569 } 571 }
570 572
571 void AddHangingNonAlternateProtocolSocketData() { 573 void AddHangingNonAlternateProtocolSocketData() {
572 scoped_ptr<StaticSocketDataProvider> hanging_data; 574 scoped_ptr<StaticSocketDataProvider> hanging_data;
573 hanging_data.reset(new StaticSocketDataProvider()); 575 hanging_data.reset(new StaticSocketDataProvider());
574 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); 576 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING);
575 hanging_data->set_connect_data(hanging_connect); 577 hanging_data->set_connect_data(hanging_connect);
576 hanging_data_.push_back(std::move(hanging_data)); 578 hanging_data_.push_back(std::move(hanging_data));
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 929
928 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 930 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
929 931
930 AddHangingNonAlternateProtocolSocketData(); 932 AddHangingNonAlternateProtocolSocketData();
931 CreateSession(); 933 CreateSession();
932 934
933 SendRequestAndExpectHttpResponse("hello world"); 935 SendRequestAndExpectHttpResponse("hello world");
934 SendRequestAndExpectQuicResponse("hello!"); 936 SendRequestAndExpectQuicResponse("hello!");
935 } 937 }
936 938
939 TEST_P(QuicNetworkTransactionTest, SetAlternativeServiceForOriginWithScheme) {
940 MockRead http_reads[] = {
941 MockRead("HTTP/1.1 200 OK\r\n"),
942 MockRead("Alt-Svc: quic=\"foo.example.org:443\", quic=\":444\"\r\n\r\n"),
943 MockRead("hello world"),
944 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
945 MockRead(ASYNC, OK)};
946
947 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
948 0);
949 socket_factory_.AddSocketDataProvider(&http_data);
950 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
951
952 CreateSession();
953 // Send http request, ignore alternative service advertising if response
954 // header advertises alternative service for mail.example.org.
955 request_.url = GURL("http://mail.example.org:443");
956 SendRequestAndExpectHttpResponse("hello world");
957 base::WeakPtr<HttpServerProperties> http_server_properties =
958 session_->http_server_properties();
959 url::SchemeHostPort http_origin("http", "mail.example.org", 443);
960 url::SchemeHostPort https_origin("https", "mail.example.org", 443);
961 // Check alternative service is set for the correct origin.
962 EXPECT_EQ(2u,
963 http_server_properties->GetAlternativeServices(http_origin).size());
964 EXPECT_EQ(
965 0u, http_server_properties->GetAlternativeServices(https_origin).size());
966 }
967
968 TEST_P(QuicNetworkTransactionTest, DoNotGetAltSvcForDifferentOrigin) {
969 MockRead http_reads[] = {
970 MockRead("HTTP/1.1 200 OK\r\n"),
971 MockRead("Alt-Svc: quic=\"foo.example.org:443\", quic=\":444\"\r\n\r\n"),
972 MockRead("hello world"),
973 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
974 MockRead(ASYNC, OK)};
975
976 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
977 0);
978 socket_factory_.AddSocketDataProvider(&http_data);
979 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
980 socket_factory_.AddSocketDataProvider(&http_data);
981 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
982
983 CreateSession();
984
985 // Send https request and set alternative services if response header
986 // advertises alternative service for mail.example.org.
987 SendRequestAndExpectHttpResponse("hello world");
988 base::WeakPtr<HttpServerProperties> http_server_properties =
989 session_->http_server_properties();
990
991 const url::SchemeHostPort https_origin(request_.url);
992 // Check alternative service is set.
993 AlternativeServiceVector alternative_service_vector =
994 http_server_properties->GetAlternativeServices(https_origin);
995 EXPECT_EQ(2u, alternative_service_vector.size());
996
997 // Send http request to the same origin but with diffrent scheme, should not
998 // use QUIC.
999 request_.url = GURL("http://mail.example.org:443");
1000 SendRequestAndExpectHttpResponse("hello world");
1001 }
1002
937 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceQuicSupportedVersion) { 1003 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceQuicSupportedVersion) {
938 std::string altsvc_header = base::StringPrintf( 1004 std::string altsvc_header = base::StringPrintf(
939 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", GetParam()); 1005 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", GetParam());
940 MockRead http_reads[] = { 1006 MockRead http_reads[] = {
941 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), 1007 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()),
942 MockRead("hello world"), 1008 MockRead("hello world"),
943 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 1009 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
944 MockRead(ASYNC, OK)}; 1010 MockRead(ASYNC, OK)};
945 1011
946 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, 1012 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr,
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 // connection to |alternate| only. 1808 // connection to |alternate| only.
1743 MockConnect refused_connect(ASYNC, ERR_CONNECTION_REFUSED); 1809 MockConnect refused_connect(ASYNC, ERR_CONNECTION_REFUSED);
1744 StaticSocketDataProvider refused_data; 1810 StaticSocketDataProvider refused_data;
1745 refused_data.set_connect_data(refused_connect); 1811 refused_data.set_connect_data(refused_connect);
1746 socket_factory_.AddSocketDataProvider(&refused_data); 1812 socket_factory_.AddSocketDataProvider(&refused_data);
1747 1813
1748 CreateSession(); 1814 CreateSession();
1749 AlternativeService alternative_service(QUIC, alternative); 1815 AlternativeService alternative_service(QUIC, alternative);
1750 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 1816 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
1751 session_->http_server_properties()->SetAlternativeService( 1817 session_->http_server_properties()->SetAlternativeService(
1752 origin, alternative_service, expiration); 1818 url::SchemeHostPort("https", origin.host(), origin.port()),
1819 alternative_service, expiration);
1753 scoped_ptr<HttpNetworkTransaction> trans( 1820 scoped_ptr<HttpNetworkTransaction> trans(
1754 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1821 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1755 TestCompletionCallback callback; 1822 TestCompletionCallback callback;
1756 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1823 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1757 EXPECT_EQ(ERR_IO_PENDING, rv); 1824 EXPECT_EQ(ERR_IO_PENDING, rv);
1758 rv = callback.WaitForResult(); 1825 rv = callback.WaitForResult();
1759 if (valid) { 1826 if (valid) {
1760 EXPECT_EQ(OK, rv); 1827 EXPECT_EQ(OK, rv);
1761 CheckWasQuicResponse(trans); 1828 CheckWasQuicResponse(trans);
1762 CheckResponsePort(trans, 443); 1829 CheckResponsePort(trans, 443);
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
2339 scoped_ptr<HttpNetworkTransaction> trans( 2406 scoped_ptr<HttpNetworkTransaction> trans(
2340 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 2407 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
2341 TestCompletionCallback callback; 2408 TestCompletionCallback callback;
2342 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 2409 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
2343 EXPECT_EQ(ERR_IO_PENDING, rv); 2410 EXPECT_EQ(ERR_IO_PENDING, rv);
2344 EXPECT_NE(OK, callback.WaitForResult()); 2411 EXPECT_NE(OK, callback.WaitForResult());
2345 } 2412 }
2346 2413
2347 } // namespace test 2414 } // namespace test
2348 } // namespace net 2415 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_unittest.cc ('k') | net/quic/quic_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698