[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 5 | #include "net/quic/quic_stream_factory.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 6 | |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 7 | #include <memory> |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8 | #include <ostream> |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 9 | #include <utility> |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 10 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/callback.h" |
xunjieli | 48e4f10 | 2017-04-11 23:06:53 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 14 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 16 | #include "base/test/test_mock_time_task_runner.h" |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 17 | #include "build/build_config.h" |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 18 | #include "net/base/mock_network_change_notifier.h" |
rsleevi | d6de830 | 2016-06-21 01:33:20 | [diff] [blame] | 19 | #include "net/cert/ct_policy_enforcer.h" |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 20 | #include "net/cert/do_nothing_ct_verifier.h" |
| 21 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 22 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 23 | #include "net/http/http_response_headers.h" |
| 24 | #include "net/http/http_response_info.h" |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 25 | #include "net/http/http_server_properties_impl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 26 | #include "net/http/http_util.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 27 | #include "net/http/transport_security_state.h" |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 28 | #include "net/http/transport_security_state_test_util.h" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 29 | #include "net/quic/crypto/proof_verifier_chromium.h" |
| 30 | #include "net/quic/mock_crypto_client_stream_factory.h" |
| 31 | #include "net/quic/mock_quic_data.h" |
| 32 | #include "net/quic/properties_based_quic_server_info.h" |
| 33 | #include "net/quic/quic_http_stream.h" |
| 34 | #include "net/quic/quic_http_utils.h" |
| 35 | #include "net/quic/quic_server_info.h" |
| 36 | #include "net/quic/quic_stream_factory_peer.h" |
| 37 | #include "net/quic/quic_test_packet_maker.h" |
| 38 | #include "net/quic/test_task_runner.h" |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 39 | #include "net/socket/next_proto.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 40 | #include "net/socket/socket_test_util.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 41 | #include "net/spdy/spdy_session_test_util.h" |
| 42 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 43 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 44 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 45 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 46 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 47 | #include "net/third_party/quic/core/crypto/crypto_handshake.h" |
| 48 | #include "net/third_party/quic/core/crypto/quic_crypto_client_config.h" |
| 49 | #include "net/third_party/quic/core/crypto/quic_decrypter.h" |
| 50 | #include "net/third_party/quic/core/crypto/quic_encrypter.h" |
Victor Vasiliev | c5b409c2 | 2018-07-24 12:23:46 | [diff] [blame] | 51 | #include "net/third_party/quic/core/http/quic_client_promised_info.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 52 | #include "net/third_party/quic/platform/api/quic_test.h" |
| 53 | #include "net/third_party/quic/test_tools/mock_clock.h" |
| 54 | #include "net/third_party/quic/test_tools/mock_random.h" |
| 55 | #include "net/third_party/quic/test_tools/quic_config_peer.h" |
| 56 | #include "net/third_party/quic/test_tools/quic_spdy_session_peer.h" |
| 57 | #include "net/third_party/quic/test_tools/quic_test_utils.h" |
Ryan Hamilton | 2e003eea | 2018-05-02 00:24:29 | [diff] [blame] | 58 | #include "net/third_party/spdy/core/spdy_test_utils.h" |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 59 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 60 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 61 | #include "testing/gtest/include/gtest/gtest.h" |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 62 | #include "url/gurl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 63 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 64 | using std::string; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 65 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 66 | namespace net { |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 67 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 68 | namespace { |
| 69 | |
| 70 | class MockSSLConfigService : public SSLConfigService { |
| 71 | public: |
| 72 | MockSSLConfigService() {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 73 | ~MockSSLConfigService() override {} |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 74 | |
| 75 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 76 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 77 | bool CanShareConnectionWithClientCerts( |
| 78 | const std::string& hostname) const override { |
| 79 | return false; |
| 80 | } |
| 81 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 82 | private: |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 83 | SSLConfig config_; |
| 84 | }; |
| 85 | |
| 86 | } // namespace |
| 87 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 88 | namespace test { |
| 89 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 90 | namespace { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 91 | |
| 92 | enum DestinationType { |
| 93 | // In pooling tests with two requests for different origins to the same |
| 94 | // destination, the destination should be |
| 95 | SAME_AS_FIRST, // the same as the first origin, |
| 96 | SAME_AS_SECOND, // the same as the second origin, or |
| 97 | DIFFERENT, // different from both. |
| 98 | }; |
| 99 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 100 | const char kDefaultServerHostName[] = "www.example.org"; |
| 101 | const char kServer2HostName[] = "mail.example.org"; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 102 | const char kDifferentHostname[] = "different.example.com"; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 103 | const int kDefaultServerPort = 443; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 104 | const char kDefaultUrl[] = "https://www.example.org/"; |
| 105 | const char kServer2Url[] = "https://mail.example.org/"; |
| 106 | const char kServer3Url[] = "https://docs.example.org/"; |
| 107 | const char kServer4Url[] = "https://images.example.org/"; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 108 | const int kDefaultRTTMilliSecs = 300; |
| 109 | const size_t kMinRetryTimeForDefaultNetworkSecs = 1; |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 110 | const size_t kWaitTimeForNewNetworkSecs = 10; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 111 | const IPAddress kCachedIPAddress = IPAddress(192, 168, 0, 2); |
| 112 | const char kNonCachedIPAddress[] = "192.168.0.1"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 113 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 114 | // Run QuicStreamFactoryTest instances with all value combinations of version |
| 115 | // and enable_connection_racting. |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 116 | struct TestParams { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 117 | friend std::ostream& operator<<(std::ostream& os, const TestParams& p) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 118 | os << "{ version: " << QuicVersionToString(p.version) |
| 119 | << ", client_headers_include_h2_stream_dependency: " |
| 120 | << p.client_headers_include_h2_stream_dependency << " }"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 121 | return os; |
| 122 | } |
| 123 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 124 | quic::QuicTransportVersion version; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 125 | bool client_headers_include_h2_stream_dependency; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 126 | }; |
| 127 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 128 | std::vector<TestParams> GetTestParams() { |
| 129 | std::vector<TestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 130 | quic::QuicTransportVersionVector all_supported_versions = |
| 131 | quic::AllSupportedTransportVersions(); |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 132 | for (const auto& version : all_supported_versions) { |
| 133 | params.push_back(TestParams{version, false}); |
| 134 | params.push_back(TestParams{version, true}); |
| 135 | } |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 136 | return params; |
| 137 | } |
| 138 | |
| 139 | // Run QuicStreamFactoryWithDestinationTest instances with all value |
| 140 | // combinations of version, enable_connection_racting, and destination_type. |
| 141 | struct PoolingTestParams { |
| 142 | friend std::ostream& operator<<(std::ostream& os, |
| 143 | const PoolingTestParams& p) { |
| 144 | os << "{ version: " << QuicVersionToString(p.version) |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 145 | << ", destination_type: "; |
| 146 | switch (p.destination_type) { |
| 147 | case SAME_AS_FIRST: |
| 148 | os << "SAME_AS_FIRST"; |
| 149 | break; |
| 150 | case SAME_AS_SECOND: |
| 151 | os << "SAME_AS_SECOND"; |
| 152 | break; |
| 153 | case DIFFERENT: |
| 154 | os << "DIFFERENT"; |
| 155 | break; |
| 156 | } |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 157 | os << ", client_headers_include_h2_stream_dependency: " |
| 158 | << p.client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 159 | os << " }"; |
| 160 | return os; |
| 161 | } |
| 162 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 163 | quic::QuicTransportVersion version; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 164 | DestinationType destination_type; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 165 | bool client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 166 | }; |
| 167 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 168 | std::vector<PoolingTestParams> GetPoolingTestParams() { |
| 169 | std::vector<PoolingTestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 170 | quic::QuicTransportVersionVector all_supported_versions = |
| 171 | quic::AllSupportedTransportVersions(); |
| 172 | for (const quic::QuicTransportVersion version : all_supported_versions) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 173 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, false}); |
| 174 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, true}); |
| 175 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, false}); |
| 176 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, true}); |
| 177 | params.push_back(PoolingTestParams{version, DIFFERENT, false}); |
| 178 | params.push_back(PoolingTestParams{version, DIFFERENT, true}); |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 179 | } |
| 180 | return params; |
| 181 | } |
| 182 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 183 | } // namespace |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 184 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 185 | class QuicHttpStreamPeer { |
| 186 | public: |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 187 | static QuicChromiumClientSession::Handle* GetSessionHandle( |
| 188 | HttpStream* stream) { |
| 189 | return static_cast<QuicHttpStream*>(stream)->quic_session(); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 190 | } |
| 191 | }; |
| 192 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 193 | // TestConnectionMigrationSocketFactory will vend sockets with incremental port |
| 194 | // number. |
| 195 | class TestConnectionMigrationSocketFactory : public MockClientSocketFactory { |
| 196 | public: |
| 197 | TestConnectionMigrationSocketFactory() : next_source_port_num_(1u) {} |
| 198 | ~TestConnectionMigrationSocketFactory() override {} |
| 199 | |
| 200 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 201 | DatagramSocket::BindType bind_type, |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 202 | NetLog* net_log, |
| 203 | const NetLogSource& source) override { |
| 204 | SocketDataProvider* data_provider = mock_data().GetNext(); |
| 205 | std::unique_ptr<MockUDPClientSocket> socket( |
| 206 | new MockUDPClientSocket(data_provider, net_log)); |
| 207 | socket->set_source_port(next_source_port_num_++); |
| 208 | return std::move(socket); |
| 209 | } |
| 210 | |
| 211 | private: |
| 212 | uint16_t next_source_port_num_; |
| 213 | |
| 214 | DISALLOW_COPY_AND_ASSIGN(TestConnectionMigrationSocketFactory); |
| 215 | }; |
| 216 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 217 | class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 218 | protected: |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 219 | QuicStreamFactoryTestBase(quic::QuicTransportVersion version, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 220 | bool client_headers_include_h2_stream_dependency) |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 221 | : host_resolver_(new MockHostResolver), |
| 222 | ssl_config_service_(new MockSSLConfigService), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 223 | socket_factory_(new MockClientSocketFactory), |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 224 | random_generator_(0), |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 225 | runner_(new TestTaskRunner(&clock_)), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 226 | version_(version), |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 227 | client_headers_include_h2_stream_dependency_( |
| 228 | client_headers_include_h2_stream_dependency), |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 229 | client_maker_(version_, |
| 230 | 0, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 231 | &clock_, |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 232 | kDefaultServerHostName, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 233 | quic::Perspective::IS_CLIENT, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 234 | client_headers_include_h2_stream_dependency_), |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 235 | server_maker_(version_, |
| 236 | 0, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 237 | &clock_, |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 238 | kDefaultServerHostName, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 239 | quic::Perspective::IS_SERVER, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 240 | false), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 241 | cert_verifier_(std::make_unique<MockCertVerifier>()), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 242 | cert_transparency_verifier_(std::make_unique<DoNothingCTVerifier>()), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 243 | scoped_mock_network_change_notifier_(nullptr), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 244 | factory_(nullptr), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 245 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 246 | url_(kDefaultUrl), |
| 247 | url2_(kServer2Url), |
| 248 | url3_(kServer3Url), |
| 249 | url4_(kServer4Url), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 250 | privacy_mode_(PRIVACY_MODE_DISABLED), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 251 | failed_on_default_network_callback_(base::BindRepeating( |
| 252 | &QuicStreamFactoryTestBase::OnFailedOnDefaultNetwork, |
| 253 | base::Unretained(this))), |
| 254 | failed_on_default_network_(false), |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 255 | store_server_configs_in_properties_(false), |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 256 | close_sessions_on_ip_change_(false), |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 257 | goaway_sessions_on_ip_change_(false), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 258 | idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 259 | reduced_ping_timeout_seconds_(quic::kPingTimeoutSecs), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 260 | max_time_before_crypto_handshake_seconds_( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 261 | quic::kMaxTimeForCryptoHandshakeSecs), |
| 262 | max_idle_time_before_crypto_handshake_seconds_( |
| 263 | quic::kInitialIdleTimeoutSecs), |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 264 | migrate_sessions_on_network_change_v2_(false), |
| 265 | migrate_sessions_early_v2_(false), |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 266 | retry_on_alternate_network_before_handshake_(false), |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 267 | race_stale_dns_on_connection_(false), |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 268 | go_away_on_path_degrading_(false), |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 269 | allow_server_migration_(false), |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 270 | race_cert_verification_(false), |
| 271 | estimate_initial_rtt_(false) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 272 | clock_.AdvanceTime(quic::QuicTime::Delta::FromSeconds(1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 273 | } |
| 274 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 275 | void Initialize() { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 276 | DCHECK(!factory_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 277 | factory_.reset(new QuicStreamFactory( |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 278 | net_log_.net_log(), host_resolver_.get(), ssl_config_service_.get(), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 279 | socket_factory_.get(), &http_server_properties_, cert_verifier_.get(), |
Nick Harper | ecf319d | 2018-10-16 07:58:54 | [diff] [blame] | 280 | &ct_policy_enforcer_, &transport_security_state_, |
| 281 | cert_transparency_verifier_.get(), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 282 | /*SocketPerformanceWatcherFactory*/ nullptr, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 283 | &crypto_client_stream_factory_, &random_generator_, &clock_, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 284 | quic::kDefaultMaxPacketSize, string(), |
| 285 | store_server_configs_in_properties_, close_sessions_on_ip_change_, |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 286 | goaway_sessions_on_ip_change_, |
rch | 9ecde09b | 2017-04-08 00:18:23 | [diff] [blame] | 287 | /*mark_quic_broken_when_network_blackholes*/ false, |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 288 | idle_connection_timeout_seconds_, reduced_ping_timeout_seconds_, |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 289 | max_time_before_crypto_handshake_seconds_, |
| 290 | max_idle_time_before_crypto_handshake_seconds_, |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 291 | migrate_sessions_on_network_change_v2_, migrate_sessions_early_v2_, |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 292 | retry_on_alternate_network_before_handshake_, |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 293 | race_stale_dns_on_connection_, go_away_on_path_degrading_, |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 294 | base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 295 | kMaxMigrationsToNonDefaultNetworkOnWriteError, |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 296 | kMaxMigrationsToNonDefaultNetworkOnPathDegrading, |
Charles 'Buck' Krasic | 0c346c9 | 2017-09-14 18:17:37 | [diff] [blame] | 297 | allow_server_migration_, race_cert_verification_, estimate_initial_rtt_, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 298 | client_headers_include_h2_stream_dependency_, connection_options_, |
Nick Harper | 2243e800 | 2018-09-28 20:33:26 | [diff] [blame] | 299 | client_connection_options_, |
kapishnikov | 7f8dd1e | 2018-01-24 06:10:49 | [diff] [blame] | 300 | /*enable_socket_recv_optimization*/ false)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 301 | } |
| 302 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 303 | void InitializeConnectionMigrationV2Test( |
| 304 | NetworkChangeNotifier::NetworkList connected_networks) { |
| 305 | scoped_mock_network_change_notifier_.reset( |
| 306 | new ScopedMockNetworkChangeNotifier()); |
| 307 | MockNetworkChangeNotifier* mock_ncn = |
| 308 | scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 309 | mock_ncn->ForceNetworkHandlesSupported(); |
| 310 | mock_ncn->SetConnectedNetworksList(connected_networks); |
| 311 | migrate_sessions_on_network_change_v2_ = true; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 312 | migrate_sessions_early_v2_ = true; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 313 | retry_on_alternate_network_before_handshake_ = true; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 314 | socket_factory_.reset(new TestConnectionMigrationSocketFactory); |
| 315 | Initialize(); |
| 316 | } |
| 317 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 318 | std::unique_ptr<HttpStream> CreateStream(QuicStreamRequest* request) { |
| 319 | std::unique_ptr<QuicChromiumClientSession::Handle> session = |
| 320 | request->ReleaseSessionHandle(); |
| 321 | if (!session || !session->IsConnected()) |
| 322 | return nullptr; |
| 323 | |
| 324 | return std::make_unique<QuicHttpStream>(std::move(session)); |
| 325 | } |
| 326 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 327 | bool HasActiveSession(const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 328 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 329 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 330 | return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 331 | } |
| 332 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 333 | bool HasLiveSession(const HostPortPair& host_port_pair) { |
| 334 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 335 | false); |
| 336 | return QuicStreamFactoryPeer::HasLiveSession(factory_.get(), host_port_pair, |
| 337 | server_id); |
| 338 | } |
| 339 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 340 | bool HasActiveJob(const HostPortPair& host_port_pair, |
| 341 | const PrivacyMode privacy_mode) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 342 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 343 | privacy_mode == PRIVACY_MODE_ENABLED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 344 | return QuicStreamFactoryPeer::HasActiveJob(factory_.get(), server_id); |
| 345 | } |
| 346 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 347 | bool HasActiveCertVerifierJob(const quic::QuicServerId& server_id) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 348 | return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 349 | server_id); |
| 350 | } |
| 351 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 352 | // Get the pending, not activated session, if there is only one session alive. |
| 353 | QuicChromiumClientSession* GetPendingSession( |
| 354 | const HostPortPair& host_port_pair) { |
| 355 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 356 | false); |
| 357 | return QuicStreamFactoryPeer::GetPendingSession(factory_.get(), server_id, |
| 358 | host_port_pair); |
| 359 | } |
| 360 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 361 | QuicChromiumClientSession* GetActiveSession( |
| 362 | const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 363 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 364 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 365 | return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 366 | } |
| 367 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 368 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 369 | return GetSourcePortForNewSessionInner(destination, false); |
| 370 | } |
| 371 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 372 | int GetSourcePortForNewSessionAndGoAway(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 373 | return GetSourcePortForNewSessionInner(destination, true); |
| 374 | } |
| 375 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 376 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 377 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 378 | // Should only be called if there is no active session for this destination. |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 379 | EXPECT_FALSE(HasActiveSession(destination)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 380 | size_t socket_count = socket_factory_->udp_client_socket_ports().size(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 381 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 382 | MockQuicData socket_data; |
| 383 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 384 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 385 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 386 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 387 | QuicStreamRequest request(factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 388 | GURL url("https://" + destination.host() + "/"); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 389 | EXPECT_EQ( |
| 390 | ERR_IO_PENDING, |
| 391 | request.Request( |
| 392 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 393 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 394 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 395 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 396 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 397 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 398 | EXPECT_TRUE(stream.get()); |
| 399 | stream.reset(); |
| 400 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 401 | QuicChromiumClientSession* session = GetActiveSession(destination); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 402 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 403 | if (socket_count + 1 != socket_factory_->udp_client_socket_ports().size()) { |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 404 | ADD_FAILURE(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 405 | return 0; |
| 406 | } |
| 407 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 408 | if (goaway_received) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 409 | quic::QuicGoAwayFrame goaway(quic::kInvalidControlFrameId, |
| 410 | quic::QUIC_NO_ERROR, 1, ""); |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 411 | session->connection()->OnGoAwayFrame(goaway); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 412 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 413 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 414 | factory_->OnSessionClosed(session); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 415 | EXPECT_FALSE(HasActiveSession(destination)); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 416 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 417 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 418 | return socket_factory_->udp_client_socket_ports()[socket_count]; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 419 | } |
| 420 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 421 | std::unique_ptr<quic::QuicEncryptedPacket> |
| 422 | ConstructClientConnectionClosePacket(quic::QuicPacketNumber num) { |
Bin Wu | 5311aca | 2018-01-22 01:19:03 | [diff] [blame] | 423 | return client_maker_.MakeConnectionClosePacket( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 424 | num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 425 | } |
| 426 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 427 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( |
| 428 | quic::QuicPacketNumber packet_number, |
| 429 | quic::QuicRstStreamErrorCode error_code) { |
| 430 | quic::QuicStreamId stream_id = GetNthClientInitiatedStreamId(0); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 431 | return client_maker_.MakeRstPacket(packet_number, true, stream_id, |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 432 | error_code); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 433 | } |
| 434 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 435 | static ProofVerifyDetailsChromium DefaultProofVerifyDetails() { |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 436 | // Load a certificate that is valid for *.example.org |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 437 | scoped_refptr<X509Certificate> test_cert( |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 438 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 439 | EXPECT_TRUE(test_cert.get()); |
| 440 | ProofVerifyDetailsChromium verify_details; |
| 441 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 442 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 443 | return verify_details; |
| 444 | } |
| 445 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 446 | void NotifyIPAddressChanged() { |
| 447 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 448 | // Spin the message loop so the notification is delivered. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 449 | base::RunLoop().RunUntilIdle(); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 450 | } |
| 451 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 452 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 453 | quic::QuicPacketNumber packet_number, |
| 454 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 455 | bool should_include_version, |
| 456 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 457 | spdy::SpdyHeaderBlock headers = |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 458 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 459 | spdy::SpdyPriority priority = |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 460 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 461 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 462 | return client_maker_.MakeRequestHeadersPacket( |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 463 | packet_number, stream_id, should_include_version, fin, priority, |
Yixin Wang | 7a3f1b8d | 2018-01-17 21:40:48 | [diff] [blame] | 464 | std::move(headers), 0, &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 465 | } |
| 466 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 467 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 468 | quic::QuicPacketNumber packet_number, |
| 469 | quic::QuicStreamId stream_id, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 470 | quic::QuicStreamId parent_stream_id, |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 471 | bool should_include_version, |
| 472 | bool fin, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 473 | quic::QuicStreamOffset* offset) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 474 | spdy::SpdyHeaderBlock headers = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 475 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 476 | spdy::SpdyPriority priority = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 477 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 478 | size_t spdy_headers_frame_len; |
| 479 | return client_maker_.MakeRequestHeadersPacket( |
| 480 | packet_number, stream_id, should_include_version, fin, priority, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 481 | std::move(headers), parent_stream_id, &spdy_headers_frame_len, offset); |
| 482 | } |
| 483 | |
| 484 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 485 | quic::QuicPacketNumber packet_number, |
| 486 | quic::QuicStreamId stream_id, |
| 487 | bool should_include_version, |
| 488 | bool fin, |
| 489 | quic::QuicStreamOffset* offset) { |
| 490 | return ConstructGetRequestPacket(packet_number, stream_id, |
| 491 | /*parent_stream_id=*/0, |
| 492 | should_include_version, fin, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 493 | } |
| 494 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 495 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( |
| 496 | quic::QuicPacketNumber packet_number, |
| 497 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 498 | bool should_include_version, |
| 499 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 500 | spdy::SpdyHeaderBlock headers = server_maker_.GetResponseHeaders("200 OK"); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 501 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 502 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 503 | packet_number, stream_id, should_include_version, fin, |
| 504 | std::move(headers), &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 505 | } |
| 506 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 507 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket() { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 508 | return client_maker_.MakeInitialSettingsPacket(1, nullptr); |
| 509 | } |
| 510 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 511 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( |
| 512 | quic::QuicPacketNumber packet_number, |
| 513 | quic::QuicStreamOffset* offset) { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 514 | return client_maker_.MakeInitialSettingsPacket(packet_number, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 515 | } |
| 516 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 517 | // Helper method for server migration tests. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 518 | void VerifyServerMigration(const quic::QuicConfig& config, |
bnc | 6a0348c | 2017-05-22 18:56:19 | [diff] [blame] | 519 | IPEndPoint expected_address) { |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 520 | allow_server_migration_ = true; |
| 521 | Initialize(); |
| 522 | |
| 523 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 524 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 525 | crypto_client_stream_factory_.SetConfig(config); |
| 526 | |
| 527 | // Set up first socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 528 | MockQuicData socket_data1; |
| 529 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 530 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 531 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 532 | // Set up second socket data provider that is used after |
| 533 | // migration. |
| 534 | MockQuicData socket_data2; |
| 535 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 536 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 537 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 538 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 539 | socket_data2.AddWrite( |
| 540 | SYNCHRONOUS, |
| 541 | client_maker_.MakeRstPacket(3, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 542 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 543 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 544 | |
| 545 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 546 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 547 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 548 | request.Request( |
| 549 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 550 | SocketTag(), |
| 551 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 552 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 553 | EXPECT_EQ(OK, callback_.WaitForResult()); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 554 | |
| 555 | // Run QuicChromiumClientSession::WriteToNewSocket() |
| 556 | // posted by QuicChromiumClientSession::MigrateToSocket(). |
| 557 | base::RunLoop().RunUntilIdle(); |
| 558 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 559 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 560 | EXPECT_TRUE(stream.get()); |
| 561 | |
| 562 | // Cause QUIC stream to be created. |
| 563 | HttpRequestInfo request_info; |
| 564 | request_info.method = "GET"; |
| 565 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 566 | request_info.traffic_annotation = |
| 567 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 568 | EXPECT_EQ(OK, |
| 569 | stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 570 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 571 | // Ensure that session is alive and active. |
| 572 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 573 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 574 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 575 | |
| 576 | IPEndPoint actual_address; |
| 577 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 578 | EXPECT_EQ(actual_address, expected_address); |
| 579 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 580 | << " " << actual_address.port(); |
| 581 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 582 | << " " << expected_address.port(); |
| 583 | |
| 584 | stream.reset(); |
| 585 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 586 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 587 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 588 | } |
| 589 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 590 | // Verifies that the QUIC stream factory is initialized correctly. |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 591 | void VerifyInitialization() { |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 592 | store_server_configs_in_properties_ = true; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 593 | idle_connection_timeout_seconds_ = 500; |
| 594 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 595 | factory_->set_require_confirmation(false); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 596 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 597 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 598 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 599 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 600 | MockCryptoClientStream::ZERO_RTT); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 601 | const quic::QuicConfig* config = |
| 602 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
ckrasic | 32b17dcd | 2016-10-31 06:15:35 | [diff] [blame] | 603 | EXPECT_EQ(500, config->IdleNetworkTimeout().ToSeconds()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 604 | |
| 605 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 606 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 607 | const AlternativeService alternative_service1( |
| 608 | kProtoQUIC, host_port_pair_.host(), host_port_pair_.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 609 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 610 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 611 | alternative_service_info_vector.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 612 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 613 | alternative_service1, expiration, {version_})); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 614 | http_server_properties_.SetAlternativeServices( |
| 615 | url::SchemeHostPort(url_), alternative_service_info_vector); |
| 616 | |
| 617 | HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 618 | url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 619 | const AlternativeService alternative_service2( |
| 620 | kProtoQUIC, host_port_pair2.host(), host_port_pair2.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 621 | AlternativeServiceInfoVector alternative_service_info_vector2; |
| 622 | alternative_service_info_vector2.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 623 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 624 | alternative_service2, expiration, {version_})); |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 625 | |
| 626 | http_server_properties_.SetAlternativeServices( |
| 627 | server2, alternative_service_info_vector2); |
| 628 | // Verify that the properties of both QUIC servers are stored in the |
| 629 | // HTTP properties map. |
| 630 | EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 631 | |
| 632 | http_server_properties_.SetMaxServerConfigsStoredInProperties( |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 633 | kDefaultMaxQuicServerEntries); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 634 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 635 | quic::QuicServerId quic_server_id(kDefaultServerHostName, 443, |
| 636 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 637 | std::unique_ptr<QuicServerInfo> quic_server_info = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 638 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 639 | quic_server_id, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 640 | |
| 641 | // Update quic_server_info's server_config and persist it. |
| 642 | QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 643 | // Minimum SCFG that passes config validation checks. |
| 644 | const char scfg[] = {// SCFG |
| 645 | 0x53, 0x43, 0x46, 0x47, |
| 646 | // num entries |
| 647 | 0x01, 0x00, |
| 648 | // padding |
| 649 | 0x00, 0x00, |
| 650 | // EXPY |
| 651 | 0x45, 0x58, 0x50, 0x59, |
| 652 | // EXPY end offset |
| 653 | 0x08, 0x00, 0x00, 0x00, |
| 654 | // Value |
| 655 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 656 | |
| 657 | // Create temporary strings becasue Persist() clears string data in |state|. |
| 658 | string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 659 | string source_address_token("test_source_address_token"); |
| 660 | string cert_sct("test_cert_sct"); |
| 661 | string chlo_hash("test_chlo_hash"); |
| 662 | string signature("test_signature"); |
| 663 | string test_cert("test_cert"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 664 | std::vector<string> certs; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 665 | certs.push_back(test_cert); |
| 666 | state->server_config = server_config; |
| 667 | state->source_address_token = source_address_token; |
| 668 | state->cert_sct = cert_sct; |
| 669 | state->chlo_hash = chlo_hash; |
| 670 | state->server_config_sig = signature; |
| 671 | state->certs = certs; |
| 672 | |
| 673 | quic_server_info->Persist(); |
| 674 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 675 | quic::QuicServerId quic_server_id2(kServer2HostName, 443, |
| 676 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 677 | std::unique_ptr<QuicServerInfo> quic_server_info2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 678 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 679 | quic_server_id2, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 680 | // Update quic_server_info2's server_config and persist it. |
| 681 | QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 682 | |
| 683 | // Minimum SCFG that passes config validation checks. |
| 684 | const char scfg2[] = {// SCFG |
| 685 | 0x53, 0x43, 0x46, 0x47, |
| 686 | // num entries |
| 687 | 0x01, 0x00, |
| 688 | // padding |
| 689 | 0x00, 0x00, |
| 690 | // EXPY |
| 691 | 0x45, 0x58, 0x50, 0x59, |
| 692 | // EXPY end offset |
| 693 | 0x08, 0x00, 0x00, 0x00, |
| 694 | // Value |
| 695 | '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 696 | |
| 697 | // Create temporary strings becasue Persist() clears string data in |
| 698 | // |state2|. |
| 699 | string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 700 | string source_address_token2("test_source_address_token2"); |
| 701 | string cert_sct2("test_cert_sct2"); |
| 702 | string chlo_hash2("test_chlo_hash2"); |
| 703 | string signature2("test_signature2"); |
| 704 | string test_cert2("test_cert2"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 705 | std::vector<string> certs2; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 706 | certs2.push_back(test_cert2); |
| 707 | state2->server_config = server_config2; |
| 708 | state2->source_address_token = source_address_token2; |
| 709 | state2->cert_sct = cert_sct2; |
| 710 | state2->chlo_hash = chlo_hash2; |
| 711 | state2->server_config_sig = signature2; |
| 712 | state2->certs = certs2; |
| 713 | |
| 714 | quic_server_info2->Persist(); |
| 715 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 716 | // Verify the MRU order is maintained. |
| 717 | const QuicServerInfoMap& quic_server_info_map = |
| 718 | http_server_properties_.quic_server_info_map(); |
| 719 | EXPECT_EQ(2u, quic_server_info_map.size()); |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 720 | auto quic_server_info_map_it = quic_server_info_map.begin(); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 721 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 722 | ++quic_server_info_map_it; |
| 723 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 724 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 725 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 726 | "192.168.0.1", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 727 | |
| 728 | // Create a session and verify that the cached state is loaded. |
| 729 | MockQuicData socket_data; |
| 730 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 731 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 732 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 733 | QuicStreamRequest request(factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 734 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 735 | request.Request( |
| 736 | HostPortPair(quic_server_id.host(), quic_server_id.port()), |
| 737 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 738 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 739 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 740 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 741 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 742 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 743 | factory_.get(), quic_server_id)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 744 | quic::QuicCryptoClientConfig* crypto_config = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 745 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 746 | quic::QuicCryptoClientConfig::CachedState* cached = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 747 | crypto_config->LookupOrCreate(quic_server_id); |
| 748 | EXPECT_FALSE(cached->server_config().empty()); |
| 749 | EXPECT_TRUE(cached->GetServerConfig()); |
| 750 | EXPECT_EQ(server_config, cached->server_config()); |
| 751 | EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 752 | EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 753 | EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 754 | EXPECT_EQ(signature, cached->signature()); |
| 755 | ASSERT_EQ(1U, cached->certs().size()); |
| 756 | EXPECT_EQ(test_cert, cached->certs()[0]); |
| 757 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 758 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 759 | |
| 760 | // Create a session and verify that the cached state is loaded. |
| 761 | MockQuicData socket_data2; |
| 762 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 763 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 764 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 765 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 766 | "192.168.0.2", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 767 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 768 | QuicStreamRequest request2(factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 769 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 770 | request2.Request( |
| 771 | HostPortPair(quic_server_id2.host(), quic_server_id2.port()), |
| 772 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 773 | /*cert_verify_flags=*/0, GURL("https://mail.example.org/"), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 774 | net_log_, &net_error_details_, |
| 775 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 776 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 777 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 778 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 779 | factory_.get(), quic_server_id2)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 780 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 781 | crypto_config->LookupOrCreate(quic_server_id2); |
| 782 | EXPECT_FALSE(cached2->server_config().empty()); |
| 783 | EXPECT_TRUE(cached2->GetServerConfig()); |
| 784 | EXPECT_EQ(server_config2, cached2->server_config()); |
| 785 | EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 786 | EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 787 | EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 788 | EXPECT_EQ(signature2, cached2->signature()); |
| 789 | ASSERT_EQ(1U, cached->certs().size()); |
| 790 | EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 791 | } |
| 792 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 793 | void RunTestLoopUntilIdle() { |
| 794 | while (!runner_->GetPostedTasks().empty()) |
| 795 | runner_->RunNextTask(); |
| 796 | } |
| 797 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 798 | quic::QuicStreamId GetNthClientInitiatedStreamId(int n) { |
| 799 | return quic::test::GetNthClientInitiatedStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 800 | } |
| 801 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 802 | quic::QuicStreamId GetNthServerInitiatedStreamId(int n) { |
| 803 | return quic::test::GetNthServerInitiatedStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 804 | } |
| 805 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 806 | void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } |
| 807 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 808 | // Helper methods for tests of connection migration on write error. |
| 809 | void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 810 | // Migratable stream triggers write error. |
| 811 | void TestMigrationOnWriteErrorMixedStreams(IoMode write_error_mode); |
| 812 | // Non-migratable stream triggers write error. |
| 813 | void TestMigrationOnWriteErrorMixedStreams2(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 814 | void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 815 | void TestMigrationOnWriteError(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 816 | void TestMigrationOnWriteErrorWithMultipleRequests(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 817 | void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 818 | void TestMigrationOnMultipleWriteErrors( |
| 819 | IoMode write_error_mode_on_old_network, |
| 820 | IoMode write_error_mode_on_new_network); |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 821 | void TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 822 | bool disconnected); |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 823 | void TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 824 | void TestMigrationOnNetworkDisconnected(bool async_write_before); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 825 | void TestMigrationOnNetworkMadeDefault(IoMode write_mode); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 826 | void TestMigrationOnPathDegrading(bool async_write_before); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 827 | void TestMigrateSessionWithDrainingStream( |
| 828 | IoMode write_mode_for_queued_packet); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 829 | void TestMigrationOnWriteErrorPauseBeforeConnected(IoMode write_error_mode); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 830 | void TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 831 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 832 | bool disconnect_before_connect); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 833 | void TestNoAlternateNetworkBeforeHandshake(quic::QuicErrorCode error); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 834 | void TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 835 | quic::QuicErrorCode error); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 836 | |
Jana Iyengar | f6b13d8 | 2017-09-04 02:09:10 | [diff] [blame] | 837 | QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 838 | std::unique_ptr<MockHostResolverBase> host_resolver_; |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 839 | std::unique_ptr<SSLConfigService> ssl_config_service_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 840 | std::unique_ptr<MockClientSocketFactory> socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 841 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 842 | quic::test::MockRandom random_generator_; |
| 843 | quic::MockClock clock_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 844 | scoped_refptr<TestTaskRunner> runner_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 845 | const quic::QuicTransportVersion version_; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 846 | const bool client_headers_include_h2_stream_dependency_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 847 | QuicTestPacketMaker client_maker_; |
| 848 | QuicTestPacketMaker server_maker_; |
rtenneti | ccab42b | 2015-10-09 06:38:16 | [diff] [blame] | 849 | HttpServerPropertiesImpl http_server_properties_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 850 | std::unique_ptr<CertVerifier> cert_verifier_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 851 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 852 | std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
Ryan Sleevi | 8a9c9c1 | 2018-05-09 02:36:23 | [diff] [blame] | 853 | DefaultCTPolicyEnforcer ct_policy_enforcer_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 854 | std::unique_ptr<ScopedMockNetworkChangeNotifier> |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 855 | scoped_mock_network_change_notifier_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 856 | std::unique_ptr<QuicStreamFactory> factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 857 | HostPortPair host_port_pair_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 858 | GURL url_; |
| 859 | GURL url2_; |
| 860 | GURL url3_; |
| 861 | GURL url4_; |
| 862 | |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 863 | PrivacyMode privacy_mode_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 864 | NetLogWithSource net_log_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 865 | TestCompletionCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 866 | const CompletionRepeatingCallback failed_on_default_network_callback_; |
| 867 | bool failed_on_default_network_; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 868 | NetErrorDetails net_error_details_; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 869 | |
| 870 | // Variables to configure QuicStreamFactory. |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 871 | bool store_server_configs_in_properties_; |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 872 | bool close_sessions_on_ip_change_; |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 873 | bool goaway_sessions_on_ip_change_; |
rtenneti | 41c0999 | 2015-11-30 18:24:01 | [diff] [blame] | 874 | int idle_connection_timeout_seconds_; |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 875 | int reduced_ping_timeout_seconds_; |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 876 | int max_time_before_crypto_handshake_seconds_; |
| 877 | int max_idle_time_before_crypto_handshake_seconds_; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 878 | bool migrate_sessions_on_network_change_v2_; |
| 879 | bool migrate_sessions_early_v2_; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 880 | bool retry_on_alternate_network_before_handshake_; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 881 | bool race_stale_dns_on_connection_; |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 882 | bool go_away_on_path_degrading_; |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 883 | bool allow_server_migration_; |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 884 | bool race_cert_verification_; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 885 | bool estimate_initial_rtt_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 886 | quic::QuicTagVector connection_options_; |
| 887 | quic::QuicTagVector client_connection_options_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 888 | }; |
| 889 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 890 | class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 891 | public ::testing::TestWithParam<TestParams> { |
| 892 | protected: |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 893 | QuicStreamFactoryTest() |
| 894 | : QuicStreamFactoryTestBase( |
| 895 | GetParam().version, |
| 896 | GetParam().client_headers_include_h2_stream_dependency) {} |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 897 | }; |
| 898 | |
Bence Béky | ce380cb | 2018-04-26 23:39:55 | [diff] [blame] | 899 | INSTANTIATE_TEST_CASE_P(VersionIncludeStreamDependencySequence, |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 900 | QuicStreamFactoryTest, |
| 901 | ::testing::ValuesIn(GetTestParams())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 902 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 903 | TEST_P(QuicStreamFactoryTest, Create) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 904 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 905 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 906 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 907 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 908 | MockQuicData socket_data; |
| 909 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 910 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 911 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 912 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 913 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 914 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 915 | request.Request( |
| 916 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 917 | SocketTag(), |
| 918 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 919 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 920 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 921 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 922 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 923 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 924 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 925 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 926 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 927 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 928 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 929 | DEFAULT_PRIORITY, SocketTag(), |
| 930 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 931 | &net_error_details_, |
| 932 | failed_on_default_network_callback_, |
| 933 | callback_.callback())); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 934 | // Will reset stream 3. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 935 | stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 936 | |
| 937 | EXPECT_TRUE(stream.get()); |
| 938 | |
| 939 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 940 | // in streams on different sessions. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 941 | QuicStreamRequest request3(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 942 | EXPECT_EQ(OK, request3.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 943 | DEFAULT_PRIORITY, SocketTag(), |
| 944 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 945 | &net_error_details_, |
| 946 | failed_on_default_network_callback_, |
| 947 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 948 | stream = CreateStream(&request3); // Will reset stream 5. |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 949 | stream.reset(); // Will reset stream 7. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 950 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 951 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 952 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 953 | } |
| 954 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 955 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 956 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 957 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 958 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 959 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 960 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 961 | MockQuicData socket_data; |
| 962 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 963 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 964 | |
| 965 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 966 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 967 | host_resolver_->set_synchronous_mode(true); |
| 968 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 969 | "192.168.0.1", ""); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 970 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 971 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 972 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 973 | DEFAULT_PRIORITY, SocketTag(), |
| 974 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 975 | &net_error_details_, |
| 976 | failed_on_default_network_callback_, |
| 977 | callback_.callback())); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 978 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 979 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 980 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 981 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 982 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 983 | } |
| 984 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 985 | TEST_P(QuicStreamFactoryTest, DefaultInitialRtt) { |
| 986 | Initialize(); |
| 987 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 988 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 989 | |
| 990 | MockQuicData socket_data; |
| 991 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 992 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 993 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 994 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 995 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 996 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 997 | request.Request( |
| 998 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 999 | SocketTag(), |
| 1000 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1001 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1002 | |
| 1003 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1004 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1005 | EXPECT_TRUE(stream.get()); |
| 1006 | |
| 1007 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1008 | EXPECT_TRUE(session->require_confirmation()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1009 | EXPECT_EQ(100000u, session->connection()->GetStats().srtt_us); |
| 1010 | ASSERT_FALSE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1011 | } |
| 1012 | |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1013 | TEST_P(QuicStreamFactoryTest, FactoryDestroyedWhenJobPending) { |
| 1014 | Initialize(); |
| 1015 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1016 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1017 | |
| 1018 | MockQuicData socket_data; |
| 1019 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1020 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1021 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1022 | |
| 1023 | auto request = std::make_unique<QuicStreamRequest>(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1024 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1025 | request->Request( |
| 1026 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1027 | SocketTag(), |
| 1028 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1029 | failed_on_default_network_callback_, callback_.callback())); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1030 | request.reset(); |
| 1031 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1032 | // Tearing down a QuicStreamFactory with a pending Job should not cause any |
| 1033 | // crash. crbug.com/768343. |
| 1034 | factory_.reset(); |
| 1035 | } |
| 1036 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1037 | TEST_P(QuicStreamFactoryTest, RequireConfirmation) { |
| 1038 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1039 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1040 | host_resolver_->set_synchronous_mode(true); |
| 1041 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1042 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1043 | Initialize(); |
| 1044 | factory_->set_require_confirmation(true); |
| 1045 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1046 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1047 | |
| 1048 | MockQuicData socket_data; |
| 1049 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1050 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1051 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1052 | |
| 1053 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1054 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1055 | request.Request( |
| 1056 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1057 | SocketTag(), |
| 1058 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1059 | failed_on_default_network_callback_, callback_.callback())); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1060 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1061 | IPAddress last_address; |
| 1062 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1063 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1064 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1065 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1066 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1067 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1068 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1069 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1070 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1071 | EXPECT_TRUE(stream.get()); |
| 1072 | |
| 1073 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1074 | EXPECT_TRUE(session->require_confirmation()); |
| 1075 | } |
| 1076 | |
| 1077 | TEST_P(QuicStreamFactoryTest, DontRequireConfirmationFromSameIP) { |
| 1078 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1079 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1080 | host_resolver_->set_synchronous_mode(true); |
| 1081 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1082 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1083 | Initialize(); |
| 1084 | factory_->set_require_confirmation(true); |
| 1085 | http_server_properties_.SetSupportsQuic(IPAddress(192, 0, 2, 33)); |
| 1086 | |
| 1087 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1088 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1089 | |
| 1090 | MockQuicData socket_data; |
| 1091 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1092 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1093 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1094 | |
| 1095 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1096 | EXPECT_THAT(request.Request( |
| 1097 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1098 | SocketTag(), |
| 1099 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1100 | failed_on_default_network_callback_, callback_.callback()), |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1101 | IsOk()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1102 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1103 | IPAddress last_address; |
| 1104 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1105 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1106 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1107 | EXPECT_TRUE(stream.get()); |
| 1108 | |
| 1109 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1110 | EXPECT_FALSE(session->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1111 | |
| 1112 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1113 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1114 | |
| 1115 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1116 | } |
| 1117 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1118 | TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { |
| 1119 | ServerNetworkStats stats; |
| 1120 | stats.srtt = base::TimeDelta::FromMilliseconds(10); |
| 1121 | http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), |
| 1122 | stats); |
| 1123 | estimate_initial_rtt_ = true; |
| 1124 | |
| 1125 | Initialize(); |
| 1126 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1127 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1128 | |
| 1129 | MockQuicData socket_data; |
| 1130 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1131 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1132 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1133 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1134 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1135 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1136 | request.Request( |
| 1137 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1138 | SocketTag(), |
| 1139 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1140 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1141 | |
| 1142 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1143 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1144 | EXPECT_TRUE(stream.get()); |
| 1145 | |
| 1146 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1147 | EXPECT_EQ(10000u, session->connection()->GetStats().srtt_us); |
| 1148 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1149 | EXPECT_EQ(10000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1150 | } |
| 1151 | |
| 1152 | TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { |
| 1153 | ScopedMockNetworkChangeNotifier notifier; |
| 1154 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1155 | NetworkChangeNotifier::CONNECTION_2G); |
| 1156 | estimate_initial_rtt_ = true; |
| 1157 | |
| 1158 | Initialize(); |
| 1159 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1160 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1161 | |
| 1162 | MockQuicData socket_data; |
| 1163 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1164 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1165 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1166 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1167 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1168 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1169 | request.Request( |
| 1170 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1171 | SocketTag(), |
| 1172 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1173 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1174 | |
| 1175 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1176 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1177 | EXPECT_TRUE(stream.get()); |
| 1178 | |
| 1179 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1180 | EXPECT_EQ(1200000u, session->connection()->GetStats().srtt_us); |
| 1181 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1182 | EXPECT_EQ(1200000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1183 | } |
| 1184 | |
| 1185 | TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { |
| 1186 | ScopedMockNetworkChangeNotifier notifier; |
| 1187 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1188 | NetworkChangeNotifier::CONNECTION_3G); |
| 1189 | estimate_initial_rtt_ = true; |
| 1190 | |
| 1191 | Initialize(); |
| 1192 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1193 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1194 | |
| 1195 | MockQuicData socket_data; |
| 1196 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1197 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1198 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1199 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1200 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1201 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1202 | request.Request( |
| 1203 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1204 | SocketTag(), |
| 1205 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1206 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1207 | |
| 1208 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1209 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1210 | EXPECT_TRUE(stream.get()); |
| 1211 | |
| 1212 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1213 | EXPECT_EQ(400000u, session->connection()->GetStats().srtt_us); |
| 1214 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1215 | EXPECT_EQ(400000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1216 | } |
| 1217 | |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1218 | TEST_P(QuicStreamFactoryTest, GoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1219 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1220 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1221 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1222 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1223 | MockQuicData socket_data; |
| 1224 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1225 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1226 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1227 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1228 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1229 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1230 | request.Request( |
| 1231 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1232 | SocketTag(), |
| 1233 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1234 | failed_on_default_network_callback_, callback_.callback())); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1235 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1236 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1237 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1238 | EXPECT_TRUE(stream.get()); |
| 1239 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1240 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1241 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1242 | session->OnGoAway(quic::QuicGoAwayFrame()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1243 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1244 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1245 | |
| 1246 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1247 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1248 | } |
| 1249 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1250 | TEST_P(QuicStreamFactoryTest, GoAwayForConnectionMigrationWithPortOnly) { |
| 1251 | Initialize(); |
| 1252 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1253 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1254 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1255 | MockQuicData socket_data; |
| 1256 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1257 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1258 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1259 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1260 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1261 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1262 | request.Request( |
| 1263 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1264 | SocketTag(), |
| 1265 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1266 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1267 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1268 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1269 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1270 | EXPECT_TRUE(stream.get()); |
| 1271 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1272 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1273 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1274 | session->OnGoAway(quic::QuicGoAwayFrame( |
| 1275 | quic::kInvalidControlFrameId, quic::QUIC_ERROR_MIGRATING_PORT, 0, |
| 1276 | "peer connection migration due to port change only")); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1277 | NetErrorDetails details; |
| 1278 | EXPECT_FALSE(details.quic_port_migration_detected); |
| 1279 | session->PopulateNetErrorDetails(&details); |
| 1280 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1281 | details.quic_port_migration_detected = false; |
| 1282 | stream->PopulateNetErrorDetails(&details); |
| 1283 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1284 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1285 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1286 | |
| 1287 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1288 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1289 | } |
| 1290 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1291 | TEST_P(QuicStreamFactoryTest, Pooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1292 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1293 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1294 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1295 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1296 | MockQuicData socket_data; |
| 1297 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1298 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1299 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1300 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1301 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1302 | host_resolver_->set_synchronous_mode(true); |
| 1303 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1304 | "192.168.0.1", ""); |
| 1305 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1306 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1307 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1308 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1309 | DEFAULT_PRIORITY, SocketTag(), |
| 1310 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1311 | &net_error_details_, |
| 1312 | failed_on_default_network_callback_, |
| 1313 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1314 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1315 | EXPECT_TRUE(stream.get()); |
| 1316 | |
| 1317 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1318 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1319 | EXPECT_EQ(OK, |
| 1320 | request2.Request( |
| 1321 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1322 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1323 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1324 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1325 | EXPECT_TRUE(stream2.get()); |
| 1326 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1327 | EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1328 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1329 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1330 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1331 | } |
| 1332 | |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1333 | TEST_P(QuicStreamFactoryTest, PoolingWithServerMigration) { |
| 1334 | // Set up session to migrate. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1335 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1336 | "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1337 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 443); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1338 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 1339 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1340 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1341 | |
| 1342 | VerifyServerMigration(config, alt_address); |
| 1343 | |
| 1344 | // Close server-migrated session. |
| 1345 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1346 | session->CloseSessionOnError(0u, quic::QUIC_NO_ERROR, |
| 1347 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1348 | |
| 1349 | // Set up server IP, socket, proof, and config for new session. |
| 1350 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1351 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1352 | |
| 1353 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1354 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 1355 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 1356 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 1357 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1358 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1359 | SequencedSocketData socket_data(reads, writes); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1360 | socket_factory_->AddSocketDataProvider(&socket_data); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1361 | |
| 1362 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1363 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1364 | quic::QuicConfig config2; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1365 | crypto_client_stream_factory_.SetConfig(config2); |
| 1366 | |
| 1367 | // Create new request to cause new session creation. |
| 1368 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1369 | QuicStreamRequest request2(factory_.get()); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1370 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1371 | request2.Request( |
| 1372 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1373 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1374 | failed_on_default_network_callback_, callback.callback())); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1375 | EXPECT_EQ(OK, callback.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1376 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1377 | EXPECT_TRUE(stream2.get()); |
| 1378 | |
| 1379 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1380 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1381 | // EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
| 1382 | } |
| 1383 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1384 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1385 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1386 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1387 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1388 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1389 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1390 | MockQuicData socket_data1; |
| 1391 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1392 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1393 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1394 | MockQuicData socket_data2; |
| 1395 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1396 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1397 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1398 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1399 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1400 | host_resolver_->set_synchronous_mode(true); |
| 1401 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1402 | "192.168.0.1", ""); |
| 1403 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1404 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1405 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1406 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1407 | DEFAULT_PRIORITY, SocketTag(), |
| 1408 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1409 | &net_error_details_, |
| 1410 | failed_on_default_network_callback_, |
| 1411 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1412 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1413 | EXPECT_TRUE(stream.get()); |
| 1414 | |
| 1415 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1416 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1417 | EXPECT_EQ(OK, |
| 1418 | request2.Request( |
| 1419 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1420 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1421 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1422 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1423 | EXPECT_TRUE(stream2.get()); |
| 1424 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1425 | factory_->OnSessionGoingAway(GetActiveSession(host_port_pair_)); |
| 1426 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1427 | EXPECT_FALSE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1428 | |
| 1429 | TestCompletionCallback callback3; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1430 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1431 | EXPECT_EQ(OK, |
| 1432 | request3.Request( |
| 1433 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1434 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1435 | failed_on_default_network_callback_, callback3.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1436 | std::unique_ptr<HttpStream> stream3 = CreateStream(&request3); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1437 | EXPECT_TRUE(stream3.get()); |
| 1438 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1439 | EXPECT_TRUE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1440 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1441 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1442 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1443 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1444 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1445 | } |
| 1446 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1447 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1448 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1449 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1450 | MockQuicData socket_data; |
| 1451 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1452 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1453 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1454 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1455 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1456 | HostPortPair server2(kServer2HostName, 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1457 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1458 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1459 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1460 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1461 | host_resolver_->set_synchronous_mode(true); |
| 1462 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1463 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1464 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1465 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1466 | EXPECT_EQ(OK, |
| 1467 | request.Request( |
| 1468 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1469 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1470 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1471 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1472 | EXPECT_TRUE(stream.get()); |
| 1473 | |
| 1474 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1475 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1476 | EXPECT_EQ(OK, |
| 1477 | request2.Request( |
| 1478 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1479 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1480 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1481 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1482 | EXPECT_TRUE(stream2.get()); |
| 1483 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1484 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1485 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1486 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1487 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1488 | } |
| 1489 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1490 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1491 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1492 | MockQuicData socket_data; |
| 1493 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1494 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1495 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1496 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1497 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1498 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 1499 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1500 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1501 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 1502 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1503 | EXPECT_TRUE(primary_pin.FromString( |
| 1504 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1505 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 1506 | verify_details.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1507 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1508 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1509 | host_resolver_->set_synchronous_mode(true); |
| 1510 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1511 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1512 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1513 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1514 | EXPECT_EQ(OK, |
| 1515 | request.Request( |
| 1516 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1517 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1518 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1519 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1520 | EXPECT_TRUE(stream.get()); |
| 1521 | |
| 1522 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1523 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1524 | EXPECT_EQ(OK, |
| 1525 | request2.Request( |
| 1526 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1527 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1528 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1529 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1530 | EXPECT_TRUE(stream2.get()); |
| 1531 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1532 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1533 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1534 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1535 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1539 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1540 | |
| 1541 | MockQuicData socket_data1; |
| 1542 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1543 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1544 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1545 | MockQuicData socket_data2; |
| 1546 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1547 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1548 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1549 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1550 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1551 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 1552 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1553 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1554 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1555 | ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 1556 | uint8_t bad_pin = 3; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1557 | verify_details1.cert_verify_result.public_key_hashes.push_back( |
| 1558 | test::GetTestHashValue(bad_pin)); |
| 1559 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 1560 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 1561 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1562 | EXPECT_TRUE(primary_pin.FromString( |
| 1563 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1564 | ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame^] | 1565 | verify_details2.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1566 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1567 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1568 | host_resolver_->set_synchronous_mode(true); |
| 1569 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1570 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1571 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1572 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1573 | EXPECT_EQ(OK, |
| 1574 | request.Request( |
| 1575 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1576 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1577 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1578 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1579 | EXPECT_TRUE(stream.get()); |
| 1580 | |
| 1581 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1582 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1583 | EXPECT_EQ(OK, |
| 1584 | request2.Request( |
| 1585 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1586 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1587 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1588 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1589 | EXPECT_TRUE(stream2.get()); |
| 1590 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1591 | EXPECT_NE(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1592 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1593 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1594 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1595 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1596 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1597 | } |
| 1598 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1599 | TEST_P(QuicStreamFactoryTest, Goaway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1600 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1601 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1602 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1603 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1604 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1605 | MockQuicData socket_data; |
| 1606 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1607 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1608 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1609 | MockQuicData socket_data2; |
| 1610 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1611 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1612 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1613 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1614 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1615 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1616 | request.Request( |
| 1617 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1618 | SocketTag(), |
| 1619 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1620 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1621 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1622 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1623 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1624 | EXPECT_TRUE(stream.get()); |
| 1625 | |
| 1626 | // Mark the session as going away. Ensure that while it is still alive |
| 1627 | // that it is no longer active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1628 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1629 | factory_->OnSessionGoingAway(session); |
| 1630 | EXPECT_EQ(true, |
| 1631 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1632 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1633 | |
| 1634 | // Create a new request for the same destination and verify that a |
| 1635 | // new session is created. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1636 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1637 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1638 | request2.Request( |
| 1639 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1640 | SocketTag(), |
| 1641 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1642 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1643 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1644 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1645 | EXPECT_TRUE(stream2.get()); |
| 1646 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1647 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1648 | EXPECT_NE(session, GetActiveSession(host_port_pair_)); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1649 | EXPECT_EQ(true, |
| 1650 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1651 | |
| 1652 | stream2.reset(); |
| 1653 | stream.reset(); |
| 1654 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1655 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1656 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1657 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1658 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1659 | } |
| 1660 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1661 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1662 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1663 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1664 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1665 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1666 | quic::QuicStreamId stream_id = GetNthClientInitiatedStreamId(0); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1667 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1668 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1669 | socket_data.AddWrite( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1670 | SYNCHRONOUS, client_maker_.MakeRstPacket(2, true, stream_id, |
| 1671 | quic::QUIC_STREAM_CANCELLED)); |
| 1672 | socket_data.AddRead(ASYNC, |
| 1673 | server_maker_.MakeRstPacket(1, false, stream_id, |
| 1674 | quic::QUIC_STREAM_CANCELLED)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1675 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1676 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1677 | |
| 1678 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1679 | request_info.traffic_annotation = |
| 1680 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1681 | |
xunjieli | 1d2b427 | 2017-04-25 22:37:17 | [diff] [blame] | 1682 | std::vector<std::unique_ptr<HttpStream>> streams; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1683 | // The MockCryptoClientStream sets max_open_streams to be |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1684 | // quic::kDefaultMaxStreamsPerConnection / 2. |
| 1685 | for (size_t i = 0; i < quic::kDefaultMaxStreamsPerConnection / 2; i++) { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1686 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1687 | int rv = request.Request( |
| 1688 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1689 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1690 | failed_on_default_network_callback_, callback_.callback()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1691 | if (i == 0) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1693 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1694 | } else { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1695 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1696 | } |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1697 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1698 | EXPECT_TRUE(stream); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1699 | EXPECT_EQ(OK, |
| 1700 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1701 | net_log_, CompletionOnceCallback())); |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 1702 | streams.push_back(std::move(stream)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1703 | } |
| 1704 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1705 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1706 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1707 | DEFAULT_PRIORITY, SocketTag(), |
| 1708 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1709 | &net_error_details_, |
| 1710 | failed_on_default_network_callback_, |
| 1711 | CompletionOnceCallback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1712 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1713 | EXPECT_TRUE(stream); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1714 | EXPECT_EQ(ERR_IO_PENDING, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1715 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
| 1716 | net_log_, callback_.callback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1717 | |
| 1718 | // Close the first stream. |
| 1719 | streams.front()->Close(false); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1720 | // Trigger exchange of RSTs that in turn allow progress for the last |
| 1721 | // stream. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1722 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1723 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1724 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1725 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1726 | |
| 1727 | // Force close of the connection to suppress the generation of RST |
| 1728 | // packets when streams are torn down, which wouldn't be relevant to |
| 1729 | // this test anyway. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1730 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1731 | session->connection()->CloseConnection( |
| 1732 | quic::QUIC_PUBLIC_RESET, "test", |
| 1733 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1734 | } |
| 1735 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1736 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1737 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1738 | MockQuicData socket_data; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1739 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1740 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1741 | host_resolver_->rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1742 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1743 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1744 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1745 | request.Request( |
| 1746 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1747 | SocketTag(), |
| 1748 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1749 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1750 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1751 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1752 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1753 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1754 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1755 | } |
| 1756 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1757 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1758 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1759 | |
| 1760 | MockQuicData socket_data; |
| 1761 | socket_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1762 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1763 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1764 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1765 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1766 | request.Request( |
| 1767 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1768 | SocketTag(), |
| 1769 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1770 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1771 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1772 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1773 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1774 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1775 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1776 | } |
| 1777 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1778 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1779 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1780 | MockQuicData socket_data; |
| 1781 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1782 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1783 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1784 | { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1785 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1786 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1787 | request.Request( |
| 1788 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1789 | SocketTag(), |
| 1790 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1791 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1792 | } |
| 1793 | |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 1794 | base::RunLoop().RunUntilIdle(); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1795 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1796 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 1797 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1798 | DEFAULT_PRIORITY, SocketTag(), |
| 1799 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1800 | &net_error_details_, |
| 1801 | failed_on_default_network_callback_, |
| 1802 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1803 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 1804 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1805 | EXPECT_TRUE(stream.get()); |
| 1806 | stream.reset(); |
| 1807 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1808 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1809 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1810 | } |
| 1811 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1812 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1813 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1814 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1815 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1816 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1817 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1818 | MockQuicData socket_data; |
| 1819 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1820 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1821 | socket_data.AddWrite( |
| 1822 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1823 | socket_data.AddWrite(SYNCHRONOUS, |
| 1824 | client_maker_.MakeConnectionClosePacket( |
| 1825 | 3, true, quic::QUIC_INTERNAL_ERROR, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1826 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1827 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1828 | MockQuicData socket_data2; |
| 1829 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1830 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1831 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1832 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1833 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1834 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1835 | request.Request( |
| 1836 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1837 | SocketTag(), |
| 1838 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1839 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1840 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1841 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1842 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1843 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1844 | request_info.traffic_annotation = |
| 1845 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1846 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1847 | net_log_, CompletionOnceCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1848 | |
| 1849 | // Close the session and verify that stream saw the error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1850 | factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, |
| 1851 | quic::QUIC_INTERNAL_ERROR); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1852 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1853 | stream->ReadResponseHeaders(callback_.callback())); |
| 1854 | |
| 1855 | // Now attempting to request a stream to the same origin should create |
| 1856 | // a new session. |
| 1857 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1858 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1859 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1860 | request2.Request( |
| 1861 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1862 | SocketTag(), |
| 1863 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1864 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1865 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1866 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1867 | stream = CreateStream(&request2); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1868 | stream.reset(); // Will reset stream 3. |
| 1869 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1870 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1871 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1872 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1873 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1874 | } |
| 1875 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1876 | // Regression test for crbug.com/700617. Test a write error during the |
| 1877 | // crypto handshake will not hang QuicStreamFactory::Job and should |
| 1878 | // report QUIC_HANDSHAKE_FAILED to upper layers. Subsequent |
| 1879 | // QuicStreamRequest should succeed without hanging. |
| 1880 | TEST_P(QuicStreamFactoryTest, |
| 1881 | WriteErrorInCryptoConnectWithAsyncHostResolution) { |
| 1882 | Initialize(); |
| 1883 | // Use unmocked crypto stream to do crypto connect. |
| 1884 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1885 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1886 | |
| 1887 | MockQuicData socket_data; |
| 1888 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1889 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1890 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1891 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1892 | |
| 1893 | // Create request, should fail after the write of the CHLO fails. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1894 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1895 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1896 | request.Request( |
| 1897 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1898 | SocketTag(), |
| 1899 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1900 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1901 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 1902 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1903 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1904 | |
| 1905 | // Verify new requests can be sent normally without hanging. |
| 1906 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1907 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1908 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1909 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1910 | MockQuicData socket_data2; |
| 1911 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1912 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1913 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1914 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1915 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1916 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1917 | request2.Request( |
| 1918 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1919 | SocketTag(), |
| 1920 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1921 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1922 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1923 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1924 | // Run the message loop to complete host resolution. |
| 1925 | base::RunLoop().RunUntilIdle(); |
| 1926 | |
| 1927 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 1928 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1929 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1930 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1931 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1932 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1933 | |
| 1934 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1935 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1936 | EXPECT_TRUE(stream.get()); |
| 1937 | stream.reset(); |
| 1938 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1939 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1940 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1941 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1942 | } |
| 1943 | |
| 1944 | TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { |
| 1945 | Initialize(); |
| 1946 | // Use unmocked crypto stream to do crypto connect. |
| 1947 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1948 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1949 | host_resolver_->set_synchronous_mode(true); |
| 1950 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1951 | "192.168.0.1", ""); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1952 | |
| 1953 | MockQuicData socket_data; |
| 1954 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1955 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1956 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1957 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1958 | |
| 1959 | // Create request, should fail immediately. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1960 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1961 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1962 | request.Request( |
| 1963 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1964 | SocketTag(), |
| 1965 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1966 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1967 | // Check no active session, or active jobs left for this server. |
| 1968 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1969 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1970 | |
| 1971 | // Verify new requests can be sent normally without hanging. |
| 1972 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1973 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1974 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1975 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1976 | MockQuicData socket_data2; |
| 1977 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1978 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1979 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1980 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1981 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1982 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1983 | request2.Request( |
| 1984 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1985 | SocketTag(), |
| 1986 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1987 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1988 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1989 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1990 | |
| 1991 | // Complete handshake. |
| 1992 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1993 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1994 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1995 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1996 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1997 | |
| 1998 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1999 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2000 | EXPECT_TRUE(stream.get()); |
| 2001 | stream.reset(); |
| 2002 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2003 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2004 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2005 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2006 | } |
| 2007 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2008 | TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 2009 | close_sessions_on_ip_change_ = true; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2010 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 2011 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2012 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2013 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2014 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2015 | MockQuicData socket_data; |
| 2016 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2017 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2018 | socket_data.AddWrite( |
| 2019 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2020 | socket_data.AddWrite( |
| 2021 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 2022 | 3, true, quic::QUIC_IP_ADDRESS_CHANGED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2023 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2024 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2025 | MockQuicData socket_data2; |
| 2026 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2027 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2028 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2029 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2030 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2031 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2032 | request.Request( |
| 2033 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2034 | SocketTag(), |
| 2035 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2036 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2037 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2038 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2039 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 2040 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2041 | request_info.traffic_annotation = |
| 2042 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2043 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2044 | net_log_, CompletionOnceCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2045 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2046 | // Check an active session exisits for the destination. |
| 2047 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2048 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2049 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2050 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2051 | IPAddress last_address; |
| 2052 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2053 | // Change the IP address and verify that stream saw the error and the active |
| 2054 | // session is closed. |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2055 | NotifyIPAddressChanged(); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2056 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 2057 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2058 | EXPECT_TRUE(factory_->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2059 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2060 | // Check no active session exists for the destination. |
| 2061 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2062 | |
| 2063 | // Now attempting to request a stream to the same origin should create |
| 2064 | // a new session. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2065 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2066 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2067 | request2.Request( |
| 2068 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2069 | SocketTag(), |
| 2070 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2071 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2072 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2073 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2074 | stream = CreateStream(&request2); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2075 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2076 | // Check a new active session exisits for the destination and the old session |
| 2077 | // is no longer live. |
| 2078 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2079 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2080 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2081 | |
| 2082 | stream.reset(); // Will reset stream 3. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2083 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2084 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2085 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2086 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2087 | } |
| 2088 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2089 | // Test that if goaway_session_on_ip_change is set, old sessions will be marked |
| 2090 | // as going away on IP address change instead of being closed. New requests will |
| 2091 | // go to a new connection. |
| 2092 | TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { |
| 2093 | goaway_sessions_on_ip_change_ = true; |
| 2094 | Initialize(); |
| 2095 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2096 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2097 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2098 | |
| 2099 | MockQuicData quic_data1; |
| 2100 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2101 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2102 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2103 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 2104 | 2, GetNthClientInitiatedStreamId(0), |
| 2105 | true, true, &header_stream_offset)); |
| 2106 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2107 | quic_data1.AddRead( |
| 2108 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 2109 | false, true)); |
| 2110 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2111 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2112 | |
| 2113 | MockQuicData quic_data2; |
| 2114 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 2115 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2116 | quic_data2.AddWrite( |
| 2117 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 2118 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2119 | |
| 2120 | // Create request and QuicHttpStream. |
| 2121 | QuicStreamRequest request(factory_.get()); |
| 2122 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2123 | request.Request( |
| 2124 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2125 | SocketTag(), |
| 2126 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2127 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2128 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2129 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2130 | EXPECT_TRUE(stream.get()); |
| 2131 | |
| 2132 | // Cause QUIC stream to be created. |
| 2133 | HttpRequestInfo request_info; |
| 2134 | request_info.method = "GET"; |
| 2135 | request_info.url = url_; |
| 2136 | request_info.traffic_annotation = |
| 2137 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2138 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2139 | net_log_, CompletionOnceCallback())); |
| 2140 | |
| 2141 | // Ensure that session is alive and active. |
| 2142 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2143 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2144 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2145 | |
| 2146 | // Send GET request on stream. |
| 2147 | HttpResponseInfo response; |
| 2148 | HttpRequestHeaders request_headers; |
| 2149 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2150 | callback_.callback())); |
| 2151 | |
| 2152 | // Receive an IP address change notification. |
| 2153 | NotifyIPAddressChanged(); |
| 2154 | |
| 2155 | // The connection should still be alive, but marked as going away. |
| 2156 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2157 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2158 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2159 | |
| 2160 | // Resume the data, response should be read from the original connection. |
| 2161 | quic_data1.Resume(); |
| 2162 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2163 | EXPECT_EQ(200, response.headers->response_code()); |
| 2164 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2165 | |
| 2166 | // Second request should be sent on a new connection. |
| 2167 | QuicStreamRequest request2(factory_.get()); |
| 2168 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2169 | request2.Request( |
| 2170 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2171 | SocketTag(), |
| 2172 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2173 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2174 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2175 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 2176 | EXPECT_TRUE(stream2.get()); |
| 2177 | |
| 2178 | // Check an active session exisits for the destination. |
| 2179 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2180 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2181 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2182 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2183 | |
| 2184 | stream.reset(); |
| 2185 | stream2.reset(); |
| 2186 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2187 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2188 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2189 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2190 | } |
| 2191 | |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2192 | TEST_P(QuicStreamFactoryTest, OnIPAddressChangedWithConnectionMigration) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 2193 | InitializeConnectionMigrationV2Test( |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2194 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2195 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2196 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2197 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2198 | |
| 2199 | MockQuicData socket_data; |
| 2200 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2201 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2202 | socket_data.AddWrite( |
| 2203 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2204 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2205 | |
| 2206 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2207 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2208 | request.Request( |
| 2209 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2210 | SocketTag(), |
| 2211 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2212 | failed_on_default_network_callback_, callback_.callback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2213 | |
| 2214 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2215 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2216 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2217 | request_info.traffic_annotation = |
| 2218 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2219 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2220 | net_log_, CompletionOnceCallback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2221 | |
| 2222 | IPAddress last_address; |
| 2223 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2224 | |
| 2225 | // Change the IP address and verify that the connection is unaffected. |
| 2226 | NotifyIPAddressChanged(); |
| 2227 | EXPECT_FALSE(factory_->require_confirmation()); |
| 2228 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2229 | |
| 2230 | // Attempting a new request to the same origin uses the same connection. |
| 2231 | QuicStreamRequest request2(factory_.get()); |
| 2232 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2233 | DEFAULT_PRIORITY, SocketTag(), |
| 2234 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2235 | &net_error_details_, |
| 2236 | failed_on_default_network_callback_, |
| 2237 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2238 | stream = CreateStream(&request2); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2239 | |
| 2240 | stream.reset(); |
| 2241 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2242 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2243 | } |
| 2244 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2245 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithSynchronousWrite) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 2246 | if (version_ == quic::QUIC_VERSION_99) |
| 2247 | return; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2248 | TestMigrationOnNetworkMadeDefault(SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2249 | } |
| 2250 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2251 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithAsyncWrite) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 2252 | if (version_ == quic::QUIC_VERSION_99) |
| 2253 | return; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2254 | TestMigrationOnNetworkMadeDefault(ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2255 | } |
| 2256 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2257 | // Sets up a test which attempts connection migration successfully after probing |
| 2258 | // when a new network is made as default and the old default is still available. |
| 2259 | // |write_mode| specifies the write mode for the last write before |
| 2260 | // OnNetworkMadeDefault is delivered to session. |
| 2261 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkMadeDefault( |
| 2262 | IoMode write_mode) { |
| 2263 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2264 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2265 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2266 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2267 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2268 | // Using a testing task runner so that we can control time. |
| 2269 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2270 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2271 | |
| 2272 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2273 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2274 | |
| 2275 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2276 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2277 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2278 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2279 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2280 | quic_data1.AddWrite( |
| 2281 | write_mode, ConstructGetRequestPacket(2, GetNthClientInitiatedStreamId(0), |
| 2282 | true, true, &header_stream_offset)); |
| 2283 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2284 | |
| 2285 | // Set up the second socket data provider that is used after migration. |
| 2286 | // The response to the earlier request is read on the new socket. |
| 2287 | MockQuicData quic_data2; |
| 2288 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2289 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2290 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2291 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2292 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2293 | quic_data2.AddRead(ASYNC, |
| 2294 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2295 | // Ping packet to send after migration is completed. |
| 2296 | quic_data2.AddWrite(ASYNC, |
| 2297 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2298 | quic_data2.AddRead( |
| 2299 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 2300 | false, false)); |
| 2301 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2302 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2303 | client_maker_.MakeAckAndRstPacket( |
| 2304 | 5, false, GetNthClientInitiatedStreamId(0), |
| 2305 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
| 2306 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2307 | |
| 2308 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2309 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2310 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2311 | request.Request( |
| 2312 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2313 | SocketTag(), |
| 2314 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2315 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2316 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2317 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2318 | EXPECT_TRUE(stream.get()); |
| 2319 | |
| 2320 | // Cause QUIC stream to be created. |
| 2321 | HttpRequestInfo request_info; |
| 2322 | request_info.method = "GET"; |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 2323 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2324 | request_info.traffic_annotation = |
| 2325 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2326 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2327 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2328 | |
| 2329 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2330 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2331 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2332 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2333 | |
| 2334 | // Send GET request on stream. |
| 2335 | HttpResponseInfo response; |
| 2336 | HttpRequestHeaders request_headers; |
| 2337 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2338 | callback_.callback())); |
| 2339 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2340 | // Deliver a signal that a alternate network is connected now, this should |
| 2341 | // cause the connection to start early migration on path degrading. |
| 2342 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2343 | ->SetConnectedNetworksList( |
| 2344 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2345 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2346 | ->NotifyNetworkConnected(kNewNetworkForTests); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2347 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2348 | // Cause the connection to report path degrading to the session. |
| 2349 | // Due to lack of alternate network, session will not mgirate connection. |
| 2350 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2351 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2352 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2353 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2354 | // A task will be posted to migrate to the new default network. |
| 2355 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2356 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2357 | |
| 2358 | // Execute the posted task to migrate back to the default network. |
| 2359 | task_runner->RunUntilIdle(); |
| 2360 | // Another task to try send a new connectivity probe is posted. And a task to |
| 2361 | // retry migrate back to default network is scheduled. |
| 2362 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2363 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2364 | // kDefaultRTTMilliSecs. |
| 2365 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2366 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2367 | next_task_delay); |
| 2368 | |
| 2369 | // The connection should still be alive, and not marked as going away. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2370 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2371 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2372 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2373 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2374 | |
| 2375 | // Resume quic data and a connectivity probe response will be read on the new |
| 2376 | // socket, declare probing as successful. And a new task to WriteToNewSocket |
| 2377 | // will be posted to complete migration. |
| 2378 | quic_data2.Resume(); |
| 2379 | |
| 2380 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2381 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2382 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2383 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2384 | // There should be three pending tasks, the nearest one will complete |
| 2385 | // migration to the new network. |
| 2386 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2387 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2388 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 2389 | task_runner->FastForwardBy(next_task_delay); |
| 2390 | |
| 2391 | // Response headers are received over the new network. |
| 2392 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2393 | EXPECT_EQ(200, response.headers->response_code()); |
| 2394 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2395 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 2396 | // probe and has been cancelled due to successful migration. |
| 2397 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2398 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2399 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2400 | next_task_delay); |
| 2401 | task_runner->FastForwardBy(next_task_delay); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2402 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2403 | // There's one more task to mgirate back to the default network in 0.4s, which |
| 2404 | // is also cancelled due to the success migration on the previous trial. |
| 2405 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2406 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2407 | base::TimeDelta expected_delay = |
| 2408 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2409 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2410 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2411 | task_runner->FastForwardBy(next_task_delay); |
| 2412 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2413 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2414 | // Verify that the session is still alive. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2415 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2416 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2417 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2418 | stream.reset(); |
| 2419 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2420 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2421 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2422 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2423 | } |
| 2424 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2425 | // Regression test for http://859674. |
| 2426 | // This test veries that a writer will not attempt to write packets until being |
| 2427 | // unblocked on both socket level and network level. In this test, a probing |
| 2428 | // writer is used to send two connectivity probes to the peer: where the first |
| 2429 | // one completes successfully, while a connectivity response is received before |
| 2430 | // completes sending the second one. The connection migration attempt will |
| 2431 | // proceed while the probing writer is blocked at the socket level, which will |
| 2432 | // block the writer on the network level. Once connection migration completes |
| 2433 | // successfully, the probing writer will be unblocked on the network level, it |
| 2434 | // will not attempt to write new packets until the socket level is unblocked. |
| 2435 | TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 2436 | if (version_ == quic::QUIC_VERSION_99) |
| 2437 | return; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2438 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 2439 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2440 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2441 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2442 | |
| 2443 | // Using a testing task runner so that we can control time. |
| 2444 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2445 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2446 | |
| 2447 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2448 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2449 | |
| 2450 | MockQuicData quic_data1; |
| 2451 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2452 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2453 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2454 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2455 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 2456 | 2, GetNthClientInitiatedStreamId(0), |
| 2457 | true, true, &header_stream_offset)); |
| 2458 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2459 | |
| 2460 | // Set up the second socket data provider that is used after migration. |
| 2461 | // The response to the earlier request is read on the new socket. |
| 2462 | MockQuicData quic_data2; |
| 2463 | // First connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2464 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2465 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2466 | quic_data2.AddRead(ASYNC, |
| 2467 | ERR_IO_PENDING); // Pause so that we can control time. |
| 2468 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2469 | quic_data2.AddRead(ASYNC, |
| 2470 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2471 | // Second connectivity probe which will complete asynchronously. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2472 | quic_data2.AddWrite(ASYNC, |
| 2473 | client_maker_.MakeConnectivityProbingPacket(4, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2474 | quic_data2.AddRead( |
| 2475 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 2476 | false, false)); |
| 2477 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2478 | quic_data2.AddWrite(ASYNC, |
| 2479 | client_maker_.MakeAckAndPingPacket(5, false, 1, 1, 1)); |
| 2480 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2481 | client_maker_.MakeAckAndRstPacket( |
| 2482 | 6, false, GetNthClientInitiatedStreamId(0), |
| 2483 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
| 2484 | |
| 2485 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2486 | |
| 2487 | // Create request and QuicHttpStream. |
| 2488 | QuicStreamRequest request(factory_.get()); |
| 2489 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2490 | request.Request( |
| 2491 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2492 | SocketTag(), |
| 2493 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2494 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2495 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2496 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2497 | EXPECT_TRUE(stream.get()); |
| 2498 | |
| 2499 | // Cause QUIC stream to be created. |
| 2500 | HttpRequestInfo request_info; |
| 2501 | request_info.method = "GET"; |
| 2502 | request_info.url = url_; |
| 2503 | request_info.traffic_annotation = |
| 2504 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2505 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2506 | net_log_, CompletionOnceCallback())); |
| 2507 | |
| 2508 | // Ensure that session is alive and active. |
| 2509 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2510 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2511 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2512 | |
| 2513 | // Send GET request on stream. |
| 2514 | HttpResponseInfo response; |
| 2515 | HttpRequestHeaders request_headers; |
| 2516 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2517 | callback_.callback())); |
| 2518 | |
| 2519 | // Deliver a signal that a alternate network is connected now, this should |
| 2520 | // cause the connection to start early migration on path degrading. |
| 2521 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2522 | ->SetConnectedNetworksList( |
| 2523 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2524 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2525 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 2526 | |
| 2527 | // Cause the connection to report path degrading to the session. |
| 2528 | // Due to lack of alternate network, session will not mgirate connection. |
| 2529 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2530 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2531 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2532 | |
| 2533 | // A task will be posted to migrate to the new default network. |
| 2534 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2535 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2536 | |
| 2537 | // Execute the posted task to migrate back to the default network. |
| 2538 | task_runner->RunUntilIdle(); |
| 2539 | // Another task to resend a new connectivity probe is posted. And a task to |
| 2540 | // retry migrate back to default network is scheduled. |
| 2541 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2542 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2543 | // kDefaultRTTMilliSecs. |
| 2544 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2545 | base::TimeDelta expected_delay = |
| 2546 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2547 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2548 | |
| 2549 | // Fast forward to send the second connectivity probe. The write will be |
| 2550 | // asynchronous and complete after the read completes. |
| 2551 | task_runner->FastForwardBy(next_task_delay); |
| 2552 | |
| 2553 | // Resume quic data and a connectivity probe response will be read on the new |
| 2554 | // socket, declare probing as successful. |
| 2555 | quic_data2.Resume(); |
| 2556 | |
| 2557 | // The connection should still be alive, and not marked as going away. |
| 2558 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2559 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2560 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2561 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2562 | |
| 2563 | // There should be three pending tasks, the nearest one will complete |
| 2564 | // migration to the new network. Second task will retry migrate back to |
| 2565 | // default but cancelled, and the third task will retry send connectivity |
| 2566 | // probe but also cancelled. |
| 2567 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2568 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2569 | task_runner->RunUntilIdle(); |
| 2570 | |
| 2571 | // Response headers are received over the new network. |
| 2572 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2573 | EXPECT_EQ(200, response.headers->response_code()); |
| 2574 | |
| 2575 | // Run the message loop to complete the asynchronous write of ack and ping. |
| 2576 | base::RunLoop().RunUntilIdle(); |
| 2577 | |
| 2578 | // Now there are two pending tasks, the nearest one was to retry migrate back |
| 2579 | // to default network and has been cancelled due to successful migration. |
| 2580 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2581 | expected_delay = |
| 2582 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2583 | expected_delay; |
| 2584 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2585 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2586 | task_runner->FastForwardBy(next_task_delay); |
| 2587 | |
| 2588 | // There's one more task to retry sending connectivity probe in 0.4s and has |
| 2589 | // also been cancelled due to the successful probing. |
| 2590 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2591 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2592 | expected_delay = |
| 2593 | base::TimeDelta::FromMilliseconds(3 * 2 * kDefaultRTTMilliSecs) - |
| 2594 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 2595 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2596 | task_runner->FastForwardBy(next_task_delay); |
| 2597 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2598 | |
| 2599 | // Verify that the session is still alive. |
| 2600 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2601 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2602 | |
| 2603 | stream.reset(); |
| 2604 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2605 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2606 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2607 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2608 | } |
| 2609 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2610 | // This test verifies that session times out connection migration attempt |
| 2611 | // with signals delivered in the following order (no alternate network is |
| 2612 | // available): |
| 2613 | // - default network disconnected is delivered: session attempts connection |
| 2614 | // migration but found not alternate network. Session waits for a new network |
| 2615 | // comes up in the next kWaitTimeForNewNetworkSecs seonds. |
| 2616 | // - no new network is connected, migration times out. Session is closed. |
| 2617 | TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 2618 | if (version_ == quic::QUIC_VERSION_99) |
| 2619 | return; |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2620 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2621 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2622 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2623 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2624 | // Using a testing task runner so that we can control time. |
| 2625 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2626 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2627 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2628 | MockQuicData socket_data; |
| 2629 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2630 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2631 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2632 | |
| 2633 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2634 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2635 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2636 | request.Request( |
| 2637 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2638 | SocketTag(), |
| 2639 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2640 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2641 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2642 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2643 | EXPECT_TRUE(stream.get()); |
| 2644 | |
| 2645 | // Cause QUIC stream to be created. |
| 2646 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2647 | request_info.traffic_annotation = |
| 2648 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2649 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2650 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2651 | |
| 2652 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2653 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2654 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2655 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2656 | |
| 2657 | // Trigger connection migration. Since there are no networks |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2658 | // to migrate to, this should cause the session to wait for a new network. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2659 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2660 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2661 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2662 | // The migration will not fail until the migration alarm timeout. |
| 2663 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2664 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2665 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2666 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2667 | EXPECT_EQ(true, session->connection()->writer()->IsWriteBlocked()); |
| 2668 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2669 | // Migration will be timed out after kWaitTimeForNewNetwokSecs. |
| 2670 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2671 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2672 | EXPECT_EQ(base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs), |
| 2673 | next_task_delay); |
| 2674 | task_runner->FastForwardBy(next_task_delay); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2675 | |
| 2676 | // The connection should now be closed. A request for response |
| 2677 | // headers should fail. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2678 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2679 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2680 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2681 | |
| 2682 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2683 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2684 | } |
| 2685 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2686 | // This test verifies that connectivity probes will be sent even if there is |
| 2687 | // a non-migratable stream. However, when connection migrates to the |
| 2688 | // successfully probed path, any non-migratable stream will be reset. And if |
| 2689 | // the connection becomes idle then, close the connection. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2690 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 2691 | if (version_ == quic::QUIC_VERSION_99) |
| 2692 | return; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2693 | InitializeConnectionMigrationV2Test( |
| 2694 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2695 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2696 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2697 | |
| 2698 | MockQuicData socket_data; |
| 2699 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2700 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2701 | socket_data.AddWrite( |
| 2702 | SYNCHRONOUS, |
| 2703 | client_maker_.MakeRstAckAndConnectionClosePacket( |
| 2704 | 3, false, 5, quic::QUIC_STREAM_CANCELLED, |
| 2705 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 2706 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
| 2707 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2708 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2709 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2710 | // Set up the second socket data provider that is used for probing. |
| 2711 | MockQuicData quic_data1; |
| 2712 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2713 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2714 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2715 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2716 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2717 | quic_data1.AddRead(ASYNC, |
| 2718 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2719 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2720 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2721 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2722 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2723 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2724 | request.Request( |
| 2725 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2726 | SocketTag(), |
| 2727 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2728 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2729 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2730 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2731 | EXPECT_TRUE(stream.get()); |
| 2732 | |
| 2733 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2734 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2735 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2736 | request_info.traffic_annotation = |
| 2737 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2738 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2739 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2740 | |
| 2741 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2742 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2743 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2744 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2745 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2746 | // Trigger connection migration. Session will start to probe the alternative |
| 2747 | // network. Although there is a non-migratable stream, session will still be |
| 2748 | // active until probing is declared as successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2749 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2750 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2751 | |
| 2752 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2753 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2754 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2755 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2756 | // Resume data to read a connectivity probing response, which will cause |
| 2757 | // non-migtable streams to be closed. As session becomes idle, connection will |
| 2758 | // be closed. |
| 2759 | quic_data1.Resume(); |
| 2760 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2761 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2762 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2763 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2764 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2765 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2766 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2767 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2768 | } |
| 2769 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2770 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2771 | InitializeConnectionMigrationV2Test( |
| 2772 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2773 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2774 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2775 | |
| 2776 | MockQuicData socket_data; |
| 2777 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2778 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2779 | socket_data.AddWrite( |
| 2780 | SYNCHRONOUS, |
| 2781 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2782 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2783 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2784 | |
| 2785 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2786 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2787 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2788 | request.Request( |
| 2789 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2790 | SocketTag(), |
| 2791 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2792 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2793 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2794 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2795 | EXPECT_TRUE(stream.get()); |
| 2796 | |
| 2797 | // Cause QUIC stream to be created. |
| 2798 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2799 | request_info.traffic_annotation = |
| 2800 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2801 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2802 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2803 | |
| 2804 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2805 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2806 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2807 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2808 | |
| 2809 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2810 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2811 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2812 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2813 | |
| 2814 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2815 | // this should cause session to continue but be marked as going away. |
| 2816 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2817 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2818 | |
| 2819 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2820 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2821 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2822 | |
| 2823 | stream.reset(); |
| 2824 | |
| 2825 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2826 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2827 | } |
| 2828 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2829 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2830 | InitializeConnectionMigrationV2Test( |
| 2831 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2832 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2833 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2834 | |
| 2835 | MockQuicData socket_data; |
| 2836 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2837 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2838 | socket_data.AddWrite( |
| 2839 | SYNCHRONOUS, |
| 2840 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 2841 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2842 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2843 | |
| 2844 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2845 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2846 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2847 | request.Request( |
| 2848 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2849 | SocketTag(), |
| 2850 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2851 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2852 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2853 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2854 | EXPECT_TRUE(stream.get()); |
| 2855 | |
| 2856 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2857 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2858 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2859 | request_info.traffic_annotation = |
| 2860 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2861 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2862 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2863 | |
| 2864 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2865 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2866 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2867 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2868 | |
| 2869 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2870 | // this should cause a RST_STREAM frame to be emitted with |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 2871 | // quic::QUIC_STREAM_CANCELLED error code, and the session will be closed. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2872 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2873 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2874 | |
| 2875 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2876 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2877 | |
| 2878 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2879 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2880 | } |
| 2881 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2882 | TEST_P(QuicStreamFactoryTest, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2883 | OnNetworkDisconnectedConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2884 | InitializeConnectionMigrationV2Test( |
| 2885 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2886 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2887 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2888 | |
| 2889 | MockQuicData socket_data; |
| 2890 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2891 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2892 | socket_data.AddWrite( |
| 2893 | SYNCHRONOUS, |
| 2894 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2895 | quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2896 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2897 | |
| 2898 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2899 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2900 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2901 | request.Request( |
| 2902 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2903 | SocketTag(), |
| 2904 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2905 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2906 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2907 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2908 | EXPECT_TRUE(stream.get()); |
| 2909 | |
| 2910 | // Cause QUIC stream to be created. |
| 2911 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2912 | request_info.traffic_annotation = |
| 2913 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2914 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2915 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2916 | |
| 2917 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2918 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2919 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2920 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2921 | |
| 2922 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2923 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2924 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2925 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2926 | |
| 2927 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2928 | // this should cause a RST_STREAM frame to be emitted with |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2929 | // quic::QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2930 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2931 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2932 | |
| 2933 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2934 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2935 | |
| 2936 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2937 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2938 | } |
| 2939 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2940 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2941 | InitializeConnectionMigrationV2Test( |
| 2942 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2943 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2944 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2945 | |
| 2946 | MockQuicData socket_data; |
| 2947 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2948 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2949 | socket_data.AddWrite( |
| 2950 | SYNCHRONOUS, |
| 2951 | client_maker_.MakeConnectionClosePacket( |
| 2952 | 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 2953 | "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2954 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2955 | |
| 2956 | // Create request and QuicHttpStream. |
| 2957 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2958 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2959 | request.Request( |
| 2960 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2961 | SocketTag(), |
| 2962 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2963 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2964 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2965 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2966 | EXPECT_TRUE(stream.get()); |
| 2967 | |
| 2968 | // Ensure that session is alive and active. |
| 2969 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2970 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2971 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2972 | |
| 2973 | // Trigger connection migration. |
| 2974 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2975 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2976 | |
| 2977 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2978 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2979 | |
| 2980 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2981 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2982 | } |
| 2983 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2984 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2985 | InitializeConnectionMigrationV2Test( |
| 2986 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2987 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2988 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2989 | |
| 2990 | MockQuicData socket_data; |
| 2991 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2992 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2993 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2994 | |
| 2995 | // Create request and QuicHttpStream. |
| 2996 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2997 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2998 | request.Request( |
| 2999 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3000 | SocketTag(), |
| 3001 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3002 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3003 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3004 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3005 | EXPECT_TRUE(stream.get()); |
| 3006 | |
| 3007 | // Ensure that session is alive and active. |
| 3008 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3009 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3010 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3011 | |
| 3012 | // Trigger connection migration. Since there are no active streams, |
| 3013 | // the session will be closed. |
| 3014 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3015 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3016 | |
| 3017 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3018 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3019 | |
| 3020 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3021 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3022 | } |
| 3023 | |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3024 | // This test verifies session migrates to the alternate network immediately when |
| 3025 | // default network disconnects with a synchronous write before migration. |
| 3026 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedSync) { |
| 3027 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ false); |
| 3028 | } |
| 3029 | |
| 3030 | // This test verifies session migrates to the alternate network immediately when |
| 3031 | // default network disconnects with an asynchronously write before migration. |
| 3032 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedAsync) { |
| 3033 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ true); |
| 3034 | } |
| 3035 | |
| 3036 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkDisconnected( |
| 3037 | bool async_write_before) { |
| 3038 | InitializeConnectionMigrationV2Test( |
| 3039 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3040 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3041 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 3042 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3043 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3044 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3045 | |
| 3046 | // Use the test task runner. |
| 3047 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3048 | |
| 3049 | int packet_number = 1; |
| 3050 | MockQuicData socket_data; |
| 3051 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3052 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3053 | socket_data.AddWrite( |
| 3054 | SYNCHRONOUS, |
| 3055 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 3056 | socket_data.AddWrite( |
| 3057 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3058 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3059 | true, &header_stream_offset)); |
| 3060 | if (async_write_before) { |
| 3061 | socket_data.AddWrite(ASYNC, OK); |
| 3062 | packet_number++; |
| 3063 | } |
| 3064 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3065 | |
| 3066 | // Create request and QuicHttpStream. |
| 3067 | QuicStreamRequest request(factory_.get()); |
| 3068 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3069 | request.Request( |
| 3070 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3071 | SocketTag(), |
| 3072 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3073 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3074 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3075 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3076 | EXPECT_TRUE(stream.get()); |
| 3077 | |
| 3078 | // Cause QUIC stream to be created. |
| 3079 | HttpRequestInfo request_info; |
| 3080 | request_info.method = "GET"; |
| 3081 | request_info.url = url_; |
| 3082 | request_info.traffic_annotation = |
| 3083 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3084 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3085 | net_log_, CompletionOnceCallback())); |
| 3086 | |
| 3087 | // Ensure that session is alive and active. |
| 3088 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3089 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3090 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3091 | |
| 3092 | // Send GET request on stream. |
| 3093 | HttpResponseInfo response; |
| 3094 | HttpRequestHeaders request_headers; |
| 3095 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3096 | callback_.callback())); |
| 3097 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3098 | if (async_write_before) |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3099 | session->SendPing(); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3100 | |
| 3101 | // Set up second socket data provider that is used after migration. |
| 3102 | // The response to the earlier request is read on this new socket. |
| 3103 | MockQuicData socket_data1; |
| 3104 | socket_data1.AddWrite( |
| 3105 | SYNCHRONOUS, |
| 3106 | client_maker_.MakePingPacket(packet_number++, /*include_version=*/true)); |
| 3107 | socket_data1.AddRead( |
| 3108 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3109 | false, false)); |
| 3110 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3111 | socket_data1.AddWrite( |
| 3112 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3113 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 3114 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 3115 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3116 | |
| 3117 | // Trigger connection migration. |
| 3118 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3119 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3120 | |
| 3121 | // The connection should still be alive, not marked as going away. |
| 3122 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3123 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3124 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3125 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3126 | |
| 3127 | // Ensure that the session is still alive. |
| 3128 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3129 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3130 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3131 | |
| 3132 | // Run the message loop so that data queued in the new socket is read by the |
| 3133 | // packet reader. |
| 3134 | runner_->RunNextTask(); |
| 3135 | |
| 3136 | // Response headers are received over the new network. |
| 3137 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3138 | EXPECT_EQ(200, response.headers->response_code()); |
| 3139 | |
| 3140 | // Check that the session is still alive. |
| 3141 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3142 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3143 | |
| 3144 | // There should be posted tasks not executed, which is to migrate back to |
| 3145 | // default network. |
| 3146 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3147 | |
| 3148 | // Receive signal to mark new network as default. |
| 3149 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3150 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3151 | |
| 3152 | stream.reset(); |
| 3153 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3154 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3155 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3156 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3157 | } |
| 3158 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3159 | // This test receives NCN signals in the following order: |
| 3160 | // - default network disconnected |
| 3161 | // - after a pause, new network is connected. |
| 3162 | // - new network is made default. |
| 3163 | TEST_P(QuicStreamFactoryTest, NewNetworkConnectedAfterNoNetwork) { |
| 3164 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 3165 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3166 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3167 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3168 | |
| 3169 | // Use the test task runner. |
| 3170 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3171 | |
| 3172 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3173 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3174 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3175 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3176 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 3177 | socket_data.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 3178 | 2, GetNthClientInitiatedStreamId(0), |
| 3179 | true, true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3180 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3181 | |
| 3182 | // Create request and QuicHttpStream. |
| 3183 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3184 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3185 | request.Request( |
| 3186 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3187 | SocketTag(), |
| 3188 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3189 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3190 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3191 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3192 | EXPECT_TRUE(stream.get()); |
| 3193 | |
| 3194 | // Cause QUIC stream to be created. |
| 3195 | HttpRequestInfo request_info; |
| 3196 | request_info.method = "GET"; |
| 3197 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 3198 | request_info.traffic_annotation = |
| 3199 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 3200 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 3201 | net_log_, CompletionOnceCallback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3202 | |
| 3203 | // Ensure that session is alive and active. |
| 3204 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3205 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3206 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3207 | |
| 3208 | // Send GET request on stream. |
| 3209 | HttpResponseInfo response; |
| 3210 | HttpRequestHeaders request_headers; |
| 3211 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3212 | callback_.callback())); |
| 3213 | |
| 3214 | // Trigger connection migration. Since there are no networks |
| 3215 | // to migrate to, this should cause the session to wait for a new network. |
| 3216 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3217 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3218 | |
| 3219 | // The connection should still be alive, not marked as going away. |
| 3220 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3221 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3222 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3223 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3224 | |
| 3225 | // Set up second socket data provider that is used after migration. |
| 3226 | // The response to the earlier request is read on this new socket. |
| 3227 | MockQuicData socket_data1; |
| 3228 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3229 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 3230 | socket_data1.AddRead( |
| 3231 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3232 | false, false)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3233 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3234 | socket_data1.AddWrite(SYNCHRONOUS, |
| 3235 | client_maker_.MakeAckAndRstPacket( |
| 3236 | 4, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3237 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3238 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3239 | |
| 3240 | // Add a new network and notify the stream factory of a new connected network. |
| 3241 | // This causes a PING packet to be sent over the new network. |
| 3242 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3243 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 3244 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3245 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 3246 | |
| 3247 | // Ensure that the session is still alive. |
| 3248 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3249 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3250 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3251 | |
| 3252 | // Run the message loop so that data queued in the new socket is read by the |
| 3253 | // packet reader. |
| 3254 | runner_->RunNextTask(); |
| 3255 | |
| 3256 | // Response headers are received over the new network. |
| 3257 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3258 | EXPECT_EQ(200, response.headers->response_code()); |
| 3259 | |
| 3260 | // Check that the session is still alive. |
| 3261 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3262 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3263 | |
| 3264 | // There should posted tasks not executed, which is to migrate back to default |
| 3265 | // network. |
| 3266 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3267 | |
| 3268 | // Receive signal to mark new network as default. |
| 3269 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3270 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3271 | |
| 3272 | stream.reset(); |
| 3273 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3274 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3275 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3276 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3277 | } |
| 3278 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3279 | // Regression test for http://crbug.com/872011. |
| 3280 | // This test verifies that migrate to the probing socket will not trigger |
| 3281 | // new packets being read synchronously and generate ACK frame while |
| 3282 | // processing the initial connectivity probe response, which may cause a |
| 3283 | // connection being closed with INTERNAL_ERROR as pending ACK frame is not |
| 3284 | // allowed when processing a new packet. |
| 3285 | TEST_P(QuicStreamFactoryTest, MigrateToProbingSocket) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 3286 | if (version_ == quic::QUIC_VERSION_99) |
| 3287 | return; |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3288 | InitializeConnectionMigrationV2Test( |
| 3289 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3290 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3291 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3292 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3293 | |
| 3294 | // Using a testing task runner so that we can control time. |
| 3295 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3296 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3297 | |
| 3298 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3299 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3300 | |
| 3301 | int packet_number = 1; |
| 3302 | MockQuicData quic_data1; |
| 3303 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3304 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 3305 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3306 | packet_number++, &header_stream_offset)); |
| 3307 | quic_data1.AddWrite( |
| 3308 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3309 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3310 | true, &header_stream_offset)); |
| 3311 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3312 | |
| 3313 | // Set up the second socket data provider that is used for probing on the |
| 3314 | // alternate network. |
| 3315 | MockQuicData quic_data2; |
| 3316 | // Connectivity probe to be sent on the new path. |
| 3317 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
| 3318 | packet_number++, true)); |
| 3319 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3320 | // First connectivity probe to receive from the server, which will complete |
| 3321 | // connection migraiton on path degrading. |
| 3322 | quic_data2.AddRead(ASYNC, |
| 3323 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3324 | // Read multiple connectivity probes synchronously. |
| 3325 | quic_data2.AddRead(SYNCHRONOUS, |
| 3326 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
| 3327 | quic_data2.AddRead(SYNCHRONOUS, |
| 3328 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
| 3329 | quic_data2.AddRead(SYNCHRONOUS, |
| 3330 | server_maker_.MakeConnectivityProbingPacket(4, false)); |
| 3331 | quic_data2.AddWrite( |
| 3332 | ASYNC, client_maker_.MakeAckPacket(packet_number++, 1, 4, 1, 1, true)); |
| 3333 | quic_data2.AddRead( |
| 3334 | ASYNC, ConstructOkResponsePacket(5, GetNthClientInitiatedStreamId(0), |
| 3335 | false, false)); |
| 3336 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3337 | quic_data2.AddWrite( |
| 3338 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3339 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 3340 | quic::QUIC_STREAM_CANCELLED, 5, 1, 1, true)); |
| 3341 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3342 | |
| 3343 | // Create request and QuicHttpStream. |
| 3344 | QuicStreamRequest request(factory_.get()); |
| 3345 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3346 | request.Request( |
| 3347 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3348 | SocketTag(), |
| 3349 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3350 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3351 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3352 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3353 | EXPECT_TRUE(stream.get()); |
| 3354 | |
| 3355 | // Cause QUIC stream to be created. |
| 3356 | HttpRequestInfo request_info; |
| 3357 | request_info.method = "GET"; |
| 3358 | request_info.url = url_; |
| 3359 | request_info.traffic_annotation = |
| 3360 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3361 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3362 | net_log_, CompletionOnceCallback())); |
| 3363 | |
| 3364 | // Ensure that session is alive and active. |
| 3365 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3366 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3367 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3368 | |
| 3369 | // Send GET request on stream. |
| 3370 | HttpResponseInfo response; |
| 3371 | HttpRequestHeaders request_headers; |
| 3372 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3373 | callback_.callback())); |
| 3374 | |
| 3375 | // Cause the connection to report path degrading to the session. |
| 3376 | // Session will start to probe the alternate network. |
| 3377 | session->connection()->OnPathDegradingTimeout(); |
| 3378 | |
| 3379 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3380 | // kDefaultRTTMilliSecs. |
| 3381 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3382 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3383 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3384 | next_task_delay); |
| 3385 | |
| 3386 | // The connection should still be alive, and not marked as going away. |
| 3387 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3388 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3389 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3390 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3391 | |
| 3392 | // Resume quic data and a connectivity probe response will be read on the new |
| 3393 | // socket. |
| 3394 | quic_data2.Resume(); |
| 3395 | |
| 3396 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3397 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3398 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3399 | |
| 3400 | // There should be three pending tasks, the nearest one will complete |
| 3401 | // migration to the new network. |
| 3402 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3403 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3404 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3405 | task_runner->FastForwardBy(next_task_delay); |
| 3406 | |
| 3407 | // Response headers are received over the new network. |
| 3408 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3409 | EXPECT_EQ(200, response.headers->response_code()); |
| 3410 | |
| 3411 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3412 | // probe and has been cancelled due to successful migration. |
| 3413 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3414 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3415 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3416 | next_task_delay); |
| 3417 | task_runner->FastForwardBy(next_task_delay); |
| 3418 | |
| 3419 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3420 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3421 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3422 | base::TimeDelta expected_delay = |
| 3423 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3424 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3425 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3426 | |
| 3427 | // Deliver a signal that the alternate network now becomes default to session, |
| 3428 | // this will cancel mgirate back to default network timer. |
| 3429 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3430 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3431 | |
| 3432 | task_runner->FastForwardBy(next_task_delay); |
| 3433 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3434 | |
| 3435 | // Verify that the session is still alive. |
| 3436 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3437 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3438 | |
| 3439 | stream.reset(); |
| 3440 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3441 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3442 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3443 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3444 | } |
| 3445 | |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3446 | // This test verifies that the connection migrates to the alternate network |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3447 | // early when path degrading is detected with an ASYNCHRONOUS write before |
| 3448 | // migration. |
| 3449 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingAysnc) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 3450 | if (version_ == quic::QUIC_VERSION_99) |
| 3451 | return; |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3452 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ true); |
| 3453 | } |
| 3454 | |
| 3455 | // This test verifies that the connection migrates to the alternate network |
| 3456 | // early when path degrading is detected with a SYNCHRONOUS write before |
| 3457 | // migration. |
| 3458 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingSync) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 3459 | if (version_ == quic::QUIC_VERSION_99) |
| 3460 | return; |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3461 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ false); |
| 3462 | } |
| 3463 | |
| 3464 | void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( |
| 3465 | bool async_write_before) { |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3466 | InitializeConnectionMigrationV2Test( |
| 3467 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3468 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3469 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3470 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3471 | |
| 3472 | // Using a testing task runner so that we can control time. |
| 3473 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3474 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3475 | |
| 3476 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3477 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3478 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3479 | int packet_number = 1; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3480 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3481 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3482 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3483 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3484 | packet_number++, &header_stream_offset)); |
| 3485 | quic_data1.AddWrite( |
| 3486 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3487 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3488 | true, &header_stream_offset)); |
| 3489 | if (async_write_before) { |
| 3490 | quic_data1.AddWrite(ASYNC, OK); |
| 3491 | packet_number++; |
| 3492 | } |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3493 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3494 | |
| 3495 | // Set up the second socket data provider that is used after migration. |
| 3496 | // The response to the earlier request is read on the new socket. |
| 3497 | MockQuicData quic_data2; |
| 3498 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3499 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3500 | packet_number++, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3501 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3502 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3503 | quic_data2.AddRead(ASYNC, |
| 3504 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3505 | // Ping packet to send after migration is completed. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3506 | quic_data2.AddWrite(ASYNC, client_maker_.MakeAckAndPingPacket( |
| 3507 | packet_number++, false, 1, 1, 1)); |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 3508 | quic_data2.AddRead( |
| 3509 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 3510 | false, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3511 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3512 | quic_data2.AddWrite( |
| 3513 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3514 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 3515 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3516 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3517 | |
| 3518 | // Create request and QuicHttpStream. |
| 3519 | QuicStreamRequest request(factory_.get()); |
| 3520 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3521 | request.Request( |
| 3522 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3523 | SocketTag(), |
| 3524 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3525 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3526 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3527 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3528 | EXPECT_TRUE(stream.get()); |
| 3529 | |
| 3530 | // Cause QUIC stream to be created. |
| 3531 | HttpRequestInfo request_info; |
| 3532 | request_info.method = "GET"; |
| 3533 | request_info.url = url_; |
| 3534 | request_info.traffic_annotation = |
| 3535 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3536 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3537 | net_log_, CompletionOnceCallback())); |
| 3538 | |
| 3539 | // Ensure that session is alive and active. |
| 3540 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3541 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3542 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3543 | |
| 3544 | // Send GET request on stream. |
| 3545 | HttpResponseInfo response; |
| 3546 | HttpRequestHeaders request_headers; |
| 3547 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3548 | callback_.callback())); |
| 3549 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3550 | if (async_write_before) |
| 3551 | session->SendPing(); |
| 3552 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 3553 | // Cause the connection to report path degrading to the session. |
| 3554 | // Session will start to probe the alternate network. |
| 3555 | session->connection()->OnPathDegradingTimeout(); |
| 3556 | |
| 3557 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3558 | // kDefaultRTTMilliSecs. |
| 3559 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3560 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3561 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3562 | next_task_delay); |
| 3563 | |
| 3564 | // The connection should still be alive, and not marked as going away. |
| 3565 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3566 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3567 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3568 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3569 | |
| 3570 | // Resume quic data and a connectivity probe response will be read on the new |
| 3571 | // socket. |
| 3572 | quic_data2.Resume(); |
| 3573 | |
| 3574 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3575 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3576 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3577 | |
| 3578 | // There should be three pending tasks, the nearest one will complete |
| 3579 | // migration to the new network. |
| 3580 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3581 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3582 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3583 | task_runner->FastForwardBy(next_task_delay); |
| 3584 | |
| 3585 | // Response headers are received over the new network. |
| 3586 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3587 | EXPECT_EQ(200, response.headers->response_code()); |
| 3588 | |
| 3589 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3590 | // probe and has been cancelled due to successful migration. |
| 3591 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3592 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3593 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3594 | next_task_delay); |
| 3595 | task_runner->FastForwardBy(next_task_delay); |
| 3596 | |
| 3597 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3598 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3599 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3600 | base::TimeDelta expected_delay = |
| 3601 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3602 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3603 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3604 | |
| 3605 | // Deliver a signal that the alternate network now becomes default to session, |
| 3606 | // this will cancel mgirate back to default network timer. |
| 3607 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3608 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3609 | |
| 3610 | task_runner->FastForwardBy(next_task_delay); |
| 3611 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3612 | |
| 3613 | // Verify that the session is still alive. |
| 3614 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3615 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3616 | |
| 3617 | stream.reset(); |
| 3618 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3619 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3620 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3621 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3622 | } |
| 3623 | |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3624 | // This test verifies that the session marks itself GOAWAY on path degrading |
| 3625 | // and it does not receive any new request |
| 3626 | TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { |
| 3627 | go_away_on_path_degrading_ = true; |
| 3628 | Initialize(); |
| 3629 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3630 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3631 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3632 | |
| 3633 | MockQuicData quic_data1; |
| 3634 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3635 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3636 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 3637 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 3638 | 2, GetNthClientInitiatedStreamId(0), |
| 3639 | true, true, &header_stream_offset)); |
| 3640 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3641 | quic_data1.AddRead( |
| 3642 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3643 | false, true)); |
| 3644 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3645 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3646 | |
| 3647 | MockQuicData quic_data2; |
| 3648 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 3649 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3650 | quic_data2.AddWrite( |
| 3651 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 3652 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3653 | |
| 3654 | // Creat request and QuicHttpStream. |
| 3655 | QuicStreamRequest request(factory_.get()); |
| 3656 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3657 | request.Request( |
| 3658 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3659 | SocketTag(), |
| 3660 | /*cerf_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3661 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3662 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3663 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3664 | EXPECT_TRUE(stream.get()); |
| 3665 | |
| 3666 | // Cause QUIC stream to be created. |
| 3667 | HttpRequestInfo request_info; |
| 3668 | request_info.method = "GET"; |
| 3669 | request_info.url = url_; |
| 3670 | request_info.traffic_annotation = |
| 3671 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3672 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3673 | net_log_, CompletionOnceCallback())); |
| 3674 | |
| 3675 | // Ensure that session is alive and active. |
| 3676 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3677 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3678 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3679 | |
| 3680 | // Send GET request on stream. |
| 3681 | HttpResponseInfo response; |
| 3682 | HttpRequestHeaders request_headers; |
| 3683 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3684 | callback_.callback())); |
| 3685 | |
| 3686 | // Trigger the connection to report path degrading to the session. |
| 3687 | // Session will mark itself GOAWAY. |
| 3688 | session->connection()->OnPathDegradingTimeout(); |
| 3689 | |
| 3690 | // The connection should still be alive, but marked as going away. |
| 3691 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3692 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3693 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3694 | |
| 3695 | // Second request should be sent on a new connection. |
| 3696 | QuicStreamRequest request2(factory_.get()); |
| 3697 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3698 | request2.Request( |
| 3699 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3700 | SocketTag(), |
| 3701 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3702 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3703 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3704 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 3705 | EXPECT_TRUE(stream2.get()); |
| 3706 | |
| 3707 | // Resume the data, verify old request can read response on the old session |
| 3708 | // successfully. |
| 3709 | quic_data1.Resume(); |
| 3710 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 3711 | EXPECT_EQ(200, response.headers->response_code()); |
| 3712 | EXPECT_EQ(0U, session->GetNumActiveStreams()); |
| 3713 | |
| 3714 | // Check an active session exists for the destination. |
| 3715 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3716 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3717 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 3718 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 3719 | EXPECT_NE(session, session2); |
| 3720 | |
| 3721 | stream.reset(); |
| 3722 | stream2.reset(); |
| 3723 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3724 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3725 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3726 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3727 | } |
| 3728 | |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3729 | // This test verifies that the connection will not migrate to a bad socket |
| 3730 | // when path degrading is detected. |
| 3731 | TEST_P(QuicStreamFactoryTest, DoNotMigrateToBadSocketOnPathDegrading) { |
| 3732 | InitializeConnectionMigrationV2Test( |
| 3733 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3734 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3735 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3736 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3737 | |
| 3738 | // Using a testing task runner so that we can control time. |
| 3739 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3740 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3741 | |
| 3742 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3743 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3744 | |
| 3745 | MockQuicData quic_data; |
| 3746 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3747 | quic_data.AddWrite(SYNCHRONOUS, |
| 3748 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 3749 | quic_data.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 3750 | 2, GetNthClientInitiatedStreamId(0), true, |
| 3751 | true, &header_stream_offset)); |
| 3752 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3753 | quic_data.AddRead( |
| 3754 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3755 | false, false)); |
| 3756 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3757 | quic_data.AddWrite(SYNCHRONOUS, |
| 3758 | client_maker_.MakeAckAndRstPacket( |
| 3759 | 3, false, GetNthClientInitiatedStreamId(0), |
| 3760 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 3761 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3762 | |
| 3763 | // Set up second socket that will immediately return disconnected. |
| 3764 | // The stream factory will abort probe the alternate network. |
| 3765 | MockConnect bad_connect = MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
| 3766 | SequencedSocketData socket_data(bad_connect, base::span<MockRead>(), |
| 3767 | base::span<MockWrite>()); |
| 3768 | socket_factory_->AddSocketDataProvider(&socket_data); |
| 3769 | |
| 3770 | // Create request and QuicHttpStream. |
| 3771 | QuicStreamRequest request(factory_.get()); |
| 3772 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3773 | request.Request( |
| 3774 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3775 | SocketTag(), |
| 3776 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3777 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3778 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3779 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3780 | EXPECT_TRUE(stream.get()); |
| 3781 | |
| 3782 | // Cause QUIC stream to be created. |
| 3783 | HttpRequestInfo request_info; |
| 3784 | request_info.method = "GET"; |
| 3785 | request_info.url = url_; |
| 3786 | request_info.traffic_annotation = |
| 3787 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3788 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3789 | net_log_, CompletionOnceCallback())); |
| 3790 | |
| 3791 | // Ensure that session is alive and active. |
| 3792 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3793 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3794 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3795 | |
| 3796 | // Send GET request on stream. |
| 3797 | HttpResponseInfo response; |
| 3798 | HttpRequestHeaders request_headers; |
| 3799 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3800 | callback_.callback())); |
| 3801 | |
| 3802 | // Cause the connection to report path degrading to the session. |
| 3803 | // Session will start to probe the alternate network. |
| 3804 | session->connection()->OnPathDegradingTimeout(); |
| 3805 | |
| 3806 | // The connection should still be alive, and not marked as going away. |
| 3807 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3808 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3809 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3810 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3811 | |
| 3812 | // Resume the data, and response header is received over the original network. |
| 3813 | quic_data.Resume(); |
| 3814 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3815 | EXPECT_EQ(200, response.headers->response_code()); |
| 3816 | |
| 3817 | // Verify there is no pending task as probing alternate network is halted. |
| 3818 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3819 | |
| 3820 | // Verify that the session is still alive. |
| 3821 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3822 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3823 | |
| 3824 | stream.reset(); |
| 3825 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 3826 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 3827 | } |
| 3828 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3829 | // Regression test for http://crbug.com/847569. |
| 3830 | // This test verifies that the connection migrates to the alternate network |
| 3831 | // early when there is no active stream but a draining stream. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3832 | // The first packet being written after migration is a synchrnous write, which |
| 3833 | // will cause a PING packet being sent. |
| 3834 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamSync) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 3835 | if (version_ == quic::QUIC_VERSION_99) |
| 3836 | return; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3837 | TestMigrateSessionWithDrainingStream(SYNCHRONOUS); |
| 3838 | } |
| 3839 | |
| 3840 | // Regression test for http://crbug.com/847569. |
| 3841 | // This test verifies that the connection migrates to the alternate network |
| 3842 | // early when there is no active stream but a draining stream. |
| 3843 | // The first packet being written after migration is an asynchronous write, no |
| 3844 | // PING packet will be sent. |
| 3845 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamAsync) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 3846 | if (version_ == quic::QUIC_VERSION_99) |
| 3847 | return; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3848 | TestMigrateSessionWithDrainingStream(ASYNC); |
| 3849 | } |
| 3850 | |
| 3851 | void QuicStreamFactoryTestBase::TestMigrateSessionWithDrainingStream( |
| 3852 | IoMode write_mode_for_queued_packet) { |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3853 | InitializeConnectionMigrationV2Test( |
| 3854 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3855 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3856 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3857 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3858 | |
| 3859 | // Using a testing task runner so that we can control time. |
| 3860 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3861 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3862 | |
| 3863 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3864 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3865 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3866 | int packet_number = 1; |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3867 | MockQuicData quic_data1; |
| 3868 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3869 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3870 | packet_number++, &header_stream_offset)); |
| 3871 | quic_data1.AddWrite( |
| 3872 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3873 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3874 | true, &header_stream_offset)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3875 | // Read an out of order packet with FIN to drain the stream. |
| 3876 | quic_data1.AddRead( |
| 3877 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 3878 | false, true)); // keep sending version. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3879 | quic_data1.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3880 | packet_number++, 2, 2, 2, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3881 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3882 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3883 | |
| 3884 | // Set up the second socket data provider that is used after migration. |
| 3885 | MockQuicData quic_data2; |
| 3886 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3887 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3888 | packet_number++, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3889 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3890 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3891 | quic_data2.AddRead(ASYNC, |
| 3892 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3893 | // Ping packet to send after migration is completed. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3894 | quic_data2.AddWrite( |
| 3895 | write_mode_for_queued_packet, |
| 3896 | client_maker_.MakeAckPacket(packet_number++, 2, 3, 3, 1, true)); |
| 3897 | if (write_mode_for_queued_packet == SYNCHRONOUS) { |
| 3898 | quic_data2.AddWrite(ASYNC, |
| 3899 | client_maker_.MakePingPacket(packet_number++, false)); |
| 3900 | } |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3901 | quic_data2.AddRead( |
| 3902 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3903 | false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3904 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3905 | packet_number++, 1, 3, 1, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3906 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3907 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3908 | |
| 3909 | // Create request and QuicHttpStream. |
| 3910 | QuicStreamRequest request(factory_.get()); |
| 3911 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3912 | request.Request( |
| 3913 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3914 | SocketTag(), |
| 3915 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3916 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3917 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3918 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3919 | EXPECT_TRUE(stream.get()); |
| 3920 | |
| 3921 | // Cause QUIC stream to be created. |
| 3922 | HttpRequestInfo request_info; |
| 3923 | request_info.method = "GET"; |
| 3924 | request_info.url = url_; |
| 3925 | request_info.traffic_annotation = |
| 3926 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3927 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3928 | net_log_, CompletionOnceCallback())); |
| 3929 | |
| 3930 | // Ensure that session is alive and active. |
| 3931 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3932 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3933 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3934 | |
| 3935 | // Send GET request on stream. |
| 3936 | HttpResponseInfo response; |
| 3937 | HttpRequestHeaders request_headers; |
| 3938 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3939 | callback_.callback())); |
| 3940 | |
| 3941 | // Run the message loop to receive the out of order packet which contains a |
| 3942 | // FIN and drains the stream. |
| 3943 | base::RunLoop().RunUntilIdle(); |
| 3944 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3945 | |
| 3946 | // Cause the connection to report path degrading to the session. |
| 3947 | // Session should still start to probe the alternate network. |
| 3948 | session->connection()->OnPathDegradingTimeout(); |
| 3949 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3950 | |
| 3951 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3952 | // kDefaultRTTMilliSecs. |
| 3953 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3954 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3955 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3956 | next_task_delay); |
| 3957 | |
| 3958 | // The connection should still be alive, and not marked as going away. |
| 3959 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3960 | |
| 3961 | // Resume quic data and a connectivity probe response will be read on the new |
| 3962 | // socket. |
| 3963 | quic_data2.Resume(); |
| 3964 | |
| 3965 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3966 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 3967 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3968 | EXPECT_EQ(1u, session->GetNumDrainingStreams()); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3969 | |
| 3970 | // There should be three pending tasks, the nearest one will complete |
| 3971 | // migration to the new network. |
| 3972 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3973 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3974 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3975 | task_runner->FastForwardBy(next_task_delay); |
| 3976 | |
| 3977 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3978 | // probe and has been cancelled due to successful migration. |
| 3979 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3980 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3981 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3982 | next_task_delay); |
| 3983 | task_runner->FastForwardBy(next_task_delay); |
| 3984 | |
| 3985 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3986 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3987 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3988 | base::TimeDelta expected_delay = |
| 3989 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3990 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3991 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3992 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3993 | base::RunLoop().RunUntilIdle(); |
| 3994 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3995 | // Deliver a signal that the alternate network now becomes default to session, |
| 3996 | // this will cancel mgirate back to default network timer. |
| 3997 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3998 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3999 | |
| 4000 | task_runner->FastForwardBy(next_task_delay); |
| 4001 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4002 | |
| 4003 | // Verify that the session is still alive. |
| 4004 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4005 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4006 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4007 | |
| 4008 | stream.reset(); |
| 4009 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4010 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4011 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4012 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4013 | } |
| 4014 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4015 | // Regression test for http://crbug.com/835444. |
| 4016 | // This test verifies that the connection migrates to the alternate network |
| 4017 | // when the alternate network is connected after path has been degrading. |
| 4018 | TEST_P(QuicStreamFactoryTest, MigrateOnNewNetworkConnectAfterPathDegrading) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 4019 | if (version_ == quic::QUIC_VERSION_99) |
| 4020 | return; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4021 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4022 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4023 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4024 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4025 | |
| 4026 | // Using a testing task runner so that we can control time. |
| 4027 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4028 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4029 | |
| 4030 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4031 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4032 | |
| 4033 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4034 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4035 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 4036 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4037 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4038 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4039 | 2, GetNthClientInitiatedStreamId(0), |
| 4040 | true, true, &header_stream_offset)); |
| 4041 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4042 | |
| 4043 | // Set up the second socket data provider that is used after migration. |
| 4044 | // The response to the earlier request is read on the new socket. |
| 4045 | MockQuicData quic_data2; |
| 4046 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4047 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4048 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4049 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4050 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4051 | quic_data2.AddRead(ASYNC, |
| 4052 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4053 | // Ping packet to send after migration is completed. |
| 4054 | quic_data2.AddWrite(ASYNC, |
| 4055 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4056 | quic_data2.AddRead( |
| 4057 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 4058 | false, false)); |
| 4059 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4060 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4061 | client_maker_.MakeAckAndRstPacket( |
| 4062 | 5, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4063 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4064 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4065 | |
| 4066 | // Create request and QuicHttpStream. |
| 4067 | QuicStreamRequest request(factory_.get()); |
| 4068 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4069 | request.Request( |
| 4070 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4071 | SocketTag(), |
| 4072 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4073 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4074 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4075 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4076 | EXPECT_TRUE(stream.get()); |
| 4077 | |
| 4078 | // Cause QUIC stream to be created. |
| 4079 | HttpRequestInfo request_info; |
| 4080 | request_info.method = "GET"; |
| 4081 | request_info.url = url_; |
| 4082 | request_info.traffic_annotation = |
| 4083 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4084 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4085 | net_log_, CompletionOnceCallback())); |
| 4086 | |
| 4087 | // Ensure that session is alive and active. |
| 4088 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4089 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4090 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4091 | |
| 4092 | // Send GET request on stream. |
| 4093 | HttpResponseInfo response; |
| 4094 | HttpRequestHeaders request_headers; |
| 4095 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4096 | callback_.callback())); |
| 4097 | |
| 4098 | // Cause the connection to report path degrading to the session. |
| 4099 | // Due to lack of alternate network, session will not mgirate connection. |
| 4100 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4101 | session->connection()->OnPathDegradingTimeout(); |
| 4102 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4103 | |
| 4104 | // Deliver a signal that a alternate network is connected now, this should |
| 4105 | // cause the connection to start early migration on path degrading. |
| 4106 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4107 | ->SetConnectedNetworksList( |
| 4108 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4109 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4110 | ->NotifyNetworkConnected(kNewNetworkForTests); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 4111 | |
| 4112 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4113 | // kDefaultRTTMilliSecs. |
| 4114 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4115 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4116 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4117 | next_task_delay); |
| 4118 | |
| 4119 | // The connection should still be alive, and not marked as going away. |
| 4120 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4121 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4122 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4123 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4124 | |
| 4125 | // Resume quic data and a connectivity probe response will be read on the new |
| 4126 | // socket. |
| 4127 | quic_data2.Resume(); |
| 4128 | |
| 4129 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4130 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4131 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4132 | |
| 4133 | // There should be three pending tasks, the nearest one will complete |
| 4134 | // migration to the new network. |
| 4135 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4136 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4137 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4138 | task_runner->FastForwardBy(next_task_delay); |
| 4139 | |
| 4140 | // Response headers are received over the new network. |
| 4141 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4142 | EXPECT_EQ(200, response.headers->response_code()); |
| 4143 | |
| 4144 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4145 | // probe and has been cancelled due to successful migration. |
| 4146 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4147 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4148 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4149 | next_task_delay); |
| 4150 | task_runner->FastForwardBy(next_task_delay); |
| 4151 | |
| 4152 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4153 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4154 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4155 | base::TimeDelta expected_delay = |
| 4156 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4157 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4158 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4159 | |
| 4160 | // Deliver a signal that the alternate network now becomes default to session, |
| 4161 | // this will cancel mgirate back to default network timer. |
| 4162 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4163 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4164 | |
| 4165 | task_runner->FastForwardBy(next_task_delay); |
| 4166 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4167 | |
| 4168 | // Verify that the session is still alive. |
| 4169 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4170 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4171 | |
| 4172 | stream.reset(); |
| 4173 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4174 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4175 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4176 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4177 | } |
| 4178 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4179 | // This test verifies that multiple sessions are migrated on connection |
| 4180 | // migration signal. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4181 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4182 | MigrateMultipleSessionsToBadSocketsAfterDisconnected) { |
| 4183 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4184 | |
| 4185 | MockQuicData socket_data1; |
| 4186 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4187 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4188 | socket_data1.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4189 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4190 | MockQuicData socket_data2; |
| 4191 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4192 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4193 | socket_data2.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4194 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4195 | |
| 4196 | HostPortPair server1(kDefaultServerHostName, 443); |
| 4197 | HostPortPair server2(kServer2HostName, 443); |
| 4198 | |
| 4199 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4200 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4201 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4202 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 4203 | host_resolver_->set_synchronous_mode(true); |
| 4204 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 4205 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.2", ""); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4206 | |
| 4207 | // Create request and QuicHttpStream to create session1. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4208 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4209 | EXPECT_EQ(OK, |
| 4210 | request1.Request( |
| 4211 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4212 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4213 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4214 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4215 | EXPECT_TRUE(stream1.get()); |
| 4216 | |
| 4217 | // Create request and QuicHttpStream to create session2. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4218 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4219 | EXPECT_EQ(OK, |
| 4220 | request2.Request( |
| 4221 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4222 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 4223 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4224 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4225 | EXPECT_TRUE(stream2.get()); |
| 4226 | |
| 4227 | QuicChromiumClientSession* session1 = GetActiveSession(server1); |
| 4228 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 4229 | EXPECT_NE(session1, session2); |
| 4230 | |
| 4231 | // Cause QUIC stream to be created and send GET so session1 has an open |
| 4232 | // stream. |
| 4233 | HttpRequestInfo request_info1; |
| 4234 | request_info1.method = "GET"; |
| 4235 | request_info1.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4236 | request_info1.traffic_annotation = |
| 4237 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4238 | EXPECT_EQ(OK, |
| 4239 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4240 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4241 | HttpResponseInfo response1; |
| 4242 | HttpRequestHeaders request_headers1; |
| 4243 | EXPECT_EQ(OK, stream1->SendRequest(request_headers1, &response1, |
| 4244 | callback_.callback())); |
| 4245 | |
| 4246 | // Cause QUIC stream to be created and send GET so session2 has an open |
| 4247 | // stream. |
| 4248 | HttpRequestInfo request_info2; |
| 4249 | request_info2.method = "GET"; |
| 4250 | request_info2.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4251 | request_info2.traffic_annotation = |
| 4252 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4253 | EXPECT_EQ(OK, |
| 4254 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4255 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4256 | HttpResponseInfo response2; |
| 4257 | HttpRequestHeaders request_headers2; |
| 4258 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4259 | callback_.callback())); |
| 4260 | |
| 4261 | // Cause both sessions to be paused due to DISCONNECTED. |
| 4262 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4263 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 4264 | |
| 4265 | // Ensure that both sessions are paused but alive. |
| 4266 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4267 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4268 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4269 | // Add new sockets to use post migration. Those are bad sockets and will cause |
| 4270 | // migration to fail. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4271 | MockConnect connect_result = |
| 4272 | MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4273 | SequencedSocketData socket_data3(connect_result, base::span<MockRead>(), |
| 4274 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4275 | socket_factory_->AddSocketDataProvider(&socket_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4276 | SequencedSocketData socket_data4(connect_result, base::span<MockRead>(), |
| 4277 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4278 | socket_factory_->AddSocketDataProvider(&socket_data4); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4279 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4280 | // Connect the new network and cause migration to bad sockets, causing |
| 4281 | // sessions to close. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4282 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4283 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 4284 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4285 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 4286 | |
| 4287 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4288 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4289 | |
| 4290 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4291 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4292 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 4293 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 4294 | } |
| 4295 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4296 | // This test verifies that session attempts connection migration with signals |
| 4297 | // delivered in the following order (no alternate network is available): |
| 4298 | // - path degrading is detected: session attempts connection migration but no |
| 4299 | // alternate network is available, session caches path degrading signal in |
| 4300 | // connection and stays on the original network. |
| 4301 | // - original network backs up, request is served in the orignal network, |
| 4302 | // session is not marked as going away. |
| 4303 | TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { |
| 4304 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4305 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4306 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4307 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4308 | MockQuicData quic_data; |
| 4309 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4310 | quic_data.AddWrite(SYNCHRONOUS, |
| 4311 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4312 | quic_data.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4313 | 2, GetNthClientInitiatedStreamId(0), true, |
| 4314 | true, &header_stream_offset)); |
| 4315 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause for path degrading signal. |
| 4316 | |
| 4317 | // The rest of the data will still flow in the original socket as there is no |
| 4318 | // new network after path degrading. |
| 4319 | quic_data.AddRead( |
| 4320 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 4321 | false, false)); |
| 4322 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4323 | quic_data.AddWrite(SYNCHRONOUS, |
| 4324 | client_maker_.MakeAckAndRstPacket( |
| 4325 | 3, false, GetNthClientInitiatedStreamId(0), |
| 4326 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4327 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4328 | |
| 4329 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4330 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4331 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4332 | request.Request( |
| 4333 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4334 | SocketTag(), |
| 4335 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4336 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4337 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4338 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4339 | EXPECT_TRUE(stream.get()); |
| 4340 | |
| 4341 | // Cause QUIC stream to be created. |
| 4342 | HttpRequestInfo request_info; |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4343 | request_info.method = "GET"; |
| 4344 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4345 | request_info.traffic_annotation = |
| 4346 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4347 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4348 | net_log_, CompletionOnceCallback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4349 | |
| 4350 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4351 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4352 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4353 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4354 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4355 | // Send GET request on stream. |
| 4356 | HttpResponseInfo response; |
| 4357 | HttpRequestHeaders request_headers; |
| 4358 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4359 | callback_.callback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4360 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4361 | // Trigger connection migration on path degrading. Since there are no networks |
| 4362 | // to migrate to, the session will remain on the original network, not marked |
| 4363 | // as going away. |
| 4364 | session->connection()->OnPathDegradingTimeout(); |
| 4365 | EXPECT_TRUE(session->connection()->IsPathDegrading()); |
| 4366 | |
| 4367 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4368 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4369 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4370 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4371 | |
| 4372 | // Resume so that rest of the data will flow in the original socket. |
| 4373 | quic_data.Resume(); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4374 | |
| 4375 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4376 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4377 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4378 | |
| 4379 | stream.reset(); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4380 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 4381 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4382 | } |
| 4383 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4384 | // This test verifies that session with non-migratable stream will probe the |
| 4385 | // alternate network on path degrading, and close the non-migratable streams |
| 4386 | // when probe is successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4387 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 4388 | if (version_ == quic::QUIC_VERSION_99) |
| 4389 | return; |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4390 | InitializeConnectionMigrationV2Test( |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4391 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4392 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4393 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4394 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4395 | MockQuicData socket_data; |
| 4396 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4397 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4398 | socket_data.AddWrite( |
| 4399 | SYNCHRONOUS, |
| 4400 | client_maker_.MakeRstAckAndConnectionClosePacket( |
| 4401 | 3, false, 5, quic::QUIC_STREAM_CANCELLED, |
| 4402 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 4403 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4404 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4405 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4406 | // Set up the second socket data provider that is used for probing. |
| 4407 | MockQuicData quic_data1; |
| 4408 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4409 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4410 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4411 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4412 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4413 | quic_data1.AddRead(ASYNC, |
| 4414 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4415 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4416 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4417 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4418 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4419 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4420 | request.Request( |
| 4421 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4422 | SocketTag(), |
| 4423 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4424 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4425 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4426 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4427 | EXPECT_TRUE(stream.get()); |
| 4428 | |
| 4429 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 4430 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 4431 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4432 | request_info.traffic_annotation = |
| 4433 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4434 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4435 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4436 | |
| 4437 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4438 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4439 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4440 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4441 | |
| 4442 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4443 | // this should cause session to be continue without migrating. |
| 4444 | session->OnPathDegrading(); |
| 4445 | |
| 4446 | // Run the message loop so that data queued in the new socket is read by the |
| 4447 | // packet reader. |
| 4448 | base::RunLoop().RunUntilIdle(); |
| 4449 | |
| 4450 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4451 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4452 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4453 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4454 | // Resume the data to read the connectivity probing response to declare probe |
| 4455 | // as successful. Non-migratable streams will be closed. |
| 4456 | quic_data1.Resume(); |
| 4457 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4458 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4459 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4460 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4461 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4462 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4463 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4464 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4465 | } |
| 4466 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4467 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyConnectionMigrationDisabled) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4468 | InitializeConnectionMigrationV2Test( |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4469 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4470 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4471 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4472 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4473 | MockQuicData socket_data; |
| 4474 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4475 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 4476 | socket_data.AddWrite( |
| 4477 | SYNCHRONOUS, |
| 4478 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4479 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4480 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4481 | |
| 4482 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4483 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4484 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4485 | request.Request( |
| 4486 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4487 | SocketTag(), |
| 4488 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4489 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4490 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4491 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4492 | EXPECT_TRUE(stream.get()); |
| 4493 | |
| 4494 | // Cause QUIC stream to be created. |
| 4495 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4496 | request_info.traffic_annotation = |
| 4497 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4498 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4499 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4500 | |
| 4501 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4502 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4503 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4504 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4505 | |
| 4506 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4507 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 4508 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4509 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 4510 | |
| 4511 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4512 | // this should cause session to be continue without migrating. |
| 4513 | session->OnPathDegrading(); |
| 4514 | |
| 4515 | // Run the message loop so that data queued in the new socket is read by the |
| 4516 | // packet reader. |
| 4517 | base::RunLoop().RunUntilIdle(); |
| 4518 | |
| 4519 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4520 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4521 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4522 | |
| 4523 | stream.reset(); |
| 4524 | |
| 4525 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4526 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4527 | } |
| 4528 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4529 | // Regression test for http://crbug.com/791886. |
| 4530 | // This test verifies that the old packet writer which encountered an |
| 4531 | // asynchronous write error will be blocked during migration on write error. New |
| 4532 | // packets would not be written until the one with write error is rewritten on |
| 4533 | // the new network. |
| 4534 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { |
| 4535 | InitializeConnectionMigrationV2Test( |
| 4536 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4537 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4538 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4539 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4540 | |
| 4541 | // Using a testing task runner so that we can control time. |
| 4542 | // base::RunLoop() controls mocked socket writes and reads. |
| 4543 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4544 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4545 | |
| 4546 | MockQuicData socket_data; |
| 4547 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4548 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4549 | socket_data.AddWrite( |
| 4550 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4551 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4552 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4553 | |
| 4554 | // Set up second socket data provider that is used after |
| 4555 | // migration. The request is rewritten to this new socket, and the |
| 4556 | // response to the request is read on this new socket. |
| 4557 | MockQuicData socket_data1; |
| 4558 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4559 | 2, GetNthClientInitiatedStreamId(0), |
| 4560 | true, true, &header_stream_offset)); |
| 4561 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4562 | 3, GetNthClientInitiatedStreamId(1), |
| 4563 | GetNthClientInitiatedStreamId(0), true, |
| 4564 | true, &header_stream_offset)); |
| 4565 | socket_data1.AddRead( |
| 4566 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 4567 | false, false)); |
| 4568 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4569 | socket_data1.AddWrite(SYNCHRONOUS, |
| 4570 | client_maker_.MakeAckAndRstPacket( |
| 4571 | 4, false, GetNthClientInitiatedStreamId(0), |
| 4572 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4573 | socket_data1.AddWrite( |
| 4574 | SYNCHRONOUS, |
| 4575 | client_maker_.MakeRstPacket(5, false, GetNthClientInitiatedStreamId(1), |
| 4576 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 4577 | |
| 4578 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4579 | |
| 4580 | // Create request #1 and QuicHttpStream. |
| 4581 | QuicStreamRequest request1(factory_.get()); |
| 4582 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4583 | request1.Request( |
| 4584 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4585 | SocketTag(), |
| 4586 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4587 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4588 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4589 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4590 | EXPECT_TRUE(stream1.get()); |
| 4591 | |
| 4592 | HttpRequestInfo request_info1; |
| 4593 | request_info1.method = "GET"; |
| 4594 | request_info1.url = GURL("https://www.example.org/"); |
| 4595 | request_info1.traffic_annotation = |
| 4596 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4597 | EXPECT_EQ(OK, |
| 4598 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4599 | net_log_, CompletionOnceCallback())); |
| 4600 | |
| 4601 | // Request #2 returns synchronously because it pools to existing session. |
| 4602 | TestCompletionCallback callback2; |
| 4603 | QuicStreamRequest request2(factory_.get()); |
| 4604 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 4605 | DEFAULT_PRIORITY, SocketTag(), |
| 4606 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4607 | &net_error_details_, |
| 4608 | failed_on_default_network_callback_, |
| 4609 | callback2.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4610 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 4611 | EXPECT_TRUE(stream2.get()); |
| 4612 | |
| 4613 | HttpRequestInfo request_info2; |
| 4614 | request_info2.method = "GET"; |
| 4615 | request_info2.url = GURL("https://www.example.org/"); |
| 4616 | request_info2.traffic_annotation = |
| 4617 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4618 | EXPECT_EQ(OK, |
| 4619 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 4620 | net_log_, CompletionOnceCallback())); |
| 4621 | |
| 4622 | // Ensure that session is alive and active. |
| 4623 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4624 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4625 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4626 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 4627 | |
| 4628 | // Send GET request on stream1. This should cause an async write error. |
| 4629 | HttpResponseInfo response; |
| 4630 | HttpRequestHeaders request_headers; |
| 4631 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4632 | callback_.callback())); |
| 4633 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4634 | |
| 4635 | // Run the message loop so that asynchronous write completes and a connection |
| 4636 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4637 | // runner. |
| 4638 | base::RunLoop().RunUntilIdle(); |
| 4639 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4640 | |
| 4641 | // Send GET request on stream. This will cause another write attempt before |
| 4642 | // migration on write error is exectued. |
| 4643 | HttpResponseInfo response2; |
| 4644 | HttpRequestHeaders request_headers2; |
| 4645 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4646 | callback2.callback())); |
| 4647 | |
| 4648 | // Run the task runner so that migration on write error is finally executed. |
| 4649 | task_runner->RunUntilIdle(); |
| 4650 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4651 | // Verify the session is still alive and not marked as going away. |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4652 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4653 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4654 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4655 | // There should be one task posted to migrate back to the default network in |
| 4656 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4657 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4658 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 4659 | task_runner->NextPendingTaskDelay()); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4660 | |
| 4661 | // Verify that response headers on the migrated socket were delivered to the |
| 4662 | // stream. |
| 4663 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4664 | EXPECT_EQ(200, response.headers->response_code()); |
| 4665 | |
| 4666 | stream1.reset(); |
| 4667 | stream2.reset(); |
| 4668 | |
| 4669 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4670 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4671 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4672 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4673 | } |
| 4674 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4675 | // Verify session is not marked as going away after connection migration on |
| 4676 | // write error and migrate back to default network logic is applied to bring the |
| 4677 | // migrated session back to the default network. Migration singals delivered |
| 4678 | // in the following order (alternate network is always availabe): |
| 4679 | // - session on the default network encountered a write error; |
| 4680 | // - session successfully migrated to the non-default network; |
| 4681 | // - session attempts to migrate back to default network post migration; |
| 4682 | // - migration back to the default network is successful. |
| 4683 | TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 4684 | if (version_ == quic::QUIC_VERSION_99) |
| 4685 | return; |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4686 | InitializeConnectionMigrationV2Test( |
| 4687 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4688 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4689 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4690 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4691 | |
| 4692 | // Using a testing task runner so that we can control time. |
| 4693 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4694 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4695 | |
| 4696 | MockQuicData socket_data; |
| 4697 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4698 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4699 | socket_data.AddWrite( |
| 4700 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4701 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4702 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4703 | |
| 4704 | // Set up second socket data provider that is used after |
| 4705 | // migration. The request is rewritten to this new socket, and the |
| 4706 | // response to the request is read on this new socket. |
| 4707 | MockQuicData quic_data2; |
| 4708 | quic_data2.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4709 | 2, GetNthClientInitiatedStreamId(0), |
| 4710 | true, true, &header_stream_offset)); |
| 4711 | quic_data2.AddRead( |
| 4712 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 4713 | false, false)); |
| 4714 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4715 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4716 | |
| 4717 | // Create request QuicHttpStream. |
| 4718 | QuicStreamRequest request1(factory_.get()); |
| 4719 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4720 | request1.Request( |
| 4721 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4722 | SocketTag(), |
| 4723 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4724 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4725 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4726 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4727 | EXPECT_TRUE(stream1.get()); |
| 4728 | |
| 4729 | HttpRequestInfo request_info1; |
| 4730 | request_info1.method = "GET"; |
| 4731 | request_info1.url = GURL("https://www.example.org/"); |
| 4732 | request_info1.traffic_annotation = |
| 4733 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4734 | EXPECT_EQ(OK, |
| 4735 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4736 | net_log_, CompletionOnceCallback())); |
| 4737 | |
| 4738 | // Ensure that session is alive and active. |
| 4739 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4740 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4741 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4742 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4743 | |
| 4744 | // Send GET request. This should cause an async write error. |
| 4745 | HttpResponseInfo response; |
| 4746 | HttpRequestHeaders request_headers; |
| 4747 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4748 | callback_.callback())); |
| 4749 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4750 | |
| 4751 | // Run the message loop so that asynchronous write completes and a connection |
| 4752 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4753 | // runner. |
| 4754 | base::RunLoop().RunUntilIdle(); |
| 4755 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4756 | |
| 4757 | // Run the task runner so that migration on write error is finally executed. |
| 4758 | task_runner->RunUntilIdle(); |
| 4759 | |
| 4760 | // Verify the session is still alive and not marked as going away. |
| 4761 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4762 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4763 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4764 | // There should be one task posted to migrate back to the default network in |
| 4765 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4766 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4767 | base::TimeDelta expected_delay = |
| 4768 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 4769 | EXPECT_EQ(expected_delay, task_runner->NextPendingTaskDelay()); |
| 4770 | |
| 4771 | // Verify that response headers on the migrated socket were delivered to the |
| 4772 | // stream. |
| 4773 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4774 | EXPECT_EQ(200, response.headers->response_code()); |
| 4775 | |
| 4776 | // Set up the third socket data provider for migrate back to default network. |
| 4777 | MockQuicData quic_data3; |
| 4778 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4779 | quic_data3.AddWrite(SYNCHRONOUS, |
| 4780 | client_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4781 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4782 | quic_data3.AddRead(ASYNC, |
| 4783 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4784 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4785 | quic_data3.AddWrite(ASYNC, client_maker_.MakeAckPacket(4, 1, 2, 1, 1, true)); |
| 4786 | quic_data3.AddWrite( |
| 4787 | SYNCHRONOUS, |
| 4788 | client_maker_.MakeRstPacket(5, false, GetNthClientInitiatedStreamId(0), |
| 4789 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 4790 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 4791 | |
| 4792 | // Fast forward to fire the migrate back timer and verify the session |
| 4793 | // successfully migrates back to the default network. |
| 4794 | task_runner->FastForwardBy(expected_delay); |
| 4795 | |
| 4796 | // Verify the session is still alive and not marked as going away. |
| 4797 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4798 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4799 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4800 | |
| 4801 | // There should be one task posted to one will resend a connectivity probe and |
| 4802 | // the other will retry migrate back, both are cancelled. |
| 4803 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4804 | task_runner->FastForwardBy( |
| 4805 | base::TimeDelta::FromSeconds(2 * kMinRetryTimeForDefaultNetworkSecs)); |
| 4806 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4807 | |
| 4808 | stream1.reset(); |
| 4809 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4810 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4811 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4812 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4813 | EXPECT_TRUE(quic_data3.AllReadDataConsumed()); |
| 4814 | EXPECT_TRUE(quic_data3.AllWriteDataConsumed()); |
| 4815 | } |
| 4816 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4817 | // This test verifies that the connection will not attempt connection migration |
| 4818 | // (send connectivity probes on alternate path) when path degrading is detected |
| 4819 | // and handshake is not confirmed. |
| 4820 | TEST_P(QuicStreamFactoryTest, |
| 4821 | NoMigrationOnPathDegradingBeforeHandshakeConfirmed) { |
| 4822 | InitializeConnectionMigrationV2Test( |
| 4823 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4824 | |
| 4825 | // Using a testing task runner. |
| 4826 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4827 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4828 | |
| 4829 | // Use cold start mode to send crypto message for handshake. |
| 4830 | crypto_client_stream_factory_.set_handshake_mode( |
| 4831 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4832 | |
| 4833 | MockQuicData socket_data; |
| 4834 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4835 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4836 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4837 | |
| 4838 | // Create request and QuicHttpStream. |
| 4839 | QuicStreamRequest request(factory_.get()); |
| 4840 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4841 | request.Request( |
| 4842 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4843 | SocketTag(), |
| 4844 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4845 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4846 | |
| 4847 | base::RunLoop().RunUntilIdle(); |
| 4848 | |
| 4849 | // Ensure that session is alive but not active. |
| 4850 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4851 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4852 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4853 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4854 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4855 | |
| 4856 | // Cause the connection to report path degrading to the session. |
| 4857 | // Session will ignore the signal as handshake is not completed. |
| 4858 | session->connection()->OnPathDegradingTimeout(); |
| 4859 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4860 | |
| 4861 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4862 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4863 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4864 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4865 | } |
| 4866 | |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4867 | // This test verifies that if a connection is closed with |
| 4868 | // QUIC_NETWORK_IDLE_TIMEOUT before handshake is completed and there is no |
| 4869 | // alternate network, no new connection will be created. |
| 4870 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkBeforeHandshakeOnIdleTimeout) { |
| 4871 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4872 | } |
| 4873 | |
| 4874 | // This test verifies that if a connection is closed with QUIC_HANDSHAKE_TIMEOUT |
| 4875 | // and there is no alternate network, no new connection will be created. |
| 4876 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkOnHandshakeTimeout) { |
| 4877 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4878 | } |
| 4879 | |
| 4880 | void QuicStreamFactoryTestBase::TestNoAlternateNetworkBeforeHandshake( |
| 4881 | quic::QuicErrorCode quic_error) { |
| 4882 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4883 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4884 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4885 | |
| 4886 | // Using a testing task runner. |
| 4887 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4888 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4889 | |
| 4890 | // Use cold start mode to send crypto message for handshake. |
| 4891 | crypto_client_stream_factory_.set_handshake_mode( |
| 4892 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4893 | |
| 4894 | MockQuicData socket_data; |
| 4895 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4896 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4897 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4898 | |
| 4899 | // Create request. |
| 4900 | QuicStreamRequest request(factory_.get()); |
| 4901 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4902 | request.Request( |
| 4903 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4904 | SocketTag(), |
| 4905 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4906 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4907 | |
| 4908 | base::RunLoop().RunUntilIdle(); |
| 4909 | |
| 4910 | // Ensure that session is alive but not active. |
| 4911 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4912 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4913 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4914 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4915 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4916 | |
| 4917 | // Cause the connection to report path degrading to the session. |
| 4918 | // Session will ignore the signal as handshake is not completed. |
| 4919 | session->connection()->OnPathDegradingTimeout(); |
| 4920 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4921 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4922 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4923 | |
| 4924 | // Cause the connection to close due to |quic_error| before handshake. |
| 4925 | quic::QuicString error_details; |
| 4926 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 4927 | error_details = "No recent network activity."; |
| 4928 | } else { |
| 4929 | error_details = "Handshake timeout expired."; |
| 4930 | } |
| 4931 | session->connection()->CloseConnection( |
| 4932 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 4933 | |
| 4934 | // A task will be posted to clean up the session in the factory. |
| 4935 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4936 | task_runner->FastForwardUntilNoTasksRemain(); |
| 4937 | |
| 4938 | // No new session should be created as there is no alternate network. |
| 4939 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4940 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4941 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4942 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4943 | } |
| 4944 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4945 | TEST_P(QuicStreamFactoryTest, NewConnectionBeforeHandshakeAfterIdleTimeout) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 4946 | if (version_ == quic::QUIC_VERSION_99) |
| 4947 | return; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4948 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4949 | quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4950 | } |
| 4951 | |
| 4952 | TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame] | 4953 | if (version_ == quic::QUIC_VERSION_99) |
| 4954 | return; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4955 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4956 | quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4957 | } |
| 4958 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 4959 | // Sets up a test to verify that a new connection will be created on the |
| 4960 | // alternate network after the initial connection fails before handshake with |
| 4961 | // signals delivered in the following order (alternate network is available): |
| 4962 | // - the default network is not able to complete crypto handshake; |
| 4963 | // - the original connection is closed with |quic_error|; |
| 4964 | // - a new connection is created on the alternate network and is able to finish |
| 4965 | // crypto handshake; |
| 4966 | // - the new session on the alternate network attempts to migrate back to the |
| 4967 | // default network by sending probes; |
| 4968 | // - default network being disconnected is delivered: session will stop probing |
| 4969 | // the original network. |
| 4970 | // - alternate network is made by default. |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4971 | void QuicStreamFactoryTestBase:: |
| 4972 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4973 | quic::QuicErrorCode quic_error) { |
| 4974 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4975 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4976 | InitializeConnectionMigrationV2Test( |
| 4977 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4978 | |
| 4979 | // Using a testing task runner. |
| 4980 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4981 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4982 | |
| 4983 | // Use cold start mode to send crypto message for handshake. |
| 4984 | crypto_client_stream_factory_.set_handshake_mode( |
| 4985 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4986 | |
| 4987 | // Socket data for connection on the default network. |
| 4988 | MockQuicData socket_data; |
| 4989 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4990 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4991 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4992 | |
| 4993 | // Socket data for connection on the alternate network. |
| 4994 | MockQuicData socket_data2; |
| 4995 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4996 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 4997 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 4998 | // Change the encryption level after handshake is confirmed. |
| 4999 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5000 | socket_data2.AddWrite( |
| 5001 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5002 | socket_data2.AddWrite( |
| 5003 | ASYNC, ConstructGetRequestPacket(3, GetNthClientInitiatedStreamId(0), |
| 5004 | true, true, &header_stream_offset)); |
| 5005 | socket_data2.AddRead( |
| 5006 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5007 | false, false)); |
| 5008 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5009 | socket_data2.AddWrite(SYNCHRONOUS, |
| 5010 | client_maker_.MakeAckAndRstPacket( |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5011 | 5, false, GetNthClientInitiatedStreamId(0), |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5012 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5013 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5014 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5015 | // Socket data for probing on the default network. |
| 5016 | MockQuicData probing_data; |
| 5017 | probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5018 | probing_data.AddWrite(SYNCHRONOUS, |
| 5019 | client_maker_.MakeConnectivityProbingPacket(4, false)); |
| 5020 | probing_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5021 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5022 | // Create request and QuicHttpStream. |
| 5023 | QuicStreamRequest request(factory_.get()); |
| 5024 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5025 | request.Request( |
| 5026 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5027 | SocketTag(), |
| 5028 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5029 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5030 | |
| 5031 | base::RunLoop().RunUntilIdle(); |
| 5032 | |
| 5033 | // Ensure that session is alive but not active. |
| 5034 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5035 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5036 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5037 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5038 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5039 | EXPECT_FALSE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5040 | |
| 5041 | quic::QuicString error_details; |
| 5042 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5043 | error_details = "No recent network activity."; |
| 5044 | } else { |
| 5045 | error_details = "Handshake timeout expired."; |
| 5046 | } |
| 5047 | session->connection()->CloseConnection( |
| 5048 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5049 | |
| 5050 | // A task will be posted to clean up the session in the factory. |
| 5051 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5052 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5053 | |
| 5054 | // Verify a new session is created on the alternate network. |
| 5055 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5056 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5057 | QuicChromiumClientSession* session2 = GetPendingSession(host_port_pair_); |
| 5058 | EXPECT_NE(session, session2); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5059 | EXPECT_TRUE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5060 | |
| 5061 | // Confirm the handshake on the alternate network. |
| 5062 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5063 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5064 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5065 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5066 | // Resume the data now so that data can be sent and read. |
| 5067 | socket_data2.Resume(); |
| 5068 | |
| 5069 | // Create the stream. |
| 5070 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5071 | EXPECT_TRUE(stream.get()); |
| 5072 | HttpRequestInfo request_info; |
| 5073 | request_info.method = "GET"; |
| 5074 | request_info.url = GURL("https://www.example.org/"); |
| 5075 | request_info.traffic_annotation = |
| 5076 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5077 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5078 | net_log_, CompletionOnceCallback())); |
| 5079 | // Send the request. |
| 5080 | HttpResponseInfo response; |
| 5081 | HttpRequestHeaders request_headers; |
| 5082 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5083 | callback_.callback())); |
| 5084 | // Run the message loop to finish asynchronous mock write. |
| 5085 | base::RunLoop().RunUntilIdle(); |
| 5086 | // Read the response. |
| 5087 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5088 | EXPECT_EQ(200, response.headers->response_code()); |
| 5089 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5090 | // There should be a new task posted to migrate back to the default network. |
| 5091 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5092 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5093 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 5094 | next_task_delay); |
| 5095 | task_runner->FastForwardBy(next_task_delay); |
| 5096 | |
| 5097 | // There should be two tasks posted. One will retry probing and the other |
| 5098 | // will retry migrate back. |
| 5099 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 5100 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5101 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 5102 | next_task_delay); |
| 5103 | |
| 5104 | // Deliver the signal that the default network is disconnected. |
| 5105 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5106 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 5107 | // Verify no connectivity probes will be sent as probing will be cancelled. |
| 5108 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5109 | // Deliver the signal that the alternate network is made default. |
| 5110 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5111 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 5112 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5113 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5114 | stream.reset(); |
| 5115 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5116 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5117 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5118 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5119 | } |
| 5120 | |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5121 | // Test that connection will be closed with PACKET_WRITE_ERROR if a write error |
| 5122 | // is triggered before handshake is confirmed and connection migration is turned |
| 5123 | // on. |
| 5124 | TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { |
| 5125 | InitializeConnectionMigrationV2Test( |
| 5126 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5127 | |
| 5128 | // Use unmocked crypto stream to do crypto connect. |
| 5129 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 5130 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5131 | |
| 5132 | MockQuicData socket_data; |
| 5133 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5134 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5135 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5136 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5137 | |
| 5138 | // Create request, should fail after the write of the CHLO fails. |
| 5139 | QuicStreamRequest request(factory_.get()); |
| 5140 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5141 | request.Request( |
| 5142 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5143 | SocketTag(), |
| 5144 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5145 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5146 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 5147 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5148 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5149 | |
| 5150 | // Verify new requests can be sent normally. |
| 5151 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 5152 | MockCryptoClientStream::COLD_START); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5153 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5154 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5155 | MockQuicData socket_data2; |
| 5156 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5157 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 5158 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5159 | |
| 5160 | QuicStreamRequest request2(factory_.get()); |
| 5161 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5162 | request2.Request( |
| 5163 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5164 | SocketTag(), |
| 5165 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5166 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5167 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5168 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5169 | // Run the message loop to complete host resolution. |
| 5170 | base::RunLoop().RunUntilIdle(); |
| 5171 | |
| 5172 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 5173 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5174 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5175 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5176 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5177 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5178 | |
| 5179 | // Create QuicHttpStream. |
| 5180 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
| 5181 | EXPECT_TRUE(stream.get()); |
| 5182 | stream.reset(); |
| 5183 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5184 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5185 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5186 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5187 | } |
| 5188 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5189 | void QuicStreamFactoryTestBase::TestMigrationOnWriteError( |
| 5190 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5191 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5192 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5193 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5194 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5195 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5196 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 5197 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5198 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5199 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5200 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5201 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 5202 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5203 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5204 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5205 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5206 | |
| 5207 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5208 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5209 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5210 | request.Request( |
| 5211 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5212 | SocketTag(), |
| 5213 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5214 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5215 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5216 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5217 | EXPECT_TRUE(stream.get()); |
| 5218 | |
| 5219 | // Cause QUIC stream to be created. |
| 5220 | HttpRequestInfo request_info; |
| 5221 | request_info.method = "GET"; |
| 5222 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5223 | request_info.traffic_annotation = |
| 5224 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5225 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5226 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5227 | |
| 5228 | // Ensure that session is alive and active. |
| 5229 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5230 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5231 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5232 | |
| 5233 | // Set up second socket data provider that is used after |
| 5234 | // migration. The request is rewritten to this new socket, and the |
| 5235 | // response to the request is read on this new socket. |
| 5236 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5237 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 5238 | 2, GetNthClientInitiatedStreamId(0), |
| 5239 | true, true, &header_stream_offset)); |
| 5240 | socket_data1.AddRead( |
| 5241 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5242 | false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5243 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5244 | socket_data1.AddWrite(SYNCHRONOUS, |
| 5245 | client_maker_.MakeAckAndRstPacket( |
| 5246 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5247 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5248 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5249 | |
| 5250 | // Send GET request on stream. This should cause a write error, which triggers |
| 5251 | // a connection migration attempt. |
| 5252 | HttpResponseInfo response; |
| 5253 | HttpRequestHeaders request_headers; |
| 5254 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5255 | callback_.callback())); |
| 5256 | |
| 5257 | // Run the message loop so that the migration attempt is executed and |
| 5258 | // data queued in the new socket is read by the packet reader. |
| 5259 | base::RunLoop().RunUntilIdle(); |
| 5260 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5261 | // Verify that session is alive and not marked as going awya. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5262 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5263 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5264 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5265 | |
| 5266 | // Verify that response headers on the migrated socket were delivered to the |
| 5267 | // stream. |
| 5268 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5269 | EXPECT_EQ(200, response.headers->response_code()); |
| 5270 | |
| 5271 | stream.reset(); |
| 5272 | |
| 5273 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5274 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5275 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5276 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5277 | } |
| 5278 | |
| 5279 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 5280 | TestMigrationOnWriteError(SYNCHRONOUS); |
| 5281 | } |
| 5282 | |
| 5283 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 5284 | TestMigrationOnWriteError(ASYNC); |
| 5285 | } |
| 5286 | |
| 5287 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNoNewNetwork( |
| 5288 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5289 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5290 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5291 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5292 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5293 | // Use the test task runner, to force the migration alarm timeout later. |
| 5294 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 5295 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5296 | MockQuicData socket_data; |
| 5297 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5298 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5299 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5300 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5301 | |
| 5302 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5303 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5304 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5305 | request.Request( |
| 5306 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5307 | SocketTag(), |
| 5308 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5309 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5310 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5311 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5312 | EXPECT_TRUE(stream.get()); |
| 5313 | |
| 5314 | // Cause QUIC stream to be created. |
| 5315 | HttpRequestInfo request_info; |
| 5316 | request_info.method = "GET"; |
| 5317 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5318 | request_info.traffic_annotation = |
| 5319 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5320 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5321 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5322 | |
| 5323 | // Ensure that session is alive and active. |
| 5324 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5325 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5326 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5327 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5328 | // Send GET request on stream. This causes a write error, which triggers |
| 5329 | // a connection migration attempt. Since there are no networks |
| 5330 | // to migrate to, this causes the session to wait for a new network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5331 | HttpResponseInfo response; |
| 5332 | HttpRequestHeaders request_headers; |
| 5333 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5334 | callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5335 | |
| 5336 | // Complete any pending writes. Pending async MockQuicData writes |
| 5337 | // are run on the message loop, not on the test runner. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5338 | base::RunLoop().RunUntilIdle(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5339 | |
| 5340 | // Write error causes migration task to be posted. Spin the loop. |
| 5341 | if (write_error_mode == ASYNC) |
| 5342 | runner_->RunNextTask(); |
| 5343 | |
| 5344 | // Migration has not yet failed. The session should be alive and active. |
| 5345 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5346 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5347 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5348 | EXPECT_TRUE(session->connection()->writer()->IsWriteBlocked()); |
| 5349 | |
| 5350 | // The migration will not fail until the migration alarm timeout. |
| 5351 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5352 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5353 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5354 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 5355 | |
| 5356 | // Force migration alarm timeout to run. |
| 5357 | RunTestLoopUntilIdle(); |
| 5358 | |
| 5359 | // The connection should be closed. A request for response headers |
| 5360 | // should fail. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5361 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5362 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5363 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
| 5364 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 5365 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5366 | |
| 5367 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5368 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5369 | } |
| 5370 | |
| 5371 | TEST_P(QuicStreamFactoryTest, |
| 5372 | MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 5373 | TestMigrationOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 5374 | } |
| 5375 | |
| 5376 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 5377 | TestMigrationOnWriteErrorNoNewNetwork(ASYNC); |
| 5378 | } |
| 5379 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5380 | TEST_P(QuicStreamFactoryTest, |
| 5381 | MigrateSessionOnWriteErrorWithMultipleRequestsSync) { |
| 5382 | TestMigrationOnWriteErrorWithMultipleRequests(SYNCHRONOUS); |
| 5383 | } |
| 5384 | |
| 5385 | TEST_P(QuicStreamFactoryTest, |
| 5386 | MigrateSessionOnWriteErrorWithMultipleRequestsAsync) { |
| 5387 | TestMigrationOnWriteErrorWithMultipleRequests(ASYNC); |
| 5388 | } |
| 5389 | |
| 5390 | // Sets up a test which verifies that connection migration on write error can |
| 5391 | // eventually succeed and rewrite the packet on the new network with *multiple* |
| 5392 | // migratable streams. |
| 5393 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( |
| 5394 | IoMode write_error_mode) { |
| 5395 | InitializeConnectionMigrationV2Test( |
| 5396 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5397 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5398 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5399 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5400 | |
| 5401 | MockQuicData socket_data; |
| 5402 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5403 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5404 | socket_data.AddWrite( |
| 5405 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5406 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5407 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5408 | |
| 5409 | // Set up second socket data provider that is used after |
| 5410 | // migration. The request is rewritten to this new socket, and the |
| 5411 | // response to the request is read on this new socket. |
| 5412 | MockQuicData socket_data1; |
| 5413 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 5414 | 2, GetNthClientInitiatedStreamId(0), |
| 5415 | true, true, &header_stream_offset)); |
| 5416 | socket_data1.AddRead( |
| 5417 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5418 | false, false)); |
| 5419 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5420 | socket_data1.AddWrite(SYNCHRONOUS, |
| 5421 | client_maker_.MakeAckAndRstPacket( |
| 5422 | 3, false, GetNthClientInitiatedStreamId(0), |
| 5423 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5424 | socket_data1.AddWrite( |
| 5425 | SYNCHRONOUS, |
| 5426 | client_maker_.MakeRstPacket(4, false, GetNthClientInitiatedStreamId(1), |
| 5427 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 5428 | |
| 5429 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5430 | |
| 5431 | // Create request #1 and QuicHttpStream. |
| 5432 | QuicStreamRequest request1(factory_.get()); |
| 5433 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5434 | request1.Request( |
| 5435 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5436 | SocketTag(), |
| 5437 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5438 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5439 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5440 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5441 | EXPECT_TRUE(stream1.get()); |
| 5442 | |
| 5443 | HttpRequestInfo request_info1; |
| 5444 | request_info1.method = "GET"; |
| 5445 | request_info1.url = GURL("https://www.example.org/"); |
| 5446 | request_info1.traffic_annotation = |
| 5447 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5448 | EXPECT_EQ(OK, |
| 5449 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5450 | net_log_, CompletionOnceCallback())); |
| 5451 | |
| 5452 | // Second request returns synchronously because it pools to existing session. |
| 5453 | TestCompletionCallback callback2; |
| 5454 | QuicStreamRequest request2(factory_.get()); |
| 5455 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5456 | DEFAULT_PRIORITY, SocketTag(), |
| 5457 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5458 | &net_error_details_, |
| 5459 | failed_on_default_network_callback_, |
| 5460 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5461 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5462 | EXPECT_TRUE(stream2.get()); |
| 5463 | HttpRequestInfo request_info2; |
| 5464 | request_info2.method = "GET"; |
| 5465 | request_info2.url = GURL("https://www.example.org/"); |
| 5466 | request_info2.traffic_annotation = |
| 5467 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5468 | EXPECT_EQ(OK, |
| 5469 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5470 | net_log_, CompletionOnceCallback())); |
| 5471 | |
| 5472 | // Ensure that session is alive and active. |
| 5473 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5474 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5475 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5476 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5477 | |
| 5478 | // Send GET request on stream. This should cause a write error, which triggers |
| 5479 | // a connection migration attempt. |
| 5480 | HttpResponseInfo response; |
| 5481 | HttpRequestHeaders request_headers; |
| 5482 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5483 | callback_.callback())); |
| 5484 | |
| 5485 | // Run the message loop so that the migration attempt is executed and |
| 5486 | // data queued in the new socket is read by the packet reader. |
| 5487 | base::RunLoop().RunUntilIdle(); |
| 5488 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5489 | // Verify session is still alive and not marked as going away. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5490 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5491 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5492 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5493 | |
| 5494 | // Verify that response headers on the migrated socket were delivered to the |
| 5495 | // stream. |
| 5496 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5497 | EXPECT_EQ(200, response.headers->response_code()); |
| 5498 | |
| 5499 | stream1.reset(); |
| 5500 | stream2.reset(); |
| 5501 | |
| 5502 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5503 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5504 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5505 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5506 | } |
| 5507 | |
| 5508 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsSync) { |
| 5509 | TestMigrationOnWriteErrorMixedStreams(SYNCHRONOUS); |
| 5510 | } |
| 5511 | |
| 5512 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsAsync) { |
| 5513 | TestMigrationOnWriteErrorMixedStreams(ASYNC); |
| 5514 | } |
| 5515 | |
| 5516 | // Sets up a test that verifies connection migration manages to migrate to |
| 5517 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5518 | // |write_error_mode| on the original network. |
| 5519 | // Note there are mixed types of unfinished requests before migration: one |
| 5520 | // migratable and one non-migratable. The *migratable* one triggers write |
| 5521 | // error. |
| 5522 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( |
| 5523 | IoMode write_error_mode) { |
| 5524 | InitializeConnectionMigrationV2Test( |
| 5525 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5526 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5527 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5528 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5529 | |
| 5530 | int packet_number = 1; |
| 5531 | MockQuicData socket_data; |
| 5532 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5533 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5534 | socket_data.AddWrite( |
| 5535 | SYNCHRONOUS, |
| 5536 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5537 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5538 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5539 | |
| 5540 | // Set up second socket data provider that is used after |
| 5541 | // migration. The request is rewritten to this new socket, and the |
| 5542 | // response to the request is read on this new socket. |
| 5543 | MockQuicData socket_data1; |
| 5544 | socket_data1.AddWrite( |
| 5545 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5546 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 5547 | true, &header_stream_offset)); |
| 5548 | socket_data1.AddWrite( |
| 5549 | SYNCHRONOUS, client_maker_.MakeRstPacket(packet_number++, true, |
| 5550 | GetNthClientInitiatedStreamId(1), |
| 5551 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 5552 | socket_data1.AddRead( |
| 5553 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5554 | false, false)); |
| 5555 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5556 | socket_data1.AddWrite( |
| 5557 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5558 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 5559 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5560 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5561 | |
| 5562 | // Create request #1 and QuicHttpStream. |
| 5563 | QuicStreamRequest request1(factory_.get()); |
| 5564 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5565 | request1.Request( |
| 5566 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5567 | SocketTag(), |
| 5568 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5569 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5570 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5571 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5572 | EXPECT_TRUE(stream1.get()); |
| 5573 | |
| 5574 | HttpRequestInfo request_info1; |
| 5575 | request_info1.method = "GET"; |
| 5576 | request_info1.url = GURL("https://www.example.org/"); |
| 5577 | request_info1.traffic_annotation = |
| 5578 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5579 | EXPECT_EQ(OK, |
| 5580 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5581 | net_log_, CompletionOnceCallback())); |
| 5582 | |
| 5583 | // Second request returns synchronously because it pools to existing session. |
| 5584 | TestCompletionCallback callback2; |
| 5585 | QuicStreamRequest request2(factory_.get()); |
| 5586 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5587 | DEFAULT_PRIORITY, SocketTag(), |
| 5588 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5589 | &net_error_details_, |
| 5590 | failed_on_default_network_callback_, |
| 5591 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5592 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5593 | EXPECT_TRUE(stream2.get()); |
| 5594 | |
| 5595 | HttpRequestInfo request_info2; |
| 5596 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5597 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5598 | request_info2.url = GURL("https://www.example.org/"); |
| 5599 | request_info2.traffic_annotation = |
| 5600 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5601 | EXPECT_EQ(OK, |
| 5602 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5603 | net_log_, CompletionOnceCallback())); |
| 5604 | |
| 5605 | // Ensure that session is alive and active. |
| 5606 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5607 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5608 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5609 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5610 | |
| 5611 | // Send GET request on stream 1. This should cause a write error, which |
| 5612 | // triggers a connection migration attempt. |
| 5613 | HttpResponseInfo response; |
| 5614 | HttpRequestHeaders request_headers; |
| 5615 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5616 | callback_.callback())); |
| 5617 | |
| 5618 | // Run the message loop so that the migration attempt is executed and |
| 5619 | // data queued in the new socket is read by the packet reader. |
| 5620 | base::RunLoop().RunUntilIdle(); |
| 5621 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5622 | // Verify that the session is still alive and not marked as going away. |
| 5623 | // Non-migratable stream should be closed due to migration. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5624 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5625 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5626 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5627 | |
| 5628 | // Verify that response headers on the migrated socket were delivered to the |
| 5629 | // stream. |
| 5630 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5631 | EXPECT_EQ(200, response.headers->response_code()); |
| 5632 | |
| 5633 | stream1.reset(); |
| 5634 | |
| 5635 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5636 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5637 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5638 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5639 | } |
| 5640 | |
| 5641 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Sync) { |
| 5642 | TestMigrationOnWriteErrorMixedStreams2(SYNCHRONOUS); |
| 5643 | } |
| 5644 | |
| 5645 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Async) { |
| 5646 | TestMigrationOnWriteErrorMixedStreams2(ASYNC); |
| 5647 | } |
| 5648 | |
| 5649 | // The one triggers write error is a non-migratable stream. |
| 5650 | // Sets up a test that verifies connection migration manages to migrate to |
| 5651 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5652 | // |write_error_mode| on the original network. |
| 5653 | // Note there are mixed types of unfinished requests before migration: one |
| 5654 | // migratable and one non-migratable. The *non-migratable* one triggers write |
| 5655 | // error. |
| 5656 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( |
| 5657 | IoMode write_error_mode) { |
| 5658 | InitializeConnectionMigrationV2Test( |
| 5659 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5660 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5661 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5662 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5663 | |
| 5664 | int packet_number = 1; |
| 5665 | MockQuicData socket_data; |
| 5666 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5667 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5668 | socket_data.AddWrite( |
| 5669 | SYNCHRONOUS, |
| 5670 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5671 | socket_data.AddWrite(write_error_mode, |
| 5672 | ERR_ADDRESS_UNREACHABLE); // Write error. |
| 5673 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5674 | |
| 5675 | // Set up second socket data provider that is used after |
| 5676 | // migration. The request is rewritten to this new socket, and the |
| 5677 | // response to the request is read on this new socket. |
| 5678 | MockQuicData socket_data1; |
| 5679 | // The packet triggered writer error will be sent anyway even if the stream |
| 5680 | // will be cancelled later. |
| 5681 | socket_data1.AddWrite( |
| 5682 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5683 | packet_number++, GetNthClientInitiatedStreamId(1), true, |
| 5684 | true, &header_stream_offset)); |
| 5685 | socket_data1.AddWrite( |
| 5686 | SYNCHRONOUS, client_maker_.MakeRstPacket(packet_number++, true, |
| 5687 | GetNthClientInitiatedStreamId(1), |
| 5688 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 5689 | socket_data1.AddWrite( |
| 5690 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5691 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 5692 | true, &header_stream_offset)); |
| 5693 | socket_data1.AddRead( |
| 5694 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5695 | false, false)); |
| 5696 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5697 | socket_data1.AddWrite( |
| 5698 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5699 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 5700 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5701 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5702 | |
| 5703 | // Create request #1 and QuicHttpStream. |
| 5704 | QuicStreamRequest request1(factory_.get()); |
| 5705 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5706 | request1.Request( |
| 5707 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5708 | SocketTag(), |
| 5709 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5710 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5711 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5712 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5713 | EXPECT_TRUE(stream1.get()); |
| 5714 | |
| 5715 | HttpRequestInfo request_info1; |
| 5716 | request_info1.method = "GET"; |
| 5717 | request_info1.url = GURL("https://www.example.org/"); |
| 5718 | request_info1.traffic_annotation = |
| 5719 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5720 | EXPECT_EQ(OK, |
| 5721 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5722 | net_log_, CompletionOnceCallback())); |
| 5723 | |
| 5724 | // Second request returns synchronously because it pools to existing session. |
| 5725 | TestCompletionCallback callback2; |
| 5726 | QuicStreamRequest request2(factory_.get()); |
| 5727 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5728 | DEFAULT_PRIORITY, SocketTag(), |
| 5729 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5730 | &net_error_details_, |
| 5731 | failed_on_default_network_callback_, |
| 5732 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5733 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5734 | EXPECT_TRUE(stream2.get()); |
| 5735 | |
| 5736 | HttpRequestInfo request_info2; |
| 5737 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5738 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5739 | request_info2.url = GURL("https://www.example.org/"); |
| 5740 | request_info2.traffic_annotation = |
| 5741 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5742 | EXPECT_EQ(OK, |
| 5743 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5744 | net_log_, CompletionOnceCallback())); |
| 5745 | |
| 5746 | // Ensure that session is alive and active. |
| 5747 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5748 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5749 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5750 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5751 | |
| 5752 | // Send GET request on stream 2 which is non-migratable. This should cause a |
| 5753 | // write error, which triggers a connection migration attempt. |
| 5754 | HttpResponseInfo response2; |
| 5755 | HttpRequestHeaders request_headers2; |
| 5756 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 5757 | callback2.callback())); |
| 5758 | |
| 5759 | // Run the message loop so that the migration attempt is executed and |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5760 | // data queued in the new socket is read by the packet reader. Session is |
| 5761 | // still alive and not marked as going away, non-migratable stream will be |
| 5762 | // closed. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5763 | base::RunLoop().RunUntilIdle(); |
| 5764 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5765 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5766 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5767 | |
| 5768 | // Send GET request on stream 1. |
| 5769 | HttpResponseInfo response; |
| 5770 | HttpRequestHeaders request_headers; |
| 5771 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5772 | callback_.callback())); |
| 5773 | |
| 5774 | base::RunLoop().RunUntilIdle(); |
| 5775 | |
| 5776 | // Verify that response headers on the migrated socket were delivered to the |
| 5777 | // stream. |
| 5778 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5779 | EXPECT_EQ(200, response.headers->response_code()); |
| 5780 | |
| 5781 | stream1.reset(); |
| 5782 | |
| 5783 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5784 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5785 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5786 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5787 | } |
| 5788 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5789 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( |
| 5790 | IoMode write_error_mode) { |
| 5791 | DVLOG(1) << "Mode: " |
| 5792 | << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5793 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5794 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5795 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5796 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5797 | |
| 5798 | MockQuicData socket_data; |
| 5799 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5800 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5801 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5802 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5803 | |
| 5804 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5805 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5806 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5807 | request.Request( |
| 5808 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5809 | SocketTag(), |
| 5810 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5811 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5812 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5813 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5814 | EXPECT_TRUE(stream.get()); |
| 5815 | |
| 5816 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 5817 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5818 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5819 | request_info.method = "GET"; |
| 5820 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5821 | request_info.traffic_annotation = |
| 5822 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5823 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5824 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5825 | |
| 5826 | // Ensure that session is alive and active. |
| 5827 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5828 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5829 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5830 | |
| 5831 | // Send GET request on stream. This should cause a write error, which triggers |
| 5832 | // a connection migration attempt. |
| 5833 | HttpResponseInfo response; |
| 5834 | HttpRequestHeaders request_headers; |
| 5835 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5836 | callback_.callback())); |
| 5837 | |
| 5838 | // Run message loop to execute migration attempt. |
| 5839 | base::RunLoop().RunUntilIdle(); |
| 5840 | |
| 5841 | // Migration fails, and session is closed and deleted. |
| 5842 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5843 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5844 | |
| 5845 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5846 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5847 | } |
| 5848 | |
| 5849 | TEST_P(QuicStreamFactoryTest, |
| 5850 | MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { |
| 5851 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS); |
| 5852 | } |
| 5853 | |
| 5854 | TEST_P(QuicStreamFactoryTest, |
| 5855 | MigrateSessionOnWriteErrorNonMigratableStreamAsync) { |
| 5856 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC); |
| 5857 | } |
| 5858 | |
| 5859 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( |
| 5860 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5861 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5862 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5863 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5864 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5865 | |
| 5866 | MockQuicData socket_data; |
| 5867 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5868 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5869 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5870 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5871 | |
| 5872 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5873 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5874 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5875 | request.Request( |
| 5876 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5877 | SocketTag(), |
| 5878 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5879 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5880 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5881 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5882 | EXPECT_TRUE(stream.get()); |
| 5883 | |
| 5884 | // Cause QUIC stream to be created. |
| 5885 | HttpRequestInfo request_info; |
| 5886 | request_info.method = "GET"; |
| 5887 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5888 | request_info.traffic_annotation = |
| 5889 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5890 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5891 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5892 | |
| 5893 | // Ensure that session is alive and active. |
| 5894 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5895 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5896 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5897 | |
| 5898 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5899 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 5900 | session->config()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5901 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 5902 | |
| 5903 | // Send GET request on stream. This should cause a write error, which triggers |
| 5904 | // a connection migration attempt. |
| 5905 | HttpResponseInfo response; |
| 5906 | HttpRequestHeaders request_headers; |
| 5907 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5908 | callback_.callback())); |
| 5909 | // Run message loop to execute migration attempt. |
| 5910 | base::RunLoop().RunUntilIdle(); |
| 5911 | // Migration fails, and session is closed and deleted. |
| 5912 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5913 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5914 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5915 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5916 | } |
| 5917 | |
| 5918 | TEST_P(QuicStreamFactoryTest, |
| 5919 | MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 5920 | TestMigrationOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 5921 | } |
| 5922 | |
| 5923 | TEST_P(QuicStreamFactoryTest, |
| 5924 | MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 5925 | TestMigrationOnWriteErrorMigrationDisabled(ASYNC); |
| 5926 | } |
| 5927 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5928 | // Sets up a test which verifies that connection migration on write error can |
| 5929 | // eventually succeed and rewrite the packet on the new network with singals |
| 5930 | // delivered in the following order (alternate network is always availabe): |
| 5931 | // - original network encounters a SYNC/ASYNC write error based on |
| 5932 | // |write_error_mode_on_old_network|, the packet failed to be written is |
| 5933 | // cached, session migrates immediately to the alternate network. |
| 5934 | // - an immediate SYNC/ASYNC write error based on |
| 5935 | // |write_error_mode_on_new_network| is encountered after migration to the |
| 5936 | // alternate network, session migrates immediately to the original network. |
| 5937 | // - an immediate SYNC/ASYNC write error based on |
| 5938 | // |write_error_mode_on_old_network| is encountered after migration to the |
| 5939 | // original network, session migrates immediately to the alternate network. |
| 5940 | // - finally, session successfully sends the packet and reads the response on |
| 5941 | // the alternate network. |
| 5942 | // TODO(zhongyi): once https://crbug.com/855666 is fixed, this test should be |
| 5943 | // modified to test that session is closed early if hopping between networks |
| 5944 | // with consecutive write errors is detected. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5945 | void QuicStreamFactoryTestBase::TestMigrationOnMultipleWriteErrors( |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5946 | IoMode write_error_mode_on_old_network, |
| 5947 | IoMode write_error_mode_on_new_network) { |
| 5948 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5949 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5950 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5951 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5952 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5953 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5954 | // Set up the socket data used by the original network, which encounters a |
| 5955 | // write erorr. |
| 5956 | MockQuicData socket_data1; |
| 5957 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5958 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5959 | socket_data1.AddWrite( |
| 5960 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5961 | socket_data1.AddWrite(write_error_mode_on_old_network, |
| 5962 | ERR_ADDRESS_UNREACHABLE); // Write Error |
| 5963 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5964 | |
| 5965 | // Set up the socket data used by the alternate network, which also |
| 5966 | // encounters a write error. |
| 5967 | MockQuicData failed_quic_data2; |
| 5968 | failed_quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5969 | failed_quic_data2.AddWrite(write_error_mode_on_new_network, ERR_FAILED); |
| 5970 | failed_quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5971 | |
| 5972 | // Set up the third socket data used by original network, which encounters a |
| 5973 | // write error again. |
| 5974 | MockQuicData failed_quic_data1; |
| 5975 | failed_quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5976 | failed_quic_data1.AddWrite(write_error_mode_on_old_network, ERR_FAILED); |
| 5977 | failed_quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5978 | |
| 5979 | // Set up the last socket data used by the alternate network, which will |
| 5980 | // finish migration successfully. The request is rewritten to this new socket, |
| 5981 | // and the response to the request is read on this socket. |
| 5982 | MockQuicData socket_data2; |
| 5983 | socket_data2.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 5984 | 2, GetNthClientInitiatedStreamId(0), |
| 5985 | true, true, &header_stream_offset)); |
| 5986 | socket_data2.AddRead( |
| 5987 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5988 | false, false)); |
| 5989 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5990 | socket_data2.AddWrite(SYNCHRONOUS, |
| 5991 | client_maker_.MakeAckAndRstPacket( |
| 5992 | 3, false, GetNthClientInitiatedStreamId(0), |
| 5993 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5994 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5995 | |
| 5996 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5997 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5998 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5999 | request.Request( |
| 6000 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6001 | SocketTag(), |
| 6002 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6003 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6004 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6005 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6006 | EXPECT_TRUE(stream.get()); |
| 6007 | |
| 6008 | // Cause QUIC stream to be created. |
| 6009 | HttpRequestInfo request_info; |
| 6010 | request_info.method = "GET"; |
| 6011 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6012 | request_info.traffic_annotation = |
| 6013 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6014 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6015 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6016 | |
| 6017 | // Ensure that session is alive and active. |
| 6018 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6019 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6020 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6021 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6022 | // Send GET request on stream. |
| 6023 | // This should encounter a write error on network 1, |
| 6024 | // then migrate to network 2, which encounters another write error, |
| 6025 | // and migrate again to network 1, which encoutners one more write error. |
| 6026 | // Finally the session migrates to network 2 successfully. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6027 | HttpResponseInfo response; |
| 6028 | HttpRequestHeaders request_headers; |
| 6029 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6030 | callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6031 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6032 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6033 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6034 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6035 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6036 | // Verify that response headers on the migrated socket were delivered to the |
| 6037 | // stream. |
| 6038 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6039 | EXPECT_EQ(200, response.headers->response_code()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6040 | |
| 6041 | stream.reset(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6042 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6043 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6044 | EXPECT_TRUE(failed_quic_data2.AllReadDataConsumed()); |
| 6045 | EXPECT_TRUE(failed_quic_data2.AllWriteDataConsumed()); |
| 6046 | EXPECT_TRUE(failed_quic_data1.AllReadDataConsumed()); |
| 6047 | EXPECT_TRUE(failed_quic_data1.AllWriteDataConsumed()); |
| 6048 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 6049 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6053 | TestMigrationOnMultipleWriteErrors( |
| 6054 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6055 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6059 | TestMigrationOnMultipleWriteErrors( |
| 6060 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6061 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6065 | TestMigrationOnMultipleWriteErrors( |
| 6066 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6067 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6068 | } |
| 6069 | |
| 6070 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6071 | TestMigrationOnMultipleWriteErrors( |
| 6072 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6073 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6074 | } |
| 6075 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6076 | // Verifies that a connection is closed when connection migration is triggered |
| 6077 | // on network being disconnected and the handshake is not confirmed. |
| 6078 | TEST_P(QuicStreamFactoryTest, NoMigrationBeforeHandshakeOnNetworkDisconnected) { |
| 6079 | InitializeConnectionMigrationV2Test( |
| 6080 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6081 | |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6082 | // Use cold start mode to do crypto connect, and send CHLO packet on wire. |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6083 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6084 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6085 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6086 | MockQuicData socket_data; |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6087 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5068bb0 | 2018-08-03 02:44:09 | [diff] [blame] | 6088 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6089 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6090 | |
| 6091 | // Create request and QuicHttpStream. |
| 6092 | QuicStreamRequest request(factory_.get()); |
| 6093 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6094 | request.Request( |
| 6095 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6096 | SocketTag(), |
| 6097 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6098 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6099 | // Deliver the network notification, which should cause the connection to be |
| 6100 | // closed. |
| 6101 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6102 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6103 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6104 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6105 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6106 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6107 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6108 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6109 | } |
| 6110 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6111 | // Sets up the connection migration test where network change notification is |
| 6112 | // queued BEFORE connection migration attempt on write error is posted. |
| 6113 | void QuicStreamFactoryTestBase:: |
| 6114 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6115 | bool disconnected) { |
| 6116 | InitializeConnectionMigrationV2Test( |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6117 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6118 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6119 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6120 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6121 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6122 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6123 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6124 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6125 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6126 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6127 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6128 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6129 | |
| 6130 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6131 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6132 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6133 | request.Request( |
| 6134 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6135 | SocketTag(), |
| 6136 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6137 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6138 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6139 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6140 | EXPECT_TRUE(stream.get()); |
| 6141 | |
| 6142 | // Cause QUIC stream to be created. |
| 6143 | HttpRequestInfo request_info; |
| 6144 | request_info.method = "GET"; |
| 6145 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6146 | request_info.traffic_annotation = |
| 6147 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6148 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6149 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6150 | |
| 6151 | // Ensure that session is alive and active. |
| 6152 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6153 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6154 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6155 | |
| 6156 | // Set up second socket data provider that is used after |
| 6157 | // migration. The request is rewritten to this new socket, and the |
| 6158 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6159 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6160 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6161 | 2, GetNthClientInitiatedStreamId(0), |
| 6162 | true, true, &header_stream_offset)); |
| 6163 | socket_data1.AddRead( |
| 6164 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6165 | false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6166 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6167 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6168 | client_maker_.MakeAckAndRstPacket( |
| 6169 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6170 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6171 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6172 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6173 | // First queue a network change notification in the message loop. |
| 6174 | if (disconnected) { |
| 6175 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6176 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6177 | } else { |
| 6178 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6179 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6180 | } |
| 6181 | // Send GET request on stream. This should cause a write error, |
| 6182 | // which triggers a connection migration attempt. This will queue a |
| 6183 | // migration attempt behind the notification in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6184 | HttpResponseInfo response; |
| 6185 | HttpRequestHeaders request_headers; |
| 6186 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6187 | callback_.callback())); |
| 6188 | |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6189 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6190 | // Verify the session is still alive and not marked as going away post |
| 6191 | // migration. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6192 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6193 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6194 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6195 | |
| 6196 | // Verify that response headers on the migrated socket were delivered to the |
| 6197 | // stream. |
| 6198 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6199 | EXPECT_EQ(200, response.headers->response_code()); |
| 6200 | |
| 6201 | stream.reset(); |
| 6202 | |
| 6203 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6204 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6205 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6206 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6207 | } |
| 6208 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6209 | // This test verifies that session attempts connection migration successfully |
| 6210 | // with signals delivered in the following order (alternate network is always |
| 6211 | // available): |
| 6212 | // - a notification that default network is disconnected is queued. |
| 6213 | // - write error is triggered: session posts a task to attempt connection |
| 6214 | // migration, |migration_pending_| set to true. |
| 6215 | // - default network disconnected is delivered: session immediately migrates to |
| 6216 | // the alternate network, |migration_pending_| set to false. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6217 | // - connection migration on write error attempt aborts: writer encountered |
| 6218 | // error is no longer in active use. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6219 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6220 | MigrateOnNetworkDisconnectedWithWriteErrorQueuedLater) { |
| 6221 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6222 | /*disconnected=*/true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6223 | } |
| 6224 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6225 | // This test verifies that session attempts connection migration successfully |
| 6226 | // with signals delivered in the following order (alternate network is always |
| 6227 | // available): |
| 6228 | // - a notification that alternate network is made default is queued. |
| 6229 | // - write error is triggered: session posts a task to attempt connection |
| 6230 | // migration, block future migrations. |
| 6231 | // - new default notification is delivered: migrate back timer spins and task is |
| 6232 | // posted to migrate to the new default network. |
| 6233 | // - connection migration on write error attempt proceeds successfully: session |
| 6234 | // is |
| 6235 | // marked as going away, future migrations unblocked. |
| 6236 | // - migrate back to default network task executed: session is already on the |
| 6237 | // default network, no-op. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6238 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6239 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedEarlier) { |
| 6240 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6241 | /*disconnected=*/false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6242 | } |
| 6243 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6244 | // Sets up the connection migration test where network change notification is |
| 6245 | // queued AFTER connection migration attempt on write error is posted. |
| 6246 | void QuicStreamFactoryTestBase:: |
| 6247 | TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6248 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6249 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6250 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6251 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6252 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6253 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6254 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6255 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6256 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6257 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6258 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6259 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6260 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6261 | |
| 6262 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6263 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6264 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6265 | request.Request( |
| 6266 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6267 | SocketTag(), |
| 6268 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6269 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6270 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6271 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6272 | EXPECT_TRUE(stream.get()); |
| 6273 | |
| 6274 | // Cause QUIC stream to be created. |
| 6275 | HttpRequestInfo request_info; |
| 6276 | request_info.method = "GET"; |
| 6277 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6278 | request_info.traffic_annotation = |
| 6279 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6280 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6281 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6282 | |
| 6283 | // Ensure that session is alive and active. |
| 6284 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6285 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6286 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6287 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6288 | // Set up second socket data provider that is used after |
| 6289 | // migration. The request is rewritten to this new socket, and the |
| 6290 | // response to the request is read on this new socket. |
| 6291 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6292 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6293 | 2, GetNthClientInitiatedStreamId(0), |
| 6294 | true, true, &header_stream_offset)); |
| 6295 | socket_data1.AddRead( |
| 6296 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6297 | false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6298 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6299 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6300 | client_maker_.MakeAckAndRstPacket( |
| 6301 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6302 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6303 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6304 | |
| 6305 | // Send GET request on stream. This should cause a write error, |
| 6306 | // which triggers a connection migration attempt. This will queue a |
| 6307 | // migration attempt in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6308 | HttpResponseInfo response; |
| 6309 | HttpRequestHeaders request_headers; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6310 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6311 | callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6312 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6313 | // Now queue a network change notification in the message loop behind |
| 6314 | // the migration attempt. |
| 6315 | if (disconnected) { |
| 6316 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6317 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6318 | } else { |
| 6319 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6320 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6321 | } |
| 6322 | |
| 6323 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6324 | // Verify session is still alive and not marked as going away. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6325 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6326 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6327 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6328 | |
| 6329 | // Verify that response headers on the migrated socket were delivered to the |
| 6330 | // stream. |
| 6331 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6332 | EXPECT_EQ(200, response.headers->response_code()); |
| 6333 | |
| 6334 | stream.reset(); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6335 | |
| 6336 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6337 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6338 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6339 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6340 | } |
| 6341 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6342 | // This test verifies that session attempts connection migration successfully |
| 6343 | // with signals delivered in the following order (alternate network is always |
| 6344 | // available): |
| 6345 | // - write error is triggered: session posts a task to complete connection |
| 6346 | // migration. |
| 6347 | // - a notification that alternate network is made default is queued. |
| 6348 | // - connection migration attempt proceeds successfully, session is marked as |
| 6349 | // going away. |
| 6350 | // - new default notification is delivered after connection migration has been |
| 6351 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6352 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6353 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedLater) { |
| 6354 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/false); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6355 | } |
| 6356 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6357 | // This test verifies that session attempts connection migration successfully |
| 6358 | // with signals delivered in the following order (alternate network is always |
| 6359 | // available): |
| 6360 | // - write error is triggered: session posts a task to complete connection |
| 6361 | // migration. |
| 6362 | // - a notification that default network is diconnected is queued. |
| 6363 | // - connection migration attempt proceeds successfully, session is marked as |
| 6364 | // going away. |
| 6365 | // - disconnect notification is delivered after connection migration has been |
| 6366 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6367 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6368 | MigrateOnWriteErrorWithNetworkDisconnectedQueuedLater) { |
| 6369 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/true); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6370 | } |
| 6371 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6372 | // This tests connection migration on write error with signals delivered in the |
| 6373 | // following order: |
| 6374 | // - a synchronous/asynchronous write error is triggered base on |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6375 | // |write_error_mode|: connection migration attempt is posted. |
| 6376 | // - old default network disconnects, migration waits for a new network. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6377 | // - after a pause, new network is connected: session will migrate to new |
| 6378 | // network immediately. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6379 | // - migration on writer error is exectued and aborts as writer passed in is no |
| 6380 | // longer active in use. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6381 | // - new network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6382 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorPauseBeforeConnected( |
| 6383 | IoMode write_error_mode) { |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6384 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6385 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6386 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6387 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6388 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6389 | // Use the test task runner. |
| 6390 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 6391 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6392 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6393 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6394 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6395 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6396 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6397 | socket_data.AddWrite(write_error_mode, ERR_FAILED); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6398 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6399 | |
| 6400 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6401 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6402 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6403 | request.Request( |
| 6404 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6405 | SocketTag(), |
| 6406 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6407 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6408 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6409 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6410 | EXPECT_TRUE(stream.get()); |
| 6411 | |
| 6412 | // Cause QUIC stream to be created. |
| 6413 | HttpRequestInfo request_info; |
| 6414 | request_info.method = "GET"; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6415 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6416 | request_info.traffic_annotation = |
| 6417 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6418 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6419 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6420 | |
| 6421 | // Ensure that session is alive and active. |
| 6422 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6423 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6424 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6425 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6426 | // Send GET request on stream. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6427 | HttpResponseInfo response; |
| 6428 | HttpRequestHeaders request_headers; |
| 6429 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6430 | callback_.callback())); |
| 6431 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6432 | // The connection should still be alive, not marked as going away. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6433 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6434 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6435 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6436 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6437 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6438 | // Set up second socket data provider that is used after migration. |
| 6439 | // The response to the earlier request is read on this new socket. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6440 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6441 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6442 | 2, GetNthClientInitiatedStreamId(0), |
| 6443 | true, true, &header_stream_offset)); |
| 6444 | socket_data1.AddRead( |
| 6445 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6446 | false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6447 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6448 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6449 | client_maker_.MakeAckAndRstPacket( |
| 6450 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6451 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6452 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6453 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6454 | // On a DISCONNECTED notification, nothing happens. |
| 6455 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6456 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6457 | // Add a new network and notify the stream factory of a new connected network. |
| 6458 | // This causes a PING packet to be sent over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6459 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6460 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 6461 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6462 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 6463 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6464 | // Ensure that the session is still alive. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6465 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6466 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6467 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6468 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6469 | // Run the message loop migration for write error can finish. |
| 6470 | runner_->RunUntilIdle(); |
| 6471 | |
| 6472 | // Response headers are received over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6473 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6474 | EXPECT_EQ(200, response.headers->response_code()); |
| 6475 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6476 | // Check that the session is still alive. |
| 6477 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6478 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6479 | |
| 6480 | // There should be no posted tasks not executed, no way to migrate back to |
| 6481 | // default network. |
| 6482 | EXPECT_TRUE(runner_->GetPostedTasks().empty()); |
| 6483 | |
| 6484 | // Receive signal to mark new network as default. |
| 6485 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6486 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6487 | |
| 6488 | stream.reset(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6489 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6490 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6491 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6492 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6493 | } |
| 6494 | |
| 6495 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6496 | MigrateSessionOnSyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6497 | TestMigrationOnWriteErrorPauseBeforeConnected(SYNCHRONOUS); |
| 6498 | } |
| 6499 | |
| 6500 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6501 | MigrateSessionOnAsyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6502 | TestMigrationOnWriteErrorPauseBeforeConnected(ASYNC); |
| 6503 | } |
| 6504 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6505 | // This test verifies that when session successfully migrate to the alternate |
| 6506 | // network, packet write error on the old writer will be ignored and will not |
| 6507 | // trigger connection migration on write error. |
| 6508 | TEST_P(QuicStreamFactoryTest, IgnoreWriteErrorFromOldWriterAfterMigration) { |
| 6509 | InitializeConnectionMigrationV2Test( |
| 6510 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6511 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6512 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6513 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6514 | |
| 6515 | // Using a testing task runner so that we can verify whether the migrate on |
| 6516 | // write error task is posted. |
| 6517 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6518 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6519 | |
| 6520 | MockQuicData socket_data; |
| 6521 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6522 | socket_data.AddWrite( |
| 6523 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6524 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6525 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6526 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6527 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6528 | |
| 6529 | // Create request and QuicHttpStream. |
| 6530 | QuicStreamRequest request(factory_.get()); |
| 6531 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6532 | request.Request( |
| 6533 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6534 | SocketTag(), |
| 6535 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6536 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6537 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6538 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6539 | EXPECT_TRUE(stream.get()); |
| 6540 | |
| 6541 | // Cause QUIC stream to be created. |
| 6542 | HttpRequestInfo request_info; |
| 6543 | request_info.method = "GET"; |
| 6544 | request_info.url = GURL("https://www.example.org/"); |
| 6545 | request_info.traffic_annotation = |
| 6546 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6547 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6548 | net_log_, CompletionOnceCallback())); |
| 6549 | |
| 6550 | // Ensure that session is alive and active. |
| 6551 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6552 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6553 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6554 | |
| 6555 | // Set up second socket data provider that is used after |
| 6556 | // migration. The response to the request is read on this new socket. |
| 6557 | MockQuicData socket_data1; |
| 6558 | socket_data1.AddWrite( |
| 6559 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 6560 | socket_data1.AddRead( |
| 6561 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6562 | false, false)); |
| 6563 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6564 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6565 | client_maker_.MakeAckAndRstPacket( |
| 6566 | 4, false, GetNthClientInitiatedStreamId(0), |
| 6567 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 6568 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6569 | |
| 6570 | // Send GET request on stream. |
| 6571 | HttpResponseInfo response; |
| 6572 | HttpRequestHeaders request_headers; |
| 6573 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6574 | callback_.callback())); |
| 6575 | |
| 6576 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6577 | // Now notify network is disconnected, cause the migration to complete |
| 6578 | // immediately. |
| 6579 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6580 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6581 | // There will be two pending task, one will complete migration with no delay |
| 6582 | // and the other will attempt to migrate back to the default network with |
| 6583 | // delay. |
| 6584 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6585 | |
| 6586 | // Complete migration. |
| 6587 | task_runner->RunUntilIdle(); |
| 6588 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6589 | |
| 6590 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6591 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6592 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6593 | |
| 6594 | // Verify that response headers on the migrated socket were delivered to the |
| 6595 | // stream. |
| 6596 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6597 | EXPECT_EQ(200, response.headers->response_code()); |
| 6598 | |
| 6599 | // Resume the old socket data, a write error will be delivered to the old |
| 6600 | // packet writer. Verify no additional task is posted. |
| 6601 | socket_data.Resume(); |
| 6602 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6603 | |
| 6604 | stream.reset(); |
| 6605 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6606 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6607 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6608 | } |
| 6609 | |
| 6610 | // This test verifies that when session successfully migrate to the alternate |
| 6611 | // network, packet read error on the old reader will be ignored and will not |
| 6612 | // close the connection. |
| 6613 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorFromOldReaderAfterMigration) { |
| 6614 | InitializeConnectionMigrationV2Test( |
| 6615 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6616 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6617 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6618 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6619 | |
| 6620 | // Using a testing task runner. |
| 6621 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6622 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6623 | |
| 6624 | MockQuicData socket_data; |
| 6625 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6626 | socket_data.AddWrite( |
| 6627 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6628 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6629 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6630 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6631 | |
| 6632 | // Create request and QuicHttpStream. |
| 6633 | QuicStreamRequest request(factory_.get()); |
| 6634 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6635 | request.Request( |
| 6636 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6637 | SocketTag(), |
| 6638 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6639 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6640 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6641 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6642 | EXPECT_TRUE(stream.get()); |
| 6643 | |
| 6644 | // Cause QUIC stream to be created. |
| 6645 | HttpRequestInfo request_info; |
| 6646 | request_info.method = "GET"; |
| 6647 | request_info.url = GURL("https://www.example.org/"); |
| 6648 | request_info.traffic_annotation = |
| 6649 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6650 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6651 | net_log_, CompletionOnceCallback())); |
| 6652 | |
| 6653 | // Ensure that session is alive and active. |
| 6654 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6655 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6656 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6657 | |
| 6658 | // Set up second socket data provider that is used after |
| 6659 | // migration. The request is written to this new socket, and the |
| 6660 | // response to the request is read on this new socket. |
| 6661 | MockQuicData socket_data1; |
| 6662 | socket_data1.AddWrite( |
| 6663 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 6664 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6665 | 3, GetNthClientInitiatedStreamId(0), |
| 6666 | true, true, &header_stream_offset)); |
| 6667 | socket_data1.AddRead( |
| 6668 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6669 | false, false)); |
| 6670 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6671 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6672 | client_maker_.MakeAckAndRstPacket( |
| 6673 | 4, false, GetNthClientInitiatedStreamId(0), |
| 6674 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 6675 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6676 | |
| 6677 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6678 | // Now notify network is disconnected, cause the migration to complete |
| 6679 | // immediately. |
| 6680 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6681 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6682 | // There will be two pending task, one will complete migration with no delay |
| 6683 | // and the other will attempt to migrate back to the default network with |
| 6684 | // delay. |
| 6685 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6686 | |
| 6687 | // Complete migration. |
| 6688 | task_runner->RunUntilIdle(); |
| 6689 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6690 | |
| 6691 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6692 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6693 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6694 | |
| 6695 | // Send GET request on stream. |
| 6696 | HttpResponseInfo response; |
| 6697 | HttpRequestHeaders request_headers; |
| 6698 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6699 | callback_.callback())); |
| 6700 | |
| 6701 | // Verify that response headers on the migrated socket were delivered to the |
| 6702 | // stream. |
| 6703 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6704 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6705 | EXPECT_EQ(200, response.headers->response_code()); |
| 6706 | |
| 6707 | // Resume the old socket data, a read error will be delivered to the old |
| 6708 | // packet reader. Verify that the session is not affected. |
| 6709 | socket_data.Resume(); |
| 6710 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6711 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6712 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6713 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6714 | |
| 6715 | stream.reset(); |
| 6716 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6717 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6718 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6719 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6720 | } |
| 6721 | |
| 6722 | // This test verifies that after migration on network is executed, packet |
| 6723 | // read error on the old reader will be ignored and will not close the |
| 6724 | // connection. |
| 6725 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorOnOldReaderDuringMigration) { |
| 6726 | InitializeConnectionMigrationV2Test( |
| 6727 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6728 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6729 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6730 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6731 | |
| 6732 | // Using a testing task runner. |
| 6733 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6734 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6735 | |
| 6736 | MockQuicData socket_data; |
| 6737 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6738 | socket_data.AddWrite( |
| 6739 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6740 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6741 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6742 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6743 | |
| 6744 | // Create request and QuicHttpStream. |
| 6745 | QuicStreamRequest request(factory_.get()); |
| 6746 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6747 | request.Request( |
| 6748 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6749 | SocketTag(), |
| 6750 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6751 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6752 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6753 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6754 | EXPECT_TRUE(stream.get()); |
| 6755 | |
| 6756 | // Cause QUIC stream to be created. |
| 6757 | HttpRequestInfo request_info; |
| 6758 | request_info.method = "GET"; |
| 6759 | request_info.url = GURL("https://www.example.org/"); |
| 6760 | request_info.traffic_annotation = |
| 6761 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6762 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6763 | net_log_, CompletionOnceCallback())); |
| 6764 | |
| 6765 | // Ensure that session is alive and active. |
| 6766 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6767 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6768 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6769 | |
| 6770 | // Set up second socket data provider that is used after |
| 6771 | // migration. The request is written to this new socket, and the |
| 6772 | // response to the request is read on this new socket. |
| 6773 | MockQuicData socket_data1; |
| 6774 | socket_data1.AddWrite( |
| 6775 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 6776 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6777 | 3, GetNthClientInitiatedStreamId(0), |
| 6778 | true, true, &header_stream_offset)); |
| 6779 | socket_data1.AddRead( |
| 6780 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6781 | false, false)); |
| 6782 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6783 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6784 | client_maker_.MakeAckAndRstPacket( |
| 6785 | 4, false, GetNthClientInitiatedStreamId(0), |
| 6786 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 6787 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6788 | |
| 6789 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6790 | // Now notify network is disconnected, cause the migration to complete |
| 6791 | // immediately. |
| 6792 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6793 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6794 | // There will be two pending task, one will complete migration with no delay |
| 6795 | // and the other will attempt to migrate back to the default network with |
| 6796 | // delay. |
| 6797 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6798 | |
| 6799 | // Resume the old socket data, a read error will be delivered to the old |
| 6800 | // packet reader. Verify that the session is not affected. |
| 6801 | socket_data.Resume(); |
| 6802 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6803 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6804 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6805 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6806 | |
| 6807 | // Complete migration. |
| 6808 | task_runner->RunUntilIdle(); |
| 6809 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6810 | |
| 6811 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6812 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6813 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6814 | |
| 6815 | // Send GET request on stream. |
| 6816 | HttpResponseInfo response; |
| 6817 | HttpRequestHeaders request_headers; |
| 6818 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6819 | callback_.callback())); |
| 6820 | |
| 6821 | // Verify that response headers on the migrated socket were delivered to the |
| 6822 | // stream. |
| 6823 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6824 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6825 | EXPECT_EQ(200, response.headers->response_code()); |
| 6826 | |
| 6827 | stream.reset(); |
| 6828 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6829 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6830 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6831 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6832 | } |
| 6833 | |
| 6834 | // This test verifies that after migration on write error is posted, packet |
| 6835 | // read error on the old reader will be ignored and will not close the |
| 6836 | // connection. |
| 6837 | TEST_P(QuicStreamFactoryTest, |
| 6838 | IgnoreReadErrorOnOldReaderDuringPendingMigrationOnWriteError) { |
| 6839 | InitializeConnectionMigrationV2Test( |
| 6840 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6841 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6842 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6843 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6844 | |
| 6845 | // Using a testing task runner. |
| 6846 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6847 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6848 | |
| 6849 | MockQuicData socket_data; |
| 6850 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6851 | socket_data.AddWrite( |
| 6852 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6853 | socket_data.AddWrite(ASYNC, ERR_FAILED); // Write error. |
| 6854 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); // Read error. |
| 6855 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6856 | |
| 6857 | // Create request and QuicHttpStream. |
| 6858 | QuicStreamRequest request(factory_.get()); |
| 6859 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6860 | request.Request( |
| 6861 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6862 | SocketTag(), |
| 6863 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6864 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6865 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6866 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6867 | EXPECT_TRUE(stream.get()); |
| 6868 | |
| 6869 | // Cause QUIC stream to be created. |
| 6870 | HttpRequestInfo request_info; |
| 6871 | request_info.method = "GET"; |
| 6872 | request_info.url = GURL("https://www.example.org/"); |
| 6873 | request_info.traffic_annotation = |
| 6874 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6875 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6876 | net_log_, CompletionOnceCallback())); |
| 6877 | |
| 6878 | // Ensure that session is alive and active. |
| 6879 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6880 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6881 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6882 | |
| 6883 | // Set up second socket data provider that is used after |
| 6884 | // migration. The request is written to this new socket, and the |
| 6885 | // response to the request is read on this new socket. |
| 6886 | MockQuicData socket_data1; |
| 6887 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6888 | 2, GetNthClientInitiatedStreamId(0), |
| 6889 | true, true, &header_stream_offset)); |
| 6890 | socket_data1.AddRead( |
| 6891 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6892 | false, false)); |
| 6893 | |
| 6894 | socket_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 6895 | socket_data1.AddRead(ASYNC, ERR_FAILED); // Read error to close connection. |
| 6896 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6897 | |
| 6898 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6899 | // Send GET request on stream. |
| 6900 | HttpResponseInfo response; |
| 6901 | HttpRequestHeaders request_headers; |
| 6902 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6903 | callback_.callback())); |
| 6904 | // Run the message loop to complete asynchronous write and read with errors. |
| 6905 | base::RunLoop().RunUntilIdle(); |
| 6906 | // There will be one pending task to complete migration on write error. |
| 6907 | // Verify session is not closed with read error. |
| 6908 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6909 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6910 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6911 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6912 | |
| 6913 | // Complete migration. |
| 6914 | task_runner->RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6915 | // There will be one more task posted attempting to migrate back to the |
| 6916 | // default network. |
| 6917 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6918 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6919 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6920 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6921 | |
| 6922 | // Verify that response headers on the migrated socket were delivered to the |
| 6923 | // stream. |
| 6924 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6925 | EXPECT_EQ(200, response.headers->response_code()); |
| 6926 | |
| 6927 | // Resume to consume the read error on new socket, which will close |
| 6928 | // the connection. |
| 6929 | socket_data1.Resume(); |
| 6930 | |
| 6931 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6932 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6933 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6934 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6935 | } |
| 6936 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6937 | // Migrate on asynchronous write error, old network disconnects after alternate |
| 6938 | // network connects. |
| 6939 | TEST_P(QuicStreamFactoryTest, |
| 6940 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectAysnc) { |
| 6941 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6942 | ASYNC, /*disconnect_before_connect*/ false); |
| 6943 | } |
| 6944 | |
| 6945 | // Migrate on synchronous write error, old network disconnects after alternate |
| 6946 | // network connects. |
| 6947 | TEST_P(QuicStreamFactoryTest, |
| 6948 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectSync) { |
| 6949 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6950 | SYNCHRONOUS, /*disconnect_before_connect*/ false); |
| 6951 | } |
| 6952 | |
| 6953 | // Migrate on asynchronous write error, old network disconnects before alternate |
| 6954 | // network connects. |
| 6955 | TEST_P(QuicStreamFactoryTest, |
| 6956 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectAysnc) { |
| 6957 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6958 | ASYNC, /*disconnect_before_connect*/ true); |
| 6959 | } |
| 6960 | |
| 6961 | // Migrate on synchronous write error, old network disconnects before alternate |
| 6962 | // network connects. |
| 6963 | TEST_P(QuicStreamFactoryTest, |
| 6964 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectSync) { |
| 6965 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6966 | SYNCHRONOUS, /*disconnect_before_connect*/ true); |
| 6967 | } |
| 6968 | |
| 6969 | // Setps up test which verifies that session successfully migrate to alternate |
| 6970 | // network with signals delivered in the following order: |
| 6971 | // *NOTE* Signal (A) and (B) can reverse order based on |
| 6972 | // |disconnect_before_connect|. |
| 6973 | // - (No alternate network is connected) session connects to |
| 6974 | // kDefaultNetworkForTests. |
| 6975 | // - An async/sync write error is encountered based on |write_error_mode|: |
| 6976 | // session posted task to migrate session on write error. |
| 6977 | // - Posted task is executed, miration moves to pending state due to lack of |
| 6978 | // alternate network. |
| 6979 | // - (A) An alternate network is connected, pending migration completes. |
| 6980 | // - (B) Old default network disconnects, no migration will be attempted as |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 6981 | // session has already migrate to the alternate network. |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6982 | // - The alternate network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6983 | void QuicStreamFactoryTestBase:: |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6984 | TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6985 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6986 | bool disconnect_before_connect) { |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 6987 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6988 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6989 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6990 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6991 | |
| 6992 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6993 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6994 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6995 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6996 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6997 | socket_data.AddWrite(write_error_mode, ERR_FAILED); // Write error. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6998 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6999 | |
| 7000 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7001 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7002 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7003 | request.Request( |
| 7004 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7005 | SocketTag(), |
| 7006 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7007 | failed_on_default_network_callback_, callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7008 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7009 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7010 | EXPECT_TRUE(stream.get()); |
| 7011 | |
| 7012 | // Cause QUIC stream to be created. |
| 7013 | HttpRequestInfo request_info; |
| 7014 | request_info.method = "GET"; |
| 7015 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7016 | request_info.traffic_annotation = |
| 7017 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7018 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7019 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7020 | |
| 7021 | // Ensure that session is alive and active. |
| 7022 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7023 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7024 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7025 | |
| 7026 | // Send GET request on stream. This should cause a write error, which triggers |
| 7027 | // a connection migration attempt. |
| 7028 | HttpResponseInfo response; |
| 7029 | HttpRequestHeaders request_headers; |
| 7030 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7031 | callback_.callback())); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7032 | // Run the message loop so that posted task to migrate to socket will be |
| 7033 | // executed. A new task will be posted to wait for a new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7034 | base::RunLoop().RunUntilIdle(); |
| 7035 | |
| 7036 | // In this particular code path, the network will not yet be marked |
| 7037 | // as going away and the session will still be alive. |
| 7038 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7039 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7040 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7041 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7042 | |
| 7043 | // Set up second socket data provider that is used after |
| 7044 | // migration. The request is rewritten to this new socket, and the |
| 7045 | // response to the request is read on this new socket. |
| 7046 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7047 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 7048 | 2, GetNthClientInitiatedStreamId(0), |
| 7049 | true, true, &header_stream_offset)); |
| 7050 | socket_data1.AddRead( |
| 7051 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 7052 | false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7053 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7054 | socket_data1.AddWrite(SYNCHRONOUS, |
| 7055 | client_maker_.MakeAckAndRstPacket( |
| 7056 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7057 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7058 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7059 | |
| 7060 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7061 | ->SetConnectedNetworksList( |
| 7062 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7063 | if (disconnect_before_connect) { |
| 7064 | // Now deliver a DISCONNECT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7065 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7066 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7067 | |
| 7068 | // Now deliver a CONNECTED notification and completes migration. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7069 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7070 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7071 | } else { |
| 7072 | // Now deliver a CONNECTED notification and completes migration. |
| 7073 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7074 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7075 | |
| 7076 | // Now deliver a DISCONNECT notification. |
| 7077 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7078 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7079 | } |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7080 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7081 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7082 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7083 | |
| 7084 | // This is the callback for the response headers that returned |
| 7085 | // pending previously, because no result was available. Check that |
| 7086 | // the result is now available due to the successful migration. |
| 7087 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7088 | EXPECT_EQ(200, response.headers->response_code()); |
| 7089 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7090 | // Deliver a MADEDEFAULT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7091 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7092 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7093 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7094 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7095 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 7096 | DEFAULT_PRIORITY, SocketTag(), |
| 7097 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7098 | &net_error_details_, |
| 7099 | failed_on_default_network_callback_, |
| 7100 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7101 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7102 | EXPECT_TRUE(stream2.get()); |
| 7103 | |
| 7104 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7105 | EXPECT_EQ(session, GetActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7106 | |
| 7107 | stream.reset(); |
| 7108 | stream2.reset(); |
| 7109 | |
| 7110 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7111 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7112 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7113 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7114 | } |
| 7115 | |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7116 | TEST_P(QuicStreamFactoryTest, ServerMigration) { |
| 7117 | allow_server_migration_ = true; |
| 7118 | Initialize(); |
| 7119 | |
| 7120 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7121 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7122 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7123 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7124 | MockQuicData socket_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7125 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7126 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7127 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7128 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 7129 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 7130 | 2, GetNthClientInitiatedStreamId(0), |
| 7131 | true, true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7132 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7133 | |
| 7134 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7135 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7136 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7137 | request.Request( |
| 7138 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7139 | SocketTag(), |
| 7140 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7141 | failed_on_default_network_callback_, callback_.callback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7142 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7143 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7144 | EXPECT_TRUE(stream.get()); |
| 7145 | |
| 7146 | // Cause QUIC stream to be created. |
| 7147 | HttpRequestInfo request_info; |
| 7148 | request_info.method = "GET"; |
| 7149 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7150 | request_info.traffic_annotation = |
| 7151 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7152 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7153 | net_log_, CompletionOnceCallback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7154 | |
| 7155 | // Ensure that session is alive and active. |
| 7156 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7157 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7158 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7159 | |
| 7160 | // Send GET request on stream. |
| 7161 | HttpResponseInfo response; |
| 7162 | HttpRequestHeaders request_headers; |
| 7163 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7164 | callback_.callback())); |
| 7165 | |
| 7166 | IPEndPoint ip; |
| 7167 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7168 | DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 7169 | << ip.port(); |
| 7170 | |
| 7171 | // Set up second socket data provider that is used after |
| 7172 | // migration. The request is rewritten to this new socket, and the |
| 7173 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7174 | MockQuicData socket_data2; |
| 7175 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7176 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 7177 | socket_data2.AddRead( |
| 7178 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 7179 | false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7180 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7181 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7182 | client_maker_.MakeAckAndRstPacket( |
| 7183 | 4, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7184 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7185 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7186 | |
| 7187 | const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 7188 | const uint16_t kTestPort = 123; |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 7189 | session->Migrate(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 7190 | IPEndPoint(IPAddress(kTestIpAddress), kTestPort), true, |
| 7191 | net_log_); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7192 | |
| 7193 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7194 | DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 7195 | << ip.port(); |
| 7196 | |
| 7197 | // The session should be alive and active. |
| 7198 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7199 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7200 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7201 | |
| 7202 | // Run the message loop so that data queued in the new socket is read by the |
| 7203 | // packet reader. |
| 7204 | base::RunLoop().RunUntilIdle(); |
| 7205 | |
| 7206 | // Verify that response headers on the migrated socket were delivered to the |
| 7207 | // stream. |
| 7208 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7209 | EXPECT_EQ(200, response.headers->response_code()); |
| 7210 | |
| 7211 | stream.reset(); |
| 7212 | |
| 7213 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7214 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7215 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7216 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7217 | } |
| 7218 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7219 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv4) { |
| 7220 | // Add alternate IPv4 server address to config. |
| 7221 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7222 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7223 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7224 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7225 | VerifyServerMigration(config, alt_address); |
| 7226 | } |
| 7227 | |
| 7228 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv6) { |
| 7229 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7230 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7231 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7232 | // Add alternate IPv6 server address to config. |
| 7233 | IPEndPoint alt_address = IPEndPoint( |
| 7234 | IPAddress(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7235 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7236 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7237 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7238 | VerifyServerMigration(config, alt_address); |
| 7239 | } |
| 7240 | |
| 7241 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { |
| 7242 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7243 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7244 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7245 | // Add alternate IPv4 server address to config. |
| 7246 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7247 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7248 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7249 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7250 | IPEndPoint expected_address( |
| 7251 | ConvertIPv4ToIPv4MappedIPv6(alt_address.address()), alt_address.port()); |
| 7252 | VerifyServerMigration(config, expected_address); |
| 7253 | } |
| 7254 | |
| 7255 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { |
| 7256 | allow_server_migration_ = true; |
| 7257 | Initialize(); |
| 7258 | |
| 7259 | // Add a resolver rule to make initial connection to an IPv4 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7260 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), "1.2.3.4", |
| 7261 | ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7262 | // Add alternate IPv6 server address to config. |
| 7263 | IPEndPoint alt_address = IPEndPoint( |
| 7264 | IPAddress(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7265 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7266 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7267 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7268 | |
| 7269 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7270 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7271 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7272 | |
| 7273 | crypto_client_stream_factory_.SetConfig(config); |
| 7274 | |
| 7275 | // Set up only socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7276 | MockQuicData socket_data1; |
| 7277 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7278 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7279 | socket_data1.AddWrite( |
| 7280 | SYNCHRONOUS, |
| 7281 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7282 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7283 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7284 | |
| 7285 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7286 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7287 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7288 | request.Request( |
| 7289 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7290 | SocketTag(), |
| 7291 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7292 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7293 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7294 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7295 | EXPECT_TRUE(stream.get()); |
| 7296 | |
| 7297 | // Cause QUIC stream to be created. |
| 7298 | HttpRequestInfo request_info; |
| 7299 | request_info.method = "GET"; |
| 7300 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7301 | request_info.traffic_annotation = |
| 7302 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7303 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7304 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7305 | |
| 7306 | // Ensure that session is alive and active. |
| 7307 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7308 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7309 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7310 | |
| 7311 | IPEndPoint actual_address; |
| 7312 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 7313 | // No migration should have happened. |
| 7314 | IPEndPoint expected_address = |
| 7315 | IPEndPoint(IPAddress(1, 2, 3, 4), kDefaultServerPort); |
| 7316 | EXPECT_EQ(actual_address, expected_address); |
| 7317 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 7318 | << " " << actual_address.port(); |
| 7319 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 7320 | << " " << expected_address.port(); |
| 7321 | |
| 7322 | stream.reset(); |
| 7323 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7324 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7325 | } |
| 7326 | |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7327 | TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7328 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7329 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7330 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7331 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7332 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7333 | MockQuicData socket_data; |
| 7334 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7335 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7336 | socket_data.AddWrite( |
| 7337 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 7338 | socket_data.AddWrite( |
| 7339 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 7340 | 3, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7341 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7342 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7343 | MockQuicData socket_data2; |
| 7344 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7345 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7346 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7347 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7348 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7349 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7350 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7351 | request.Request( |
| 7352 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7353 | SocketTag(), |
| 7354 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7355 | failed_on_default_network_callback_, callback_.callback())); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7356 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7357 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7358 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7359 | HttpRequestInfo request_info; |
| 7360 | request_info.traffic_annotation = |
| 7361 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7362 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 7363 | net_log_, CompletionOnceCallback())); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7364 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 7365 | ssl_config_service_->NotifySSLConfigChange(); |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7366 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 7367 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7368 | EXPECT_FALSE(factory_->require_confirmation()); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7369 | |
| 7370 | // Now attempting to request a stream to the same origin should create |
| 7371 | // a new session. |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7372 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7373 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7374 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7375 | request2.Request( |
| 7376 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7377 | SocketTag(), |
| 7378 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7379 | failed_on_default_network_callback_, callback_.callback())); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7380 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7381 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7382 | stream = CreateStream(&request2); |
| 7383 | stream.reset(); // Will reset stream 3. |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7384 | |
| 7385 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7386 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7387 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7388 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7389 | } |
| 7390 | |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 7391 | TEST_P(QuicStreamFactoryTest, OnCertDBChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7392 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7393 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7394 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7395 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7396 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7397 | MockQuicData socket_data; |
| 7398 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7399 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7400 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7401 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7402 | MockQuicData socket_data2; |
| 7403 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7404 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7405 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7406 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7407 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7408 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7409 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7410 | request.Request( |
| 7411 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7412 | SocketTag(), |
| 7413 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7414 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7415 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7416 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7417 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7418 | EXPECT_TRUE(stream); |
| 7419 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7420 | |
| 7421 | // Change the CA cert and verify that stream saw the event. |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 7422 | factory_->OnCertDBChanged(); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7423 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7424 | EXPECT_FALSE(factory_->require_confirmation()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7425 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7426 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7427 | |
| 7428 | // Now attempting to request a stream to the same origin should create |
| 7429 | // a new session. |
| 7430 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7431 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7432 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7433 | request2.Request( |
| 7434 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7435 | SocketTag(), |
| 7436 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7437 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7438 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7439 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7440 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 7441 | EXPECT_TRUE(stream2); |
| 7442 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 7443 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7444 | EXPECT_NE(session, session2); |
| 7445 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7446 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 7447 | |
| 7448 | stream2.reset(); |
| 7449 | stream.reset(); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7450 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7451 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7452 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7453 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7454 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7455 | } |
| 7456 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7457 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7458 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7459 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7460 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7461 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7462 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7463 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7464 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7465 | string r1_host_name("r1"); |
| 7466 | string r2_host_name("r2"); |
| 7467 | r1_host_name.append(cannoncial_suffixes[i]); |
| 7468 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7469 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7470 | HostPortPair host_port_pair1(r1_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7471 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7472 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7473 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7474 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7475 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7476 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7477 | EXPECT_FALSE(cached1->proof_valid()); |
| 7478 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7479 | |
| 7480 | // Mutate the cached1 to have different data. |
| 7481 | // TODO(rtenneti): mutate other members of CachedState. |
| 7482 | cached1->set_source_address_token(r1_host_name); |
| 7483 | cached1->SetProofValid(); |
| 7484 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7485 | HostPortPair host_port_pair2(r2_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7486 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7487 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7488 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7489 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7490 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 7491 | EXPECT_TRUE(cached2->proof_valid()); |
| 7492 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7493 | } |
| 7494 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7495 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7496 | Initialize(); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7497 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7498 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7499 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7500 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7501 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7502 | string r3_host_name("r3"); |
| 7503 | string r4_host_name("r4"); |
| 7504 | r3_host_name.append(cannoncial_suffixes[i]); |
| 7505 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7506 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7507 | HostPortPair host_port_pair1(r3_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7508 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7509 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7510 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7511 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7512 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7513 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7514 | EXPECT_FALSE(cached1->proof_valid()); |
| 7515 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7516 | |
| 7517 | // Mutate the cached1 to have different data. |
| 7518 | // TODO(rtenneti): mutate other members of CachedState. |
| 7519 | cached1->set_source_address_token(r3_host_name); |
| 7520 | cached1->SetProofInvalid(); |
| 7521 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7522 | HostPortPair host_port_pair2(r4_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7523 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7524 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7525 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7526 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7527 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 7528 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 7529 | EXPECT_FALSE(cached2->proof_valid()); |
| 7530 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7531 | } |
| 7532 | |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7533 | TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7534 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7535 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7536 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7537 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7538 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7539 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7540 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7541 | MockQuicData socket_data; |
| 7542 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7543 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7544 | |
| 7545 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7546 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7547 | host_resolver_->set_synchronous_mode(true); |
| 7548 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7549 | "192.168.0.1", ""); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7550 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7551 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7552 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7553 | DEFAULT_PRIORITY, SocketTag(), |
| 7554 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7555 | &net_error_details_, |
| 7556 | failed_on_default_network_callback_, |
| 7557 | callback_.callback())); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7558 | |
| 7559 | // If we are waiting for disk cache, we would have posted a task. Verify that |
| 7560 | // the CancelWaitForDataReady task hasn't been posted. |
| 7561 | ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
| 7562 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7563 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7564 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7565 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7566 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7567 | } |
| 7568 | |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7569 | TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { |
| 7570 | reduced_ping_timeout_seconds_ = 10; |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7571 | Initialize(); |
| 7572 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7573 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7574 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7575 | |
| 7576 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7577 | |
| 7578 | MockQuicData socket_data; |
| 7579 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7580 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7581 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7582 | |
| 7583 | MockQuicData socket_data2; |
| 7584 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7585 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7586 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7587 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7588 | |
| 7589 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
| 7590 | |
| 7591 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7592 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7593 | host_resolver_->set_synchronous_mode(true); |
| 7594 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7595 | "192.168.0.1", ""); |
| 7596 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7597 | |
| 7598 | // Quic should use default PING timeout when no previous connection times out |
| 7599 | // with open stream. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7600 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7601 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7602 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7603 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7604 | DEFAULT_PRIORITY, SocketTag(), |
| 7605 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7606 | &net_error_details_, |
| 7607 | failed_on_default_network_callback_, |
| 7608 | callback_.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7609 | |
| 7610 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7611 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7612 | session->connection()->ping_timeout()); |
| 7613 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7614 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7615 | EXPECT_TRUE(stream.get()); |
| 7616 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7617 | request_info.traffic_annotation = |
| 7618 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7619 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7620 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7621 | |
| 7622 | DVLOG(1) |
| 7623 | << "Created 1st session and initialized a stream. Now trigger timeout"; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7624 | session->connection()->CloseConnection( |
| 7625 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7626 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7627 | // Need to spin the loop now to ensure that |
| 7628 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7629 | base::RunLoop run_loop; |
| 7630 | run_loop.RunUntilIdle(); |
| 7631 | |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7632 | // The first connection times out with open stream, QUIC should reduce initial |
| 7633 | // PING time for subsequent connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7634 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7635 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 7636 | |
| 7637 | // Test two-in-a-row timeouts with open streams. |
| 7638 | DVLOG(1) << "Create 2nd session and timeout with open stream"; |
| 7639 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7640 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7641 | EXPECT_EQ(OK, |
| 7642 | request2.Request( |
| 7643 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 7644 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 7645 | failed_on_default_network_callback_, callback2.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7646 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7647 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7648 | session2->connection()->ping_timeout()); |
| 7649 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7650 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7651 | EXPECT_TRUE(stream2.get()); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7652 | EXPECT_EQ(OK, |
| 7653 | stream2->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7654 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7655 | session2->connection()->CloseConnection( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7656 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7657 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7658 | // Need to spin the loop now to ensure that |
| 7659 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7660 | base::RunLoop run_loop2; |
| 7661 | run_loop2.RunUntilIdle(); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7662 | |
| 7663 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7664 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7665 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7666 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7667 | } |
| 7668 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 7669 | // Verifies that the QUIC stream factory is initialized correctly. |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 7670 | TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 7671 | VerifyInitialization(); |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 7672 | } |
| 7673 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7674 | TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 7675 | Initialize(); |
| 7676 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7677 | MockQuicData socket_data; |
| 7678 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7679 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7680 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7681 | |
| 7682 | // Save current state of |race_cert_verification|. |
| 7683 | bool race_cert_verification = |
| 7684 | QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 7685 | |
| 7686 | // Load server config. |
| 7687 | HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7688 | quic::QuicServerId quic_server_id(host_port_pair_.host(), |
| 7689 | host_port_pair_.port(), |
| 7690 | privacy_mode_ == PRIVACY_MODE_ENABLED); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7691 | QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 7692 | |
| 7693 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 7694 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7695 | |
| 7696 | // Start CertVerifyJob. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7697 | quic::QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7698 | factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7699 | if (status == quic::QUIC_PENDING) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7700 | // Verify CertVerifierJob has started. |
| 7701 | EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 7702 | |
| 7703 | while (HasActiveCertVerifierJob(quic_server_id)) { |
| 7704 | base::RunLoop().RunUntilIdle(); |
| 7705 | } |
| 7706 | } |
| 7707 | // Verify CertVerifierJob has finished. |
| 7708 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7709 | |
| 7710 | // Start a QUIC request. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7711 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7712 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7713 | request.Request( |
| 7714 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7715 | SocketTag(), |
| 7716 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7717 | failed_on_default_network_callback_, callback_.callback())); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7718 | |
| 7719 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7720 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7721 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7722 | EXPECT_TRUE(stream.get()); |
| 7723 | |
| 7724 | // Restore |race_cert_verification|. |
| 7725 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 7726 | race_cert_verification); |
| 7727 | |
| 7728 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7729 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7730 | |
| 7731 | // Verify there are no outstanding CertVerifierJobs after request has |
| 7732 | // finished. |
| 7733 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7734 | } |
| 7735 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7736 | TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7737 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7738 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7739 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7740 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7741 | QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7742 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7743 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7744 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(0)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7745 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7746 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7747 | |
| 7748 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7749 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7750 | host_resolver_->set_synchronous_mode(true); |
| 7751 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7752 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7753 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7754 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7755 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7756 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7757 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7758 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7759 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7760 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7761 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7762 | DEFAULT_PRIORITY, SocketTag(), |
| 7763 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7764 | &net_error_details_, |
| 7765 | failed_on_default_network_callback_, |
| 7766 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7767 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7768 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7769 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7770 | base::RunLoop run_loop; |
| 7771 | run_loop.RunUntilIdle(); |
| 7772 | |
| 7773 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7774 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7775 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7776 | EXPECT_EQ(1u, observer.executed_count()); |
| 7777 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7778 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7779 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7780 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7781 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7782 | } |
| 7783 | |
| 7784 | TEST_P(QuicStreamFactoryTest, YieldAfterDuration) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7785 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7786 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7787 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7788 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7789 | QuicStreamFactoryPeer::SetYieldAfterDuration( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7790 | factory_.get(), quic::QuicTime::Delta::FromMilliseconds(-1)); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7791 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7792 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7793 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(0)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7794 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7795 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7796 | |
| 7797 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7798 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7799 | host_resolver_->set_synchronous_mode(true); |
| 7800 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7801 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7802 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7803 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7804 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7805 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7806 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7807 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7808 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7809 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7810 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7811 | DEFAULT_PRIORITY, SocketTag(), |
| 7812 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7813 | &net_error_details_, |
| 7814 | failed_on_default_network_callback_, |
| 7815 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7816 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7817 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7818 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7819 | base::RunLoop run_loop; |
| 7820 | run_loop.RunUntilIdle(); |
| 7821 | |
| 7822 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7823 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7824 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7825 | EXPECT_EQ(1u, observer.executed_count()); |
| 7826 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7827 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7828 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7829 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7830 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7831 | } |
| 7832 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7833 | TEST_P(QuicStreamFactoryTest, ServerPushSessionAffinity) { |
| 7834 | Initialize(); |
| 7835 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7836 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7837 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7838 | MockQuicData socket_data; |
| 7839 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7840 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7841 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7842 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7843 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7844 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7845 | request.Request( |
| 7846 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7847 | SocketTag(), |
| 7848 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7849 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7850 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7851 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7852 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7853 | EXPECT_TRUE(stream.get()); |
| 7854 | |
| 7855 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7856 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 7857 | string url = "https://www.example.org/"; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7858 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 7859 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7860 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7861 | quic::QuicClientPromisedInfo promised( |
| 7862 | session, GetNthServerInitiatedStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7863 | (*QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()) |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7864 | ->promised_by_url())[kDefaultUrl] = &promised; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7865 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7866 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 7867 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7868 | DEFAULT_PRIORITY, SocketTag(), |
| 7869 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7870 | &net_error_details_, |
| 7871 | failed_on_default_network_callback_, |
| 7872 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7873 | |
| 7874 | EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7875 | } |
| 7876 | |
| 7877 | TEST_P(QuicStreamFactoryTest, ServerPushPrivacyModeMismatch) { |
| 7878 | Initialize(); |
| 7879 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7880 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7881 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7882 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7883 | MockQuicData socket_data1; |
| 7884 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7885 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7886 | socket_data1.AddWrite( |
| 7887 | SYNCHRONOUS, |
| 7888 | client_maker_.MakeRstPacket(2, true, GetNthServerInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7889 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7890 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7891 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7892 | MockQuicData socket_data2; |
| 7893 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7894 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7895 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7896 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7897 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7898 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7899 | request.Request( |
| 7900 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7901 | SocketTag(), |
| 7902 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7903 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7904 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7905 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7906 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7907 | EXPECT_TRUE(stream.get()); |
| 7908 | |
| 7909 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7910 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 7911 | string url = "https://www.example.org/"; |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 7912 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7913 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7914 | quic::QuicClientPromisedInfo promised( |
| 7915 | session, GetNthServerInitiatedStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7916 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7917 | quic::QuicClientPushPromiseIndex* index = |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7918 | QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()); |
| 7919 | |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7920 | (*index->promised_by_url())[kDefaultUrl] = &promised; |
| 7921 | EXPECT_EQ(index->GetPromised(kDefaultUrl), &promised); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7922 | |
| 7923 | // Doing the request should not use the push stream, but rather |
| 7924 | // cancel it because the privacy modes do not match. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7925 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7926 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7927 | request2.Request( |
| 7928 | host_port_pair_, version_, PRIVACY_MODE_ENABLED, |
| 7929 | DEFAULT_PRIORITY, SocketTag(), |
| 7930 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7931 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7932 | |
| 7933 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7934 | EXPECT_EQ(index->GetPromised(kDefaultUrl), nullptr); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7935 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7936 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7937 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7938 | EXPECT_TRUE(stream2.get()); |
| 7939 | |
| 7940 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7941 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7942 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7943 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7944 | } |
| 7945 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7946 | // Pool to existing session with matching quic::QuicServerId |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7947 | // even if destination is different. |
| 7948 | TEST_P(QuicStreamFactoryTest, PoolByOrigin) { |
| 7949 | Initialize(); |
| 7950 | |
| 7951 | HostPortPair destination1("first.example.com", 443); |
| 7952 | HostPortPair destination2("second.example.com", 443); |
| 7953 | |
| 7954 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7955 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7956 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7957 | MockQuicData socket_data; |
| 7958 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7959 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7960 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7961 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7962 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7963 | EXPECT_EQ( |
| 7964 | ERR_IO_PENDING, |
| 7965 | request1.Request( |
| 7966 | destination1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 7967 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7968 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7969 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7970 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7971 | EXPECT_TRUE(stream1.get()); |
| 7972 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7973 | |
| 7974 | // Second request returns synchronously because it pools to existing session. |
| 7975 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7976 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 7977 | EXPECT_EQ(OK, request2.Request(destination2, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7978 | DEFAULT_PRIORITY, SocketTag(), |
| 7979 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7980 | &net_error_details_, |
| 7981 | failed_on_default_network_callback_, |
| 7982 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7983 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7984 | EXPECT_TRUE(stream2.get()); |
| 7985 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 7986 | QuicChromiumClientSession::Handle* session1 = |
| 7987 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 7988 | QuicChromiumClientSession::Handle* session2 = |
| 7989 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 7990 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7991 | EXPECT_EQ(quic::QuicServerId(host_port_pair_.host(), host_port_pair_.port(), |
| 7992 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7993 | session1->server_id()); |
| 7994 | |
| 7995 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7996 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7997 | } |
| 7998 | |
| 7999 | class QuicStreamFactoryWithDestinationTest |
| 8000 | : public QuicStreamFactoryTestBase, |
| 8001 | public ::testing::TestWithParam<PoolingTestParams> { |
| 8002 | protected: |
| 8003 | QuicStreamFactoryWithDestinationTest() |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 8004 | : QuicStreamFactoryTestBase( |
| 8005 | GetParam().version, |
| 8006 | GetParam().client_headers_include_h2_stream_dependency), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8007 | destination_type_(GetParam().destination_type), |
| 8008 | hanging_read_(SYNCHRONOUS, ERR_IO_PENDING, 0) {} |
| 8009 | |
| 8010 | HostPortPair GetDestination() { |
| 8011 | switch (destination_type_) { |
| 8012 | case SAME_AS_FIRST: |
| 8013 | return origin1_; |
| 8014 | case SAME_AS_SECOND: |
| 8015 | return origin2_; |
| 8016 | case DIFFERENT: |
| 8017 | return HostPortPair(kDifferentHostname, 443); |
| 8018 | default: |
| 8019 | NOTREACHED(); |
| 8020 | return HostPortPair(); |
| 8021 | } |
| 8022 | } |
| 8023 | |
| 8024 | void AddHangingSocketData() { |
| 8025 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8026 | new SequencedSocketData(base::make_span(&hanging_read_, 1), |
| 8027 | base::span<MockWrite>())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8028 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8029 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8030 | } |
| 8031 | |
| 8032 | bool AllDataConsumed() { |
| 8033 | for (const auto& socket_data_ptr : sequenced_socket_data_vector_) { |
| 8034 | if (!socket_data_ptr->AllReadDataConsumed() || |
| 8035 | !socket_data_ptr->AllWriteDataConsumed()) { |
| 8036 | return false; |
| 8037 | } |
| 8038 | } |
| 8039 | return true; |
| 8040 | } |
| 8041 | |
| 8042 | DestinationType destination_type_; |
| 8043 | HostPortPair origin1_; |
| 8044 | HostPortPair origin2_; |
| 8045 | MockRead hanging_read_; |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8046 | std::vector<std::unique_ptr<SequencedSocketData>> |
| 8047 | sequenced_socket_data_vector_; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8048 | }; |
| 8049 | |
Bence Béky | ce380cb | 2018-04-26 23:39:55 | [diff] [blame] | 8050 | INSTANTIATE_TEST_CASE_P(VersionIncludeStreamDependencySequence, |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8051 | QuicStreamFactoryWithDestinationTest, |
| 8052 | ::testing::ValuesIn(GetPoolingTestParams())); |
| 8053 | |
| 8054 | // A single QUIC request fails because the certificate does not match the origin |
| 8055 | // hostname, regardless of whether it matches the alternative service hostname. |
| 8056 | TEST_P(QuicStreamFactoryWithDestinationTest, InvalidCertificate) { |
| 8057 | if (destination_type_ == DIFFERENT) |
| 8058 | return; |
| 8059 | |
| 8060 | Initialize(); |
| 8061 | |
| 8062 | GURL url("https://mail.example.com/"); |
| 8063 | origin1_ = HostPortPair::FromURL(url); |
| 8064 | |
| 8065 | // Not used for requests, but this provides a test case where the certificate |
| 8066 | // is valid for the hostname of the alternative service. |
| 8067 | origin2_ = HostPortPair("mail.example.org", 433); |
| 8068 | |
| 8069 | HostPortPair destination = GetDestination(); |
| 8070 | |
| 8071 | scoped_refptr<X509Certificate> cert( |
| 8072 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8073 | ASSERT_FALSE(cert->VerifyNameMatch(origin1_.host())); |
| 8074 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8075 | |
| 8076 | ProofVerifyDetailsChromium verify_details; |
| 8077 | verify_details.cert_verify_result.verified_cert = cert; |
| 8078 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8079 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8080 | |
| 8081 | AddHangingSocketData(); |
| 8082 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8083 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8084 | EXPECT_EQ( |
| 8085 | ERR_IO_PENDING, |
| 8086 | request.Request( |
| 8087 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8088 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 8089 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8090 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8091 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_QUIC_HANDSHAKE_FAILED)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8092 | |
| 8093 | EXPECT_TRUE(AllDataConsumed()); |
| 8094 | } |
| 8095 | |
| 8096 | // QuicStreamRequest is pooled based on |destination| if certificate matches. |
| 8097 | TEST_P(QuicStreamFactoryWithDestinationTest, SharedCertificate) { |
| 8098 | Initialize(); |
| 8099 | |
| 8100 | GURL url1("https://www.example.org/"); |
| 8101 | GURL url2("https://mail.example.org/"); |
| 8102 | origin1_ = HostPortPair::FromURL(url1); |
| 8103 | origin2_ = HostPortPair::FromURL(url2); |
| 8104 | |
| 8105 | HostPortPair destination = GetDestination(); |
| 8106 | |
| 8107 | scoped_refptr<X509Certificate> cert( |
| 8108 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8109 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8110 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8111 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8112 | |
| 8113 | ProofVerifyDetailsChromium verify_details; |
| 8114 | verify_details.cert_verify_result.verified_cert = cert; |
| 8115 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8116 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8117 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8118 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8119 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8120 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8121 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8122 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8123 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8124 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8125 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8126 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8127 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8128 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8129 | EXPECT_EQ( |
| 8130 | ERR_IO_PENDING, |
| 8131 | request1.Request( |
| 8132 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8133 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8134 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8135 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8136 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8137 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8138 | EXPECT_TRUE(stream1.get()); |
| 8139 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8140 | |
| 8141 | // Second request returns synchronously because it pools to existing session. |
| 8142 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8143 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8144 | EXPECT_EQ(OK, request2.Request(destination, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8145 | DEFAULT_PRIORITY, SocketTag(), |
| 8146 | /*cert_verify_flags=*/0, url2, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8147 | &net_error_details_, |
| 8148 | failed_on_default_network_callback_, |
| 8149 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8150 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8151 | EXPECT_TRUE(stream2.get()); |
| 8152 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8153 | QuicChromiumClientSession::Handle* session1 = |
| 8154 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8155 | QuicChromiumClientSession::Handle* session2 = |
| 8156 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8157 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8158 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8159 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8160 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8161 | session1->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8162 | |
| 8163 | EXPECT_TRUE(AllDataConsumed()); |
| 8164 | } |
| 8165 | |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8166 | // QuicStreamRequest is not pooled if PrivacyMode differs. |
| 8167 | TEST_P(QuicStreamFactoryWithDestinationTest, DifferentPrivacyMode) { |
| 8168 | Initialize(); |
| 8169 | |
| 8170 | GURL url1("https://www.example.org/"); |
| 8171 | GURL url2("https://mail.example.org/"); |
| 8172 | origin1_ = HostPortPair::FromURL(url1); |
| 8173 | origin2_ = HostPortPair::FromURL(url2); |
| 8174 | |
| 8175 | HostPortPair destination = GetDestination(); |
| 8176 | |
| 8177 | scoped_refptr<X509Certificate> cert( |
| 8178 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8179 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8180 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8181 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8182 | |
| 8183 | ProofVerifyDetailsChromium verify_details1; |
| 8184 | verify_details1.cert_verify_result.verified_cert = cert; |
| 8185 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8186 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8187 | |
| 8188 | ProofVerifyDetailsChromium verify_details2; |
| 8189 | verify_details2.cert_verify_result.verified_cert = cert; |
| 8190 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8191 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8192 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8193 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8194 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8195 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8196 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8197 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8198 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8199 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8200 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8201 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8202 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8203 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8204 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8205 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8206 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8207 | QuicStreamRequest request1(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8208 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8209 | request1.Request( |
| 8210 | destination, version_, PRIVACY_MODE_DISABLED, DEFAULT_PRIORITY, |
| 8211 | SocketTag(), |
| 8212 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8213 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8214 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8215 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8216 | EXPECT_TRUE(stream1.get()); |
| 8217 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8218 | |
| 8219 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8220 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8221 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8222 | request2.Request( |
| 8223 | destination, version_, PRIVACY_MODE_ENABLED, DEFAULT_PRIORITY, |
| 8224 | SocketTag(), |
| 8225 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8226 | failed_on_default_network_callback_, callback2.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8227 | EXPECT_EQ(OK, callback2.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8228 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8229 | EXPECT_TRUE(stream2.get()); |
| 8230 | |
| 8231 | // |request2| does not pool to the first session, because PrivacyMode does not |
| 8232 | // match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8233 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8234 | QuicChromiumClientSession::Handle* session1 = |
| 8235 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8236 | QuicChromiumClientSession::Handle* session2 = |
| 8237 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8238 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8239 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8240 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), false), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8241 | session1->server_id()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8242 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), true), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8243 | session2->server_id()); |
| 8244 | |
| 8245 | EXPECT_TRUE(AllDataConsumed()); |
| 8246 | } |
| 8247 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8248 | // QuicStreamRequest is not pooled if certificate does not match its origin. |
| 8249 | TEST_P(QuicStreamFactoryWithDestinationTest, DisjointCertificate) { |
| 8250 | Initialize(); |
| 8251 | |
| 8252 | GURL url1("https://news.example.org/"); |
| 8253 | GURL url2("https://mail.example.com/"); |
| 8254 | origin1_ = HostPortPair::FromURL(url1); |
| 8255 | origin2_ = HostPortPair::FromURL(url2); |
| 8256 | |
| 8257 | HostPortPair destination = GetDestination(); |
| 8258 | |
| 8259 | scoped_refptr<X509Certificate> cert1( |
| 8260 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8261 | ASSERT_TRUE(cert1->VerifyNameMatch(origin1_.host())); |
| 8262 | ASSERT_FALSE(cert1->VerifyNameMatch(origin2_.host())); |
| 8263 | ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8264 | |
| 8265 | ProofVerifyDetailsChromium verify_details1; |
| 8266 | verify_details1.cert_verify_result.verified_cert = cert1; |
| 8267 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8268 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8269 | |
| 8270 | scoped_refptr<X509Certificate> cert2( |
| 8271 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8272 | ASSERT_TRUE(cert2->VerifyNameMatch(origin2_.host())); |
| 8273 | ASSERT_FALSE(cert2->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8274 | |
| 8275 | ProofVerifyDetailsChromium verify_details2; |
| 8276 | verify_details2.cert_verify_result.verified_cert = cert2; |
| 8277 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8278 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8279 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8280 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8281 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8282 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8283 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8284 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8285 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8286 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8287 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8288 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8289 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8290 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8291 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8292 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8293 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8294 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8295 | EXPECT_EQ( |
| 8296 | ERR_IO_PENDING, |
| 8297 | request1.Request( |
| 8298 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8299 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8300 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8301 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8302 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8303 | EXPECT_TRUE(stream1.get()); |
| 8304 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8305 | |
| 8306 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8307 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8308 | EXPECT_EQ( |
| 8309 | ERR_IO_PENDING, |
| 8310 | request2.Request( |
| 8311 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8312 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8313 | failed_on_default_network_callback_, callback2.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8314 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8315 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8316 | EXPECT_TRUE(stream2.get()); |
| 8317 | |
| 8318 | // |request2| does not pool to the first session, because the certificate does |
| 8319 | // not match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8320 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8321 | QuicChromiumClientSession::Handle* session1 = |
| 8322 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8323 | QuicChromiumClientSession::Handle* session2 = |
| 8324 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8325 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8326 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8327 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8328 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8329 | session1->server_id()); |
| 8330 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), |
| 8331 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8332 | session2->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8333 | |
| 8334 | EXPECT_TRUE(AllDataConsumed()); |
| 8335 | } |
| 8336 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8337 | // This test verifies that QuicStreamFactory::ClearCachedStatesInCryptoConfig |
| 8338 | // correctly transform an origin filter to a ServerIdFilter. Whether the |
| 8339 | // deletion itself works correctly is tested in QuicCryptoClientConfigTest. |
| 8340 | TEST_P(QuicStreamFactoryTest, ClearCachedStatesInCryptoConfig) { |
| 8341 | Initialize(); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8342 | quic::QuicCryptoClientConfig* crypto_config = |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8343 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 8344 | |
| 8345 | struct TestCase { |
| 8346 | TestCase(const std::string& host, |
| 8347 | int port, |
| 8348 | PrivacyMode privacy_mode, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8349 | quic::QuicCryptoClientConfig* crypto_config) |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8350 | : server_id(host, port, privacy_mode), |
| 8351 | state(crypto_config->LookupOrCreate(server_id)) { |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8352 | std::vector<string> certs(1); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8353 | certs[0] = "cert"; |
| 8354 | state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); |
| 8355 | state->set_source_address_token("TOKEN"); |
| 8356 | state->SetProofValid(); |
| 8357 | |
| 8358 | EXPECT_FALSE(state->certs().empty()); |
| 8359 | } |
| 8360 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8361 | quic::QuicServerId server_id; |
| 8362 | quic::QuicCryptoClientConfig::CachedState* state; |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8363 | } test_cases[] = { |
| 8364 | TestCase("www.google.com", 443, privacy_mode_, crypto_config), |
| 8365 | TestCase("www.example.com", 443, privacy_mode_, crypto_config), |
| 8366 | TestCase("www.example.com", 4433, privacy_mode_, crypto_config)}; |
| 8367 | |
| 8368 | // Clear cached states for the origin https://www.example.com:4433. |
| 8369 | GURL origin("https://www.example.com:4433"); |
csharrison | ebeca8e | 2016-10-18 02:35:36 | [diff] [blame] | 8370 | factory_->ClearCachedStatesInCryptoConfig(base::Bind( |
| 8371 | static_cast<bool (*)(const GURL&, const GURL&)>(::operator==), origin)); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8372 | EXPECT_FALSE(test_cases[0].state->certs().empty()); |
| 8373 | EXPECT_FALSE(test_cases[1].state->certs().empty()); |
| 8374 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8375 | |
| 8376 | // Clear all cached states. |
| 8377 | factory_->ClearCachedStatesInCryptoConfig( |
| 8378 | base::Callback<bool(const GURL&)>()); |
| 8379 | EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 8380 | EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 8381 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8382 | } |
| 8383 | |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8384 | // Passes connection options and client connection options to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8385 | // then checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8386 | TEST_P(QuicStreamFactoryTest, ConfigConnectionOptions) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8387 | connection_options_.push_back(quic::kTIME); |
| 8388 | connection_options_.push_back(quic::kTBBR); |
| 8389 | connection_options_.push_back(quic::kREJ); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8390 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8391 | client_connection_options_.push_back(quic::kTBBR); |
| 8392 | client_connection_options_.push_back(quic::k1RTT); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8393 | |
| 8394 | Initialize(); |
| 8395 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8396 | const quic::QuicConfig* config = |
| 8397 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8398 | EXPECT_EQ(connection_options_, config->SendConnectionOptions()); |
| 8399 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8400 | quic::kTBBR, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8401 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8402 | quic::k1RTT, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8403 | } |
| 8404 | |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8405 | // Verifies that the host resolver uses the request priority passed to |
| 8406 | // QuicStreamRequest::Request(). |
| 8407 | TEST_P(QuicStreamFactoryTest, HostResolverUsesRequestPriority) { |
| 8408 | Initialize(); |
| 8409 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8410 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8411 | |
| 8412 | MockQuicData socket_data; |
| 8413 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8414 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8415 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8416 | |
| 8417 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8418 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8419 | request.Request( |
| 8420 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8421 | SocketTag(), |
| 8422 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8423 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8424 | |
| 8425 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8426 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8427 | EXPECT_TRUE(stream.get()); |
| 8428 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8429 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8430 | |
| 8431 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8432 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8433 | } |
| 8434 | |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8435 | // Passes |max_time_before_crypto_handshake_seconds| and |
| 8436 | // |max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, then |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8437 | // checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8438 | TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { |
| 8439 | max_time_before_crypto_handshake_seconds_ = 11; |
| 8440 | max_idle_time_before_crypto_handshake_seconds_ = 13; |
| 8441 | |
| 8442 | Initialize(); |
| 8443 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8444 | const quic::QuicConfig* config = |
| 8445 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 8446 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(11), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8447 | config->max_time_before_crypto_handshake()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8448 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(13), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8449 | config->max_idle_time_before_crypto_handshake()); |
| 8450 | } |
| 8451 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8452 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8453 | // succeeds asynchronously, then crypto handshake fails synchronously. |
| 8454 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncSync) { |
| 8455 | Initialize(); |
| 8456 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8457 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8458 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8459 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8460 | |
| 8461 | MockQuicData socket_data; |
| 8462 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8463 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8464 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8465 | |
| 8466 | QuicStreamRequest request(factory_.get()); |
| 8467 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8468 | request.Request( |
| 8469 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8470 | SocketTag(), |
| 8471 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8472 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8473 | |
| 8474 | TestCompletionCallback host_resolution_callback; |
| 8475 | EXPECT_TRUE( |
| 8476 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8477 | |
| 8478 | // |host_resolver_| has not finished host resolution at this point, so |
| 8479 | // |host_resolution_callback| should not have a result. |
| 8480 | base::RunLoop().RunUntilIdle(); |
| 8481 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8482 | |
| 8483 | // Allow |host_resolver_| to finish host resolution. |
| 8484 | // Since the request fails immediately after host resolution (getting |
| 8485 | // ERR_FAILED from socket reads/writes), |host_resolution_callback| should be |
| 8486 | // called with ERR_QUIC_PROTOCOL_ERROR since that's the next result in |
| 8487 | // forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8488 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8489 | base::RunLoop().RunUntilIdle(); |
| 8490 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8491 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, host_resolution_callback.WaitForResult()); |
| 8492 | |
| 8493 | // Calling WaitForHostResolution() a second time should return |
| 8494 | // false since host resolution has finished already. |
| 8495 | EXPECT_FALSE( |
| 8496 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8497 | |
| 8498 | EXPECT_TRUE(callback_.have_result()); |
| 8499 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8500 | } |
| 8501 | |
| 8502 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8503 | // succeeds asynchronously, then crypto handshake fails asynchronously. |
| 8504 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncAsync) { |
| 8505 | Initialize(); |
| 8506 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8507 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8508 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8509 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8510 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8511 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8512 | factory_->set_require_confirmation(true); |
| 8513 | |
| 8514 | MockQuicData socket_data; |
| 8515 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8516 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8517 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8518 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8519 | |
| 8520 | QuicStreamRequest request(factory_.get()); |
| 8521 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8522 | request.Request( |
| 8523 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8524 | SocketTag(), |
| 8525 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8526 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8527 | |
| 8528 | TestCompletionCallback host_resolution_callback; |
| 8529 | EXPECT_TRUE( |
| 8530 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8531 | |
| 8532 | // |host_resolver_| has not finished host resolution at this point, so |
| 8533 | // |host_resolution_callback| should not have a result. |
| 8534 | base::RunLoop().RunUntilIdle(); |
| 8535 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8536 | |
| 8537 | // Allow |host_resolver_| to finish host resolution. Since crypto handshake |
| 8538 | // will hang after host resolution, |host_resolution_callback| should run with |
| 8539 | // ERR_IO_PENDING since that's the next result in forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8540 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8541 | base::RunLoop().RunUntilIdle(); |
| 8542 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8543 | EXPECT_EQ(ERR_IO_PENDING, host_resolution_callback.WaitForResult()); |
| 8544 | |
| 8545 | // Calling WaitForHostResolution() a second time should return |
| 8546 | // false since host resolution has finished already. |
| 8547 | EXPECT_FALSE( |
| 8548 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8549 | |
| 8550 | EXPECT_FALSE(callback_.have_result()); |
| 8551 | socket_data.GetSequencedSocketData()->Resume(); |
| 8552 | base::RunLoop().RunUntilIdle(); |
| 8553 | EXPECT_TRUE(callback_.have_result()); |
| 8554 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8555 | } |
| 8556 | |
| 8557 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8558 | // succeeds synchronously, then crypto handshake fails synchronously. |
| 8559 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncSync) { |
| 8560 | Initialize(); |
| 8561 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8562 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8563 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8564 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8565 | |
| 8566 | MockQuicData socket_data; |
| 8567 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8568 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8569 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8570 | |
| 8571 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8572 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8573 | request.Request( |
| 8574 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8575 | SocketTag(), |
| 8576 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8577 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8578 | |
| 8579 | // WaitForHostResolution() should return false since host |
| 8580 | // resolution has finished already. |
| 8581 | TestCompletionCallback host_resolution_callback; |
| 8582 | EXPECT_FALSE( |
| 8583 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8584 | base::RunLoop().RunUntilIdle(); |
| 8585 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8586 | EXPECT_FALSE(callback_.have_result()); |
| 8587 | } |
| 8588 | |
| 8589 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8590 | // succeeds synchronously, then crypto handshake fails asynchronously. |
| 8591 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncAsync) { |
| 8592 | Initialize(); |
| 8593 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8594 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8595 | |
| 8596 | // Host resolution will succeed synchronously, but Request() as a whole |
| 8597 | // will fail asynchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8598 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8599 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8600 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8601 | factory_->set_require_confirmation(true); |
| 8602 | |
| 8603 | MockQuicData socket_data; |
| 8604 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8605 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8606 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8607 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8608 | |
| 8609 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8610 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8611 | request.Request( |
| 8612 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8613 | SocketTag(), |
| 8614 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8615 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8616 | |
| 8617 | // WaitForHostResolution() should return false since host |
| 8618 | // resolution has finished already. |
| 8619 | TestCompletionCallback host_resolution_callback; |
| 8620 | EXPECT_FALSE( |
| 8621 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8622 | base::RunLoop().RunUntilIdle(); |
| 8623 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8624 | |
| 8625 | EXPECT_FALSE(callback_.have_result()); |
| 8626 | socket_data.GetSequencedSocketData()->Resume(); |
| 8627 | base::RunLoop().RunUntilIdle(); |
| 8628 | EXPECT_TRUE(callback_.have_result()); |
| 8629 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8630 | } |
| 8631 | |
| 8632 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8633 | // synchronously. |
| 8634 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailSync) { |
| 8635 | Initialize(); |
| 8636 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8637 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8638 | |
| 8639 | // Host resolution will fail synchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8640 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 8641 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8642 | |
| 8643 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8644 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8645 | request.Request( |
| 8646 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8647 | SocketTag(), |
| 8648 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8649 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8650 | |
| 8651 | // WaitForHostResolution() should return false since host |
| 8652 | // resolution has failed already. |
| 8653 | TestCompletionCallback host_resolution_callback; |
| 8654 | EXPECT_FALSE( |
| 8655 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8656 | base::RunLoop().RunUntilIdle(); |
| 8657 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8658 | } |
| 8659 | |
| 8660 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8661 | // asynchronously. |
| 8662 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { |
| 8663 | Initialize(); |
| 8664 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8665 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8666 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8667 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8668 | |
| 8669 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8670 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8671 | request.Request( |
| 8672 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8673 | SocketTag(), |
| 8674 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8675 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8676 | |
| 8677 | TestCompletionCallback host_resolution_callback; |
| 8678 | EXPECT_TRUE( |
| 8679 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8680 | |
| 8681 | // Allow |host_resolver_| to fail host resolution. |host_resolution_callback| |
| 8682 | // Should run with ERR_NAME_NOT_RESOLVED since that's the error host |
| 8683 | // resolution failed with. |
| 8684 | base::RunLoop().RunUntilIdle(); |
| 8685 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8686 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, host_resolution_callback.WaitForResult()); |
| 8687 | |
| 8688 | EXPECT_TRUE(callback_.have_result()); |
| 8689 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 8690 | } |
| 8691 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8692 | // With dns race experiment turned on, and DNS resolve succeeds synchronously, |
| 8693 | // the final connection is established through the resolved DNS. No racing |
| 8694 | // connection. |
| 8695 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { |
| 8696 | race_stale_dns_on_connection_ = true; |
| 8697 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8698 | Initialize(); |
| 8699 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8700 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8701 | |
| 8702 | // Set an address in resolver for synchronous return. |
| 8703 | host_resolver_->set_synchronous_mode(true); |
| 8704 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8705 | kNonCachedIPAddress, ""); |
| 8706 | |
| 8707 | // Set up a different address in stale resolver cache. |
| 8708 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8709 | HostCache::Entry entry(OK, |
| 8710 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8711 | HostCache::Entry::SOURCE_DNS); |
| 8712 | base::TimeDelta zero; |
| 8713 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8714 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8715 | // Expire the cache |
| 8716 | cache->OnNetworkChange(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 8717 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8718 | MockQuicData quic_data; |
| 8719 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8720 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8721 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8722 | |
| 8723 | QuicStreamRequest request(factory_.get()); |
| 8724 | EXPECT_THAT(request.Request( |
| 8725 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8726 | SocketTag(), |
| 8727 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8728 | failed_on_default_network_callback_, callback_.callback()), |
| 8729 | IsOk()); |
| 8730 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8731 | EXPECT_TRUE(stream.get()); |
| 8732 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8733 | EXPECT_EQ( |
| 8734 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8735 | kNonCachedIPAddress); |
| 8736 | |
| 8737 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8738 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8739 | } |
| 8740 | |
| 8741 | // With dns race experiment on, DNS resolve returns async, no matching cache in |
| 8742 | // host resolver, connection should be successful and through resolved DNS. No |
| 8743 | // racing connection. |
| 8744 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { |
| 8745 | race_stale_dns_on_connection_ = true; |
| 8746 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8747 | Initialize(); |
| 8748 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8749 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8750 | |
| 8751 | // Set an address in resolver for asynchronous return. |
| 8752 | host_resolver_->set_ondemand_mode(true); |
| 8753 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8754 | kNonCachedIPAddress, ""); |
| 8755 | |
| 8756 | MockQuicData quic_data; |
| 8757 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8758 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8759 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8760 | |
| 8761 | QuicStreamRequest request(factory_.get()); |
| 8762 | EXPECT_EQ(ERR_IO_PENDING, |
| 8763 | request.Request( |
| 8764 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8765 | SocketTag(), |
| 8766 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8767 | failed_on_default_network_callback_, callback_.callback())); |
| 8768 | TestCompletionCallback host_resolution_callback; |
| 8769 | EXPECT_TRUE( |
| 8770 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8771 | base::RunLoop().RunUntilIdle(); |
| 8772 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8773 | |
| 8774 | // Cause the host resolution to return. |
| 8775 | host_resolver_->ResolveAllPending(); |
| 8776 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 8777 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8778 | |
| 8779 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8780 | EXPECT_TRUE(stream.get()); |
| 8781 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8782 | |
| 8783 | EXPECT_EQ( |
| 8784 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8785 | kNonCachedIPAddress); |
| 8786 | |
| 8787 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8788 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8789 | } |
| 8790 | |
| 8791 | // With dns race experiment on, DNS resolve returns async, stale dns used, |
| 8792 | // connects synchrounously, and then the resolved DNS matches. |
| 8793 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { |
| 8794 | race_stale_dns_on_connection_ = true; |
| 8795 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8796 | Initialize(); |
| 8797 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8798 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8799 | |
| 8800 | // Set an address in resolver for asynchronous return. |
| 8801 | host_resolver_->set_ondemand_mode(true); |
| 8802 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8803 | kCachedIPAddress.ToString(), ""); |
| 8804 | |
| 8805 | // Set up the same address in the stale resolver cache. |
| 8806 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8807 | HostCache::Entry entry(OK, |
| 8808 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8809 | HostCache::Entry::SOURCE_DNS); |
| 8810 | base::TimeDelta zero; |
| 8811 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8812 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8813 | // Expire the cache |
| 8814 | cache->OnNetworkChange(); |
| 8815 | |
| 8816 | MockQuicData quic_data; |
| 8817 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8818 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8819 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8820 | |
| 8821 | QuicStreamRequest request(factory_.get()); |
| 8822 | EXPECT_EQ(ERR_IO_PENDING, |
| 8823 | request.Request( |
| 8824 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8825 | SocketTag(), |
| 8826 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8827 | failed_on_default_network_callback_, callback_.callback())); |
| 8828 | |
| 8829 | // Check that the racing job is running. |
| 8830 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8831 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8832 | |
| 8833 | // Resolve dns and return. |
| 8834 | host_resolver_->ResolveAllPending(); |
| 8835 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8836 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8837 | EXPECT_TRUE(stream.get()); |
| 8838 | |
| 8839 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8840 | |
| 8841 | EXPECT_EQ( |
| 8842 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8843 | kCachedIPAddress.ToString()); |
| 8844 | |
| 8845 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8846 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8847 | } |
| 8848 | |
| 8849 | // With dns race experiment on, dns resolve async, stale dns used, connect |
| 8850 | // async, and then the result matches. |
| 8851 | TEST_P(QuicStreamFactoryTest, |
| 8852 | ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { |
| 8853 | race_stale_dns_on_connection_ = true; |
| 8854 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8855 | Initialize(); |
| 8856 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8857 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8858 | |
| 8859 | // Set an address in resolver for asynchronous return. |
| 8860 | host_resolver_->set_ondemand_mode(true); |
| 8861 | factory_->set_require_confirmation(true); |
| 8862 | crypto_client_stream_factory_.set_handshake_mode( |
| 8863 | MockCryptoClientStream::ZERO_RTT); |
| 8864 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8865 | kCachedIPAddress.ToString(), ""); |
| 8866 | |
| 8867 | // Set up the same address in the stale resolver cache. |
| 8868 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8869 | HostCache::Entry entry(OK, |
| 8870 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8871 | HostCache::Entry::SOURCE_DNS); |
| 8872 | base::TimeDelta zero; |
| 8873 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8874 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8875 | // Expire the cache |
| 8876 | cache->OnNetworkChange(); |
| 8877 | |
| 8878 | MockQuicData quic_data; |
| 8879 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8880 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8881 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8882 | |
| 8883 | QuicStreamRequest request(factory_.get()); |
| 8884 | EXPECT_EQ(ERR_IO_PENDING, |
| 8885 | request.Request( |
| 8886 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8887 | SocketTag(), |
| 8888 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8889 | failed_on_default_network_callback_, callback_.callback())); |
| 8890 | |
| 8891 | // Send Crypto handshake so connect will call back. |
| 8892 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 8893 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 8894 | base::RunLoop().RunUntilIdle(); |
| 8895 | |
| 8896 | // Check that the racing job is running. |
| 8897 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8898 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8899 | |
| 8900 | // Resolve dns and call back, make sure job finishes. |
| 8901 | host_resolver_->ResolveAllPending(); |
| 8902 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8903 | |
| 8904 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8905 | EXPECT_TRUE(stream.get()); |
| 8906 | |
| 8907 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8908 | |
| 8909 | EXPECT_EQ( |
| 8910 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8911 | kCachedIPAddress.ToString()); |
| 8912 | |
| 8913 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8914 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8915 | } |
| 8916 | |
| 8917 | // With dns race experiment on, dns resolve async, stale dns used, dns resolve |
| 8918 | // return, then connection finishes and matches with the result. |
| 8919 | TEST_P(QuicStreamFactoryTest, |
| 8920 | ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { |
| 8921 | race_stale_dns_on_connection_ = true; |
| 8922 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8923 | Initialize(); |
| 8924 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8925 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8926 | |
| 8927 | // Set an address in resolver for asynchronous return. |
| 8928 | host_resolver_->set_ondemand_mode(true); |
| 8929 | factory_->set_require_confirmation(true); |
| 8930 | crypto_client_stream_factory_.set_handshake_mode( |
| 8931 | MockCryptoClientStream::ZERO_RTT); |
| 8932 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8933 | kCachedIPAddress.ToString(), ""); |
| 8934 | |
| 8935 | // Set up the same address in the stale resolver cache. |
| 8936 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8937 | HostCache::Entry entry(OK, |
| 8938 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8939 | HostCache::Entry::SOURCE_DNS); |
| 8940 | base::TimeDelta zero; |
| 8941 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8942 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8943 | // Expire the cache |
| 8944 | cache->OnNetworkChange(); |
| 8945 | |
| 8946 | MockQuicData quic_data; |
| 8947 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8948 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8949 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8950 | |
| 8951 | QuicStreamRequest request(factory_.get()); |
| 8952 | EXPECT_EQ(ERR_IO_PENDING, |
| 8953 | request.Request( |
| 8954 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8955 | SocketTag(), |
| 8956 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8957 | failed_on_default_network_callback_, callback_.callback())); |
| 8958 | |
| 8959 | // Finish dns async, check we still need to wait for stale connection async. |
| 8960 | host_resolver_->ResolveAllPending(); |
| 8961 | base::RunLoop().RunUntilIdle(); |
| 8962 | EXPECT_FALSE(callback_.have_result()); |
| 8963 | |
| 8964 | // Finish stale connection async, and the stale connection should pass dns |
| 8965 | // validation. |
| 8966 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 8967 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 8968 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8969 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8970 | EXPECT_TRUE(stream.get()); |
| 8971 | |
| 8972 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8973 | EXPECT_EQ( |
| 8974 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8975 | kCachedIPAddress.ToString()); |
| 8976 | |
| 8977 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8978 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8979 | } |
| 8980 | |
| 8981 | // With dns race experiment on, dns resolve async, stale used and connects |
| 8982 | // sync, but dns no match |
| 8983 | TEST_P(QuicStreamFactoryTest, |
| 8984 | ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { |
| 8985 | race_stale_dns_on_connection_ = true; |
| 8986 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8987 | Initialize(); |
| 8988 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8989 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8990 | |
| 8991 | // Set an address in resolver for asynchronous return. |
| 8992 | host_resolver_->set_ondemand_mode(true); |
| 8993 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8994 | kNonCachedIPAddress, ""); |
| 8995 | |
| 8996 | // Set up a different address in the stale resolver cache. |
| 8997 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8998 | HostCache::Entry entry(OK, |
| 8999 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9000 | HostCache::Entry::SOURCE_DNS); |
| 9001 | base::TimeDelta zero; |
| 9002 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9003 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9004 | // Expire the cache |
| 9005 | cache->OnNetworkChange(); |
| 9006 | |
| 9007 | // Socket for the stale connection which will invoke connection closure. |
| 9008 | MockQuicData quic_data; |
| 9009 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9010 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9011 | quic_data.AddWrite( |
| 9012 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9013 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9014 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9015 | |
| 9016 | // Socket for the new connection. |
| 9017 | MockQuicData quic_data2; |
| 9018 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9019 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9020 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9021 | |
| 9022 | QuicStreamRequest request(factory_.get()); |
| 9023 | EXPECT_EQ(ERR_IO_PENDING, |
| 9024 | request.Request( |
| 9025 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9026 | SocketTag(), |
| 9027 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9028 | failed_on_default_network_callback_, callback_.callback())); |
| 9029 | |
| 9030 | // Check the stale connection is running. |
| 9031 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9032 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9033 | |
| 9034 | // Finish dns resolution and check the job has finished. |
| 9035 | host_resolver_->ResolveAllPending(); |
| 9036 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9037 | |
| 9038 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9039 | EXPECT_TRUE(stream.get()); |
| 9040 | |
| 9041 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9042 | |
| 9043 | EXPECT_EQ( |
| 9044 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9045 | kNonCachedIPAddress); |
| 9046 | |
| 9047 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9048 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9049 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9050 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9051 | } |
| 9052 | |
| 9053 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9054 | // async, finishes before dns, but no match |
| 9055 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { |
| 9056 | race_stale_dns_on_connection_ = true; |
| 9057 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9058 | Initialize(); |
| 9059 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9060 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9061 | |
| 9062 | // Set an address in resolver for asynchronous return. |
| 9063 | host_resolver_->set_ondemand_mode(true); |
| 9064 | factory_->set_require_confirmation(true); |
| 9065 | crypto_client_stream_factory_.set_handshake_mode( |
| 9066 | MockCryptoClientStream::ZERO_RTT); |
| 9067 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9068 | kNonCachedIPAddress, ""); |
| 9069 | |
| 9070 | // Set up a different address in the stale resolvercache. |
| 9071 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9072 | HostCache::Entry entry(OK, |
| 9073 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9074 | HostCache::Entry::SOURCE_DNS); |
| 9075 | base::TimeDelta zero; |
| 9076 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9077 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9078 | // Expire the cache |
| 9079 | cache->OnNetworkChange(); |
| 9080 | |
| 9081 | MockQuicData quic_data; |
| 9082 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9083 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9084 | quic_data.AddWrite( |
| 9085 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9086 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9087 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9088 | |
| 9089 | MockQuicData quic_data2; |
| 9090 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9091 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9092 | |
| 9093 | QuicStreamRequest request(factory_.get()); |
| 9094 | EXPECT_EQ(ERR_IO_PENDING, |
| 9095 | request.Request( |
| 9096 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9097 | SocketTag(), |
| 9098 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9099 | failed_on_default_network_callback_, callback_.callback())); |
| 9100 | |
| 9101 | // Finish the stale connection. |
| 9102 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9103 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9104 | base::RunLoop().RunUntilIdle(); |
| 9105 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9106 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9107 | |
| 9108 | // Finish host resolution and check the job is done. |
| 9109 | host_resolver_->ResolveAllPending(); |
| 9110 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9111 | |
| 9112 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9113 | EXPECT_TRUE(stream.get()); |
| 9114 | |
| 9115 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9116 | EXPECT_EQ( |
| 9117 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9118 | kNonCachedIPAddress); |
| 9119 | |
| 9120 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9121 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9122 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9123 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9124 | } |
| 9125 | |
| 9126 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9127 | // async, dns finishes first, but no match |
| 9128 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { |
| 9129 | race_stale_dns_on_connection_ = true; |
| 9130 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9131 | Initialize(); |
| 9132 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9133 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9134 | |
| 9135 | // Set an address in resolver for asynchronous return. |
| 9136 | host_resolver_->set_ondemand_mode(true); |
| 9137 | factory_->set_require_confirmation(true); |
| 9138 | crypto_client_stream_factory_.set_handshake_mode( |
| 9139 | MockCryptoClientStream::ZERO_RTT); |
| 9140 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9141 | kNonCachedIPAddress, ""); |
| 9142 | |
| 9143 | // Set up a different address in the stale resolver cache. |
| 9144 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9145 | HostCache::Entry entry(OK, |
| 9146 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9147 | HostCache::Entry::SOURCE_DNS); |
| 9148 | base::TimeDelta zero; |
| 9149 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9150 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9151 | // Expire the cache |
| 9152 | cache->OnNetworkChange(); |
| 9153 | |
| 9154 | MockQuicData quic_data; |
| 9155 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9156 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9157 | quic_data.AddWrite( |
| 9158 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9159 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9160 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9161 | |
| 9162 | MockQuicData quic_data2; |
| 9163 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9164 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 9165 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9166 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9167 | |
| 9168 | QuicStreamRequest request(factory_.get()); |
| 9169 | EXPECT_EQ(ERR_IO_PENDING, |
| 9170 | request.Request( |
| 9171 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9172 | SocketTag(), |
| 9173 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9174 | failed_on_default_network_callback_, callback_.callback())); |
| 9175 | // Finish dns resolution, but need to wait for stale connection. |
| 9176 | host_resolver_->ResolveAllPending(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9177 | base::RunLoop().RunUntilIdle(); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9178 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9179 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9180 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9181 | |
| 9182 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9183 | EXPECT_TRUE(stream.get()); |
| 9184 | |
| 9185 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9186 | EXPECT_EQ( |
| 9187 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9188 | kNonCachedIPAddress); |
| 9189 | |
| 9190 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9191 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9192 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9193 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9194 | } |
| 9195 | |
| 9196 | // With dns race experiment on, dns resolve returns error sync, same behavior |
| 9197 | // as experiment is not on |
| 9198 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { |
| 9199 | race_stale_dns_on_connection_ = true; |
| 9200 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9201 | Initialize(); |
| 9202 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9203 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9204 | |
| 9205 | // Set synchronous failure in resolver. |
| 9206 | host_resolver_->set_synchronous_mode(true); |
| 9207 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9208 | |
| 9209 | MockQuicData quic_data; |
| 9210 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9211 | QuicStreamRequest request(factory_.get()); |
| 9212 | |
| 9213 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 9214 | request.Request( |
| 9215 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9216 | SocketTag(), |
| 9217 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9218 | failed_on_default_network_callback_, callback_.callback())); |
| 9219 | } |
| 9220 | |
| 9221 | // With dns race experiment on, no cache available, dns resolve returns error |
| 9222 | // async |
| 9223 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { |
| 9224 | race_stale_dns_on_connection_ = true; |
| 9225 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9226 | Initialize(); |
| 9227 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9228 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9229 | |
| 9230 | // Set asynchronous failure in resolver. |
| 9231 | host_resolver_->set_ondemand_mode(true); |
| 9232 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9233 | |
| 9234 | MockQuicData quic_data; |
| 9235 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9236 | QuicStreamRequest request(factory_.get()); |
| 9237 | |
| 9238 | EXPECT_EQ(ERR_IO_PENDING, |
| 9239 | request.Request( |
| 9240 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9241 | SocketTag(), |
| 9242 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9243 | failed_on_default_network_callback_, callback_.callback())); |
| 9244 | |
| 9245 | // Resolve and expect result that shows the resolution error. |
| 9246 | host_resolver_->ResolveAllPending(); |
| 9247 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9248 | } |
| 9249 | |
| 9250 | // With dns race experiment on, dns resolve async, staled used and connects |
| 9251 | // sync, dns returns error and no connection is established. |
| 9252 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { |
| 9253 | race_stale_dns_on_connection_ = true; |
| 9254 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9255 | Initialize(); |
| 9256 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9257 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9258 | |
| 9259 | // Set asynchronous failure in resolver. |
| 9260 | host_resolver_->set_ondemand_mode(true); |
| 9261 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9262 | |
| 9263 | // Set up an address in the stale cache. |
| 9264 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9265 | HostCache::Entry entry(OK, |
| 9266 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9267 | HostCache::Entry::SOURCE_DNS); |
| 9268 | base::TimeDelta zero; |
| 9269 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9270 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9271 | // Expire the cache |
| 9272 | cache->OnNetworkChange(); |
| 9273 | |
| 9274 | // Socket for the stale connection which is supposed to disconnect. |
| 9275 | MockQuicData quic_data; |
| 9276 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9277 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9278 | quic_data.AddWrite( |
| 9279 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9280 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9281 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9282 | |
| 9283 | QuicStreamRequest request(factory_.get()); |
| 9284 | EXPECT_EQ(ERR_IO_PENDING, |
| 9285 | request.Request( |
| 9286 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9287 | SocketTag(), |
| 9288 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9289 | failed_on_default_network_callback_, callback_.callback())); |
| 9290 | |
| 9291 | // Check that the stale connection is running. |
| 9292 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9293 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9294 | |
| 9295 | // Finish host resolution. |
| 9296 | host_resolver_->ResolveAllPending(); |
| 9297 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9298 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9299 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9300 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9301 | } |
| 9302 | |
| 9303 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9304 | // return error, then dns matches |
| 9305 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { |
| 9306 | race_stale_dns_on_connection_ = true; |
| 9307 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9308 | Initialize(); |
| 9309 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9310 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9311 | |
| 9312 | // Set an address in host resolver for asynchronous return. |
| 9313 | host_resolver_->set_ondemand_mode(true); |
| 9314 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9315 | kCachedIPAddress.ToString(), ""); |
| 9316 | |
| 9317 | // Set up the same address in the stale resolver cache. |
| 9318 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9319 | HostCache::Entry entry(OK, |
| 9320 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9321 | HostCache::Entry::SOURCE_DNS); |
| 9322 | base::TimeDelta zero; |
| 9323 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9324 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9325 | // Expire the cache |
| 9326 | cache->OnNetworkChange(); |
| 9327 | |
| 9328 | // Simulate synchronous connect failure. |
| 9329 | MockQuicData quic_data; |
| 9330 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9331 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9332 | |
| 9333 | MockQuicData quic_data2; |
| 9334 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9335 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9336 | |
| 9337 | QuicStreamRequest request(factory_.get()); |
| 9338 | EXPECT_EQ(ERR_IO_PENDING, |
| 9339 | request.Request( |
| 9340 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9341 | SocketTag(), |
| 9342 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9343 | failed_on_default_network_callback_, callback_.callback())); |
| 9344 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9345 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9346 | |
| 9347 | host_resolver_->ResolveAllPending(); |
| 9348 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9349 | } |
| 9350 | |
| 9351 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9352 | // returns error, dns no match, new connection is established |
| 9353 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { |
| 9354 | race_stale_dns_on_connection_ = true; |
| 9355 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9356 | Initialize(); |
| 9357 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9358 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9359 | |
| 9360 | // Set an address in host resolver. |
| 9361 | host_resolver_->set_ondemand_mode(true); |
| 9362 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9363 | kNonCachedIPAddress, ""); |
| 9364 | |
| 9365 | // Set up a different address in stale resolver cache. |
| 9366 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9367 | HostCache::Entry entry(OK, |
| 9368 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9369 | HostCache::Entry::SOURCE_DNS); |
| 9370 | base::TimeDelta zero; |
| 9371 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9372 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9373 | // Expire the cache |
| 9374 | cache->OnNetworkChange(); |
| 9375 | |
| 9376 | // Add failure for the stale connection. |
| 9377 | MockQuicData quic_data; |
| 9378 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9379 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9380 | |
| 9381 | MockQuicData quic_data2; |
| 9382 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9383 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9384 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9385 | |
| 9386 | QuicStreamRequest request(factory_.get()); |
| 9387 | EXPECT_EQ(ERR_IO_PENDING, |
| 9388 | request.Request( |
| 9389 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9390 | SocketTag(), |
| 9391 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9392 | failed_on_default_network_callback_, callback_.callback())); |
| 9393 | |
| 9394 | // Check that the stale connection fails. |
| 9395 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9396 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9397 | |
| 9398 | // Finish host resolution and check the job finishes ok. |
| 9399 | host_resolver_->ResolveAllPending(); |
| 9400 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9401 | |
| 9402 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9403 | EXPECT_TRUE(stream.get()); |
| 9404 | |
| 9405 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9406 | |
| 9407 | EXPECT_EQ( |
| 9408 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9409 | kNonCachedIPAddress); |
| 9410 | |
| 9411 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9412 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9413 | } |
| 9414 | |
| 9415 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9416 | // returns error, dns no match, new connection error |
| 9417 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { |
| 9418 | race_stale_dns_on_connection_ = true; |
| 9419 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9420 | Initialize(); |
| 9421 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9422 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9423 | |
| 9424 | // Set an address in host resolver asynchronously. |
| 9425 | host_resolver_->set_ondemand_mode(true); |
| 9426 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9427 | kNonCachedIPAddress, ""); |
| 9428 | |
| 9429 | // Set up a different address in the stale cache. |
| 9430 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9431 | HostCache::Entry entry(OK, |
| 9432 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9433 | HostCache::Entry::SOURCE_DNS); |
| 9434 | base::TimeDelta zero; |
| 9435 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9436 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9437 | // Expire the cache |
| 9438 | cache->OnNetworkChange(); |
| 9439 | |
| 9440 | // Add failure for stale connection. |
| 9441 | MockQuicData quic_data; |
| 9442 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9443 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9444 | |
| 9445 | // Add failure for resolved dns connection. |
| 9446 | MockQuicData quic_data2; |
| 9447 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9448 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9449 | |
| 9450 | QuicStreamRequest request(factory_.get()); |
| 9451 | EXPECT_EQ(ERR_IO_PENDING, |
| 9452 | request.Request( |
| 9453 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9454 | SocketTag(), |
| 9455 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9456 | failed_on_default_network_callback_, callback_.callback())); |
| 9457 | |
| 9458 | // Check the stale connection fails. |
| 9459 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9460 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9461 | |
| 9462 | // Check the resolved dns connection fails. |
| 9463 | host_resolver_->ResolveAllPending(); |
| 9464 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9465 | } |
| 9466 | |
| 9467 | // With dns race experiment on, dns resolve async and stale connect async, dns |
| 9468 | // resolve returns error and then preconnect finishes |
| 9469 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { |
| 9470 | race_stale_dns_on_connection_ = true; |
| 9471 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9472 | Initialize(); |
| 9473 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9474 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9475 | |
| 9476 | // Add asynchronous failure in host resolver. |
| 9477 | host_resolver_->set_ondemand_mode(true); |
| 9478 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9479 | factory_->set_require_confirmation(true); |
| 9480 | crypto_client_stream_factory_.set_handshake_mode( |
| 9481 | MockCryptoClientStream::ZERO_RTT); |
| 9482 | |
| 9483 | // Set up an address in stale resolver cache. |
| 9484 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9485 | HostCache::Entry entry(OK, |
| 9486 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9487 | HostCache::Entry::SOURCE_DNS); |
| 9488 | base::TimeDelta zero; |
| 9489 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9490 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9491 | // Expire the cache |
| 9492 | cache->OnNetworkChange(); |
| 9493 | |
| 9494 | // Socket data for stale connection which is supposed to disconnect. |
| 9495 | MockQuicData quic_data; |
| 9496 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9497 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9498 | quic_data.AddWrite( |
| 9499 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9500 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9501 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9502 | |
| 9503 | QuicStreamRequest request(factory_.get()); |
| 9504 | EXPECT_EQ(ERR_IO_PENDING, |
| 9505 | request.Request( |
| 9506 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9507 | SocketTag(), |
| 9508 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9509 | failed_on_default_network_callback_, callback_.callback())); |
| 9510 | |
| 9511 | // host resolution returned but stale connection hasn't finished yet. |
| 9512 | host_resolver_->ResolveAllPending(); |
| 9513 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9514 | |
| 9515 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9516 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9517 | } |
| 9518 | |
| 9519 | // With dns race experiment on, dns resolve async and stale connect async, dns |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9520 | // resolve returns error and then preconnect fails. |
| 9521 | TEST_P(QuicStreamFactoryTest, |
| 9522 | ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { |
| 9523 | race_stale_dns_on_connection_ = true; |
| 9524 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9525 | Initialize(); |
| 9526 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9527 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9528 | |
| 9529 | // Add asynchronous failure to host resolver. |
| 9530 | host_resolver_->set_ondemand_mode(true); |
| 9531 | factory_->set_require_confirmation(true); |
| 9532 | crypto_client_stream_factory_.set_handshake_mode( |
| 9533 | MockCryptoClientStream::ZERO_RTT); |
| 9534 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9535 | |
| 9536 | // Set up an address in stale resolver cache. |
| 9537 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9538 | HostCache::Entry entry(OK, |
| 9539 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9540 | HostCache::Entry::SOURCE_DNS); |
| 9541 | base::TimeDelta zero; |
| 9542 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9543 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9544 | // Expire the cache |
| 9545 | cache->OnNetworkChange(); |
| 9546 | |
| 9547 | MockQuicData quic_data; |
| 9548 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9549 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9550 | quic_data.AddWrite( |
| 9551 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9552 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9553 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9554 | |
| 9555 | QuicStreamRequest request(factory_.get()); |
| 9556 | EXPECT_EQ(ERR_IO_PENDING, |
| 9557 | request.Request( |
| 9558 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9559 | SocketTag(), |
| 9560 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9561 | failed_on_default_network_callback_, callback_.callback())); |
| 9562 | |
| 9563 | // Host Resolution returns failure but stale connection hasn't finished. |
| 9564 | host_resolver_->ResolveAllPending(); |
| 9565 | |
| 9566 | // Check that the final error is on resolution failure. |
| 9567 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9568 | |
| 9569 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9570 | } |
| 9571 | |
| 9572 | // With dns race experiment on, test that host resolution callback behaves |
| 9573 | // normal as experiment is not on |
| 9574 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { |
| 9575 | race_stale_dns_on_connection_ = true; |
| 9576 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9577 | Initialize(); |
| 9578 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9579 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9580 | |
| 9581 | host_resolver_->set_ondemand_mode(true); |
| 9582 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9583 | kNonCachedIPAddress, ""); |
| 9584 | |
| 9585 | MockQuicData quic_data; |
| 9586 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9587 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9588 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9589 | |
| 9590 | QuicStreamRequest request(factory_.get()); |
| 9591 | EXPECT_EQ(ERR_IO_PENDING, |
| 9592 | request.Request( |
| 9593 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9594 | SocketTag(), |
| 9595 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9596 | failed_on_default_network_callback_, callback_.callback())); |
| 9597 | |
| 9598 | // Check that expect_on_host_resolution_ is properlly set. |
| 9599 | TestCompletionCallback host_resolution_callback; |
| 9600 | EXPECT_TRUE( |
| 9601 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9602 | base::RunLoop().RunUntilIdle(); |
| 9603 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9604 | |
| 9605 | host_resolver_->ResolveAllPending(); |
| 9606 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 9607 | |
| 9608 | // Check that expect_on_host_resolution_ is flipped back. |
| 9609 | EXPECT_FALSE( |
| 9610 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9611 | |
| 9612 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9613 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9614 | } |
| 9615 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9616 | // Test that QuicStreamRequests with similar and different tags results in |
| 9617 | // reused and unique QUIC streams using appropriately tagged sockets. |
| 9618 | TEST_P(QuicStreamFactoryTest, Tag) { |
| 9619 | MockTaggingClientSocketFactory* socket_factory = |
| 9620 | new MockTaggingClientSocketFactory(); |
| 9621 | socket_factory_.reset(socket_factory); |
| 9622 | Initialize(); |
| 9623 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9624 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9625 | |
| 9626 | // Prepare to establish two QUIC sessions. |
| 9627 | MockQuicData socket_data; |
| 9628 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9629 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9630 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9631 | MockQuicData socket_data2; |
| 9632 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9633 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9634 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9635 | |
| 9636 | #if defined(OS_ANDROID) |
| 9637 | SocketTag tag1(SocketTag::UNSET_UID, 0x12345678); |
| 9638 | SocketTag tag2(getuid(), 0x87654321); |
| 9639 | #else |
| 9640 | // On non-Android platforms we can only use the default constructor. |
| 9641 | SocketTag tag1, tag2; |
| 9642 | #endif |
| 9643 | |
| 9644 | // Request a stream with |tag1|. |
| 9645 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9646 | int rv = request1.Request( |
| 9647 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9648 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9649 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9650 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9651 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag1); |
| 9652 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9653 | ->tagged_before_data_transferred()); |
| 9654 | std::unique_ptr<QuicChromiumClientSession::Handle> stream1 = |
| 9655 | request1.ReleaseSessionHandle(); |
| 9656 | EXPECT_TRUE(stream1); |
| 9657 | EXPECT_TRUE(stream1->IsConnected()); |
| 9658 | |
| 9659 | // Request a stream with |tag1| and verify underlying session is reused. |
| 9660 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9661 | rv = request2.Request( |
| 9662 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9663 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9664 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9665 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9666 | std::unique_ptr<QuicChromiumClientSession::Handle> stream2 = |
| 9667 | request2.ReleaseSessionHandle(); |
| 9668 | EXPECT_TRUE(stream2); |
| 9669 | EXPECT_TRUE(stream2->IsConnected()); |
| 9670 | EXPECT_TRUE(stream2->SharesSameSession(*stream1)); |
| 9671 | |
| 9672 | // Request a stream with |tag2| and verify a new session is created. |
| 9673 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9674 | rv = request3.Request( |
| 9675 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag2, |
| 9676 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9677 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9678 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9679 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag2); |
| 9680 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9681 | ->tagged_before_data_transferred()); |
| 9682 | std::unique_ptr<QuicChromiumClientSession::Handle> stream3 = |
| 9683 | request3.ReleaseSessionHandle(); |
| 9684 | EXPECT_TRUE(stream3); |
| 9685 | EXPECT_TRUE(stream3->IsConnected()); |
| 9686 | #if defined(OS_ANDROID) |
| 9687 | EXPECT_FALSE(stream3->SharesSameSession(*stream1)); |
| 9688 | #else |
| 9689 | // Same tag should reuse session. |
| 9690 | EXPECT_TRUE(stream3->SharesSameSession(*stream1)); |
| 9691 | #endif |
| 9692 | } |
| 9693 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9694 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9695 | } // namespace net |