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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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/quic/quic_http_stream_test.cc ('k') | net/quic/quic_stream_factory_test.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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "net/socket/client_socket_factory.h" 47 #include "net/socket/client_socket_factory.h"
48 #include "net/socket/mock_client_socket_pool_manager.h" 48 #include "net/socket/mock_client_socket_pool_manager.h"
49 #include "net/socket/socket_performance_watcher.h" 49 #include "net/socket/socket_performance_watcher.h"
50 #include "net/socket/socket_performance_watcher_factory.h" 50 #include "net/socket/socket_performance_watcher_factory.h"
51 #include "net/socket/socket_test_util.h" 51 #include "net/socket/socket_test_util.h"
52 #include "net/socket/ssl_client_socket.h" 52 #include "net/socket/ssl_client_socket.h"
53 #include "net/spdy/spdy_frame_builder.h" 53 #include "net/spdy/spdy_frame_builder.h"
54 #include "net/spdy/spdy_framer.h" 54 #include "net/spdy/spdy_framer.h"
55 #include "net/ssl/ssl_config_service_defaults.h" 55 #include "net/ssl/ssl_config_service_defaults.h"
56 #include "net/test/cert_test_util.h" 56 #include "net/test/cert_test_util.h"
57 #include "net/test/gtest_util.h"
57 #include "net/test/test_data_directory.h" 58 #include "net/test/test_data_directory.h"
59 #include "testing/gmock/include/gmock/gmock.h"
58 #include "testing/gtest/include/gtest/gtest.h" 60 #include "testing/gtest/include/gtest/gtest.h"
59 #include "testing/platform_test.h" 61 #include "testing/platform_test.h"
60 #include "url/gurl.h" 62 #include "url/gurl.h"
61 63
64 using net::test::IsError;
65 using net::test::IsOk;
66
62 namespace net { 67 namespace net {
63 namespace test { 68 namespace test {
64 69
65 namespace { 70 namespace {
66 71
67 enum DestinationType { 72 enum DestinationType {
68 // In pooling tests with two requests for different origins to the same 73 // In pooling tests with two requests for different origins to the same
69 // destination, the destination should be 74 // destination, the destination should be
70 SAME_AS_FIRST, // the same as the first origin, 75 SAME_AS_FIRST, // the same as the first origin,
71 SAME_AS_SECOND, // the same as the second origin, or 76 SAME_AS_SECOND, // the same as the second origin, or
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 587 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
583 EXPECT_FALSE(response->was_fetched_via_spdy); 588 EXPECT_FALSE(response->was_fetched_via_spdy);
584 EXPECT_FALSE(response->was_npn_negotiated); 589 EXPECT_FALSE(response->was_npn_negotiated);
585 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, 590 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1,
586 response->connection_info); 591 response->connection_info);
587 } 592 }
588 593
589 void CheckResponseData(const std::unique_ptr<HttpNetworkTransaction>& trans, 594 void CheckResponseData(const std::unique_ptr<HttpNetworkTransaction>& trans,
590 const std::string& expected) { 595 const std::string& expected) {
591 std::string response_data; 596 std::string response_data;
592 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 597 ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk());
593 EXPECT_EQ(expected, response_data); 598 EXPECT_EQ(expected, response_data);
594 } 599 }
595 600
596 void RunTransaction(const std::unique_ptr<HttpNetworkTransaction>& trans) { 601 void RunTransaction(const std::unique_ptr<HttpNetworkTransaction>& trans) {
597 TestCompletionCallback callback; 602 TestCompletionCallback callback;
598 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 603 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
599 EXPECT_EQ(ERR_IO_PENDING, rv); 604 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
600 EXPECT_EQ(OK, callback.WaitForResult()); 605 EXPECT_THAT(callback.WaitForResult(), IsOk());
601 } 606 }
602 607
603 void SendRequestAndExpectHttpResponse(const std::string& expected) { 608 void SendRequestAndExpectHttpResponse(const std::string& expected) {
604 std::unique_ptr<HttpNetworkTransaction> trans( 609 std::unique_ptr<HttpNetworkTransaction> trans(
605 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 610 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
606 RunTransaction(trans); 611 RunTransaction(trans);
607 CheckWasHttpResponse(trans); 612 CheckWasHttpResponse(trans);
608 CheckResponseData(trans, expected); 613 CheckResponseData(trans, expected);
609 } 614 }
610 615
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 mock_quic_data2.AddSocketDataToFactory(&socket_factory_); 922 mock_quic_data2.AddSocketDataToFactory(&socket_factory_);
918 923
919 CreateSession(); 924 CreateSession();
920 925
921 EXPECT_EQ(0U, test_socket_performance_watcher_factory_.watcher_count()); 926 EXPECT_EQ(0U, test_socket_performance_watcher_factory_.watcher_count());
922 for (size_t i = 0; i < 2; ++i) { 927 for (size_t i = 0; i < 2; ++i) {
923 std::unique_ptr<HttpNetworkTransaction> trans( 928 std::unique_ptr<HttpNetworkTransaction> trans(
924 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 929 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
925 TestCompletionCallback callback; 930 TestCompletionCallback callback;
926 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 931 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
927 EXPECT_EQ(ERR_IO_PENDING, rv); 932 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
928 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); 933 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED));
929 EXPECT_EQ(1 + i, test_socket_performance_watcher_factory_.watcher_count()); 934 EXPECT_EQ(1 + i, test_socket_performance_watcher_factory_.watcher_count());
930 } 935 }
931 } 936 }
932 937
933 TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { 938 TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) {
934 // Attempt to "force" quic on 443, which will not be honored. 939 // Attempt to "force" quic on 443, which will not be honored.
935 params_.origins_to_force_quic_on.insert( 940 params_.origins_to_force_quic_on.insert(
936 HostPortPair::FromString("www.google.com:443")); 941 HostPortPair::FromString("www.google.com:443"));
937 942
938 MockRead http_reads[] = { 943 MockRead http_reads[] = {
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 nullptr, net_log_.bound()); 1165 nullptr, net_log_.bound());
1161 1166
1162 CreateSession(); 1167 CreateSession();
1163 session_->quic_stream_factory()->set_require_confirmation(true); 1168 session_->quic_stream_factory()->set_require_confirmation(true);
1164 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 1169 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1165 1170
1166 std::unique_ptr<HttpNetworkTransaction> trans( 1171 std::unique_ptr<HttpNetworkTransaction> trans(
1167 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1172 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1168 TestCompletionCallback callback; 1173 TestCompletionCallback callback;
1169 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1174 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1170 EXPECT_EQ(ERR_IO_PENDING, rv); 1175 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1171 1176
1172 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( 1177 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1173 QuicSession::HANDSHAKE_CONFIRMED); 1178 QuicSession::HANDSHAKE_CONFIRMED);
1174 EXPECT_EQ(OK, callback.WaitForResult()); 1179 EXPECT_THAT(callback.WaitForResult(), IsOk());
1175 1180
1176 // Check whether this transaction is correctly marked as received a go-away 1181 // Check whether this transaction is correctly marked as received a go-away
1177 // because of migrating port. 1182 // because of migrating port.
1178 NetErrorDetails details; 1183 NetErrorDetails details;
1179 EXPECT_FALSE(details.quic_port_migration_detected); 1184 EXPECT_FALSE(details.quic_port_migration_detected);
1180 trans->PopulateNetErrorDetails(&details); 1185 trans->PopulateNetErrorDetails(&details);
1181 EXPECT_TRUE(details.quic_port_migration_detected); 1186 EXPECT_TRUE(details.quic_port_migration_detected);
1182 } 1187 }
1183 1188
1184 TEST_P(QuicNetworkTransactionTest, 1189 TEST_P(QuicNetworkTransactionTest,
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1777 nullptr, net_log_.bound()); 1782 nullptr, net_log_.bound());
1778 1783
1779 CreateSession(); 1784 CreateSession();
1780 session_->quic_stream_factory()->set_require_confirmation(true); 1785 session_->quic_stream_factory()->set_require_confirmation(true);
1781 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 1786 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1782 1787
1783 std::unique_ptr<HttpNetworkTransaction> trans( 1788 std::unique_ptr<HttpNetworkTransaction> trans(
1784 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1789 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1785 TestCompletionCallback callback; 1790 TestCompletionCallback callback;
1786 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1791 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1787 EXPECT_EQ(ERR_IO_PENDING, rv); 1792 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1788 1793
1789 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( 1794 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1790 QuicSession::HANDSHAKE_CONFIRMED); 1795 QuicSession::HANDSHAKE_CONFIRMED);
1791 EXPECT_EQ(OK, callback.WaitForResult()); 1796 EXPECT_THAT(callback.WaitForResult(), IsOk());
1792 1797
1793 CheckWasQuicResponse(trans); 1798 CheckWasQuicResponse(trans);
1794 CheckResponseData(trans, "hello!"); 1799 CheckResponseData(trans, "hello!");
1795 } 1800 }
1796 1801
1797 TEST_P(QuicNetworkTransactionTest, 1802 TEST_P(QuicNetworkTransactionTest,
1798 LogGranularQuicErrorCodeOnQuicProtocolErrorLocal) { 1803 LogGranularQuicErrorCodeOnQuicProtocolErrorLocal) {
1799 MockQuicData mock_quic_data; 1804 MockQuicData mock_quic_data;
1800 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( 1805 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
1801 1, kClientDataStreamId1, true, true, 1806 1, kClientDataStreamId1, true, true,
(...skipping 21 matching lines...) Expand all
1823 nullptr, net_log_.bound()); 1828 nullptr, net_log_.bound());
1824 1829
1825 CreateSession(); 1830 CreateSession();
1826 session_->quic_stream_factory()->set_require_confirmation(true); 1831 session_->quic_stream_factory()->set_require_confirmation(true);
1827 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 1832 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1828 1833
1829 std::unique_ptr<HttpNetworkTransaction> trans( 1834 std::unique_ptr<HttpNetworkTransaction> trans(
1830 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1835 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1831 TestCompletionCallback callback; 1836 TestCompletionCallback callback;
1832 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1837 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1833 EXPECT_EQ(ERR_IO_PENDING, rv); 1838 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1834 1839
1835 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( 1840 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1836 QuicSession::HANDSHAKE_CONFIRMED); 1841 QuicSession::HANDSHAKE_CONFIRMED);
1837 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); 1842 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_QUIC_PROTOCOL_ERROR));
1838 1843
1839 NetErrorDetails details; 1844 NetErrorDetails details;
1840 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); 1845 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error);
1841 1846
1842 trans->PopulateNetErrorDetails(&details); 1847 trans->PopulateNetErrorDetails(&details);
1843 // Verify the error code logged is what sent by the peer. 1848 // Verify the error code logged is what sent by the peer.
1844 EXPECT_EQ(QUIC_CRYPTO_VERSION_NOT_SUPPORTED, details.quic_connection_error); 1849 EXPECT_EQ(QUIC_CRYPTO_VERSION_NOT_SUPPORTED, details.quic_connection_error);
1845 } 1850 }
1846 1851
1847 TEST_P(QuicNetworkTransactionTest, 1852 TEST_P(QuicNetworkTransactionTest,
(...skipping 30 matching lines...) Expand all
1878 nullptr, net_log_.bound()); 1883 nullptr, net_log_.bound());
1879 1884
1880 CreateSession(); 1885 CreateSession();
1881 session_->quic_stream_factory()->set_require_confirmation(true); 1886 session_->quic_stream_factory()->set_require_confirmation(true);
1882 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 1887 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1883 1888
1884 std::unique_ptr<HttpNetworkTransaction> trans( 1889 std::unique_ptr<HttpNetworkTransaction> trans(
1885 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1890 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1886 TestCompletionCallback callback; 1891 TestCompletionCallback callback;
1887 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1892 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1888 EXPECT_EQ(ERR_IO_PENDING, rv); 1893 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1889 1894
1890 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( 1895 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1891 QuicSession::HANDSHAKE_CONFIRMED); 1896 QuicSession::HANDSHAKE_CONFIRMED);
1892 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); 1897 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_QUIC_PROTOCOL_ERROR));
1893 NetErrorDetails details; 1898 NetErrorDetails details;
1894 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); 1899 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error);
1895 1900
1896 trans->PopulateNetErrorDetails(&details); 1901 trans->PopulateNetErrorDetails(&details);
1897 EXPECT_EQ(QUIC_INVALID_STREAM_ID, details.quic_connection_error); 1902 EXPECT_EQ(QUIC_INVALID_STREAM_ID, details.quic_connection_error);
1898 } 1903 }
1899 1904
1900 TEST_P(QuicNetworkTransactionTest, RstSteamErrorHandling) { 1905 TEST_P(QuicNetworkTransactionTest, RstSteamErrorHandling) {
1901 MockQuicData mock_quic_data; 1906 MockQuicData mock_quic_data;
1902 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( 1907 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
(...skipping 26 matching lines...) Expand all
1929 nullptr, net_log_.bound()); 1934 nullptr, net_log_.bound());
1930 1935
1931 CreateSession(); 1936 CreateSession();
1932 session_->quic_stream_factory()->set_require_confirmation(true); 1937 session_->quic_stream_factory()->set_require_confirmation(true);
1933 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 1938 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1934 1939
1935 std::unique_ptr<HttpNetworkTransaction> trans( 1940 std::unique_ptr<HttpNetworkTransaction> trans(
1936 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1941 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1937 TestCompletionCallback callback; 1942 TestCompletionCallback callback;
1938 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1943 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1939 EXPECT_EQ(ERR_IO_PENDING, rv); 1944 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1940 1945
1941 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( 1946 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1942 QuicSession::HANDSHAKE_CONFIRMED); 1947 QuicSession::HANDSHAKE_CONFIRMED);
1943 // Read the headers. 1948 // Read the headers.
1944 EXPECT_EQ(OK, callback.WaitForResult()); 1949 EXPECT_THAT(callback.WaitForResult(), IsOk());
1945 1950
1946 const HttpResponseInfo* response = trans->GetResponseInfo(); 1951 const HttpResponseInfo* response = trans->GetResponseInfo();
1947 ASSERT_TRUE(response != nullptr); 1952 ASSERT_TRUE(response != nullptr);
1948 ASSERT_TRUE(response->headers.get() != nullptr); 1953 ASSERT_TRUE(response->headers.get() != nullptr);
1949 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 1954 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
1950 EXPECT_TRUE(response->was_fetched_via_spdy); 1955 EXPECT_TRUE(response->was_fetched_via_spdy);
1951 EXPECT_TRUE(response->was_npn_negotiated); 1956 EXPECT_TRUE(response->was_npn_negotiated);
1952 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, 1957 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3,
1953 response->connection_info); 1958 response->connection_info);
1954 1959
(...skipping 30 matching lines...) Expand all
1985 nullptr, net_log_.bound()); 1990 nullptr, net_log_.bound());
1986 1991
1987 CreateSession(); 1992 CreateSession();
1988 session_->quic_stream_factory()->set_require_confirmation(true); 1993 session_->quic_stream_factory()->set_require_confirmation(true);
1989 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 1994 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
1990 1995
1991 std::unique_ptr<HttpNetworkTransaction> trans( 1996 std::unique_ptr<HttpNetworkTransaction> trans(
1992 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 1997 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
1993 TestCompletionCallback callback; 1998 TestCompletionCallback callback;
1994 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 1999 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
1995 EXPECT_EQ(ERR_IO_PENDING, rv); 2000 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
1996 2001
1997 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( 2002 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
1998 QuicSession::HANDSHAKE_CONFIRMED); 2003 QuicSession::HANDSHAKE_CONFIRMED);
1999 // Read the headers. 2004 // Read the headers.
2000 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); 2005 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_QUIC_PROTOCOL_ERROR));
2001 } 2006 }
2002 2007
2003 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { 2008 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) {
2004 // Alternate-protocol job 2009 // Alternate-protocol job
2005 std::unique_ptr<QuicEncryptedPacket> close( 2010 std::unique_ptr<QuicEncryptedPacket> close(
2006 ConstructServerConnectionClosePacket(1)); 2011 ConstructServerConnectionClosePacket(1));
2007 MockRead quic_reads[] = { 2012 MockRead quic_reads[] = {
2008 MockRead(ASYNC, close->data(), close->length()), 2013 MockRead(ASYNC, close->data(), close->length()),
2009 MockRead(ASYNC, ERR_IO_PENDING), // No more data to read 2014 MockRead(ASYNC, ERR_IO_PENDING), // No more data to read
2010 MockRead(ASYNC, OK), // EOF 2015 MockRead(ASYNC, OK), // EOF
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); 2083 socket_factory_.AddSSLSocketDataProvider(&ssl_data_);
2079 2084
2080 AddHangingNonAlternateProtocolSocketData(); 2085 AddHangingNonAlternateProtocolSocketData();
2081 CreateSession(); 2086 CreateSession();
2082 2087
2083 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); 2088 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START);
2084 std::unique_ptr<HttpNetworkTransaction> trans( 2089 std::unique_ptr<HttpNetworkTransaction> trans(
2085 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 2090 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
2086 TestCompletionCallback callback; 2091 TestCompletionCallback callback;
2087 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 2092 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
2088 EXPECT_EQ(ERR_IO_PENDING, rv); 2093 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
2089 EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, callback.WaitForResult()); 2094 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_SOCKET_NOT_CONNECTED));
2090 ExpectQuicAlternateProtocolMapping(); 2095 ExpectQuicAlternateProtocolMapping();
2091 } 2096 }
2092 2097
2093 TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { 2098 TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) {
2094 // Alternate-protocol job 2099 // Alternate-protocol job
2095 MockRead quic_reads[] = { 2100 MockRead quic_reads[] = {
2096 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), 2101 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED),
2097 }; 2102 };
2098 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), nullptr, 2103 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), nullptr,
2099 0); 2104 0);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2260 request_.method = "POST"; 2265 request_.method = "POST";
2261 ChunkedUploadDataStream upload_data(0); 2266 ChunkedUploadDataStream upload_data(0);
2262 upload_data.AppendData("1", 1, true); 2267 upload_data.AppendData("1", 1, true);
2263 2268
2264 request_.upload_data_stream = &upload_data; 2269 request_.upload_data_stream = &upload_data;
2265 2270
2266 std::unique_ptr<HttpNetworkTransaction> trans( 2271 std::unique_ptr<HttpNetworkTransaction> trans(
2267 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 2272 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
2268 TestCompletionCallback callback; 2273 TestCompletionCallback callback;
2269 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 2274 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
2270 EXPECT_EQ(ERR_IO_PENDING, rv); 2275 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
2271 EXPECT_NE(OK, callback.WaitForResult()); 2276 EXPECT_NE(OK, callback.WaitForResult());
2272 } 2277 }
2273 2278
2274 // Adds coverage to catch regression such as https://crbug.com/622043 2279 // Adds coverage to catch regression such as https://crbug.com/622043
2275 TEST_P(QuicNetworkTransactionTest, QuicServerPush) { 2280 TEST_P(QuicNetworkTransactionTest, QuicServerPush) {
2276 params_.origins_to_force_quic_on.insert( 2281 params_.origins_to_force_quic_on.insert(
2277 HostPortPair::FromString("mail.example.org:443")); 2282 HostPortPair::FromString("mail.example.org:443"));
2278 2283
2279 MockQuicData mock_quic_data; 2284 MockQuicData mock_quic_data;
2280 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( 2285 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2502 void SendRequestAndExpectQuicResponse(const std::string& host) { 2507 void SendRequestAndExpectQuicResponse(const std::string& host) {
2503 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); 2508 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
2504 HttpRequestInfo request; 2509 HttpRequestInfo request;
2505 std::string url("https://"); 2510 std::string url("https://");
2506 url.append(host); 2511 url.append(host);
2507 request.url = GURL(url); 2512 request.url = GURL(url);
2508 request.load_flags = 0; 2513 request.load_flags = 0;
2509 request.method = "GET"; 2514 request.method = "GET";
2510 TestCompletionCallback callback; 2515 TestCompletionCallback callback;
2511 int rv = trans.Start(&request, callback.callback(), net_log_.bound()); 2516 int rv = trans.Start(&request, callback.callback(), net_log_.bound());
2512 EXPECT_EQ(OK, callback.GetResult(rv)); 2517 EXPECT_THAT(callback.GetResult(rv), IsOk());
2513 2518
2514 std::string response_data; 2519 std::string response_data;
2515 ASSERT_EQ(OK, ReadTransaction(&trans, &response_data)); 2520 ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk());
2516 EXPECT_EQ("hello", response_data); 2521 EXPECT_EQ("hello", response_data);
2517 2522
2518 const HttpResponseInfo* response = trans.GetResponseInfo(); 2523 const HttpResponseInfo* response = trans.GetResponseInfo();
2519 ASSERT_TRUE(response != nullptr); 2524 ASSERT_TRUE(response != nullptr);
2520 ASSERT_TRUE(response->headers.get() != nullptr); 2525 ASSERT_TRUE(response->headers.get() != nullptr);
2521 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 2526 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
2522 EXPECT_TRUE(response->was_fetched_via_spdy); 2527 EXPECT_TRUE(response->was_fetched_via_spdy);
2523 EXPECT_TRUE(response->was_npn_negotiated); 2528 EXPECT_TRUE(response->was_npn_negotiated);
2524 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, 2529 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3,
2525 response->connection_info); 2530 response->connection_info);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2588 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 2593 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
2589 2594
2590 AddRefusedSocketData(); 2595 AddRefusedSocketData();
2591 2596
2592 HttpRequestInfo request; 2597 HttpRequestInfo request;
2593 request.url = url; 2598 request.url = url;
2594 2599
2595 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get()); 2600 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session_.get());
2596 TestCompletionCallback callback; 2601 TestCompletionCallback callback;
2597 int rv = trans.Start(&request, callback.callback(), net_log_.bound()); 2602 int rv = trans.Start(&request, callback.callback(), net_log_.bound());
2598 EXPECT_EQ(ERR_CONNECTION_REFUSED, callback.GetResult(rv)); 2603 EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED));
2599 2604
2600 EXPECT_TRUE(AllDataConsumed()); 2605 EXPECT_TRUE(AllDataConsumed());
2601 } 2606 }
2602 2607
2603 // First request opens QUIC session to alternative service. Second request 2608 // First request opens QUIC session to alternative service. Second request
2604 // pools to it, because destination matches and certificate is valid, even 2609 // pools to it, because destination matches and certificate is valid, even
2605 // though QuicServerId is different. 2610 // though QuicServerId is different.
2606 TEST_P(QuicNetworkTransactionWithDestinationTest, PoolIfCertificateValid) { 2611 TEST_P(QuicNetworkTransactionWithDestinationTest, PoolIfCertificateValid) {
2607 origin1_ = "mail.example.org"; 2612 origin1_ = "mail.example.org";
2608 origin2_ = "news.example.org"; 2613 origin2_ = "news.example.org";
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
2742 AddHangingSocketData(); 2747 AddHangingSocketData();
2743 2748
2744 SendRequestAndExpectQuicResponse(origin1_); 2749 SendRequestAndExpectQuicResponse(origin1_);
2745 SendRequestAndExpectQuicResponse(origin2_); 2750 SendRequestAndExpectQuicResponse(origin2_);
2746 2751
2747 EXPECT_TRUE(AllDataConsumed()); 2752 EXPECT_TRUE(AllDataConsumed());
2748 } 2753 }
2749 2754
2750 } // namespace test 2755 } // namespace test
2751 } // namespace net 2756 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_http_stream_test.cc ('k') | net/quic/quic_stream_factory_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698