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

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

Issue 2373663002: Unify enum NextProto and enum AlternateProtocol. (Closed)
Patch Set: Fix compile errors. Created 4 years, 1 month 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/net.gypi ('k') | net/quic/chromium/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 <memory> 5 #include <memory>
6 #include <ostream> 6 #include <ostream>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "net/quic/core/quic_framer.h" 44 #include "net/quic/core/quic_framer.h"
45 #include "net/quic/core/quic_http_utils.h" 45 #include "net/quic/core/quic_http_utils.h"
46 #include "net/quic/test_tools/crypto_test_utils.h" 46 #include "net/quic/test_tools/crypto_test_utils.h"
47 #include "net/quic/test_tools/mock_clock.h" 47 #include "net/quic/test_tools/mock_clock.h"
48 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" 48 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
49 #include "net/quic/test_tools/mock_random.h" 49 #include "net/quic/test_tools/mock_random.h"
50 #include "net/quic/test_tools/quic_test_packet_maker.h" 50 #include "net/quic/test_tools/quic_test_packet_maker.h"
51 #include "net/quic/test_tools/quic_test_utils.h" 51 #include "net/quic/test_tools/quic_test_utils.h"
52 #include "net/socket/client_socket_factory.h" 52 #include "net/socket/client_socket_factory.h"
53 #include "net/socket/mock_client_socket_pool_manager.h" 53 #include "net/socket/mock_client_socket_pool_manager.h"
54 #include "net/socket/next_proto.h"
54 #include "net/socket/socket_performance_watcher.h" 55 #include "net/socket/socket_performance_watcher.h"
55 #include "net/socket/socket_performance_watcher_factory.h" 56 #include "net/socket/socket_performance_watcher_factory.h"
56 #include "net/socket/socket_test_util.h" 57 #include "net/socket/socket_test_util.h"
57 #include "net/socket/ssl_client_socket.h"
58 #include "net/spdy/spdy_frame_builder.h" 58 #include "net/spdy/spdy_frame_builder.h"
59 #include "net/spdy/spdy_framer.h" 59 #include "net/spdy/spdy_framer.h"
60 #include "net/ssl/ssl_config_service_defaults.h" 60 #include "net/ssl/ssl_config_service_defaults.h"
61 #include "net/test/cert_test_util.h" 61 #include "net/test/cert_test_util.h"
62 #include "net/test/gtest_util.h" 62 #include "net/test/gtest_util.h"
63 #include "net/test/test_data_directory.h" 63 #include "net/test/test_data_directory.h"
64 #include "net/url_request/url_request.h" 64 #include "net/url_request/url_request.h"
65 #include "net/url_request/url_request_job_factory_impl.h" 65 #include "net/url_request/url_request_job_factory_impl.h"
66 #include "net/url_request/url_request_test_util.h" 66 #include "net/url_request/url_request_test_util.h"
67 #include "testing/gmock/include/gmock/gmock.h" 67 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 void SendRequestAndExpectQuicResponseFromProxyOnPort( 560 void SendRequestAndExpectQuicResponseFromProxyOnPort(
561 const std::string& expected, 561 const std::string& expected,
562 uint16_t port) { 562 uint16_t port) {
563 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); 563 SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port);
564 } 564 }
565 565
566 void AddQuicAlternateProtocolMapping( 566 void AddQuicAlternateProtocolMapping(
567 MockCryptoClientStream::HandshakeMode handshake_mode) { 567 MockCryptoClientStream::HandshakeMode handshake_mode) {
568 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); 568 crypto_client_stream_factory_.set_handshake_mode(handshake_mode);
569 url::SchemeHostPort server(request_.url); 569 url::SchemeHostPort server(request_.url);
570 AlternativeService alternative_service(QUIC, server.host(), 443); 570 AlternativeService alternative_service(kProtoQUIC, server.host(), 443);
571 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 571 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
572 http_server_properties_.SetAlternativeService(server, alternative_service, 572 http_server_properties_.SetAlternativeService(server, alternative_service,
573 expiration); 573 expiration);
574 } 574 }
575 575
576 void AddQuicRemoteAlternativeServiceMapping( 576 void AddQuicRemoteAlternativeServiceMapping(
577 MockCryptoClientStream::HandshakeMode handshake_mode, 577 MockCryptoClientStream::HandshakeMode handshake_mode,
578 const HostPortPair& alternative) { 578 const HostPortPair& alternative) {
579 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); 579 crypto_client_stream_factory_.set_handshake_mode(handshake_mode);
580 url::SchemeHostPort server(request_.url); 580 url::SchemeHostPort server(request_.url);
581 AlternativeService alternative_service(QUIC, alternative.host(), 581 AlternativeService alternative_service(kProtoQUIC, alternative.host(),
582 alternative.port()); 582 alternative.port());
583 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 583 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
584 http_server_properties_.SetAlternativeService(server, alternative_service, 584 http_server_properties_.SetAlternativeService(server, alternative_service,
585 expiration); 585 expiration);
586 } 586 }
587 587
588 void ExpectBrokenAlternateProtocolMapping() { 588 void ExpectBrokenAlternateProtocolMapping() {
589 const url::SchemeHostPort server(request_.url); 589 const url::SchemeHostPort server(request_.url);
590 const AlternativeServiceVector alternative_service_vector = 590 const AlternativeServiceVector alternative_service_vector =
591 http_server_properties_.GetAlternativeServices(server); 591 http_server_properties_.GetAlternativeServices(server);
592 EXPECT_EQ(1u, alternative_service_vector.size()); 592 EXPECT_EQ(1u, alternative_service_vector.size());
593 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( 593 EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken(
594 alternative_service_vector[0])); 594 alternative_service_vector[0]));
595 } 595 }
596 596
597 void ExpectQuicAlternateProtocolMapping() { 597 void ExpectQuicAlternateProtocolMapping() {
598 const url::SchemeHostPort server(request_.url); 598 const url::SchemeHostPort server(request_.url);
599 const AlternativeServiceVector alternative_service_vector = 599 const AlternativeServiceVector alternative_service_vector =
600 http_server_properties_.GetAlternativeServices(server); 600 http_server_properties_.GetAlternativeServices(server);
601 EXPECT_EQ(1u, alternative_service_vector.size()); 601 EXPECT_EQ(1u, alternative_service_vector.size());
602 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); 602 EXPECT_EQ(kProtoQUIC, alternative_service_vector[0].protocol);
603 } 603 }
604 604
605 void AddHangingNonAlternateProtocolSocketData() { 605 void AddHangingNonAlternateProtocolSocketData() {
606 std::unique_ptr<StaticSocketDataProvider> hanging_data; 606 std::unique_ptr<StaticSocketDataProvider> hanging_data;
607 hanging_data.reset(new StaticSocketDataProvider()); 607 hanging_data.reset(new StaticSocketDataProvider());
608 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); 608 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING);
609 hanging_data->set_connect_data(hanging_connect); 609 hanging_data->set_connect_data(hanging_connect);
610 hanging_data_.push_back(std::move(hanging_data)); 610 hanging_data_.push_back(std::move(hanging_data));
611 socket_factory_.AddSocketDataProvider(hanging_data_.back().get()); 611 socket_factory_.AddSocketDataProvider(hanging_data_.back().get());
612 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); 612 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 AddHangingNonAlternateProtocolSocketData(); 1409 AddHangingNonAlternateProtocolSocketData();
1410 AddHangingNonAlternateProtocolSocketData(); 1410 AddHangingNonAlternateProtocolSocketData();
1411 1411
1412 CreateSession(); 1412 CreateSession();
1413 1413
1414 const char destination1[] = "first.example.com"; 1414 const char destination1[] = "first.example.com";
1415 const char destination2[] = "second.example.com"; 1415 const char destination2[] = "second.example.com";
1416 1416
1417 // Set up alternative service entry to destination1. 1417 // Set up alternative service entry to destination1.
1418 url::SchemeHostPort server(request_.url); 1418 url::SchemeHostPort server(request_.url);
1419 AlternativeService alternative_service(QUIC, destination1, 443); 1419 AlternativeService alternative_service(kProtoQUIC, destination1, 443);
1420 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 1420 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
1421 http_server_properties_.SetAlternativeService(server, alternative_service, 1421 http_server_properties_.SetAlternativeService(server, alternative_service,
1422 expiration); 1422 expiration);
1423 // First request opens connection to |destination1| 1423 // First request opens connection to |destination1|
1424 // with QuicServerId.host() == kDefaultServerHostName. 1424 // with QuicServerId.host() == kDefaultServerHostName.
1425 SendRequestAndExpectQuicResponse("hello!"); 1425 SendRequestAndExpectQuicResponse("hello!");
1426 1426
1427 // Set up alternative service entry to a different destination. 1427 // Set up alternative service entry to a different destination.
1428 alternative_service = AlternativeService(QUIC, destination2, 443); 1428 alternative_service = AlternativeService(kProtoQUIC, destination2, 443);
1429 http_server_properties_.SetAlternativeService(server, alternative_service, 1429 http_server_properties_.SetAlternativeService(server, alternative_service,
1430 expiration); 1430 expiration);
1431 // Second request pools to existing connection with same QuicServerId, 1431 // Second request pools to existing connection with same QuicServerId,
1432 // even though alternative service destination is different. 1432 // even though alternative service destination is different.
1433 SendRequestAndExpectQuicResponse("hello!"); 1433 SendRequestAndExpectQuicResponse("hello!");
1434 } 1434 }
1435 1435
1436 // Pool to existing session with matching destination and matching certificate 1436 // Pool to existing session with matching destination and matching certificate
1437 // even if origin is different, and even if the alternative service with 1437 // even if origin is different, and even if the alternative service with
1438 // matching destination is not the first one on the list. 1438 // matching destination is not the first one on the list.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 1479
1480 AddHangingNonAlternateProtocolSocketData(); 1480 AddHangingNonAlternateProtocolSocketData();
1481 AddHangingNonAlternateProtocolSocketData(); 1481 AddHangingNonAlternateProtocolSocketData();
1482 1482
1483 CreateSession(); 1483 CreateSession();
1484 1484
1485 const char destination1[] = "first.example.com"; 1485 const char destination1[] = "first.example.com";
1486 const char destination2[] = "second.example.com"; 1486 const char destination2[] = "second.example.com";
1487 1487
1488 // Set up alternative service for |origin1|. 1488 // Set up alternative service for |origin1|.
1489 AlternativeService alternative_service1(QUIC, destination1, 443); 1489 AlternativeService alternative_service1(kProtoQUIC, destination1, 443);
1490 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 1490 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
1491 http_server_properties_.SetAlternativeService( 1491 http_server_properties_.SetAlternativeService(
1492 url::SchemeHostPort(origin1), alternative_service1, expiration); 1492 url::SchemeHostPort(origin1), alternative_service1, expiration);
1493 1493
1494 // Set up multiple alternative service entries for |origin2|, 1494 // Set up multiple alternative service entries for |origin2|,
1495 // the first one with a different destination as for |origin1|, 1495 // the first one with a different destination as for |origin1|,
1496 // the second one with the same. The second one should be used, 1496 // the second one with the same. The second one should be used,
1497 // because the request can be pooled to that one. 1497 // because the request can be pooled to that one.
1498 AlternativeService alternative_service2(QUIC, destination2, 443); 1498 AlternativeService alternative_service2(kProtoQUIC, destination2, 443);
1499 AlternativeServiceInfoVector alternative_services; 1499 AlternativeServiceInfoVector alternative_services;
1500 alternative_services.push_back( 1500 alternative_services.push_back(
1501 AlternativeServiceInfo(alternative_service2, expiration)); 1501 AlternativeServiceInfo(alternative_service2, expiration));
1502 alternative_services.push_back( 1502 alternative_services.push_back(
1503 AlternativeServiceInfo(alternative_service1, expiration)); 1503 AlternativeServiceInfo(alternative_service1, expiration));
1504 http_server_properties_.SetAlternativeServices(url::SchemeHostPort(origin2), 1504 http_server_properties_.SetAlternativeServices(url::SchemeHostPort(origin2),
1505 alternative_services); 1505 alternative_services);
1506 // First request opens connection to |destination1| 1506 // First request opens connection to |destination1|
1507 // with QuicServerId.host() == origin1.host(). 1507 // with QuicServerId.host() == origin1.host().
1508 SendRequestAndExpectQuicResponse("hello!"); 1508 SendRequestAndExpectQuicResponse("hello!");
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 AddHangingNonAlternateProtocolSocketData(); 1620 AddHangingNonAlternateProtocolSocketData();
1621 CreateSession(); 1621 CreateSession();
1622 1622
1623 SendRequestAndExpectHttpResponse("hello world"); 1623 SendRequestAndExpectHttpResponse("hello world");
1624 1624
1625 url::SchemeHostPort http_server("https", kDefaultServerHostName, 443); 1625 url::SchemeHostPort http_server("https", kDefaultServerHostName, 443);
1626 AlternativeServiceVector alternative_service_vector = 1626 AlternativeServiceVector alternative_service_vector =
1627 http_server_properties_.GetAlternativeServices(http_server); 1627 http_server_properties_.GetAlternativeServices(http_server);
1628 ASSERT_EQ(1u, alternative_service_vector.size()); 1628 ASSERT_EQ(1u, alternative_service_vector.size());
1629 const AlternativeService alternative_service = alternative_service_vector[0]; 1629 const AlternativeService alternative_service = alternative_service_vector[0];
1630 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); 1630 EXPECT_EQ(kProtoQUIC, alternative_service_vector[0].protocol);
1631 EXPECT_EQ(kDefaultServerHostName, alternative_service_vector[0].host); 1631 EXPECT_EQ(kDefaultServerHostName, alternative_service_vector[0].host);
1632 EXPECT_EQ(137, alternative_service_vector[0].port); 1632 EXPECT_EQ(137, alternative_service_vector[0].port);
1633 } 1633 }
1634 1634
1635 TEST_P(QuicNetworkTransactionTest, ConfirmAlternativeService) { 1635 TEST_P(QuicNetworkTransactionTest, ConfirmAlternativeService) {
1636 MockRead http_reads[] = { 1636 MockRead http_reads[] = {
1637 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(kQuicAlternativeServiceHeader), 1637 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(kQuicAlternativeServiceHeader),
1638 MockRead("hello world"), 1638 MockRead("hello world"),
1639 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 1639 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
1640 MockRead(ASYNC, OK)}; 1640 MockRead(ASYNC, OK)};
(...skipping 13 matching lines...) Expand all
1654 false, true, 0, "hello!")); 1654 false, true, 0, "hello!"));
1655 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1)); 1655 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1));
1656 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read 1656 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
1657 mock_quic_data.AddRead(ASYNC, 0); // EOF 1657 mock_quic_data.AddRead(ASYNC, 0); // EOF
1658 1658
1659 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 1659 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
1660 1660
1661 AddHangingNonAlternateProtocolSocketData(); 1661 AddHangingNonAlternateProtocolSocketData();
1662 CreateSession(); 1662 CreateSession();
1663 1663
1664 AlternativeService alternative_service(QUIC, 1664 AlternativeService alternative_service(kProtoQUIC,
1665 HostPortPair::FromURL(request_.url)); 1665 HostPortPair::FromURL(request_.url));
1666 http_server_properties_.MarkAlternativeServiceRecentlyBroken( 1666 http_server_properties_.MarkAlternativeServiceRecentlyBroken(
1667 alternative_service); 1667 alternative_service);
1668 EXPECT_TRUE(http_server_properties_.WasAlternativeServiceRecentlyBroken( 1668 EXPECT_TRUE(http_server_properties_.WasAlternativeServiceRecentlyBroken(
1669 alternative_service)); 1669 alternative_service));
1670 1670
1671 SendRequestAndExpectHttpResponse("hello world"); 1671 SendRequestAndExpectHttpResponse("hello world");
1672 SendRequestAndExpectQuicResponse("hello!"); 1672 SendRequestAndExpectQuicResponse("hello!");
1673 1673
1674 mock_quic_data.Resume(); 1674 mock_quic_data.Resume();
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 case SAME_AS_FIRST: 2933 case SAME_AS_FIRST:
2934 destination = HostPortPair(origin1_, 443); 2934 destination = HostPortPair(origin1_, 443);
2935 break; 2935 break;
2936 case SAME_AS_SECOND: 2936 case SAME_AS_SECOND:
2937 destination = HostPortPair(origin2_, 443); 2937 destination = HostPortPair(origin2_, 443);
2938 break; 2938 break;
2939 case DIFFERENT: 2939 case DIFFERENT:
2940 destination = HostPortPair(kDifferentHostname, 443); 2940 destination = HostPortPair(kDifferentHostname, 443);
2941 break; 2941 break;
2942 } 2942 }
2943 AlternativeService alternative_service(QUIC, destination); 2943 AlternativeService alternative_service(kProtoQUIC, destination);
2944 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 2944 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
2945 http_server_properties_.SetAlternativeService( 2945 http_server_properties_.SetAlternativeService(
2946 url::SchemeHostPort("https", origin, 443), alternative_service, 2946 url::SchemeHostPort("https", origin, 443), alternative_service,
2947 expiration); 2947 expiration);
2948 } 2948 }
2949 2949
2950 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket( 2950 std::unique_ptr<QuicEncryptedPacket> ConstructClientRequestHeadersPacket(
2951 QuicPacketNumber packet_number, 2951 QuicPacketNumber packet_number,
2952 QuicStreamId stream_id, 2952 QuicStreamId stream_id,
2953 bool should_include_version, 2953 bool should_include_version,
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 AddHangingSocketData(); 3278 AddHangingSocketData();
3279 3279
3280 SendRequestAndExpectQuicResponse(origin1_); 3280 SendRequestAndExpectQuicResponse(origin1_);
3281 SendRequestAndExpectQuicResponse(origin2_); 3281 SendRequestAndExpectQuicResponse(origin2_);
3282 3282
3283 EXPECT_TRUE(AllDataConsumed()); 3283 EXPECT_TRUE(AllDataConsumed());
3284 } 3284 }
3285 3285
3286 } // namespace test 3286 } // namespace test
3287 } // namespace net 3287 } // namespace net
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/quic/chromium/quic_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698