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

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

Issue 2595413002: Race preconnects to HTTP2 proxies that support alternate proxies
Patch Set: Rebased, rch comments Created 3 years, 11 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 <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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 EXPECT_TRUE(session_->proxy_service()->proxy_retry_info().empty()); 693 EXPECT_TRUE(session_->proxy_service()->proxy_retry_info().empty());
694 694
695 // The alternative proxy server should no longer be in use. 695 // The alternative proxy server should no longer be in use.
696 EXPECT_FALSE(test_proxy_delegate.alternative_proxy_server().is_valid()); 696 EXPECT_FALSE(test_proxy_delegate.alternative_proxy_server().is_valid());
697 697
698 // Verify that the second request completes successfully, and the 698 // Verify that the second request completes successfully, and the
699 // alternative proxy server job is not started. 699 // alternative proxy server job is not started.
700 SendRequestAndExpectHttpResponseFromProxy("hello from http", true, 443); 700 SendRequestAndExpectHttpResponseFromProxy("hello from http", true, 443);
701 } 701 }
702 702
703 // Preconnects to a HTTPS proxy with a QUIC alternative proxy. Verifies that
704 // if the alternative proxy job returns |error_code|, the preconnection still
705 // succeeds.
706 void TestAlternativeProxyPreconnect(int error_code) {
707 base::HistogramTester histogram_tester;
708 // Data for the alternative proxy server job.
709 MockWrite quic_writes[] = {MockWrite(SYNCHRONOUS, error_code, 1)};
710 MockRead quic_reads[] = {
711 MockRead(SYNCHRONOUS, error_code, 0),
712 };
713
714 SequencedSocketData quic_data(quic_reads, arraysize(quic_reads),
715 quic_writes, arraysize(quic_writes));
716 socket_factory_.AddSocketDataProvider(&quic_data);
717
718 // Main job succeeds and the alternative job fails.
719 // Add data for two requests that will be read by the main job.
720 MockRead http_reads[] = {
721 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello from http"),
722 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
723 MockRead(ASYNC, OK)};
724
725 StaticSocketDataProvider http_data_1(http_reads, arraysize(http_reads),
726 nullptr, 0);
727 socket_factory_.AddSocketDataProvider(&http_data_1);
728 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
729
730 TestProxyDelegate test_proxy_delegate;
731 // Proxy URL is different from the request URL.
732 test_proxy_delegate.set_alternative_proxy_server(
733 ProxyServer::FromPacString("QUIC myproxy.org:443"));
734
735 params_.proxy_delegate = &test_proxy_delegate;
736 params_.race_preconnects_to_http2_proxies = true;
737 proxy_service_ =
738 ProxyService::CreateFixedFromPacResult("HTTPS myproxy.org:443");
739
740 CreateSession();
741 EXPECT_TRUE(test_proxy_delegate.alternative_proxy_server().is_valid());
742
743 HttpRequestInfo request_info;
744 request_info.method = "GET";
745 // Use a non-cryptographic scheme for the preconnect URL since this will be
746 // fetched via proxy with QUIC as the alternative service.
747 request_info.url = GURL("http://www.google.com");
748
749 session_->http_stream_factory()->PreconnectStreams(1 /*num_streams*/,
750 request_info);
751 base::RunLoop().RunUntilIdle();
752
753 // Even through the alternative proxy server job failed, the proxy should
754 // not be marked as bad since the main job succeeded.
755 EXPECT_TRUE(session_->proxy_service()->proxy_retry_info().empty());
756
757 // The alternative proxy server should no longer be in use.
758 EXPECT_TRUE(test_proxy_delegate.alternative_proxy_server().is_valid());
759
760 histogram_tester.ExpectTotalCount(
761 "Net.QuicAlternativeProxy.PreconnectRace.FirstJobFinished", 1);
762 }
763
703 const QuicVersion version_; 764 const QuicVersion version_;
704 QuicFlagSaver flags_; // Save/restore all QUIC flag values. 765 QuicFlagSaver flags_; // Save/restore all QUIC flag values.
705 MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. 766 MockClock* clock_; // Owned by QuicStreamFactory after CreateSession.
706 QuicTestPacketMaker client_maker_; 767 QuicTestPacketMaker client_maker_;
707 QuicTestPacketMaker server_maker_; 768 QuicTestPacketMaker server_maker_;
708 std::unique_ptr<HttpNetworkSession> session_; 769 std::unique_ptr<HttpNetworkSession> session_;
709 MockClientSocketFactory socket_factory_; 770 MockClientSocketFactory socket_factory_;
710 ProofVerifyDetailsChromium verify_details_; 771 ProofVerifyDetailsChromium verify_details_;
711 MockCryptoClientStreamFactory crypto_client_stream_factory_; 772 MockCryptoClientStreamFactory crypto_client_stream_factory_;
712 MockHostResolver host_resolver_; 773 MockHostResolver host_resolver_;
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1846 EXPECT_TRUE(test_proxy_delegate.alternative_proxy_server().is_quic()); 1907 EXPECT_TRUE(test_proxy_delegate.alternative_proxy_server().is_quic());
1847 1908
1848 // Verify that the proxy server is not marked as broken. 1909 // Verify that the proxy server is not marked as broken.
1849 EXPECT_TRUE(session_->proxy_service()->proxy_retry_info().empty()); 1910 EXPECT_TRUE(session_->proxy_service()->proxy_retry_info().empty());
1850 1911
1851 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage", 1912 histogram_tester.ExpectUniqueSample("Net.QuicAlternativeProxy.Usage",
1852 1 /* ALTERNATIVE_PROXY_USAGE_WON_RACE */, 1913 1 /* ALTERNATIVE_PROXY_USAGE_WON_RACE */,
1853 1); 1914 1);
1854 } 1915 }
1855 1916
1917 // Tests that the connection to an HTTPS proxy is raced with an available
1918 // alternative proxy server.
1919 TEST_P(QuicNetworkTransactionTest, QuicProxyWithRacingForPreconnect) {
1920 base::HistogramTester histogram_tester;
1921 proxy_service_ =
1922 ProxyService::CreateFixedFromPacResult("HTTPS mail.example.org:443");
1923
1924 MockQuicData mock_quic_data;
1925 QuicStreamOffset header_stream_offset = 0;
1926 mock_quic_data.AddWrite(ConstructSettingsPacket(
1927 1, SETTINGS_MAX_HEADER_LIST_SIZE, kDefaultMaxUncompressedHeaderSize,
1928 &header_stream_offset));
1929 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
1930 2, kClientDataStreamId1, true, true,
1931 GetRequestHeaders("GET", "http", "/"), &header_stream_offset));
1932 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
1933 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK")));
1934 mock_quic_data.AddRead(ConstructServerDataPacket(2, kClientDataStreamId1,
1935 false, true, 0, "hello!"));
1936 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 2, 1));
1937 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
1938 mock_quic_data.AddRead(ASYNC, 0); // EOF
1939
1940 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
1941
1942 // There is no need to set up main job, because no attempt will be made to
1943 // speak to the proxy over TCP.
1944 params_.enable_quic_alternative_service_with_different_host = false;
1945 TestProxyDelegate test_proxy_delegate;
1946 const HostPortPair host_port_pair("mail.example.org", 443);
1947
1948 test_proxy_delegate.set_alternative_proxy_server(
1949 ProxyServer::FromPacString("QUIC mail.example.org:443"));
1950 params_.proxy_delegate = &test_proxy_delegate;
1951 params_.race_preconnects_to_http2_proxies = true;
1952 CreateSession();
1953 EXPECT_TRUE(test_proxy_delegate.alternative_proxy_server().is_quic());
1954
1955 // The main job needs to hang in order to guarantee that the alternative
1956 // proxy server job will "win".
1957 AddHangingNonAlternateProtocolSocketData();
1958
1959 HttpRequestInfo request_info;
1960 request_info.method = "GET";
1961 request_info.url = GURL("http://www.google.com");
1962
1963 session_->http_stream_factory()->PreconnectStreams(1 /* num_streams */,
1964 request_info);
1965 base::RunLoop().RunUntilIdle();
1966 histogram_tester.ExpectTotalCount(
1967 "Net.QuicAlternativeProxy.PreconnectRace.FirstJobFinished", 1);
1968
1969 // Verify that the alternative proxy server is not marked as broken.
1970 EXPECT_TRUE(test_proxy_delegate.alternative_proxy_server().is_quic());
1971
1972 // Verify that the proxy server is not marked as broken.
1973 EXPECT_TRUE(session_->proxy_service()->proxy_retry_info().empty());
1974 }
1975
1856 TEST_P(QuicNetworkTransactionTest, HungAlternativeService) { 1976 TEST_P(QuicNetworkTransactionTest, HungAlternativeService) {
1857 crypto_client_stream_factory_.set_handshake_mode( 1977 crypto_client_stream_factory_.set_handshake_mode(
1858 MockCryptoClientStream::COLD_START); 1978 MockCryptoClientStream::COLD_START);
1859 1979
1860 MockWrite http_writes[] = { 1980 MockWrite http_writes[] = {
1861 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), 1981 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"),
1862 MockWrite(SYNCHRONOUS, 1, "Host: mail.example.org\r\n"), 1982 MockWrite(SYNCHRONOUS, 1, "Host: mail.example.org\r\n"),
1863 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n")}; 1983 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n")};
1864 1984
1865 MockRead http_reads[] = { 1985 MockRead http_reads[] = {
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
2508 TEST_P(QuicNetworkTransactionTest, BrokenAlternativeProxyQuicProtocolError) { 2628 TEST_P(QuicNetworkTransactionTest, BrokenAlternativeProxyQuicProtocolError) {
2509 TestAlternativeProxy(ERR_QUIC_PROTOCOL_ERROR); 2629 TestAlternativeProxy(ERR_QUIC_PROTOCOL_ERROR);
2510 } 2630 }
2511 TEST_P(QuicNetworkTransactionTest, BrokenAlternativeProxyIOPending) { 2631 TEST_P(QuicNetworkTransactionTest, BrokenAlternativeProxyIOPending) {
2512 TestAlternativeProxy(ERR_IO_PENDING); 2632 TestAlternativeProxy(ERR_IO_PENDING);
2513 } 2633 }
2514 TEST_P(QuicNetworkTransactionTest, BrokenAlternativeProxyAddressUnreachable) { 2634 TEST_P(QuicNetworkTransactionTest, BrokenAlternativeProxyAddressUnreachable) {
2515 TestAlternativeProxy(ERR_ADDRESS_UNREACHABLE); 2635 TestAlternativeProxy(ERR_ADDRESS_UNREACHABLE);
2516 } 2636 }
2517 2637
2638 TEST_P(QuicNetworkTransactionTest,
2639 BrokenAlternativeProxySocketNotConnectedPreconnect) {
2640 TestAlternativeProxyPreconnect(ERR_SOCKET_NOT_CONNECTED);
2641 }
2642 TEST_P(QuicNetworkTransactionTest,
2643 BrokenAlternativeProxyConnectionFailedPreconnect) {
2644 TestAlternativeProxyPreconnect(ERR_CONNECTION_FAILED);
2645 }
2646 TEST_P(QuicNetworkTransactionTest,
2647 BrokenAlternativeProxyConnectionTimedOutPreconnect) {
2648 TestAlternativeProxyPreconnect(ERR_CONNECTION_TIMED_OUT);
2649 }
2650 TEST_P(QuicNetworkTransactionTest,
2651 BrokenAlternativeProxyConnectionRefusedPreconnect) {
2652 TestAlternativeProxyPreconnect(ERR_CONNECTION_REFUSED);
2653 }
2654 TEST_P(QuicNetworkTransactionTest,
2655 BrokenAlternativeProxyQuicHandshakeFailedPreconnect) {
2656 TestAlternativeProxyPreconnect(ERR_QUIC_HANDSHAKE_FAILED);
2657 }
2658 TEST_P(QuicNetworkTransactionTest,
2659 BrokenAlternativeProxyQuicProtocolErrorPreconnect) {
2660 TestAlternativeProxyPreconnect(ERR_QUIC_PROTOCOL_ERROR);
2661 }
2662 TEST_P(QuicNetworkTransactionTest, BrokenAlternativeProxyIOPendingPreconnect) {
2663 TestAlternativeProxyPreconnect(ERR_IO_PENDING);
2664 }
2665 TEST_P(QuicNetworkTransactionTest,
2666 BrokenAlternativeProxyAddressUnreachablePreconnect) {
2667 TestAlternativeProxyPreconnect(ERR_ADDRESS_UNREACHABLE);
2668 }
2669
2518 TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnectProxy) { 2670 TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnectProxy) {
2519 MockQuicData mock_quic_data; 2671 MockQuicData mock_quic_data;
2520 mock_quic_data.AddSynchronousRead(ConstructServerConnectionClosePacket(1)); 2672 mock_quic_data.AddSynchronousRead(ConstructServerConnectionClosePacket(1));
2521 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( 2673 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
2522 1, kClientDataStreamId1, true, true, 2674 1, kClientDataStreamId1, true, true,
2523 GetRequestHeaders("GET", "https", "/"))); 2675 GetRequestHeaders("GET", "https", "/")));
2524 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1)); 2676 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1));
2525 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 2677 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
2526 2678
2527 // When the QUIC connection fails, we will try the request again over HTTP. 2679 // When the QUIC connection fails, we will try the request again over HTTP.
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
3436 AddHangingSocketData(); 3588 AddHangingSocketData();
3437 3589
3438 SendRequestAndExpectQuicResponse(origin1_); 3590 SendRequestAndExpectQuicResponse(origin1_);
3439 SendRequestAndExpectQuicResponse(origin2_); 3591 SendRequestAndExpectQuicResponse(origin2_);
3440 3592
3441 EXPECT_TRUE(AllDataConsumed()); 3593 EXPECT_TRUE(AllDataConsumed());
3442 } 3594 }
3443 3595
3444 } // namespace test 3596 } // namespace test
3445 } // namespace net 3597 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698