[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 | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 16 | #include "base/test/simple_test_tick_clock.h" |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 17 | #include "base/test/test_mock_time_task_runner.h" |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 18 | #include "build/build_config.h" |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 19 | #include "net/base/mock_network_change_notifier.h" |
rsleevi | d6de830 | 2016-06-21 01:33:20 | [diff] [blame] | 20 | #include "net/cert/ct_policy_enforcer.h" |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 21 | #include "net/cert/do_nothing_ct_verifier.h" |
| 22 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 23 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 24 | #include "net/http/http_response_headers.h" |
| 25 | #include "net/http/http_response_info.h" |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 26 | #include "net/http/http_server_properties_impl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 27 | #include "net/http/http_util.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 28 | #include "net/http/transport_security_state.h" |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 29 | #include "net/http/transport_security_state_test_util.h" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 30 | #include "net/quic/crypto/proof_verifier_chromium.h" |
| 31 | #include "net/quic/mock_crypto_client_stream_factory.h" |
| 32 | #include "net/quic/mock_quic_data.h" |
| 33 | #include "net/quic/properties_based_quic_server_info.h" |
| 34 | #include "net/quic/quic_http_stream.h" |
| 35 | #include "net/quic/quic_http_utils.h" |
| 36 | #include "net/quic/quic_server_info.h" |
| 37 | #include "net/quic/quic_stream_factory_peer.h" |
| 38 | #include "net/quic/quic_test_packet_maker.h" |
| 39 | #include "net/quic/test_task_runner.h" |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 40 | #include "net/socket/next_proto.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 41 | #include "net/socket/socket_test_util.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 42 | #include "net/spdy/spdy_session_test_util.h" |
| 43 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 44 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 45 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 46 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 47 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 48 | #include "net/third_party/quic/core/crypto/crypto_handshake.h" |
| 49 | #include "net/third_party/quic/core/crypto/quic_crypto_client_config.h" |
| 50 | #include "net/third_party/quic/core/crypto/quic_decrypter.h" |
| 51 | #include "net/third_party/quic/core/crypto/quic_encrypter.h" |
Victor Vasiliev | c5b409c2 | 2018-07-24 12:23:46 | [diff] [blame] | 52 | #include "net/third_party/quic/core/http/quic_client_promised_info.h" |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 53 | #include "net/third_party/quic/core/quic_utils.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 54 | #include "net/third_party/quic/platform/api/quic_test.h" |
| 55 | #include "net/third_party/quic/test_tools/mock_clock.h" |
| 56 | #include "net/third_party/quic/test_tools/mock_random.h" |
| 57 | #include "net/third_party/quic/test_tools/quic_config_peer.h" |
| 58 | #include "net/third_party/quic/test_tools/quic_spdy_session_peer.h" |
| 59 | #include "net/third_party/quic/test_tools/quic_test_utils.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 60 | #include "net/third_party/quiche/src/spdy/core/spdy_test_utils.h" |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 61 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 62 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 63 | #include "testing/gtest/include/gtest/gtest.h" |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 64 | #include "url/gurl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 65 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 66 | using std::string; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 67 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 68 | namespace net { |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 69 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 70 | namespace { |
| 71 | |
| 72 | class MockSSLConfigService : public SSLConfigService { |
| 73 | public: |
| 74 | MockSSLConfigService() {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 75 | ~MockSSLConfigService() override {} |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 76 | |
| 77 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 78 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 79 | bool CanShareConnectionWithClientCerts( |
| 80 | const std::string& hostname) const override { |
| 81 | return false; |
| 82 | } |
| 83 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 84 | private: |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 85 | SSLConfig config_; |
| 86 | }; |
| 87 | |
| 88 | } // namespace |
| 89 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 90 | namespace test { |
| 91 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 92 | namespace { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 93 | |
| 94 | enum DestinationType { |
| 95 | // In pooling tests with two requests for different origins to the same |
| 96 | // destination, the destination should be |
| 97 | SAME_AS_FIRST, // the same as the first origin, |
| 98 | SAME_AS_SECOND, // the same as the second origin, or |
| 99 | DIFFERENT, // different from both. |
| 100 | }; |
| 101 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 102 | const char kDefaultServerHostName[] = "www.example.org"; |
| 103 | const char kServer2HostName[] = "mail.example.org"; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 104 | const char kDifferentHostname[] = "different.example.com"; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 105 | const int kDefaultServerPort = 443; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 106 | const char kDefaultUrl[] = "https://www.example.org/"; |
| 107 | const char kServer2Url[] = "https://mail.example.org/"; |
| 108 | const char kServer3Url[] = "https://docs.example.org/"; |
| 109 | const char kServer4Url[] = "https://images.example.org/"; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 110 | const int kDefaultRTTMilliSecs = 300; |
| 111 | const size_t kMinRetryTimeForDefaultNetworkSecs = 1; |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 112 | const size_t kWaitTimeForNewNetworkSecs = 10; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 113 | const IPAddress kCachedIPAddress = IPAddress(192, 168, 0, 2); |
| 114 | const char kNonCachedIPAddress[] = "192.168.0.1"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 115 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 116 | // Run QuicStreamFactoryTest instances with all value combinations of version |
| 117 | // and enable_connection_racting. |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 118 | struct TestParams { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 119 | friend std::ostream& operator<<(std::ostream& os, const TestParams& p) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 120 | os << "{ version: " << QuicVersionToString(p.version) |
| 121 | << ", client_headers_include_h2_stream_dependency: " |
| 122 | << p.client_headers_include_h2_stream_dependency << " }"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 123 | return os; |
| 124 | } |
| 125 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 126 | quic::QuicTransportVersion version; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 127 | bool client_headers_include_h2_stream_dependency; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 128 | }; |
| 129 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 130 | std::vector<TestParams> GetTestParams() { |
| 131 | std::vector<TestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 132 | quic::QuicTransportVersionVector all_supported_versions = |
| 133 | quic::AllSupportedTransportVersions(); |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 134 | for (const auto& version : all_supported_versions) { |
| 135 | params.push_back(TestParams{version, false}); |
| 136 | params.push_back(TestParams{version, true}); |
| 137 | } |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 138 | return params; |
| 139 | } |
| 140 | |
| 141 | // Run QuicStreamFactoryWithDestinationTest instances with all value |
| 142 | // combinations of version, enable_connection_racting, and destination_type. |
| 143 | struct PoolingTestParams { |
| 144 | friend std::ostream& operator<<(std::ostream& os, |
| 145 | const PoolingTestParams& p) { |
| 146 | os << "{ version: " << QuicVersionToString(p.version) |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 147 | << ", destination_type: "; |
| 148 | switch (p.destination_type) { |
| 149 | case SAME_AS_FIRST: |
| 150 | os << "SAME_AS_FIRST"; |
| 151 | break; |
| 152 | case SAME_AS_SECOND: |
| 153 | os << "SAME_AS_SECOND"; |
| 154 | break; |
| 155 | case DIFFERENT: |
| 156 | os << "DIFFERENT"; |
| 157 | break; |
| 158 | } |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 159 | os << ", client_headers_include_h2_stream_dependency: " |
| 160 | << p.client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 161 | os << " }"; |
| 162 | return os; |
| 163 | } |
| 164 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 165 | quic::QuicTransportVersion version; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 166 | DestinationType destination_type; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 167 | bool client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 168 | }; |
| 169 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 170 | std::vector<PoolingTestParams> GetPoolingTestParams() { |
| 171 | std::vector<PoolingTestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 172 | quic::QuicTransportVersionVector all_supported_versions = |
| 173 | quic::AllSupportedTransportVersions(); |
| 174 | for (const quic::QuicTransportVersion version : all_supported_versions) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 175 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, false}); |
| 176 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, true}); |
| 177 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, false}); |
| 178 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, true}); |
| 179 | params.push_back(PoolingTestParams{version, DIFFERENT, false}); |
| 180 | params.push_back(PoolingTestParams{version, DIFFERENT, true}); |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 181 | } |
| 182 | return params; |
| 183 | } |
| 184 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 185 | } // namespace |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 186 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 187 | class QuicHttpStreamPeer { |
| 188 | public: |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 189 | static QuicChromiumClientSession::Handle* GetSessionHandle( |
| 190 | HttpStream* stream) { |
| 191 | return static_cast<QuicHttpStream*>(stream)->quic_session(); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 192 | } |
| 193 | }; |
| 194 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 195 | // TestConnectionMigrationSocketFactory will vend sockets with incremental port |
| 196 | // number. |
| 197 | class TestConnectionMigrationSocketFactory : public MockClientSocketFactory { |
| 198 | public: |
| 199 | TestConnectionMigrationSocketFactory() : next_source_port_num_(1u) {} |
| 200 | ~TestConnectionMigrationSocketFactory() override {} |
| 201 | |
| 202 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 203 | DatagramSocket::BindType bind_type, |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 204 | NetLog* net_log, |
| 205 | const NetLogSource& source) override { |
| 206 | SocketDataProvider* data_provider = mock_data().GetNext(); |
| 207 | std::unique_ptr<MockUDPClientSocket> socket( |
| 208 | new MockUDPClientSocket(data_provider, net_log)); |
| 209 | socket->set_source_port(next_source_port_num_++); |
| 210 | return std::move(socket); |
| 211 | } |
| 212 | |
| 213 | private: |
| 214 | uint16_t next_source_port_num_; |
| 215 | |
| 216 | DISALLOW_COPY_AND_ASSIGN(TestConnectionMigrationSocketFactory); |
| 217 | }; |
| 218 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 219 | class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 220 | protected: |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 221 | QuicStreamFactoryTestBase(quic::QuicTransportVersion version, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 222 | bool client_headers_include_h2_stream_dependency) |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 223 | : host_resolver_(new MockHostResolver), |
| 224 | ssl_config_service_(new MockSSLConfigService), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 225 | socket_factory_(new MockClientSocketFactory), |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 226 | random_generator_(0), |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 227 | runner_(new TestTaskRunner(&clock_)), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 228 | version_(version), |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 229 | client_maker_( |
| 230 | version_, |
| 231 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 232 | &clock_, |
| 233 | kDefaultServerHostName, |
| 234 | quic::Perspective::IS_CLIENT, |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 235 | client_headers_include_h2_stream_dependency), |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 236 | server_maker_( |
| 237 | version_, |
| 238 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 239 | &clock_, |
| 240 | kDefaultServerHostName, |
| 241 | quic::Perspective::IS_SERVER, |
| 242 | false), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 243 | cert_verifier_(std::make_unique<MockCertVerifier>()), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 244 | cert_transparency_verifier_(std::make_unique<DoNothingCTVerifier>()), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 245 | scoped_mock_network_change_notifier_(nullptr), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 246 | factory_(nullptr), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 247 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 248 | url_(kDefaultUrl), |
| 249 | url2_(kServer2Url), |
| 250 | url3_(kServer3Url), |
| 251 | url4_(kServer4Url), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 252 | privacy_mode_(PRIVACY_MODE_DISABLED), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 253 | failed_on_default_network_callback_(base::BindRepeating( |
| 254 | &QuicStreamFactoryTestBase::OnFailedOnDefaultNetwork, |
| 255 | base::Unretained(this))), |
| 256 | failed_on_default_network_(false), |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 257 | store_server_configs_in_properties_(false) { |
| 258 | test_params_.quic_headers_include_h2_stream_dependency = |
| 259 | client_headers_include_h2_stream_dependency; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 260 | clock_.AdvanceTime(quic::QuicTime::Delta::FromSeconds(1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 261 | } |
| 262 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 263 | void Initialize() { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 264 | DCHECK(!factory_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 265 | factory_.reset(new QuicStreamFactory( |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 266 | net_log_.net_log(), host_resolver_.get(), ssl_config_service_.get(), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 267 | socket_factory_.get(), &http_server_properties_, cert_verifier_.get(), |
Nick Harper | ecf319d | 2018-10-16 07:58:54 | [diff] [blame] | 268 | &ct_policy_enforcer_, &transport_security_state_, |
| 269 | cert_transparency_verifier_.get(), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 270 | /*SocketPerformanceWatcherFactory*/ nullptr, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 271 | &crypto_client_stream_factory_, &random_generator_, &clock_, |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 272 | test_params_.quic_max_packet_length, test_params_.quic_user_agent_id, |
| 273 | store_server_configs_in_properties_, |
| 274 | test_params_.quic_close_sessions_on_ip_change, |
| 275 | test_params_.quic_goaway_sessions_on_ip_change, |
| 276 | test_params_.mark_quic_broken_when_network_blackholes, |
| 277 | test_params_.quic_idle_connection_timeout_seconds, |
| 278 | test_params_.quic_reduced_ping_timeout_seconds, |
Zhongyi Shi | e01f2db | 2019-02-22 19:53:23 | [diff] [blame] | 279 | test_params_.quic_retransmittable_on_wire_timeout_milliseconds, |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 280 | test_params_.quic_max_time_before_crypto_handshake_seconds, |
| 281 | test_params_.quic_max_idle_time_before_crypto_handshake_seconds, |
| 282 | test_params_.quic_migrate_sessions_on_network_change_v2, |
| 283 | test_params_.quic_migrate_sessions_early_v2, |
| 284 | test_params_.quic_retry_on_alternate_network_before_handshake, |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 285 | test_params_.quic_migrate_idle_sessions, |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 286 | test_params_.quic_idle_session_migration_period, |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 287 | test_params_.quic_max_time_on_non_default_network, |
| 288 | test_params_.quic_max_migrations_to_non_default_network_on_write_error, |
| 289 | test_params_ |
| 290 | .quic_max_migrations_to_non_default_network_on_path_degrading, |
| 291 | test_params_.quic_allow_server_migration, |
| 292 | test_params_.quic_race_stale_dns_on_connection, |
| 293 | test_params_.quic_go_away_on_path_degrading, |
| 294 | test_params_.quic_race_cert_verification, |
| 295 | test_params_.quic_estimate_initial_rtt, |
| 296 | test_params_.quic_headers_include_h2_stream_dependency, |
| 297 | test_params_.quic_connection_options, |
| 298 | test_params_.quic_client_connection_options, |
| 299 | test_params_.quic_enable_socket_recv_optimization)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 300 | } |
| 301 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 302 | void InitializeConnectionMigrationV2Test( |
| 303 | NetworkChangeNotifier::NetworkList connected_networks) { |
| 304 | scoped_mock_network_change_notifier_.reset( |
| 305 | new ScopedMockNetworkChangeNotifier()); |
| 306 | MockNetworkChangeNotifier* mock_ncn = |
| 307 | scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 308 | mock_ncn->ForceNetworkHandlesSupported(); |
| 309 | mock_ncn->SetConnectedNetworksList(connected_networks); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 310 | test_params_.quic_migrate_sessions_on_network_change_v2 = true; |
| 311 | test_params_.quic_migrate_sessions_early_v2 = true; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 312 | socket_factory_.reset(new TestConnectionMigrationSocketFactory); |
| 313 | Initialize(); |
| 314 | } |
| 315 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 316 | std::unique_ptr<HttpStream> CreateStream(QuicStreamRequest* request) { |
| 317 | std::unique_ptr<QuicChromiumClientSession::Handle> session = |
| 318 | request->ReleaseSessionHandle(); |
| 319 | if (!session || !session->IsConnected()) |
| 320 | return nullptr; |
| 321 | |
| 322 | return std::make_unique<QuicHttpStream>(std::move(session)); |
| 323 | } |
| 324 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 325 | bool HasActiveSession(const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 326 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 327 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 328 | return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 329 | } |
| 330 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 331 | bool HasLiveSession(const HostPortPair& host_port_pair) { |
| 332 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 333 | false); |
| 334 | return QuicStreamFactoryPeer::HasLiveSession(factory_.get(), host_port_pair, |
| 335 | server_id); |
| 336 | } |
| 337 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 338 | bool HasActiveJob(const HostPortPair& host_port_pair, |
| 339 | const PrivacyMode privacy_mode) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 340 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 341 | privacy_mode == PRIVACY_MODE_ENABLED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 342 | return QuicStreamFactoryPeer::HasActiveJob(factory_.get(), server_id); |
| 343 | } |
| 344 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 345 | bool HasActiveCertVerifierJob(const quic::QuicServerId& server_id) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 346 | return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 347 | server_id); |
| 348 | } |
| 349 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 350 | // Get the pending, not activated session, if there is only one session alive. |
| 351 | QuicChromiumClientSession* GetPendingSession( |
| 352 | const HostPortPair& host_port_pair) { |
| 353 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 354 | false); |
| 355 | return QuicStreamFactoryPeer::GetPendingSession(factory_.get(), server_id, |
| 356 | host_port_pair); |
| 357 | } |
| 358 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 359 | QuicChromiumClientSession* GetActiveSession( |
| 360 | const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 361 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 362 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 363 | return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 364 | } |
| 365 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 366 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 367 | return GetSourcePortForNewSessionInner(destination, false); |
| 368 | } |
| 369 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 370 | int GetSourcePortForNewSessionAndGoAway(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 371 | return GetSourcePortForNewSessionInner(destination, true); |
| 372 | } |
| 373 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 374 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 375 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 376 | // Should only be called if there is no active session for this destination. |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 377 | EXPECT_FALSE(HasActiveSession(destination)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 378 | size_t socket_count = socket_factory_->udp_client_socket_ports().size(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 379 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 380 | MockQuicData socket_data; |
| 381 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 382 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 383 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 384 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 385 | QuicStreamRequest request(factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 386 | GURL url("https://" + destination.host() + "/"); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 387 | EXPECT_EQ( |
| 388 | ERR_IO_PENDING, |
| 389 | request.Request( |
| 390 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 391 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 392 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 393 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 394 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 395 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 396 | EXPECT_TRUE(stream.get()); |
| 397 | stream.reset(); |
| 398 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 399 | QuicChromiumClientSession* session = GetActiveSession(destination); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 400 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 401 | if (socket_count + 1 != socket_factory_->udp_client_socket_ports().size()) { |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 402 | ADD_FAILURE(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 403 | return 0; |
| 404 | } |
| 405 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 406 | if (goaway_received) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 407 | quic::QuicGoAwayFrame goaway(quic::kInvalidControlFrameId, |
| 408 | quic::QUIC_NO_ERROR, 1, ""); |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 409 | session->connection()->OnGoAwayFrame(goaway); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 410 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 411 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 412 | factory_->OnSessionClosed(session); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 413 | EXPECT_FALSE(HasActiveSession(destination)); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 414 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 415 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 416 | return socket_factory_->udp_client_socket_ports()[socket_count]; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 417 | } |
| 418 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 419 | std::unique_ptr<quic::QuicEncryptedPacket> |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 420 | ConstructClientConnectionClosePacket(uint64_t num) { |
Bin Wu | 5311aca | 2018-01-22 01:19:03 | [diff] [blame] | 421 | return client_maker_.MakeConnectionClosePacket( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 422 | num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 423 | } |
| 424 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 425 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 426 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 427 | quic::QuicRstStreamErrorCode error_code) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 428 | quic::QuicStreamId stream_id = |
| 429 | GetNthClientInitiatedBidirectionalStreamId(0); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 430 | return client_maker_.MakeRstPacket(packet_number, true, stream_id, |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 431 | error_code); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 432 | } |
| 433 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 434 | static ProofVerifyDetailsChromium DefaultProofVerifyDetails() { |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 435 | // Load a certificate that is valid for *.example.org |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 436 | scoped_refptr<X509Certificate> test_cert( |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 437 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 438 | EXPECT_TRUE(test_cert.get()); |
| 439 | ProofVerifyDetailsChromium verify_details; |
| 440 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 441 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 442 | return verify_details; |
| 443 | } |
| 444 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 445 | void NotifyIPAddressChanged() { |
| 446 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 447 | // Spin the message loop so the notification is delivered. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 448 | base::RunLoop().RunUntilIdle(); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 449 | } |
| 450 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 451 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 452 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 453 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 454 | bool should_include_version, |
| 455 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 456 | spdy::SpdyHeaderBlock headers = |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 457 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 458 | spdy::SpdyPriority priority = |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 459 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 460 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 461 | return client_maker_.MakeRequestHeadersPacket( |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 462 | packet_number, stream_id, should_include_version, fin, priority, |
Yixin Wang | 7a3f1b8d | 2018-01-17 21:40:48 | [diff] [blame] | 463 | std::move(headers), 0, &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 464 | } |
| 465 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 466 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 467 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 468 | quic::QuicStreamId stream_id, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 469 | quic::QuicStreamId parent_stream_id, |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 470 | bool should_include_version, |
| 471 | bool fin, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 472 | quic::QuicStreamOffset* offset) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 473 | spdy::SpdyHeaderBlock headers = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 474 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 475 | spdy::SpdyPriority priority = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 476 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 477 | size_t spdy_headers_frame_len; |
| 478 | return client_maker_.MakeRequestHeadersPacket( |
| 479 | packet_number, stream_id, should_include_version, fin, priority, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 480 | std::move(headers), parent_stream_id, &spdy_headers_frame_len, offset); |
| 481 | } |
| 482 | |
| 483 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 484 | uint64_t packet_number, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 485 | quic::QuicStreamId stream_id, |
| 486 | bool should_include_version, |
| 487 | bool fin, |
| 488 | quic::QuicStreamOffset* offset) { |
| 489 | return ConstructGetRequestPacket(packet_number, stream_id, |
| 490 | /*parent_stream_id=*/0, |
| 491 | should_include_version, fin, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 492 | } |
| 493 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 494 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 495 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 496 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 497 | bool should_include_version, |
| 498 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 499 | spdy::SpdyHeaderBlock headers = server_maker_.GetResponseHeaders("200 OK"); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 500 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 501 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 502 | packet_number, stream_id, should_include_version, fin, |
| 503 | std::move(headers), &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 504 | } |
| 505 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 506 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket() { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 507 | return client_maker_.MakeInitialSettingsPacket(1, nullptr); |
| 508 | } |
| 509 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 510 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 511 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 512 | quic::QuicStreamOffset* offset) { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 513 | return client_maker_.MakeInitialSettingsPacket(packet_number, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 514 | } |
| 515 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 516 | // Helper method for server migration tests. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 517 | void VerifyServerMigration(const quic::QuicConfig& config, |
bnc | 6a0348c | 2017-05-22 18:56:19 | [diff] [blame] | 518 | IPEndPoint expected_address) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 519 | test_params_.quic_allow_server_migration = true; |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 520 | Initialize(); |
| 521 | |
| 522 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 523 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 524 | crypto_client_stream_factory_.SetConfig(config); |
| 525 | |
| 526 | // Set up first socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 527 | MockQuicData socket_data1; |
| 528 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 529 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 530 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 531 | // Set up second socket data provider that is used after |
| 532 | // migration. |
| 533 | MockQuicData socket_data2; |
| 534 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 535 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 536 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 537 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 538 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 539 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 540 | 3, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 541 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 542 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 543 | |
| 544 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 545 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 546 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 547 | request.Request( |
| 548 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 549 | SocketTag(), |
| 550 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 551 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 552 | EXPECT_EQ(OK, callback_.WaitForResult()); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 553 | |
| 554 | // Run QuicChromiumClientSession::WriteToNewSocket() |
| 555 | // posted by QuicChromiumClientSession::MigrateToSocket(). |
| 556 | base::RunLoop().RunUntilIdle(); |
| 557 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 558 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 559 | EXPECT_TRUE(stream.get()); |
| 560 | |
| 561 | // Cause QUIC stream to be created. |
| 562 | HttpRequestInfo request_info; |
| 563 | request_info.method = "GET"; |
| 564 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 565 | request_info.traffic_annotation = |
| 566 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 567 | EXPECT_EQ(OK, |
| 568 | stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 569 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 570 | // Ensure that session is alive and active. |
| 571 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 572 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 573 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 574 | |
| 575 | IPEndPoint actual_address; |
| 576 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 577 | EXPECT_EQ(actual_address, expected_address); |
| 578 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 579 | << " " << actual_address.port(); |
| 580 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 581 | << " " << expected_address.port(); |
| 582 | |
| 583 | stream.reset(); |
| 584 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 585 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 586 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 587 | } |
| 588 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 589 | // Verifies that the QUIC stream factory is initialized correctly. |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 590 | void VerifyInitialization() { |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 591 | store_server_configs_in_properties_ = true; |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 592 | test_params_.quic_idle_connection_timeout_seconds = 500; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 593 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 594 | factory_->set_require_confirmation(false); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 595 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 596 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 597 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 598 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 599 | MockCryptoClientStream::ZERO_RTT); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 600 | const quic::QuicConfig* config = |
| 601 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
ckrasic | 32b17dcd | 2016-10-31 06:15:35 | [diff] [blame] | 602 | EXPECT_EQ(500, config->IdleNetworkTimeout().ToSeconds()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 603 | |
| 604 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 605 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 606 | const AlternativeService alternative_service1( |
| 607 | kProtoQUIC, host_port_pair_.host(), host_port_pair_.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 608 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 609 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 610 | alternative_service_info_vector.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 611 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 612 | alternative_service1, expiration, {version_})); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 613 | http_server_properties_.SetAlternativeServices( |
| 614 | url::SchemeHostPort(url_), alternative_service_info_vector); |
| 615 | |
| 616 | HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 617 | url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 618 | const AlternativeService alternative_service2( |
| 619 | kProtoQUIC, host_port_pair2.host(), host_port_pair2.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 620 | AlternativeServiceInfoVector alternative_service_info_vector2; |
| 621 | alternative_service_info_vector2.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 622 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 623 | alternative_service2, expiration, {version_})); |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 624 | |
| 625 | http_server_properties_.SetAlternativeServices( |
| 626 | server2, alternative_service_info_vector2); |
| 627 | // Verify that the properties of both QUIC servers are stored in the |
| 628 | // HTTP properties map. |
| 629 | EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 630 | |
| 631 | http_server_properties_.SetMaxServerConfigsStoredInProperties( |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 632 | kDefaultMaxQuicServerEntries); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 633 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 634 | quic::QuicServerId quic_server_id(kDefaultServerHostName, 443, |
| 635 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 636 | std::unique_ptr<QuicServerInfo> quic_server_info = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 637 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 638 | quic_server_id, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 639 | |
| 640 | // Update quic_server_info's server_config and persist it. |
| 641 | QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 642 | // Minimum SCFG that passes config validation checks. |
| 643 | const char scfg[] = {// SCFG |
| 644 | 0x53, 0x43, 0x46, 0x47, |
| 645 | // num entries |
| 646 | 0x01, 0x00, |
| 647 | // padding |
| 648 | 0x00, 0x00, |
| 649 | // EXPY |
| 650 | 0x45, 0x58, 0x50, 0x59, |
| 651 | // EXPY end offset |
| 652 | 0x08, 0x00, 0x00, 0x00, |
| 653 | // Value |
| 654 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 655 | |
| 656 | // Create temporary strings becasue Persist() clears string data in |state|. |
| 657 | string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 658 | string source_address_token("test_source_address_token"); |
| 659 | string cert_sct("test_cert_sct"); |
| 660 | string chlo_hash("test_chlo_hash"); |
| 661 | string signature("test_signature"); |
| 662 | string test_cert("test_cert"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 663 | std::vector<string> certs; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 664 | certs.push_back(test_cert); |
| 665 | state->server_config = server_config; |
| 666 | state->source_address_token = source_address_token; |
| 667 | state->cert_sct = cert_sct; |
| 668 | state->chlo_hash = chlo_hash; |
| 669 | state->server_config_sig = signature; |
| 670 | state->certs = certs; |
| 671 | |
| 672 | quic_server_info->Persist(); |
| 673 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 674 | quic::QuicServerId quic_server_id2(kServer2HostName, 443, |
| 675 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 676 | std::unique_ptr<QuicServerInfo> quic_server_info2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 677 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 678 | quic_server_id2, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 679 | // Update quic_server_info2's server_config and persist it. |
| 680 | QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 681 | |
| 682 | // Minimum SCFG that passes config validation checks. |
| 683 | const char scfg2[] = {// SCFG |
| 684 | 0x53, 0x43, 0x46, 0x47, |
| 685 | // num entries |
| 686 | 0x01, 0x00, |
| 687 | // padding |
| 688 | 0x00, 0x00, |
| 689 | // EXPY |
| 690 | 0x45, 0x58, 0x50, 0x59, |
| 691 | // EXPY end offset |
| 692 | 0x08, 0x00, 0x00, 0x00, |
| 693 | // Value |
| 694 | '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 695 | |
| 696 | // Create temporary strings becasue Persist() clears string data in |
| 697 | // |state2|. |
| 698 | string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 699 | string source_address_token2("test_source_address_token2"); |
| 700 | string cert_sct2("test_cert_sct2"); |
| 701 | string chlo_hash2("test_chlo_hash2"); |
| 702 | string signature2("test_signature2"); |
| 703 | string test_cert2("test_cert2"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 704 | std::vector<string> certs2; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 705 | certs2.push_back(test_cert2); |
| 706 | state2->server_config = server_config2; |
| 707 | state2->source_address_token = source_address_token2; |
| 708 | state2->cert_sct = cert_sct2; |
| 709 | state2->chlo_hash = chlo_hash2; |
| 710 | state2->server_config_sig = signature2; |
| 711 | state2->certs = certs2; |
| 712 | |
| 713 | quic_server_info2->Persist(); |
| 714 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 715 | // Verify the MRU order is maintained. |
| 716 | const QuicServerInfoMap& quic_server_info_map = |
| 717 | http_server_properties_.quic_server_info_map(); |
| 718 | EXPECT_EQ(2u, quic_server_info_map.size()); |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 719 | auto quic_server_info_map_it = quic_server_info_map.begin(); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 720 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 721 | ++quic_server_info_map_it; |
| 722 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 723 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 724 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 725 | "192.168.0.1", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 726 | |
| 727 | // Create a session and verify that the cached state is loaded. |
| 728 | MockQuicData socket_data; |
| 729 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 730 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 731 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 732 | QuicStreamRequest request(factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 733 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 734 | request.Request( |
| 735 | HostPortPair(quic_server_id.host(), quic_server_id.port()), |
| 736 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 737 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 738 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 739 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 740 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 741 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 742 | factory_.get(), quic_server_id)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 743 | quic::QuicCryptoClientConfig* crypto_config = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 744 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 745 | quic::QuicCryptoClientConfig::CachedState* cached = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 746 | crypto_config->LookupOrCreate(quic_server_id); |
| 747 | EXPECT_FALSE(cached->server_config().empty()); |
| 748 | EXPECT_TRUE(cached->GetServerConfig()); |
| 749 | EXPECT_EQ(server_config, cached->server_config()); |
| 750 | EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 751 | EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 752 | EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 753 | EXPECT_EQ(signature, cached->signature()); |
| 754 | ASSERT_EQ(1U, cached->certs().size()); |
| 755 | EXPECT_EQ(test_cert, cached->certs()[0]); |
| 756 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 757 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 758 | |
| 759 | // Create a session and verify that the cached state is loaded. |
| 760 | MockQuicData socket_data2; |
| 761 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 762 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 763 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 764 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 765 | "192.168.0.2", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 766 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 767 | QuicStreamRequest request2(factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 768 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 769 | request2.Request( |
| 770 | HostPortPair(quic_server_id2.host(), quic_server_id2.port()), |
| 771 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 772 | /*cert_verify_flags=*/0, GURL("https://mail.example.org/"), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 773 | net_log_, &net_error_details_, |
| 774 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 775 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 776 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 777 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 778 | factory_.get(), quic_server_id2)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 779 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 780 | crypto_config->LookupOrCreate(quic_server_id2); |
| 781 | EXPECT_FALSE(cached2->server_config().empty()); |
| 782 | EXPECT_TRUE(cached2->GetServerConfig()); |
| 783 | EXPECT_EQ(server_config2, cached2->server_config()); |
| 784 | EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 785 | EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 786 | EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 787 | EXPECT_EQ(signature2, cached2->signature()); |
| 788 | ASSERT_EQ(1U, cached->certs().size()); |
| 789 | EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 790 | } |
| 791 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 792 | void RunTestLoopUntilIdle() { |
| 793 | while (!runner_->GetPostedTasks().empty()) |
| 794 | runner_->RunNextTask(); |
| 795 | } |
| 796 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 797 | quic::QuicStreamId GetNthClientInitiatedBidirectionalStreamId(int n) { |
| 798 | return quic::test::GetNthClientInitiatedBidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 799 | } |
| 800 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 801 | quic::QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(int n) { |
| 802 | return quic::test::GetNthServerInitiatedUnidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 803 | } |
| 804 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 805 | void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } |
| 806 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 807 | // Helper methods for tests of connection migration on write error. |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 808 | void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode, |
| 809 | bool migrate_idle_sessions); |
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); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 836 | void TestOnNetworkMadeDefaultNonMigratableStream(bool migrate_idle_sessions); |
| 837 | void TestMigrateSessionEarlyNonMigratableStream(bool migrate_idle_sessions); |
| 838 | void TestOnNetworkDisconnectedNoOpenStreams(bool migrate_idle_sessions); |
| 839 | void TestOnNetworkMadeDefaultNoOpenStreams(bool migrate_idle_sessions); |
| 840 | void TestOnNetworkDisconnectedNonMigratableStream(bool migrate_idle_sessions); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 841 | |
Jana Iyengar | f6b13d8 | 2017-09-04 02:09:10 | [diff] [blame] | 842 | QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 843 | std::unique_ptr<MockHostResolverBase> host_resolver_; |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 844 | std::unique_ptr<SSLConfigService> ssl_config_service_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 845 | std::unique_ptr<MockClientSocketFactory> socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 846 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 847 | quic::test::MockRandom random_generator_; |
| 848 | quic::MockClock clock_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 849 | scoped_refptr<TestTaskRunner> runner_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 850 | const quic::QuicTransportVersion version_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 851 | QuicTestPacketMaker client_maker_; |
| 852 | QuicTestPacketMaker server_maker_; |
rtenneti | ccab42b | 2015-10-09 06:38:16 | [diff] [blame] | 853 | HttpServerPropertiesImpl http_server_properties_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 854 | std::unique_ptr<CertVerifier> cert_verifier_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 855 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 856 | std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
Ryan Sleevi | 8a9c9c1 | 2018-05-09 02:36:23 | [diff] [blame] | 857 | DefaultCTPolicyEnforcer ct_policy_enforcer_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 858 | std::unique_ptr<ScopedMockNetworkChangeNotifier> |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 859 | scoped_mock_network_change_notifier_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 860 | std::unique_ptr<QuicStreamFactory> factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 861 | HostPortPair host_port_pair_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 862 | GURL url_; |
| 863 | GURL url2_; |
| 864 | GURL url3_; |
| 865 | GURL url4_; |
| 866 | |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 867 | PrivacyMode privacy_mode_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 868 | NetLogWithSource net_log_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 869 | TestCompletionCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 870 | const CompletionRepeatingCallback failed_on_default_network_callback_; |
| 871 | bool failed_on_default_network_; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 872 | NetErrorDetails net_error_details_; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 873 | |
| 874 | // Variables to configure QuicStreamFactory. |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 875 | HttpNetworkSession::Params test_params_; |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 876 | bool store_server_configs_in_properties_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 877 | }; |
| 878 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 879 | class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 880 | public ::testing::TestWithParam<TestParams> { |
| 881 | protected: |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 882 | QuicStreamFactoryTest() |
| 883 | : QuicStreamFactoryTestBase( |
| 884 | GetParam().version, |
| 885 | GetParam().client_headers_include_h2_stream_dependency) {} |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 886 | }; |
| 887 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 888 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 889 | QuicStreamFactoryTest, |
| 890 | ::testing::ValuesIn(GetTestParams())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 891 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 892 | TEST_P(QuicStreamFactoryTest, Create) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 893 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 894 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 895 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 896 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 897 | MockQuicData socket_data; |
| 898 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 899 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 900 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 901 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 902 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 903 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 904 | request.Request( |
| 905 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 906 | SocketTag(), |
| 907 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 908 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 909 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 910 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 911 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 912 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 913 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 914 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 915 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 916 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 917 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 918 | DEFAULT_PRIORITY, SocketTag(), |
| 919 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 920 | &net_error_details_, |
| 921 | failed_on_default_network_callback_, |
| 922 | callback_.callback())); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 923 | // Will reset stream 3. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 924 | stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 925 | |
| 926 | EXPECT_TRUE(stream.get()); |
| 927 | |
| 928 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 929 | // in streams on different sessions. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 930 | QuicStreamRequest request3(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 931 | EXPECT_EQ(OK, request3.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 932 | DEFAULT_PRIORITY, SocketTag(), |
| 933 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 934 | &net_error_details_, |
| 935 | failed_on_default_network_callback_, |
| 936 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 937 | stream = CreateStream(&request3); // Will reset stream 5. |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 938 | stream.reset(); // Will reset stream 7. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 939 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 940 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 941 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 942 | } |
| 943 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 944 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 945 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 946 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 947 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 948 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 949 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 950 | MockQuicData socket_data; |
| 951 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 952 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 953 | |
| 954 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 955 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 956 | host_resolver_->set_synchronous_mode(true); |
| 957 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 958 | "192.168.0.1", ""); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 959 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 960 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 961 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 962 | DEFAULT_PRIORITY, SocketTag(), |
| 963 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 964 | &net_error_details_, |
| 965 | failed_on_default_network_callback_, |
| 966 | callback_.callback())); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 967 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 968 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 969 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 970 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 971 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 972 | } |
| 973 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 974 | TEST_P(QuicStreamFactoryTest, DefaultInitialRtt) { |
| 975 | Initialize(); |
| 976 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 977 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 978 | |
| 979 | MockQuicData socket_data; |
| 980 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 981 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 982 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 983 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 984 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 985 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 986 | request.Request( |
| 987 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 988 | SocketTag(), |
| 989 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 990 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 991 | |
| 992 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 993 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 994 | EXPECT_TRUE(stream.get()); |
| 995 | |
| 996 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 997 | EXPECT_TRUE(session->require_confirmation()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 998 | EXPECT_EQ(100000u, session->connection()->GetStats().srtt_us); |
| 999 | ASSERT_FALSE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1000 | } |
| 1001 | |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1002 | TEST_P(QuicStreamFactoryTest, FactoryDestroyedWhenJobPending) { |
| 1003 | Initialize(); |
| 1004 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1005 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1006 | |
| 1007 | MockQuicData socket_data; |
| 1008 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1009 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1010 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1011 | |
| 1012 | auto request = std::make_unique<QuicStreamRequest>(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1013 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1014 | request->Request( |
| 1015 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1016 | SocketTag(), |
| 1017 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1018 | failed_on_default_network_callback_, callback_.callback())); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1019 | request.reset(); |
| 1020 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1021 | // Tearing down a QuicStreamFactory with a pending Job should not cause any |
| 1022 | // crash. crbug.com/768343. |
| 1023 | factory_.reset(); |
| 1024 | } |
| 1025 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1026 | TEST_P(QuicStreamFactoryTest, RequireConfirmation) { |
| 1027 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1028 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1029 | host_resolver_->set_synchronous_mode(true); |
| 1030 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1031 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1032 | Initialize(); |
| 1033 | factory_->set_require_confirmation(true); |
| 1034 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1035 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1036 | |
| 1037 | MockQuicData socket_data; |
| 1038 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1039 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1040 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1041 | |
| 1042 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1043 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1044 | request.Request( |
| 1045 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1046 | SocketTag(), |
| 1047 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1048 | failed_on_default_network_callback_, callback_.callback())); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1049 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1050 | IPAddress last_address; |
| 1051 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1052 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1053 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1054 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1055 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1056 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1057 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1058 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1059 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1060 | EXPECT_TRUE(stream.get()); |
| 1061 | |
| 1062 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1063 | EXPECT_TRUE(session->require_confirmation()); |
| 1064 | } |
| 1065 | |
| 1066 | TEST_P(QuicStreamFactoryTest, DontRequireConfirmationFromSameIP) { |
| 1067 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1068 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1069 | host_resolver_->set_synchronous_mode(true); |
| 1070 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1071 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1072 | Initialize(); |
| 1073 | factory_->set_require_confirmation(true); |
| 1074 | http_server_properties_.SetSupportsQuic(IPAddress(192, 0, 2, 33)); |
| 1075 | |
| 1076 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1077 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1078 | |
| 1079 | MockQuicData socket_data; |
| 1080 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1081 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1082 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1083 | |
| 1084 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1085 | EXPECT_THAT(request.Request( |
| 1086 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1087 | SocketTag(), |
| 1088 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1089 | failed_on_default_network_callback_, callback_.callback()), |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1090 | IsOk()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1091 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1092 | IPAddress last_address; |
| 1093 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1094 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1095 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1096 | EXPECT_TRUE(stream.get()); |
| 1097 | |
| 1098 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1099 | EXPECT_FALSE(session->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1100 | |
| 1101 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1102 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1103 | |
| 1104 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1105 | } |
| 1106 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1107 | TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { |
| 1108 | ServerNetworkStats stats; |
| 1109 | stats.srtt = base::TimeDelta::FromMilliseconds(10); |
| 1110 | http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), |
| 1111 | stats); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 1112 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1113 | |
| 1114 | Initialize(); |
| 1115 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1116 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1117 | |
| 1118 | MockQuicData socket_data; |
| 1119 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1120 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1121 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1122 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1123 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1124 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1125 | request.Request( |
| 1126 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1127 | SocketTag(), |
| 1128 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1129 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1130 | |
| 1131 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1132 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1133 | EXPECT_TRUE(stream.get()); |
| 1134 | |
| 1135 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1136 | EXPECT_EQ(10000u, session->connection()->GetStats().srtt_us); |
| 1137 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1138 | EXPECT_EQ(10000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1139 | } |
| 1140 | |
| 1141 | TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { |
| 1142 | ScopedMockNetworkChangeNotifier notifier; |
| 1143 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1144 | NetworkChangeNotifier::CONNECTION_2G); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 1145 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1146 | |
| 1147 | Initialize(); |
| 1148 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1149 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1150 | |
| 1151 | MockQuicData socket_data; |
| 1152 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1153 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1154 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1155 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1156 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1157 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1158 | request.Request( |
| 1159 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1160 | SocketTag(), |
| 1161 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1162 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1163 | |
| 1164 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1165 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1166 | EXPECT_TRUE(stream.get()); |
| 1167 | |
| 1168 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1169 | EXPECT_EQ(1200000u, session->connection()->GetStats().srtt_us); |
| 1170 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1171 | EXPECT_EQ(1200000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1172 | } |
| 1173 | |
| 1174 | TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { |
| 1175 | ScopedMockNetworkChangeNotifier notifier; |
| 1176 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1177 | NetworkChangeNotifier::CONNECTION_3G); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 1178 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1179 | |
| 1180 | Initialize(); |
| 1181 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1182 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1183 | |
| 1184 | MockQuicData socket_data; |
| 1185 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1186 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1187 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1188 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1189 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1190 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1191 | request.Request( |
| 1192 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1193 | SocketTag(), |
| 1194 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1195 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1196 | |
| 1197 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1198 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1199 | EXPECT_TRUE(stream.get()); |
| 1200 | |
| 1201 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1202 | EXPECT_EQ(400000u, session->connection()->GetStats().srtt_us); |
| 1203 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1204 | EXPECT_EQ(400000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1205 | } |
| 1206 | |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1207 | TEST_P(QuicStreamFactoryTest, GoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1208 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1209 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1210 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1211 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1212 | MockQuicData socket_data; |
| 1213 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1214 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1215 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1216 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1217 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1218 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1219 | request.Request( |
| 1220 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1221 | SocketTag(), |
| 1222 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1223 | failed_on_default_network_callback_, callback_.callback())); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1224 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1225 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1226 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1227 | EXPECT_TRUE(stream.get()); |
| 1228 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1229 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1230 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1231 | session->OnGoAway(quic::QuicGoAwayFrame()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1232 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1233 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1234 | |
| 1235 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1236 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1237 | } |
| 1238 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1239 | TEST_P(QuicStreamFactoryTest, GoAwayForConnectionMigrationWithPortOnly) { |
| 1240 | Initialize(); |
| 1241 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1242 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1243 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1244 | MockQuicData socket_data; |
| 1245 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1246 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1247 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1248 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1249 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1250 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1251 | request.Request( |
| 1252 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1253 | SocketTag(), |
| 1254 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1255 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1256 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1257 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1258 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1259 | EXPECT_TRUE(stream.get()); |
| 1260 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1261 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1262 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1263 | session->OnGoAway(quic::QuicGoAwayFrame( |
| 1264 | quic::kInvalidControlFrameId, quic::QUIC_ERROR_MIGRATING_PORT, 0, |
| 1265 | "peer connection migration due to port change only")); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1266 | NetErrorDetails details; |
| 1267 | EXPECT_FALSE(details.quic_port_migration_detected); |
| 1268 | session->PopulateNetErrorDetails(&details); |
| 1269 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1270 | details.quic_port_migration_detected = false; |
| 1271 | stream->PopulateNetErrorDetails(&details); |
| 1272 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1273 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1274 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1275 | |
| 1276 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1277 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1278 | } |
| 1279 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1280 | TEST_P(QuicStreamFactoryTest, Pooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1281 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1282 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1283 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1284 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1285 | MockQuicData socket_data; |
| 1286 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1287 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1288 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1289 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1290 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1291 | host_resolver_->set_synchronous_mode(true); |
| 1292 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1293 | "192.168.0.1", ""); |
| 1294 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1295 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1296 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1297 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1298 | DEFAULT_PRIORITY, SocketTag(), |
| 1299 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1300 | &net_error_details_, |
| 1301 | failed_on_default_network_callback_, |
| 1302 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1303 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1304 | EXPECT_TRUE(stream.get()); |
| 1305 | |
| 1306 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1307 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1308 | EXPECT_EQ(OK, |
| 1309 | request2.Request( |
| 1310 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1311 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1312 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1313 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1314 | EXPECT_TRUE(stream2.get()); |
| 1315 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1316 | EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1317 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1318 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1319 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1320 | } |
| 1321 | |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1322 | TEST_P(QuicStreamFactoryTest, PoolingWithServerMigration) { |
| 1323 | // Set up session to migrate. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1324 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1325 | "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1326 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 443); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1327 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 1328 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1329 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1330 | |
| 1331 | VerifyServerMigration(config, alt_address); |
| 1332 | |
| 1333 | // Close server-migrated session. |
| 1334 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1335 | session->CloseSessionOnError(0u, quic::QUIC_NO_ERROR, |
| 1336 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1337 | |
| 1338 | // Set up server IP, socket, proof, and config for new session. |
| 1339 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1340 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1341 | |
| 1342 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1343 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 1344 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 1345 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 1346 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1347 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1348 | SequencedSocketData socket_data(reads, writes); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1349 | socket_factory_->AddSocketDataProvider(&socket_data); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1350 | |
| 1351 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1352 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1353 | quic::QuicConfig config2; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1354 | crypto_client_stream_factory_.SetConfig(config2); |
| 1355 | |
| 1356 | // Create new request to cause new session creation. |
| 1357 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1358 | QuicStreamRequest request2(factory_.get()); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1359 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1360 | request2.Request( |
| 1361 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1362 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1363 | failed_on_default_network_callback_, callback.callback())); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1364 | EXPECT_EQ(OK, callback.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1365 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1366 | EXPECT_TRUE(stream2.get()); |
| 1367 | |
| 1368 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1369 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1370 | // EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
| 1371 | } |
| 1372 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1373 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1374 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1375 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1376 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1377 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1378 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1379 | MockQuicData socket_data1; |
| 1380 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1381 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1382 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1383 | MockQuicData socket_data2; |
| 1384 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1385 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1386 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1387 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1388 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1389 | host_resolver_->set_synchronous_mode(true); |
| 1390 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1391 | "192.168.0.1", ""); |
| 1392 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1393 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1394 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1395 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1396 | DEFAULT_PRIORITY, SocketTag(), |
| 1397 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1398 | &net_error_details_, |
| 1399 | failed_on_default_network_callback_, |
| 1400 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1401 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1402 | EXPECT_TRUE(stream.get()); |
| 1403 | |
| 1404 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1405 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1406 | EXPECT_EQ(OK, |
| 1407 | request2.Request( |
| 1408 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1409 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1410 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1411 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1412 | EXPECT_TRUE(stream2.get()); |
| 1413 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1414 | factory_->OnSessionGoingAway(GetActiveSession(host_port_pair_)); |
| 1415 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1416 | EXPECT_FALSE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1417 | |
| 1418 | TestCompletionCallback callback3; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1419 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1420 | EXPECT_EQ(OK, |
| 1421 | request3.Request( |
| 1422 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1423 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1424 | failed_on_default_network_callback_, callback3.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1425 | std::unique_ptr<HttpStream> stream3 = CreateStream(&request3); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1426 | EXPECT_TRUE(stream3.get()); |
| 1427 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1428 | EXPECT_TRUE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1429 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1430 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1431 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1432 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1433 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1434 | } |
| 1435 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1436 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1437 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1438 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1439 | MockQuicData socket_data; |
| 1440 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1441 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1442 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1443 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1444 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1445 | HostPortPair server2(kServer2HostName, 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1446 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1447 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1448 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1449 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1450 | host_resolver_->set_synchronous_mode(true); |
| 1451 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1452 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1453 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1454 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1455 | EXPECT_EQ(OK, |
| 1456 | request.Request( |
| 1457 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1458 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1459 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1460 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1461 | EXPECT_TRUE(stream.get()); |
| 1462 | |
| 1463 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1464 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1465 | EXPECT_EQ(OK, |
| 1466 | request2.Request( |
| 1467 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1468 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1469 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1470 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1471 | EXPECT_TRUE(stream2.get()); |
| 1472 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1473 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1474 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1475 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1476 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1477 | } |
| 1478 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1479 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1480 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1481 | MockQuicData socket_data; |
| 1482 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1483 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1484 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1485 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1486 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1487 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1488 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1489 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1490 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1491 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1492 | EXPECT_TRUE(primary_pin.FromString( |
| 1493 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1494 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1495 | verify_details.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1496 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1497 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1498 | host_resolver_->set_synchronous_mode(true); |
| 1499 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1500 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1501 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1502 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1503 | EXPECT_EQ(OK, |
| 1504 | request.Request( |
| 1505 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1506 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1507 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1508 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1509 | EXPECT_TRUE(stream.get()); |
| 1510 | |
| 1511 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1512 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1513 | EXPECT_EQ(OK, |
| 1514 | request2.Request( |
| 1515 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1516 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1517 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1518 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1519 | EXPECT_TRUE(stream2.get()); |
| 1520 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1521 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1522 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1523 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1524 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1528 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1529 | |
| 1530 | MockQuicData socket_data1; |
| 1531 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1532 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1533 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1534 | MockQuicData socket_data2; |
| 1535 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1536 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1537 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1538 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1539 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1540 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1541 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1542 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1543 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1544 | ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1545 | uint8_t bad_pin = 3; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1546 | verify_details1.cert_verify_result.public_key_hashes.push_back( |
| 1547 | test::GetTestHashValue(bad_pin)); |
| 1548 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 1549 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1550 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1551 | EXPECT_TRUE(primary_pin.FromString( |
| 1552 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1553 | ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1554 | verify_details2.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1555 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1556 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1557 | host_resolver_->set_synchronous_mode(true); |
| 1558 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1559 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1560 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1561 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1562 | EXPECT_EQ(OK, |
| 1563 | request.Request( |
| 1564 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1565 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1566 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1567 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1568 | EXPECT_TRUE(stream.get()); |
| 1569 | |
| 1570 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1571 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1572 | EXPECT_EQ(OK, |
| 1573 | request2.Request( |
| 1574 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1575 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1576 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1577 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1578 | EXPECT_TRUE(stream2.get()); |
| 1579 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1580 | EXPECT_NE(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1581 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1582 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1583 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1584 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1585 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1586 | } |
| 1587 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1588 | TEST_P(QuicStreamFactoryTest, Goaway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1589 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1590 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1591 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1592 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1593 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1594 | MockQuicData socket_data; |
| 1595 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1596 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1597 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1598 | MockQuicData socket_data2; |
| 1599 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1600 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1601 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1602 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1603 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1604 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1605 | request.Request( |
| 1606 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1607 | SocketTag(), |
| 1608 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1609 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1610 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1611 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1612 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1613 | EXPECT_TRUE(stream.get()); |
| 1614 | |
| 1615 | // Mark the session as going away. Ensure that while it is still alive |
| 1616 | // that it is no longer active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1617 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1618 | factory_->OnSessionGoingAway(session); |
| 1619 | EXPECT_EQ(true, |
| 1620 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1621 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1622 | |
| 1623 | // Create a new request for the same destination and verify that a |
| 1624 | // new session is created. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1625 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1626 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1627 | request2.Request( |
| 1628 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1629 | SocketTag(), |
| 1630 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1631 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1632 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1633 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1634 | EXPECT_TRUE(stream2.get()); |
| 1635 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1636 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1637 | EXPECT_NE(session, GetActiveSession(host_port_pair_)); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1638 | EXPECT_EQ(true, |
| 1639 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1640 | |
| 1641 | stream2.reset(); |
| 1642 | stream.reset(); |
| 1643 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1644 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1645 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1646 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1647 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1648 | } |
| 1649 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1650 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1651 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1652 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1653 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1654 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1655 | quic::QuicStreamId stream_id = GetNthClientInitiatedBidirectionalStreamId(0); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1656 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1657 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1658 | if (version_ == quic::QUIC_VERSION_99) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1659 | socket_data.AddWrite( |
| 1660 | SYNCHRONOUS, |
| 1661 | client_maker_.MakeStreamIdBlockedPacket( |
| 1662 | 2, true, GetNthClientInitiatedBidirectionalStreamId(49))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1663 | socket_data.AddWrite( |
| 1664 | SYNCHRONOUS, client_maker_.MakeRstPacket(3, true, stream_id, |
| 1665 | quic::QUIC_STREAM_CANCELLED)); |
| 1666 | socket_data.AddRead( |
| 1667 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1668 | quic::QUIC_STREAM_CANCELLED)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1669 | socket_data.AddRead( |
| 1670 | ASYNC, server_maker_.MakeMaxStreamIdPacket( |
| 1671 | 4, true, GetNthClientInitiatedBidirectionalStreamId(50))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1672 | } else { |
| 1673 | socket_data.AddWrite( |
| 1674 | SYNCHRONOUS, client_maker_.MakeRstPacket(2, true, stream_id, |
| 1675 | quic::QUIC_STREAM_CANCELLED)); |
| 1676 | socket_data.AddRead( |
| 1677 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1678 | quic::QUIC_STREAM_CANCELLED)); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1679 | } |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1680 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1681 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1682 | |
| 1683 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1684 | request_info.traffic_annotation = |
| 1685 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1686 | |
xunjieli | 1d2b427 | 2017-04-25 22:37:17 | [diff] [blame] | 1687 | std::vector<std::unique_ptr<HttpStream>> streams; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1688 | // The MockCryptoClientStream sets max_open_streams to be |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1689 | // quic::kDefaultMaxStreamsPerConnection / 2. |
| 1690 | for (size_t i = 0; i < quic::kDefaultMaxStreamsPerConnection / 2; i++) { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1691 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1692 | int rv = request.Request( |
| 1693 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1694 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1695 | failed_on_default_network_callback_, callback_.callback()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1696 | if (i == 0) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1698 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1699 | } else { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1700 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1701 | } |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1702 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1703 | EXPECT_TRUE(stream); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1704 | EXPECT_EQ(OK, |
| 1705 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1706 | net_log_, CompletionOnceCallback())); |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 1707 | streams.push_back(std::move(stream)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1708 | } |
| 1709 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1710 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1711 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1712 | DEFAULT_PRIORITY, SocketTag(), |
| 1713 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1714 | &net_error_details_, |
| 1715 | failed_on_default_network_callback_, |
| 1716 | CompletionOnceCallback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1717 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1718 | EXPECT_TRUE(stream); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1719 | EXPECT_EQ(ERR_IO_PENDING, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1720 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
| 1721 | net_log_, callback_.callback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1722 | |
| 1723 | // Close the first stream. |
| 1724 | streams.front()->Close(false); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1725 | // Trigger exchange of RSTs that in turn allow progress for the last |
| 1726 | // stream. |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1727 | base::RunLoop().RunUntilIdle(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1728 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1729 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1730 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1731 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1732 | |
| 1733 | // Force close of the connection to suppress the generation of RST |
| 1734 | // packets when streams are torn down, which wouldn't be relevant to |
| 1735 | // this test anyway. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1736 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1737 | session->connection()->CloseConnection( |
| 1738 | quic::QUIC_PUBLIC_RESET, "test", |
| 1739 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1740 | } |
| 1741 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1742 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1743 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1744 | MockQuicData socket_data; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1745 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1746 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1747 | host_resolver_->rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1748 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1749 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1750 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1751 | request.Request( |
| 1752 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1753 | SocketTag(), |
| 1754 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1755 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1756 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1757 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1758 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1759 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1760 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1761 | } |
| 1762 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1763 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1764 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1765 | |
| 1766 | MockQuicData socket_data; |
| 1767 | socket_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1768 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1769 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1770 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1771 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1772 | request.Request( |
| 1773 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1774 | SocketTag(), |
| 1775 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1776 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1777 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1778 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1779 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1780 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1781 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1782 | } |
| 1783 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1784 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1785 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1786 | MockQuicData socket_data; |
| 1787 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1788 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1789 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1790 | { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1791 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1792 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1793 | request.Request( |
| 1794 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1795 | SocketTag(), |
| 1796 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1797 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1798 | } |
| 1799 | |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 1800 | base::RunLoop().RunUntilIdle(); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1801 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1802 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 1803 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1804 | DEFAULT_PRIORITY, SocketTag(), |
| 1805 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1806 | &net_error_details_, |
| 1807 | failed_on_default_network_callback_, |
| 1808 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1809 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 1810 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1811 | EXPECT_TRUE(stream.get()); |
| 1812 | stream.reset(); |
| 1813 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1814 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1815 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1816 | } |
| 1817 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1818 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1819 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1820 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1821 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1822 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1823 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1824 | MockQuicData socket_data; |
| 1825 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1826 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1827 | socket_data.AddWrite( |
| 1828 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1829 | socket_data.AddWrite(SYNCHRONOUS, |
| 1830 | client_maker_.MakeConnectionClosePacket( |
| 1831 | 3, true, quic::QUIC_INTERNAL_ERROR, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1832 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1833 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1834 | MockQuicData socket_data2; |
| 1835 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1836 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1837 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1838 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1839 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1840 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1841 | request.Request( |
| 1842 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1843 | SocketTag(), |
| 1844 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1845 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1846 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1847 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1848 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1849 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1850 | request_info.traffic_annotation = |
| 1851 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1852 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1853 | net_log_, CompletionOnceCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1854 | |
| 1855 | // Close the session and verify that stream saw the error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1856 | factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, |
| 1857 | quic::QUIC_INTERNAL_ERROR); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1858 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1859 | stream->ReadResponseHeaders(callback_.callback())); |
| 1860 | |
| 1861 | // Now attempting to request a stream to the same origin should create |
| 1862 | // a new session. |
| 1863 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1864 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1865 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1866 | request2.Request( |
| 1867 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1868 | SocketTag(), |
| 1869 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1870 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1871 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1872 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1873 | stream = CreateStream(&request2); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1874 | stream.reset(); // Will reset stream 3. |
| 1875 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1876 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1877 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1878 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1879 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1880 | } |
| 1881 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1882 | // Regression test for crbug.com/700617. Test a write error during the |
| 1883 | // crypto handshake will not hang QuicStreamFactory::Job and should |
| 1884 | // report QUIC_HANDSHAKE_FAILED to upper layers. Subsequent |
| 1885 | // QuicStreamRequest should succeed without hanging. |
| 1886 | TEST_P(QuicStreamFactoryTest, |
| 1887 | WriteErrorInCryptoConnectWithAsyncHostResolution) { |
| 1888 | Initialize(); |
| 1889 | // Use unmocked crypto stream to do crypto connect. |
| 1890 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1891 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1892 | |
| 1893 | MockQuicData socket_data; |
| 1894 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1895 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1896 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1897 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1898 | |
| 1899 | // Create request, should fail after the write of the CHLO fails. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1900 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1901 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1902 | request.Request( |
| 1903 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1904 | SocketTag(), |
| 1905 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1906 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1907 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 1908 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1909 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1910 | |
| 1911 | // Verify new requests can be sent normally without hanging. |
| 1912 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1913 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1914 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1915 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1916 | MockQuicData socket_data2; |
| 1917 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1918 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1919 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1920 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1921 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1922 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1923 | request2.Request( |
| 1924 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1925 | SocketTag(), |
| 1926 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1927 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1928 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1929 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1930 | // Run the message loop to complete host resolution. |
| 1931 | base::RunLoop().RunUntilIdle(); |
| 1932 | |
| 1933 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 1934 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1935 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1936 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1937 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1938 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1939 | |
| 1940 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1941 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1942 | EXPECT_TRUE(stream.get()); |
| 1943 | stream.reset(); |
| 1944 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1945 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1946 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1947 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1948 | } |
| 1949 | |
| 1950 | TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { |
| 1951 | Initialize(); |
| 1952 | // Use unmocked crypto stream to do crypto connect. |
| 1953 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1954 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1955 | host_resolver_->set_synchronous_mode(true); |
| 1956 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1957 | "192.168.0.1", ""); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1958 | |
| 1959 | MockQuicData socket_data; |
| 1960 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1961 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1962 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1963 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1964 | |
| 1965 | // Create request, should fail immediately. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1966 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1967 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1968 | request.Request( |
| 1969 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1970 | SocketTag(), |
| 1971 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1972 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1973 | // Check no active session, or active jobs left for this server. |
| 1974 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1975 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1976 | |
| 1977 | // Verify new requests can be sent normally without hanging. |
| 1978 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1979 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1980 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1981 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1982 | MockQuicData socket_data2; |
| 1983 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1984 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1985 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1986 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1987 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1988 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1989 | request2.Request( |
| 1990 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1991 | SocketTag(), |
| 1992 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1993 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1994 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1995 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1996 | |
| 1997 | // Complete handshake. |
| 1998 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1999 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2000 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2001 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2002 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 2003 | |
| 2004 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2005 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2006 | EXPECT_TRUE(stream.get()); |
| 2007 | stream.reset(); |
| 2008 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2009 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2010 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2011 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2012 | } |
| 2013 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2014 | TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 2015 | test_params_.quic_close_sessions_on_ip_change = true; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2016 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 2017 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2018 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2019 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2020 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2021 | MockQuicData socket_data; |
| 2022 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2023 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2024 | socket_data.AddWrite( |
| 2025 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2026 | socket_data.AddWrite( |
| 2027 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 2028 | 3, true, quic::QUIC_IP_ADDRESS_CHANGED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2029 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2030 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2031 | MockQuicData socket_data2; |
| 2032 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2033 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2034 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2035 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2036 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2037 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2038 | request.Request( |
| 2039 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2040 | SocketTag(), |
| 2041 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2042 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2043 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2044 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2045 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 2046 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2047 | request_info.traffic_annotation = |
| 2048 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2049 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2050 | net_log_, CompletionOnceCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2051 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2052 | // Check an active session exisits for the destination. |
| 2053 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2054 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2055 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2056 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2057 | IPAddress last_address; |
| 2058 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2059 | // Change the IP address and verify that stream saw the error and the active |
| 2060 | // session is closed. |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2061 | NotifyIPAddressChanged(); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2062 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 2063 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2064 | EXPECT_TRUE(factory_->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2065 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2066 | // Check no active session exists for the destination. |
| 2067 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2068 | |
| 2069 | // Now attempting to request a stream to the same origin should create |
| 2070 | // a new session. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2071 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2072 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2073 | request2.Request( |
| 2074 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2075 | SocketTag(), |
| 2076 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2077 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2078 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2079 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2080 | stream = CreateStream(&request2); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2081 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2082 | // Check a new active session exisits for the destination and the old session |
| 2083 | // is no longer live. |
| 2084 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2085 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2086 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2087 | |
| 2088 | stream.reset(); // Will reset stream 3. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2089 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2090 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2091 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2092 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2093 | } |
| 2094 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2095 | // Test that if goaway_session_on_ip_change is set, old sessions will be marked |
| 2096 | // as going away on IP address change instead of being closed. New requests will |
| 2097 | // go to a new connection. |
| 2098 | TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 2099 | test_params_.quic_goaway_sessions_on_ip_change = true; |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2100 | Initialize(); |
| 2101 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2102 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2103 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2104 | |
| 2105 | MockQuicData quic_data1; |
| 2106 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2107 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2108 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2109 | quic_data1.AddWrite( |
| 2110 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2111 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2112 | true, &header_stream_offset)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2113 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2114 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2115 | ASYNC, |
| 2116 | ConstructOkResponsePacket( |
| 2117 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2118 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2119 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2120 | |
| 2121 | MockQuicData quic_data2; |
| 2122 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 2123 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2124 | quic_data2.AddWrite( |
| 2125 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 2126 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2127 | |
| 2128 | // Create request and QuicHttpStream. |
| 2129 | QuicStreamRequest request(factory_.get()); |
| 2130 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2131 | request.Request( |
| 2132 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2133 | SocketTag(), |
| 2134 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2135 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2136 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2137 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2138 | EXPECT_TRUE(stream.get()); |
| 2139 | |
| 2140 | // Cause QUIC stream to be created. |
| 2141 | HttpRequestInfo request_info; |
| 2142 | request_info.method = "GET"; |
| 2143 | request_info.url = url_; |
| 2144 | request_info.traffic_annotation = |
| 2145 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2146 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2147 | net_log_, CompletionOnceCallback())); |
| 2148 | |
| 2149 | // Ensure that session is alive and active. |
| 2150 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2151 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2152 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2153 | |
| 2154 | // Send GET request on stream. |
| 2155 | HttpResponseInfo response; |
| 2156 | HttpRequestHeaders request_headers; |
| 2157 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2158 | callback_.callback())); |
| 2159 | |
| 2160 | // Receive an IP address change notification. |
| 2161 | NotifyIPAddressChanged(); |
| 2162 | |
| 2163 | // The connection should still be alive, but marked as going away. |
| 2164 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2165 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2166 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2167 | |
| 2168 | // Resume the data, response should be read from the original connection. |
| 2169 | quic_data1.Resume(); |
| 2170 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2171 | EXPECT_EQ(200, response.headers->response_code()); |
| 2172 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2173 | |
| 2174 | // Second request should be sent on a new connection. |
| 2175 | QuicStreamRequest request2(factory_.get()); |
| 2176 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2177 | request2.Request( |
| 2178 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2179 | SocketTag(), |
| 2180 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2181 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2182 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2183 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 2184 | EXPECT_TRUE(stream2.get()); |
| 2185 | |
| 2186 | // Check an active session exisits for the destination. |
| 2187 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2188 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2189 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2190 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2191 | |
| 2192 | stream.reset(); |
| 2193 | stream2.reset(); |
| 2194 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2195 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2196 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2197 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2198 | } |
| 2199 | |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2200 | TEST_P(QuicStreamFactoryTest, OnIPAddressChangedWithConnectionMigration) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 2201 | InitializeConnectionMigrationV2Test( |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2202 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2203 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2204 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2205 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2206 | |
| 2207 | MockQuicData socket_data; |
| 2208 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2209 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2210 | socket_data.AddWrite( |
| 2211 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2212 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2213 | |
| 2214 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2215 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2216 | request.Request( |
| 2217 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2218 | SocketTag(), |
| 2219 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2220 | failed_on_default_network_callback_, callback_.callback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2221 | |
| 2222 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2223 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2224 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2225 | request_info.traffic_annotation = |
| 2226 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2227 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2228 | net_log_, CompletionOnceCallback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2229 | |
| 2230 | IPAddress last_address; |
| 2231 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2232 | |
| 2233 | // Change the IP address and verify that the connection is unaffected. |
| 2234 | NotifyIPAddressChanged(); |
| 2235 | EXPECT_FALSE(factory_->require_confirmation()); |
| 2236 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2237 | |
| 2238 | // Attempting a new request to the same origin uses the same connection. |
| 2239 | QuicStreamRequest request2(factory_.get()); |
| 2240 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2241 | DEFAULT_PRIORITY, SocketTag(), |
| 2242 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2243 | &net_error_details_, |
| 2244 | failed_on_default_network_callback_, |
| 2245 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2246 | stream = CreateStream(&request2); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2247 | |
| 2248 | stream.reset(); |
| 2249 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2250 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2251 | } |
| 2252 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2253 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithSynchronousWrite) { |
| 2254 | TestMigrationOnNetworkMadeDefault(SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2255 | } |
| 2256 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2257 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithAsyncWrite) { |
| 2258 | TestMigrationOnNetworkMadeDefault(ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2259 | } |
| 2260 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2261 | // Sets up a test which attempts connection migration successfully after probing |
| 2262 | // when a new network is made as default and the old default is still available. |
| 2263 | // |write_mode| specifies the write mode for the last write before |
| 2264 | // OnNetworkMadeDefault is delivered to session. |
| 2265 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkMadeDefault( |
| 2266 | IoMode write_mode) { |
| 2267 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2268 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2269 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2270 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2271 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2272 | // Using a testing task runner so that we can control time. |
| 2273 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2274 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2275 | |
| 2276 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2277 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2278 | |
| 2279 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2280 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2281 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2282 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2283 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2284 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2285 | write_mode, ConstructGetRequestPacket( |
| 2286 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2287 | true, &header_stream_offset)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2288 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2289 | |
| 2290 | // Set up the second socket data provider that is used after migration. |
| 2291 | // The response to the earlier request is read on the new socket. |
| 2292 | MockQuicData quic_data2; |
| 2293 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2294 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2295 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2296 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2297 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2298 | quic_data2.AddRead(ASYNC, |
| 2299 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2300 | // Ping packet to send after migration is completed. |
| 2301 | quic_data2.AddWrite(ASYNC, |
| 2302 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2303 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2304 | ASYNC, |
| 2305 | ConstructOkResponsePacket( |
| 2306 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2307 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2308 | quic_data2.AddWrite( |
| 2309 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2310 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2311 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2312 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2313 | |
| 2314 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2315 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2316 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2317 | request.Request( |
| 2318 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2319 | SocketTag(), |
| 2320 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2321 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2322 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2323 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2324 | EXPECT_TRUE(stream.get()); |
| 2325 | |
| 2326 | // Cause QUIC stream to be created. |
| 2327 | HttpRequestInfo request_info; |
| 2328 | request_info.method = "GET"; |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 2329 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2330 | request_info.traffic_annotation = |
| 2331 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2332 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2333 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2334 | |
| 2335 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2336 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2337 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2338 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2339 | |
| 2340 | // Send GET request on stream. |
| 2341 | HttpResponseInfo response; |
| 2342 | HttpRequestHeaders request_headers; |
| 2343 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2344 | callback_.callback())); |
| 2345 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2346 | // Deliver a signal that a alternate network is connected now, this should |
| 2347 | // cause the connection to start early migration on path degrading. |
| 2348 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2349 | ->SetConnectedNetworksList( |
| 2350 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2351 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2352 | ->NotifyNetworkConnected(kNewNetworkForTests); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2353 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2354 | // Cause the connection to report path degrading to the session. |
| 2355 | // Due to lack of alternate network, session will not mgirate connection. |
| 2356 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2357 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2358 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2359 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2360 | // A task will be posted to migrate to the new default network. |
| 2361 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2362 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2363 | |
| 2364 | // Execute the posted task to migrate back to the default network. |
| 2365 | task_runner->RunUntilIdle(); |
| 2366 | // Another task to try send a new connectivity probe is posted. And a task to |
| 2367 | // retry migrate back to default network is scheduled. |
| 2368 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2369 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2370 | // kDefaultRTTMilliSecs. |
| 2371 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2372 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2373 | next_task_delay); |
| 2374 | |
| 2375 | // The connection should still be alive, and not marked as going away. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2376 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2377 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2378 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2379 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2380 | |
| 2381 | // Resume quic data and a connectivity probe response will be read on the new |
| 2382 | // socket, declare probing as successful. And a new task to WriteToNewSocket |
| 2383 | // will be posted to complete migration. |
| 2384 | quic_data2.Resume(); |
| 2385 | |
| 2386 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2387 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2388 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2389 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2390 | // There should be three pending tasks, the nearest one will complete |
| 2391 | // migration to the new network. |
| 2392 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2393 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2394 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 2395 | task_runner->FastForwardBy(next_task_delay); |
| 2396 | |
| 2397 | // Response headers are received over the new network. |
| 2398 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2399 | EXPECT_EQ(200, response.headers->response_code()); |
| 2400 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2401 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 2402 | // probe and has been cancelled due to successful migration. |
| 2403 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2404 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2405 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2406 | next_task_delay); |
| 2407 | task_runner->FastForwardBy(next_task_delay); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2408 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2409 | // There's one more task to mgirate back to the default network in 0.4s, which |
| 2410 | // is also cancelled due to the success migration on the previous trial. |
| 2411 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2412 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2413 | base::TimeDelta expected_delay = |
| 2414 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2415 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2416 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2417 | task_runner->FastForwardBy(next_task_delay); |
| 2418 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2419 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2420 | // Verify that the session is still alive. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2421 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2422 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2423 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2424 | stream.reset(); |
| 2425 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2426 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2427 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2428 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2429 | } |
| 2430 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2431 | // Regression test for http://859674. |
| 2432 | // This test veries that a writer will not attempt to write packets until being |
| 2433 | // unblocked on both socket level and network level. In this test, a probing |
| 2434 | // writer is used to send two connectivity probes to the peer: where the first |
| 2435 | // one completes successfully, while a connectivity response is received before |
| 2436 | // completes sending the second one. The connection migration attempt will |
| 2437 | // proceed while the probing writer is blocked at the socket level, which will |
| 2438 | // block the writer on the network level. Once connection migration completes |
| 2439 | // successfully, the probing writer will be unblocked on the network level, it |
| 2440 | // will not attempt to write new packets until the socket level is unblocked. |
| 2441 | TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { |
| 2442 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 2443 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2444 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2445 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2446 | |
| 2447 | // Using a testing task runner so that we can control time. |
| 2448 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2449 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2450 | |
| 2451 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2452 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2453 | |
| 2454 | MockQuicData quic_data1; |
| 2455 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2456 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2457 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2458 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2459 | quic_data1.AddWrite( |
| 2460 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2461 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2462 | true, &header_stream_offset)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2463 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2464 | |
| 2465 | // Set up the second socket data provider that is used after migration. |
| 2466 | // The response to the earlier request is read on the new socket. |
| 2467 | MockQuicData quic_data2; |
| 2468 | // First connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2469 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2470 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2471 | quic_data2.AddRead(ASYNC, |
| 2472 | ERR_IO_PENDING); // Pause so that we can control time. |
| 2473 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2474 | quic_data2.AddRead(ASYNC, |
| 2475 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2476 | // Second connectivity probe which will complete asynchronously. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2477 | quic_data2.AddWrite(ASYNC, |
| 2478 | client_maker_.MakeConnectivityProbingPacket(4, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2479 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2480 | ASYNC, |
| 2481 | ConstructOkResponsePacket( |
| 2482 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2483 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2484 | quic_data2.AddWrite(ASYNC, |
| 2485 | client_maker_.MakeAckAndPingPacket(5, false, 1, 1, 1)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2486 | quic_data2.AddWrite( |
| 2487 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2488 | 6, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2489 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2490 | |
| 2491 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2492 | |
| 2493 | // Create request and QuicHttpStream. |
| 2494 | QuicStreamRequest request(factory_.get()); |
| 2495 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2496 | request.Request( |
| 2497 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2498 | SocketTag(), |
| 2499 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2500 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2501 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2502 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2503 | EXPECT_TRUE(stream.get()); |
| 2504 | |
| 2505 | // Cause QUIC stream to be created. |
| 2506 | HttpRequestInfo request_info; |
| 2507 | request_info.method = "GET"; |
| 2508 | request_info.url = url_; |
| 2509 | request_info.traffic_annotation = |
| 2510 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2511 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2512 | net_log_, CompletionOnceCallback())); |
| 2513 | |
| 2514 | // Ensure that session is alive and active. |
| 2515 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2516 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2517 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2518 | |
| 2519 | // Send GET request on stream. |
| 2520 | HttpResponseInfo response; |
| 2521 | HttpRequestHeaders request_headers; |
| 2522 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2523 | callback_.callback())); |
| 2524 | |
| 2525 | // Deliver a signal that a alternate network is connected now, this should |
| 2526 | // cause the connection to start early migration on path degrading. |
| 2527 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2528 | ->SetConnectedNetworksList( |
| 2529 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2530 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2531 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 2532 | |
| 2533 | // Cause the connection to report path degrading to the session. |
| 2534 | // Due to lack of alternate network, session will not mgirate connection. |
| 2535 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2536 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2537 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2538 | |
| 2539 | // A task will be posted to migrate to the new default network. |
| 2540 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2541 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2542 | |
| 2543 | // Execute the posted task to migrate back to the default network. |
| 2544 | task_runner->RunUntilIdle(); |
| 2545 | // Another task to resend a new connectivity probe is posted. And a task to |
| 2546 | // retry migrate back to default network is scheduled. |
| 2547 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2548 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2549 | // kDefaultRTTMilliSecs. |
| 2550 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2551 | base::TimeDelta expected_delay = |
| 2552 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2553 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2554 | |
| 2555 | // Fast forward to send the second connectivity probe. The write will be |
| 2556 | // asynchronous and complete after the read completes. |
| 2557 | task_runner->FastForwardBy(next_task_delay); |
| 2558 | |
| 2559 | // Resume quic data and a connectivity probe response will be read on the new |
| 2560 | // socket, declare probing as successful. |
| 2561 | quic_data2.Resume(); |
| 2562 | |
| 2563 | // The connection should still be alive, and not marked as going away. |
| 2564 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2565 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2566 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2567 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2568 | |
| 2569 | // There should be three pending tasks, the nearest one will complete |
| 2570 | // migration to the new network. Second task will retry migrate back to |
| 2571 | // default but cancelled, and the third task will retry send connectivity |
| 2572 | // probe but also cancelled. |
| 2573 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2574 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2575 | task_runner->RunUntilIdle(); |
| 2576 | |
| 2577 | // Response headers are received over the new network. |
| 2578 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2579 | EXPECT_EQ(200, response.headers->response_code()); |
| 2580 | |
| 2581 | // Run the message loop to complete the asynchronous write of ack and ping. |
| 2582 | base::RunLoop().RunUntilIdle(); |
| 2583 | |
| 2584 | // Now there are two pending tasks, the nearest one was to retry migrate back |
| 2585 | // to default network and has been cancelled due to successful migration. |
| 2586 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2587 | expected_delay = |
| 2588 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2589 | expected_delay; |
| 2590 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2591 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2592 | task_runner->FastForwardBy(next_task_delay); |
| 2593 | |
| 2594 | // There's one more task to retry sending connectivity probe in 0.4s and has |
| 2595 | // also been cancelled due to the successful probing. |
| 2596 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2597 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2598 | expected_delay = |
| 2599 | base::TimeDelta::FromMilliseconds(3 * 2 * kDefaultRTTMilliSecs) - |
| 2600 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 2601 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2602 | task_runner->FastForwardBy(next_task_delay); |
| 2603 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2604 | |
| 2605 | // Verify that the session is still alive. |
| 2606 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2607 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2608 | |
| 2609 | stream.reset(); |
| 2610 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2611 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2612 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2613 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2614 | } |
| 2615 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2616 | // This test verifies that session times out connection migration attempt |
| 2617 | // with signals delivered in the following order (no alternate network is |
| 2618 | // available): |
| 2619 | // - default network disconnected is delivered: session attempts connection |
| 2620 | // migration but found not alternate network. Session waits for a new network |
Zhongyi Shi | e01f2db | 2019-02-22 19:53:23 | [diff] [blame] | 2621 | // comes up in the next kWaitTimeForNewNetworkSecs seconds. |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2622 | // - no new network is connected, migration times out. Session is closed. |
| 2623 | TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { |
| 2624 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2625 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2626 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2627 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2628 | // Using a testing task runner so that we can control time. |
| 2629 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2630 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2631 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2632 | MockQuicData socket_data; |
| 2633 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2634 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2635 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2636 | |
| 2637 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2638 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2639 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2640 | request.Request( |
| 2641 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2642 | SocketTag(), |
| 2643 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2644 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2645 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2646 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2647 | EXPECT_TRUE(stream.get()); |
| 2648 | |
| 2649 | // Cause QUIC stream to be created. |
| 2650 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2651 | request_info.traffic_annotation = |
| 2652 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2653 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2654 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2655 | |
| 2656 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2657 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2658 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2659 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2660 | |
| 2661 | // Trigger connection migration. Since there are no networks |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2662 | // to migrate to, this should cause the session to wait for a new network. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2663 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2664 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2665 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2666 | // The migration will not fail until the migration alarm timeout. |
| 2667 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2668 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2669 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2670 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2671 | EXPECT_EQ(true, session->connection()->writer()->IsWriteBlocked()); |
| 2672 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2673 | // Migration will be timed out after kWaitTimeForNewNetwokSecs. |
| 2674 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2675 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2676 | EXPECT_EQ(base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs), |
| 2677 | next_task_delay); |
| 2678 | task_runner->FastForwardBy(next_task_delay); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2679 | |
| 2680 | // The connection should now be closed. A request for response |
| 2681 | // headers should fail. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2682 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2683 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2684 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2685 | |
| 2686 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2687 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2688 | } |
| 2689 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2690 | // This test verifies that connectivity probes will be sent even if there is |
| 2691 | // a non-migratable stream. However, when connection migrates to the |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2692 | // successfully probed path, any non-migratable streams will be reset. |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2693 | TEST_P(QuicStreamFactoryTest, |
| 2694 | OnNetworkMadeDefaultNonMigratableStream_MigrateIdleSessions) { |
| 2695 | TestOnNetworkMadeDefaultNonMigratableStream(true); |
| 2696 | } |
| 2697 | |
| 2698 | // This test verifies that connectivity probes will be sent even if there is |
| 2699 | // a non-migratable stream. However, when connection migrates to the |
| 2700 | // successfully probed path, any non-migratable stream will be reset. And if |
| 2701 | // the connection becomes idle then, close the connection. |
| 2702 | TEST_P(QuicStreamFactoryTest, |
| 2703 | OnNetworkMadeDefaultNonMigratableStream_DoNotMigrateIdleSessions) { |
| 2704 | TestOnNetworkMadeDefaultNonMigratableStream(false); |
| 2705 | } |
| 2706 | |
| 2707 | void QuicStreamFactoryTestBase::TestOnNetworkMadeDefaultNonMigratableStream( |
| 2708 | bool migrate_idle_sessions) { |
| 2709 | test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2710 | InitializeConnectionMigrationV2Test( |
| 2711 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2712 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2713 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2714 | |
| 2715 | MockQuicData socket_data; |
| 2716 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2717 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2718 | if (!migrate_idle_sessions) { |
| 2719 | socket_data.AddWrite( |
| 2720 | SYNCHRONOUS, |
| 2721 | client_maker_.MakeRstAckAndConnectionClosePacket( |
| 2722 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2723 | quic::QUIC_STREAM_CANCELLED, |
| 2724 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 2725 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 2726 | "net error")); |
| 2727 | } |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2728 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2729 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2730 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2731 | // Set up the second socket data provider that is used for probing. |
| 2732 | MockQuicData quic_data1; |
| 2733 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2734 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2735 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2736 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2737 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2738 | quic_data1.AddRead(ASYNC, |
| 2739 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2740 | if (migrate_idle_sessions) { |
| 2741 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2742 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 2743 | quic_data1.AddWrite( |
| 2744 | SYNCHRONOUS, |
| 2745 | client_maker_.MakeRstPacket( |
| 2746 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2747 | quic::QUIC_STREAM_CANCELLED)); |
| 2748 | // Ping packet to send after migration is completed. |
| 2749 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2750 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2751 | } |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2752 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2753 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2754 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2755 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2756 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2757 | request.Request( |
| 2758 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2759 | SocketTag(), |
| 2760 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2761 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2762 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2763 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2764 | EXPECT_TRUE(stream.get()); |
| 2765 | |
| 2766 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2767 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2768 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2769 | request_info.traffic_annotation = |
| 2770 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2771 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2772 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2773 | |
| 2774 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2775 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2776 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2777 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2778 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2779 | // Trigger connection migration. Session will start to probe the alternative |
| 2780 | // network. Although there is a non-migratable stream, session will still be |
| 2781 | // active until probing is declared as successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2782 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2783 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2784 | |
| 2785 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2786 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2787 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2788 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2789 | // Resume data to read a connectivity probing response, which will cause |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2790 | // non-migtable streams to be closed. |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2791 | quic_data1.Resume(); |
| 2792 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2793 | EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2794 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2795 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2796 | base::RunLoop().RunUntilIdle(); |
| 2797 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2798 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2799 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2800 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2801 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2802 | } |
| 2803 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2804 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2805 | InitializeConnectionMigrationV2Test( |
| 2806 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2807 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2808 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2809 | |
| 2810 | MockQuicData socket_data; |
| 2811 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2812 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2813 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2814 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2815 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2816 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2817 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2818 | |
| 2819 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2820 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2821 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2822 | request.Request( |
| 2823 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2824 | SocketTag(), |
| 2825 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2826 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2827 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2828 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2829 | EXPECT_TRUE(stream.get()); |
| 2830 | |
| 2831 | // Cause QUIC stream to be created. |
| 2832 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2833 | request_info.traffic_annotation = |
| 2834 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2835 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2836 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2837 | |
| 2838 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2839 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2840 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2841 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2842 | |
| 2843 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2844 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2845 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2846 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2847 | |
| 2848 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2849 | // this should cause session to continue but be marked as going away. |
| 2850 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2851 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2852 | |
| 2853 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2854 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2855 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2856 | |
| 2857 | stream.reset(); |
| 2858 | |
| 2859 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2860 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2861 | } |
| 2862 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2863 | TEST_P(QuicStreamFactoryTest, |
| 2864 | OnNetworkDisconnectedNonMigratableStream_DoNotMigrateIdleSessions) { |
| 2865 | TestOnNetworkDisconnectedNonMigratableStream(false); |
| 2866 | } |
| 2867 | |
| 2868 | TEST_P(QuicStreamFactoryTest, |
| 2869 | OnNetworkDisconnectedNonMigratableStream_MigrateIdleSessions) { |
| 2870 | TestOnNetworkDisconnectedNonMigratableStream(true); |
| 2871 | } |
| 2872 | |
| 2873 | void QuicStreamFactoryTestBase::TestOnNetworkDisconnectedNonMigratableStream( |
| 2874 | bool migrate_idle_sessions) { |
| 2875 | test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2876 | InitializeConnectionMigrationV2Test( |
| 2877 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2878 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2879 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2880 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2881 | MockQuicData failed_socket_data; |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2882 | MockQuicData socket_data; |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2883 | if (migrate_idle_sessions) { |
| 2884 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2885 | failed_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2886 | failed_socket_data.AddWrite( |
| 2887 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2888 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 2889 | failed_socket_data.AddWrite( |
| 2890 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2891 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2892 | quic::QUIC_STREAM_CANCELLED)); |
| 2893 | failed_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2894 | |
| 2895 | // Set up second socket data provider that is used after migration. |
| 2896 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2897 | // Ping packet to send after migration. |
| 2898 | socket_data.AddWrite( |
| 2899 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 2900 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2901 | } else { |
| 2902 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2903 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2904 | socket_data.AddWrite( |
| 2905 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2906 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2907 | quic::QUIC_STREAM_CANCELLED)); |
| 2908 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2909 | } |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2910 | |
| 2911 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2912 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2913 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2914 | request.Request( |
| 2915 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2916 | SocketTag(), |
| 2917 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2918 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2919 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2920 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2921 | EXPECT_TRUE(stream.get()); |
| 2922 | |
| 2923 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2924 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2925 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2926 | request_info.traffic_annotation = |
| 2927 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2928 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2929 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2930 | |
| 2931 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2932 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2933 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2934 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2935 | |
| 2936 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2937 | // this should cause a RST_STREAM frame to be emitted with |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2938 | // quic::QUIC_STREAM_CANCELLED error code. |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2939 | // If migate idle session, the connection will then be migrated to the |
| 2940 | // alternate network. Otherwise, the connection will be closed. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2941 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2942 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2943 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2944 | EXPECT_EQ(migrate_idle_sessions, |
| 2945 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2946 | EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2947 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2948 | if (migrate_idle_sessions) { |
| 2949 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2950 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2951 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 2952 | EXPECT_TRUE(failed_socket_data.AllReadDataConsumed()); |
| 2953 | EXPECT_TRUE(failed_socket_data.AllWriteDataConsumed()); |
| 2954 | } |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2955 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2956 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2957 | } |
| 2958 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2959 | TEST_P(QuicStreamFactoryTest, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2960 | OnNetworkDisconnectedConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2961 | InitializeConnectionMigrationV2Test( |
| 2962 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2963 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2964 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2965 | |
| 2966 | MockQuicData socket_data; |
| 2967 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2968 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2969 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2970 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2971 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2972 | quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2973 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2974 | |
| 2975 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2976 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2977 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2978 | request.Request( |
| 2979 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2980 | SocketTag(), |
| 2981 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2982 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2983 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2984 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2985 | EXPECT_TRUE(stream.get()); |
| 2986 | |
| 2987 | // Cause QUIC stream to be created. |
| 2988 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2989 | request_info.traffic_annotation = |
| 2990 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2991 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2992 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2993 | |
| 2994 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2995 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2996 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2997 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2998 | |
| 2999 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3000 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 3001 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 3002 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 3003 | |
| 3004 | // Trigger connection migration. Since there is a non-migratable stream, |
| 3005 | // this should cause a RST_STREAM frame to be emitted with |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3006 | // quic::QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 3007 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3008 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3009 | |
| 3010 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3011 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3012 | |
| 3013 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3014 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3015 | } |
| 3016 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3017 | TEST_P(QuicStreamFactoryTest, |
| 3018 | OnNetworkMadeDefaultNoOpenStreams_DoNotMigrateIdleSessions) { |
| 3019 | TestOnNetworkMadeDefaultNoOpenStreams(false); |
| 3020 | } |
| 3021 | |
| 3022 | TEST_P(QuicStreamFactoryTest, |
| 3023 | OnNetworkMadeDefaultNoOpenStreams_MigrateIdleSessions) { |
| 3024 | TestOnNetworkMadeDefaultNoOpenStreams(true); |
| 3025 | } |
| 3026 | |
| 3027 | void QuicStreamFactoryTestBase::TestOnNetworkMadeDefaultNoOpenStreams( |
| 3028 | bool migrate_idle_sessions) { |
| 3029 | test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3030 | InitializeConnectionMigrationV2Test( |
| 3031 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3032 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3033 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3034 | |
| 3035 | MockQuicData socket_data; |
| 3036 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3037 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3038 | if (!migrate_idle_sessions) { |
| 3039 | socket_data.AddWrite( |
| 3040 | SYNCHRONOUS, |
| 3041 | client_maker_.MakeConnectionClosePacket( |
| 3042 | 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 3043 | "net error")); |
| 3044 | } |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3045 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3046 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3047 | MockQuicData quic_data1; |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3048 | if (migrate_idle_sessions) { |
| 3049 | // Set up the second socket data provider that is used for probing. |
| 3050 | // Connectivity probe to be sent on the new path. |
| 3051 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3052 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
| 3053 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3054 | // Connectivity probe to receive from the server. |
| 3055 | quic_data1.AddRead(ASYNC, |
| 3056 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3057 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3058 | // Ping packet to send after migration is completed. |
| 3059 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3060 | client_maker_.MakeAckAndPingPacket(3, false, 1, 1, 1)); |
| 3061 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3062 | } |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3063 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3064 | // Create request and QuicHttpStream. |
| 3065 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3066 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3067 | request.Request( |
| 3068 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3069 | SocketTag(), |
| 3070 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3071 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3072 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3073 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3074 | EXPECT_TRUE(stream.get()); |
| 3075 | |
| 3076 | // Ensure that session is alive and active. |
| 3077 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3078 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3079 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3080 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3081 | EXPECT_EQ(0u, session->GetNumDrainingStreams()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3082 | |
| 3083 | // Trigger connection migration. |
| 3084 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3085 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3086 | EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3087 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3088 | if (migrate_idle_sessions) { |
| 3089 | quic_data1.Resume(); |
| 3090 | base::RunLoop().RunUntilIdle(); |
| 3091 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3092 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3093 | } |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3094 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3095 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3096 | } |
| 3097 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3098 | TEST_P(QuicStreamFactoryTest, |
| 3099 | OnNetworkDisconnectedNoOpenStreams_DoNotMigateIdleSessions) { |
| 3100 | TestOnNetworkDisconnectedNoOpenStreams(false); |
| 3101 | } |
| 3102 | |
| 3103 | TEST_P(QuicStreamFactoryTest, |
| 3104 | OnNetworkDisconnectedNoOpenStreams_MigateIdleSessions) { |
| 3105 | TestOnNetworkDisconnectedNoOpenStreams(true); |
| 3106 | } |
| 3107 | |
| 3108 | void QuicStreamFactoryTestBase::TestOnNetworkDisconnectedNoOpenStreams( |
| 3109 | bool migrate_idle_sessions) { |
| 3110 | test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3111 | InitializeConnectionMigrationV2Test( |
| 3112 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3113 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3114 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3115 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3116 | MockQuicData default_socket_data; |
| 3117 | default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3118 | default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 3119 | default_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3120 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3121 | MockQuicData alternate_socket_data; |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3122 | if (migrate_idle_sessions) { |
| 3123 | // Set up second socket data provider that is used after migration. |
| 3124 | alternate_socket_data.AddRead(SYNCHRONOUS, |
| 3125 | ERR_IO_PENDING); // Hanging read. |
| 3126 | // Ping packet to send after migration. |
| 3127 | alternate_socket_data.AddWrite( |
| 3128 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 3129 | alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3130 | } |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3131 | |
| 3132 | // Create request and QuicHttpStream. |
| 3133 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3134 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3135 | request.Request( |
| 3136 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3137 | SocketTag(), |
| 3138 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3139 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3140 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3141 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3142 | EXPECT_TRUE(stream.get()); |
| 3143 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3144 | // Ensure that session is active. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3145 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3146 | |
| 3147 | // Trigger connection migration. Since there are no active streams, |
| 3148 | // the session will be closed. |
| 3149 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3150 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3151 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3152 | EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3153 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3154 | EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); |
| 3155 | EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 3156 | if (migrate_idle_sessions) { |
| 3157 | EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); |
| 3158 | EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); |
| 3159 | } |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3160 | } |
| 3161 | |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3162 | // This test verifies session migrates to the alternate network immediately when |
| 3163 | // default network disconnects with a synchronous write before migration. |
| 3164 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedSync) { |
| 3165 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ false); |
| 3166 | } |
| 3167 | |
| 3168 | // This test verifies session migrates to the alternate network immediately when |
| 3169 | // default network disconnects with an asynchronously write before migration. |
| 3170 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedAsync) { |
| 3171 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ true); |
| 3172 | } |
| 3173 | |
| 3174 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkDisconnected( |
| 3175 | bool async_write_before) { |
| 3176 | InitializeConnectionMigrationV2Test( |
| 3177 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3178 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3179 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 3180 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3181 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3182 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3183 | |
| 3184 | // Use the test task runner. |
| 3185 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3186 | |
| 3187 | int packet_number = 1; |
| 3188 | MockQuicData socket_data; |
| 3189 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3190 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3191 | socket_data.AddWrite( |
| 3192 | SYNCHRONOUS, |
| 3193 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 3194 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3195 | SYNCHRONOUS, |
| 3196 | ConstructGetRequestPacket(packet_number++, |
| 3197 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3198 | true, true, &header_stream_offset)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3199 | if (async_write_before) { |
| 3200 | socket_data.AddWrite(ASYNC, OK); |
| 3201 | packet_number++; |
| 3202 | } |
| 3203 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3204 | |
| 3205 | // Create request and QuicHttpStream. |
| 3206 | QuicStreamRequest request(factory_.get()); |
| 3207 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3208 | request.Request( |
| 3209 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3210 | SocketTag(), |
| 3211 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3212 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3213 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3214 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3215 | EXPECT_TRUE(stream.get()); |
| 3216 | |
| 3217 | // Cause QUIC stream to be created. |
| 3218 | HttpRequestInfo request_info; |
| 3219 | request_info.method = "GET"; |
| 3220 | request_info.url = url_; |
| 3221 | request_info.traffic_annotation = |
| 3222 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3223 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3224 | net_log_, CompletionOnceCallback())); |
| 3225 | |
| 3226 | // Ensure that session is alive and active. |
| 3227 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3228 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3229 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3230 | |
| 3231 | // Send GET request on stream. |
| 3232 | HttpResponseInfo response; |
| 3233 | HttpRequestHeaders request_headers; |
| 3234 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3235 | callback_.callback())); |
| 3236 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3237 | if (async_write_before) |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3238 | session->SendPing(); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3239 | |
| 3240 | // Set up second socket data provider that is used after migration. |
| 3241 | // The response to the earlier request is read on this new socket. |
| 3242 | MockQuicData socket_data1; |
| 3243 | socket_data1.AddWrite( |
| 3244 | SYNCHRONOUS, |
| 3245 | client_maker_.MakePingPacket(packet_number++, /*include_version=*/true)); |
| 3246 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3247 | ASYNC, |
| 3248 | ConstructOkResponsePacket( |
| 3249 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3250 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3251 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3252 | SYNCHRONOUS, |
| 3253 | client_maker_.MakeAckAndRstPacket( |
| 3254 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3255 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3256 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3257 | |
| 3258 | // Trigger connection migration. |
| 3259 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3260 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3261 | |
| 3262 | // The connection should still be alive, not marked as going away. |
| 3263 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3264 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3265 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3266 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3267 | |
| 3268 | // Ensure that the session is still alive. |
| 3269 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3270 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3271 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3272 | |
| 3273 | // Run the message loop so that data queued in the new socket is read by the |
| 3274 | // packet reader. |
| 3275 | runner_->RunNextTask(); |
| 3276 | |
| 3277 | // Response headers are received over the new network. |
| 3278 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3279 | EXPECT_EQ(200, response.headers->response_code()); |
| 3280 | |
| 3281 | // Check that the session is still alive. |
| 3282 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3283 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3284 | |
| 3285 | // There should be posted tasks not executed, which is to migrate back to |
| 3286 | // default network. |
| 3287 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3288 | |
| 3289 | // Receive signal to mark new network as default. |
| 3290 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3291 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3292 | |
| 3293 | stream.reset(); |
| 3294 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3295 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3296 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3297 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3298 | } |
| 3299 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3300 | // This test receives NCN signals in the following order: |
| 3301 | // - default network disconnected |
| 3302 | // - after a pause, new network is connected. |
| 3303 | // - new network is made default. |
| 3304 | TEST_P(QuicStreamFactoryTest, NewNetworkConnectedAfterNoNetwork) { |
| 3305 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 3306 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3307 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3308 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3309 | |
| 3310 | // Use the test task runner. |
| 3311 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3312 | |
| 3313 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3314 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3315 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3316 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3317 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3318 | socket_data.AddWrite( |
| 3319 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3320 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3321 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3322 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3323 | |
| 3324 | // Create request and QuicHttpStream. |
| 3325 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3326 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3327 | request.Request( |
| 3328 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3329 | SocketTag(), |
| 3330 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3331 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3332 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3333 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3334 | EXPECT_TRUE(stream.get()); |
| 3335 | |
| 3336 | // Cause QUIC stream to be created. |
| 3337 | HttpRequestInfo request_info; |
| 3338 | request_info.method = "GET"; |
| 3339 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 3340 | request_info.traffic_annotation = |
| 3341 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 3342 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 3343 | net_log_, CompletionOnceCallback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3344 | |
| 3345 | // Ensure that session is alive and active. |
| 3346 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3347 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3348 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3349 | |
| 3350 | // Send GET request on stream. |
| 3351 | HttpResponseInfo response; |
| 3352 | HttpRequestHeaders request_headers; |
| 3353 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3354 | callback_.callback())); |
| 3355 | |
| 3356 | // Trigger connection migration. Since there are no networks |
| 3357 | // to migrate to, this should cause the session to wait for a new network. |
| 3358 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3359 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3360 | |
| 3361 | // The connection should still be alive, not marked as going away. |
| 3362 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3363 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3364 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3365 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3366 | |
| 3367 | // Set up second socket data provider that is used after migration. |
| 3368 | // The response to the earlier request is read on this new socket. |
| 3369 | MockQuicData socket_data1; |
| 3370 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3371 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 3372 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3373 | ASYNC, |
| 3374 | ConstructOkResponsePacket( |
| 3375 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3376 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3377 | socket_data1.AddWrite( |
| 3378 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3379 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3380 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3381 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3382 | |
| 3383 | // Add a new network and notify the stream factory of a new connected network. |
| 3384 | // This causes a PING packet to be sent over the new network. |
| 3385 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3386 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 3387 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3388 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 3389 | |
| 3390 | // Ensure that the session is still alive. |
| 3391 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3392 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3393 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3394 | |
| 3395 | // Run the message loop so that data queued in the new socket is read by the |
| 3396 | // packet reader. |
| 3397 | runner_->RunNextTask(); |
| 3398 | |
| 3399 | // Response headers are received over the new network. |
| 3400 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3401 | EXPECT_EQ(200, response.headers->response_code()); |
| 3402 | |
| 3403 | // Check that the session is still alive. |
| 3404 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3405 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3406 | |
| 3407 | // There should posted tasks not executed, which is to migrate back to default |
| 3408 | // network. |
| 3409 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3410 | |
| 3411 | // Receive signal to mark new network as default. |
| 3412 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3413 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3414 | |
| 3415 | stream.reset(); |
| 3416 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3417 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3418 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3419 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3420 | } |
| 3421 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3422 | // Regression test for http://crbug.com/872011. |
| 3423 | // This test verifies that migrate to the probing socket will not trigger |
| 3424 | // new packets being read synchronously and generate ACK frame while |
| 3425 | // processing the initial connectivity probe response, which may cause a |
| 3426 | // connection being closed with INTERNAL_ERROR as pending ACK frame is not |
| 3427 | // allowed when processing a new packet. |
Zhongyi Shi | 6a7323b | 2018-12-07 01:26:32 | [diff] [blame] | 3428 | TEST_P(QuicStreamFactoryTest, MigrateToProbingSocket) { |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3429 | InitializeConnectionMigrationV2Test( |
| 3430 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3431 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3432 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3433 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3434 | |
| 3435 | // Using a testing task runner so that we can control time. |
| 3436 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3437 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3438 | |
| 3439 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3440 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3441 | |
| 3442 | int packet_number = 1; |
| 3443 | MockQuicData quic_data1; |
| 3444 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3445 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 3446 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3447 | packet_number++, &header_stream_offset)); |
| 3448 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3449 | SYNCHRONOUS, |
| 3450 | ConstructGetRequestPacket(packet_number++, |
| 3451 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3452 | true, true, &header_stream_offset)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3453 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3454 | |
| 3455 | // Set up the second socket data provider that is used for probing on the |
| 3456 | // alternate network. |
| 3457 | MockQuicData quic_data2; |
| 3458 | // Connectivity probe to be sent on the new path. |
| 3459 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
| 3460 | packet_number++, true)); |
| 3461 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3462 | // First connectivity probe to receive from the server, which will complete |
| 3463 | // connection migraiton on path degrading. |
| 3464 | quic_data2.AddRead(ASYNC, |
| 3465 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3466 | // Read multiple connectivity probes synchronously. |
| 3467 | quic_data2.AddRead(SYNCHRONOUS, |
| 3468 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
| 3469 | quic_data2.AddRead(SYNCHRONOUS, |
| 3470 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
| 3471 | quic_data2.AddRead(SYNCHRONOUS, |
| 3472 | server_maker_.MakeConnectivityProbingPacket(4, false)); |
| 3473 | quic_data2.AddWrite( |
| 3474 | ASYNC, client_maker_.MakeAckPacket(packet_number++, 1, 4, 1, 1, true)); |
| 3475 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3476 | ASYNC, |
| 3477 | ConstructOkResponsePacket( |
| 3478 | 5, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3479 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3480 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3481 | SYNCHRONOUS, |
| 3482 | client_maker_.MakeAckAndRstPacket( |
| 3483 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3484 | quic::QUIC_STREAM_CANCELLED, 5, 1, 1, true)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3485 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3486 | |
| 3487 | // Create request and QuicHttpStream. |
| 3488 | QuicStreamRequest request(factory_.get()); |
| 3489 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3490 | request.Request( |
| 3491 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3492 | SocketTag(), |
| 3493 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3494 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3495 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3496 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3497 | EXPECT_TRUE(stream.get()); |
| 3498 | |
| 3499 | // Cause QUIC stream to be created. |
| 3500 | HttpRequestInfo request_info; |
| 3501 | request_info.method = "GET"; |
| 3502 | request_info.url = url_; |
| 3503 | request_info.traffic_annotation = |
| 3504 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3505 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3506 | net_log_, CompletionOnceCallback())); |
| 3507 | |
| 3508 | // Ensure that session is alive and active. |
| 3509 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3510 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3511 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3512 | |
| 3513 | // Send GET request on stream. |
| 3514 | HttpResponseInfo response; |
| 3515 | HttpRequestHeaders request_headers; |
| 3516 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3517 | callback_.callback())); |
| 3518 | |
| 3519 | // Cause the connection to report path degrading to the session. |
| 3520 | // Session will start to probe the alternate network. |
| 3521 | session->connection()->OnPathDegradingTimeout(); |
| 3522 | |
| 3523 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3524 | // kDefaultRTTMilliSecs. |
| 3525 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3526 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3527 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3528 | next_task_delay); |
| 3529 | |
| 3530 | // The connection should still be alive, and not marked as going away. |
| 3531 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3532 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3533 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3534 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3535 | |
| 3536 | // Resume quic data and a connectivity probe response will be read on the new |
| 3537 | // socket. |
| 3538 | quic_data2.Resume(); |
| 3539 | |
| 3540 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3541 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3542 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3543 | |
| 3544 | // There should be three pending tasks, the nearest one will complete |
| 3545 | // migration to the new network. |
| 3546 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3547 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3548 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3549 | task_runner->FastForwardBy(next_task_delay); |
| 3550 | |
| 3551 | // Response headers are received over the new network. |
| 3552 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3553 | EXPECT_EQ(200, response.headers->response_code()); |
| 3554 | |
| 3555 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3556 | // probe and has been cancelled due to successful migration. |
| 3557 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3558 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3559 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3560 | next_task_delay); |
| 3561 | task_runner->FastForwardBy(next_task_delay); |
| 3562 | |
| 3563 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3564 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3565 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3566 | base::TimeDelta expected_delay = |
| 3567 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3568 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3569 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3570 | |
| 3571 | // Deliver a signal that the alternate network now becomes default to session, |
| 3572 | // this will cancel mgirate back to default network timer. |
| 3573 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3574 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3575 | |
| 3576 | task_runner->FastForwardBy(next_task_delay); |
| 3577 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3578 | |
| 3579 | // Verify that the session is still alive. |
| 3580 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3581 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3582 | |
| 3583 | stream.reset(); |
| 3584 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3585 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3586 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3587 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3588 | } |
| 3589 | |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3590 | // This test verifies that the connection migrates to the alternate network |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3591 | // early when path degrading is detected with an ASYNCHRONOUS write before |
| 3592 | // migration. |
| 3593 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingAysnc) { |
| 3594 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ true); |
| 3595 | } |
| 3596 | |
| 3597 | // This test verifies that the connection migrates to the alternate network |
| 3598 | // early when path degrading is detected with a SYNCHRONOUS write before |
| 3599 | // migration. |
| 3600 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingSync) { |
| 3601 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ false); |
| 3602 | } |
| 3603 | |
| 3604 | void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( |
| 3605 | bool async_write_before) { |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3606 | InitializeConnectionMigrationV2Test( |
| 3607 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3608 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3609 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3610 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3611 | |
| 3612 | // Using a testing task runner so that we can control time. |
| 3613 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3614 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3615 | |
| 3616 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3617 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3618 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3619 | int packet_number = 1; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3620 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3621 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3622 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3623 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3624 | packet_number++, &header_stream_offset)); |
| 3625 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3626 | SYNCHRONOUS, |
| 3627 | ConstructGetRequestPacket(packet_number++, |
| 3628 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3629 | true, true, &header_stream_offset)); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3630 | if (async_write_before) { |
| 3631 | quic_data1.AddWrite(ASYNC, OK); |
| 3632 | packet_number++; |
| 3633 | } |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3634 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3635 | |
| 3636 | // Set up the second socket data provider that is used after migration. |
| 3637 | // The response to the earlier request is read on the new socket. |
| 3638 | MockQuicData quic_data2; |
| 3639 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3640 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3641 | packet_number++, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3642 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3643 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3644 | quic_data2.AddRead(ASYNC, |
| 3645 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3646 | // Ping packet to send after migration is completed. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3647 | quic_data2.AddWrite(ASYNC, client_maker_.MakeAckAndPingPacket( |
| 3648 | packet_number++, false, 1, 1, 1)); |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 3649 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3650 | ASYNC, |
| 3651 | ConstructOkResponsePacket( |
| 3652 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3653 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3654 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3655 | SYNCHRONOUS, |
| 3656 | client_maker_.MakeAckAndRstPacket( |
| 3657 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3658 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3659 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3660 | |
| 3661 | // Create request and QuicHttpStream. |
| 3662 | QuicStreamRequest request(factory_.get()); |
| 3663 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3664 | request.Request( |
| 3665 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3666 | SocketTag(), |
| 3667 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3668 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3669 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3670 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3671 | EXPECT_TRUE(stream.get()); |
| 3672 | |
| 3673 | // Cause QUIC stream to be created. |
| 3674 | HttpRequestInfo request_info; |
| 3675 | request_info.method = "GET"; |
| 3676 | request_info.url = url_; |
| 3677 | request_info.traffic_annotation = |
| 3678 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3679 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3680 | net_log_, CompletionOnceCallback())); |
| 3681 | |
| 3682 | // Ensure that session is alive and active. |
| 3683 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3684 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3685 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3686 | |
| 3687 | // Send GET request on stream. |
| 3688 | HttpResponseInfo response; |
| 3689 | HttpRequestHeaders request_headers; |
| 3690 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3691 | callback_.callback())); |
| 3692 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3693 | if (async_write_before) |
| 3694 | session->SendPing(); |
| 3695 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 3696 | // Cause the connection to report path degrading to the session. |
| 3697 | // Session will start to probe the alternate network. |
| 3698 | session->connection()->OnPathDegradingTimeout(); |
| 3699 | |
| 3700 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3701 | // kDefaultRTTMilliSecs. |
| 3702 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3703 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3704 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3705 | next_task_delay); |
| 3706 | |
| 3707 | // The connection should still be alive, and not marked as going away. |
| 3708 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3709 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3710 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3711 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3712 | |
| 3713 | // Resume quic data and a connectivity probe response will be read on the new |
| 3714 | // socket. |
| 3715 | quic_data2.Resume(); |
| 3716 | |
| 3717 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3718 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3719 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3720 | |
| 3721 | // There should be three pending tasks, the nearest one will complete |
| 3722 | // migration to the new network. |
| 3723 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3724 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3725 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3726 | task_runner->FastForwardBy(next_task_delay); |
| 3727 | |
| 3728 | // Response headers are received over the new network. |
| 3729 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3730 | EXPECT_EQ(200, response.headers->response_code()); |
| 3731 | |
| 3732 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3733 | // probe and has been cancelled due to successful migration. |
| 3734 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3735 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3736 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3737 | next_task_delay); |
| 3738 | task_runner->FastForwardBy(next_task_delay); |
| 3739 | |
| 3740 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3741 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3742 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3743 | base::TimeDelta expected_delay = |
| 3744 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3745 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3746 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3747 | |
| 3748 | // Deliver a signal that the alternate network now becomes default to session, |
| 3749 | // this will cancel mgirate back to default network timer. |
| 3750 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3751 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3752 | |
| 3753 | task_runner->FastForwardBy(next_task_delay); |
| 3754 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3755 | |
| 3756 | // Verify that the session is still alive. |
| 3757 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3758 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3759 | |
| 3760 | stream.reset(); |
| 3761 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3762 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3763 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3764 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3765 | } |
| 3766 | |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3767 | // This test verifies that the session marks itself GOAWAY on path degrading |
| 3768 | // and it does not receive any new request |
| 3769 | TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 3770 | test_params_.quic_go_away_on_path_degrading = true; |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3771 | Initialize(); |
| 3772 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3773 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3774 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3775 | |
| 3776 | MockQuicData quic_data1; |
| 3777 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3778 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3779 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3780 | quic_data1.AddWrite( |
| 3781 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3782 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3783 | true, &header_stream_offset)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3784 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3785 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3786 | ASYNC, |
| 3787 | ConstructOkResponsePacket( |
| 3788 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3789 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3790 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3791 | |
| 3792 | MockQuicData quic_data2; |
| 3793 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 3794 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3795 | quic_data2.AddWrite( |
| 3796 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 3797 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3798 | |
| 3799 | // Creat request and QuicHttpStream. |
| 3800 | QuicStreamRequest request(factory_.get()); |
| 3801 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3802 | request.Request( |
| 3803 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3804 | SocketTag(), |
| 3805 | /*cerf_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3806 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3807 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3808 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3809 | EXPECT_TRUE(stream.get()); |
| 3810 | |
| 3811 | // Cause QUIC stream to be created. |
| 3812 | HttpRequestInfo request_info; |
| 3813 | request_info.method = "GET"; |
| 3814 | request_info.url = url_; |
| 3815 | request_info.traffic_annotation = |
| 3816 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3817 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3818 | net_log_, CompletionOnceCallback())); |
| 3819 | |
| 3820 | // Ensure that session is alive and active. |
| 3821 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3822 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3823 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3824 | |
| 3825 | // Send GET request on stream. |
| 3826 | HttpResponseInfo response; |
| 3827 | HttpRequestHeaders request_headers; |
| 3828 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3829 | callback_.callback())); |
| 3830 | |
| 3831 | // Trigger the connection to report path degrading to the session. |
| 3832 | // Session will mark itself GOAWAY. |
| 3833 | session->connection()->OnPathDegradingTimeout(); |
| 3834 | |
| 3835 | // The connection should still be alive, but marked as going away. |
| 3836 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3837 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3838 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3839 | |
| 3840 | // Second request should be sent on a new connection. |
| 3841 | QuicStreamRequest request2(factory_.get()); |
| 3842 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3843 | request2.Request( |
| 3844 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3845 | SocketTag(), |
| 3846 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3847 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3848 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3849 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 3850 | EXPECT_TRUE(stream2.get()); |
| 3851 | |
| 3852 | // Resume the data, verify old request can read response on the old session |
| 3853 | // successfully. |
| 3854 | quic_data1.Resume(); |
| 3855 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 3856 | EXPECT_EQ(200, response.headers->response_code()); |
| 3857 | EXPECT_EQ(0U, session->GetNumActiveStreams()); |
| 3858 | |
| 3859 | // Check an active session exists for the destination. |
| 3860 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3861 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3862 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 3863 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 3864 | EXPECT_NE(session, session2); |
| 3865 | |
| 3866 | stream.reset(); |
| 3867 | stream2.reset(); |
| 3868 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3869 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3870 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3871 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3872 | } |
| 3873 | |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3874 | // This test verifies that the connection will not migrate to a bad socket |
| 3875 | // when path degrading is detected. |
| 3876 | TEST_P(QuicStreamFactoryTest, DoNotMigrateToBadSocketOnPathDegrading) { |
| 3877 | InitializeConnectionMigrationV2Test( |
| 3878 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3879 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3880 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3881 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3882 | |
| 3883 | // Using a testing task runner so that we can control time. |
| 3884 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3885 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3886 | |
| 3887 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3888 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3889 | |
| 3890 | MockQuicData quic_data; |
| 3891 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3892 | quic_data.AddWrite(SYNCHRONOUS, |
| 3893 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3894 | quic_data.AddWrite(SYNCHRONOUS, |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3895 | ConstructGetRequestPacket( |
| 3896 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3897 | true, &header_stream_offset)); |
| 3898 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3899 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 3900 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3901 | false, false)); |
| 3902 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3903 | quic_data.AddWrite( |
| 3904 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3905 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3906 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3907 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3908 | |
| 3909 | // Set up second socket that will immediately return disconnected. |
| 3910 | // The stream factory will abort probe the alternate network. |
| 3911 | MockConnect bad_connect = MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
| 3912 | SequencedSocketData socket_data(bad_connect, base::span<MockRead>(), |
| 3913 | base::span<MockWrite>()); |
| 3914 | socket_factory_->AddSocketDataProvider(&socket_data); |
| 3915 | |
| 3916 | // Create request and QuicHttpStream. |
| 3917 | QuicStreamRequest request(factory_.get()); |
| 3918 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3919 | request.Request( |
| 3920 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3921 | SocketTag(), |
| 3922 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3923 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3924 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3925 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3926 | EXPECT_TRUE(stream.get()); |
| 3927 | |
| 3928 | // Cause QUIC stream to be created. |
| 3929 | HttpRequestInfo request_info; |
| 3930 | request_info.method = "GET"; |
| 3931 | request_info.url = url_; |
| 3932 | request_info.traffic_annotation = |
| 3933 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3934 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3935 | net_log_, CompletionOnceCallback())); |
| 3936 | |
| 3937 | // Ensure that session is alive and active. |
| 3938 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3939 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3940 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3941 | |
| 3942 | // Send GET request on stream. |
| 3943 | HttpResponseInfo response; |
| 3944 | HttpRequestHeaders request_headers; |
| 3945 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3946 | callback_.callback())); |
| 3947 | |
| 3948 | // Cause the connection to report path degrading to the session. |
| 3949 | // Session will start to probe the alternate network. |
| 3950 | session->connection()->OnPathDegradingTimeout(); |
| 3951 | |
| 3952 | // The connection should still be alive, and not marked as going away. |
| 3953 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3954 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3955 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3956 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3957 | |
| 3958 | // Resume the data, and response header is received over the original network. |
| 3959 | quic_data.Resume(); |
| 3960 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3961 | EXPECT_EQ(200, response.headers->response_code()); |
| 3962 | |
| 3963 | // Verify there is no pending task as probing alternate network is halted. |
| 3964 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3965 | |
| 3966 | // Verify that the session is still alive. |
| 3967 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3968 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3969 | |
| 3970 | stream.reset(); |
| 3971 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 3972 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 3973 | } |
| 3974 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3975 | // Regression test for http://crbug.com/847569. |
| 3976 | // This test verifies that the connection migrates to the alternate network |
| 3977 | // early when there is no active stream but a draining stream. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3978 | // The first packet being written after migration is a synchrnous write, which |
| 3979 | // will cause a PING packet being sent. |
| 3980 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamSync) { |
| 3981 | TestMigrateSessionWithDrainingStream(SYNCHRONOUS); |
| 3982 | } |
| 3983 | |
| 3984 | // Regression test for http://crbug.com/847569. |
| 3985 | // This test verifies that the connection migrates to the alternate network |
| 3986 | // early when there is no active stream but a draining stream. |
| 3987 | // The first packet being written after migration is an asynchronous write, no |
| 3988 | // PING packet will be sent. |
| 3989 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamAsync) { |
| 3990 | TestMigrateSessionWithDrainingStream(ASYNC); |
| 3991 | } |
| 3992 | |
| 3993 | void QuicStreamFactoryTestBase::TestMigrateSessionWithDrainingStream( |
| 3994 | IoMode write_mode_for_queued_packet) { |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3995 | InitializeConnectionMigrationV2Test( |
| 3996 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3997 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3998 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3999 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4000 | |
| 4001 | // Using a testing task runner so that we can control time. |
| 4002 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4003 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4004 | |
| 4005 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4006 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4007 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4008 | int packet_number = 1; |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4009 | MockQuicData quic_data1; |
| 4010 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4011 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 4012 | packet_number++, &header_stream_offset)); |
| 4013 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4014 | SYNCHRONOUS, |
| 4015 | ConstructGetRequestPacket(packet_number++, |
| 4016 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 4017 | true, true, &header_stream_offset)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4018 | // Read an out of order packet with FIN to drain the stream. |
| 4019 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4020 | ASYNC, ConstructOkResponsePacket( |
| 4021 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, |
| 4022 | true)); // keep sending version. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4023 | quic_data1.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 4024 | packet_number++, 2, 2, 2, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4025 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4026 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4027 | |
| 4028 | // Set up the second socket data provider that is used after migration. |
| 4029 | MockQuicData quic_data2; |
| 4030 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4031 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4032 | packet_number++, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4033 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4034 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4035 | quic_data2.AddRead(ASYNC, |
| 4036 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4037 | // Ping packet to send after migration is completed. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4038 | quic_data2.AddWrite( |
| 4039 | write_mode_for_queued_packet, |
| 4040 | client_maker_.MakeAckPacket(packet_number++, 2, 3, 3, 1, true)); |
| 4041 | if (write_mode_for_queued_packet == SYNCHRONOUS) { |
| 4042 | quic_data2.AddWrite(ASYNC, |
| 4043 | client_maker_.MakePingPacket(packet_number++, false)); |
| 4044 | } |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4045 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4046 | ASYNC, |
| 4047 | ConstructOkResponsePacket( |
| 4048 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4049 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 4050 | packet_number++, 1, 3, 1, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4051 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4052 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4053 | |
| 4054 | // Create request and QuicHttpStream. |
| 4055 | QuicStreamRequest request(factory_.get()); |
| 4056 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4057 | request.Request( |
| 4058 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4059 | SocketTag(), |
| 4060 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4061 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4062 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4063 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4064 | EXPECT_TRUE(stream.get()); |
| 4065 | |
| 4066 | // Cause QUIC stream to be created. |
| 4067 | HttpRequestInfo request_info; |
| 4068 | request_info.method = "GET"; |
| 4069 | request_info.url = url_; |
| 4070 | request_info.traffic_annotation = |
| 4071 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4072 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4073 | net_log_, CompletionOnceCallback())); |
| 4074 | |
| 4075 | // Ensure that session is alive and active. |
| 4076 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4077 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4078 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4079 | |
| 4080 | // Send GET request on stream. |
| 4081 | HttpResponseInfo response; |
| 4082 | HttpRequestHeaders request_headers; |
| 4083 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4084 | callback_.callback())); |
| 4085 | |
| 4086 | // Run the message loop to receive the out of order packet which contains a |
| 4087 | // FIN and drains the stream. |
| 4088 | base::RunLoop().RunUntilIdle(); |
| 4089 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 4090 | |
| 4091 | // Cause the connection to report path degrading to the session. |
| 4092 | // Session should still start to probe the alternate network. |
| 4093 | session->connection()->OnPathDegradingTimeout(); |
| 4094 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4095 | |
| 4096 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4097 | // kDefaultRTTMilliSecs. |
| 4098 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4099 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4100 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4101 | next_task_delay); |
| 4102 | |
| 4103 | // The connection should still be alive, and not marked as going away. |
| 4104 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4105 | |
| 4106 | // Resume quic data and a connectivity probe response will be read on the new |
| 4107 | // socket. |
| 4108 | quic_data2.Resume(); |
| 4109 | |
| 4110 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4111 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4112 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 4113 | EXPECT_EQ(1u, session->GetNumDrainingStreams()); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4114 | |
| 4115 | // There should be three pending tasks, the nearest one will complete |
| 4116 | // migration to the new network. |
| 4117 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4118 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4119 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4120 | task_runner->FastForwardBy(next_task_delay); |
| 4121 | |
| 4122 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4123 | // probe and has been cancelled due to successful migration. |
| 4124 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4125 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4126 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4127 | next_task_delay); |
| 4128 | task_runner->FastForwardBy(next_task_delay); |
| 4129 | |
| 4130 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4131 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4132 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4133 | base::TimeDelta expected_delay = |
| 4134 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4135 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4136 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4137 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4138 | base::RunLoop().RunUntilIdle(); |
| 4139 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4140 | // Deliver a signal that the alternate network now becomes default to session, |
| 4141 | // this will cancel mgirate back to default network timer. |
| 4142 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4143 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4144 | |
| 4145 | task_runner->FastForwardBy(next_task_delay); |
| 4146 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4147 | |
| 4148 | // Verify that the session is still alive. |
| 4149 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4150 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4151 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4152 | |
| 4153 | stream.reset(); |
| 4154 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4155 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4156 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4157 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4158 | } |
| 4159 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4160 | // Regression test for http://crbug.com/835444. |
| 4161 | // This test verifies that the connection migrates to the alternate network |
| 4162 | // when the alternate network is connected after path has been degrading. |
| 4163 | TEST_P(QuicStreamFactoryTest, MigrateOnNewNetworkConnectAfterPathDegrading) { |
| 4164 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4165 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4166 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4167 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4168 | |
| 4169 | // Using a testing task runner so that we can control time. |
| 4170 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4171 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4172 | |
| 4173 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4174 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4175 | |
| 4176 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4177 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4178 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 4179 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4180 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4181 | quic_data1.AddWrite( |
| 4182 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4183 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4184 | true, &header_stream_offset)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4185 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4186 | |
| 4187 | // Set up the second socket data provider that is used after migration. |
| 4188 | // The response to the earlier request is read on the new socket. |
| 4189 | MockQuicData quic_data2; |
| 4190 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4191 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4192 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4193 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4194 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4195 | quic_data2.AddRead(ASYNC, |
| 4196 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4197 | // Ping packet to send after migration is completed. |
| 4198 | quic_data2.AddWrite(ASYNC, |
| 4199 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4200 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4201 | ASYNC, |
| 4202 | ConstructOkResponsePacket( |
| 4203 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4204 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4205 | quic_data2.AddWrite( |
| 4206 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4207 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4208 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4209 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4210 | |
| 4211 | // Create request and QuicHttpStream. |
| 4212 | QuicStreamRequest request(factory_.get()); |
| 4213 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4214 | request.Request( |
| 4215 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4216 | SocketTag(), |
| 4217 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4218 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4219 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4220 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4221 | EXPECT_TRUE(stream.get()); |
| 4222 | |
| 4223 | // Cause QUIC stream to be created. |
| 4224 | HttpRequestInfo request_info; |
| 4225 | request_info.method = "GET"; |
| 4226 | request_info.url = url_; |
| 4227 | request_info.traffic_annotation = |
| 4228 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4229 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4230 | net_log_, CompletionOnceCallback())); |
| 4231 | |
| 4232 | // Ensure that session is alive and active. |
| 4233 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4234 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4235 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4236 | |
| 4237 | // Send GET request on stream. |
| 4238 | HttpResponseInfo response; |
| 4239 | HttpRequestHeaders request_headers; |
| 4240 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4241 | callback_.callback())); |
| 4242 | |
| 4243 | // Cause the connection to report path degrading to the session. |
| 4244 | // Due to lack of alternate network, session will not mgirate connection. |
| 4245 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4246 | session->connection()->OnPathDegradingTimeout(); |
| 4247 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4248 | |
| 4249 | // Deliver a signal that a alternate network is connected now, this should |
| 4250 | // cause the connection to start early migration on path degrading. |
| 4251 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4252 | ->SetConnectedNetworksList( |
| 4253 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4254 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4255 | ->NotifyNetworkConnected(kNewNetworkForTests); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 4256 | |
| 4257 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4258 | // kDefaultRTTMilliSecs. |
| 4259 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4260 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4261 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4262 | next_task_delay); |
| 4263 | |
| 4264 | // The connection should still be alive, and not marked as going away. |
| 4265 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4266 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4267 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4268 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4269 | |
| 4270 | // Resume quic data and a connectivity probe response will be read on the new |
| 4271 | // socket. |
| 4272 | quic_data2.Resume(); |
| 4273 | |
| 4274 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4275 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4276 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4277 | |
| 4278 | // There should be three pending tasks, the nearest one will complete |
| 4279 | // migration to the new network. |
| 4280 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4281 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4282 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4283 | task_runner->FastForwardBy(next_task_delay); |
| 4284 | |
| 4285 | // Response headers are received over the new network. |
| 4286 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4287 | EXPECT_EQ(200, response.headers->response_code()); |
| 4288 | |
| 4289 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4290 | // probe and has been cancelled due to successful migration. |
| 4291 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4292 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4293 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4294 | next_task_delay); |
| 4295 | task_runner->FastForwardBy(next_task_delay); |
| 4296 | |
| 4297 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4298 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4299 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4300 | base::TimeDelta expected_delay = |
| 4301 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4302 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4303 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4304 | |
| 4305 | // Deliver a signal that the alternate network now becomes default to session, |
| 4306 | // this will cancel mgirate back to default network timer. |
| 4307 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4308 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4309 | |
| 4310 | task_runner->FastForwardBy(next_task_delay); |
| 4311 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4312 | |
| 4313 | // Verify that the session is still alive. |
| 4314 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4315 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4316 | |
| 4317 | stream.reset(); |
| 4318 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4319 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4320 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4321 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4322 | } |
| 4323 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4324 | // This test verifies that multiple sessions are migrated on connection |
| 4325 | // migration signal. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4326 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4327 | MigrateMultipleSessionsToBadSocketsAfterDisconnected) { |
| 4328 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4329 | |
| 4330 | MockQuicData socket_data1; |
| 4331 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4332 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4333 | socket_data1.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4334 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4335 | MockQuicData socket_data2; |
| 4336 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4337 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4338 | socket_data2.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4339 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4340 | |
| 4341 | HostPortPair server1(kDefaultServerHostName, 443); |
| 4342 | HostPortPair server2(kServer2HostName, 443); |
| 4343 | |
| 4344 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4345 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4346 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4347 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 4348 | host_resolver_->set_synchronous_mode(true); |
| 4349 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 4350 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.2", ""); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4351 | |
| 4352 | // Create request and QuicHttpStream to create session1. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4353 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4354 | EXPECT_EQ(OK, |
| 4355 | request1.Request( |
| 4356 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4357 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4358 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4359 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4360 | EXPECT_TRUE(stream1.get()); |
| 4361 | |
| 4362 | // Create request and QuicHttpStream to create session2. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4363 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4364 | EXPECT_EQ(OK, |
| 4365 | request2.Request( |
| 4366 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4367 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 4368 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4369 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4370 | EXPECT_TRUE(stream2.get()); |
| 4371 | |
| 4372 | QuicChromiumClientSession* session1 = GetActiveSession(server1); |
| 4373 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 4374 | EXPECT_NE(session1, session2); |
| 4375 | |
| 4376 | // Cause QUIC stream to be created and send GET so session1 has an open |
| 4377 | // stream. |
| 4378 | HttpRequestInfo request_info1; |
| 4379 | request_info1.method = "GET"; |
| 4380 | request_info1.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4381 | request_info1.traffic_annotation = |
| 4382 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4383 | EXPECT_EQ(OK, |
| 4384 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4385 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4386 | HttpResponseInfo response1; |
| 4387 | HttpRequestHeaders request_headers1; |
| 4388 | EXPECT_EQ(OK, stream1->SendRequest(request_headers1, &response1, |
| 4389 | callback_.callback())); |
| 4390 | |
| 4391 | // Cause QUIC stream to be created and send GET so session2 has an open |
| 4392 | // stream. |
| 4393 | HttpRequestInfo request_info2; |
| 4394 | request_info2.method = "GET"; |
| 4395 | request_info2.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4396 | request_info2.traffic_annotation = |
| 4397 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4398 | EXPECT_EQ(OK, |
| 4399 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4400 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4401 | HttpResponseInfo response2; |
| 4402 | HttpRequestHeaders request_headers2; |
| 4403 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4404 | callback_.callback())); |
| 4405 | |
| 4406 | // Cause both sessions to be paused due to DISCONNECTED. |
| 4407 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4408 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 4409 | |
| 4410 | // Ensure that both sessions are paused but alive. |
| 4411 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4412 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4413 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4414 | // Add new sockets to use post migration. Those are bad sockets and will cause |
| 4415 | // migration to fail. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4416 | MockConnect connect_result = |
| 4417 | MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4418 | SequencedSocketData socket_data3(connect_result, base::span<MockRead>(), |
| 4419 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4420 | socket_factory_->AddSocketDataProvider(&socket_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4421 | SequencedSocketData socket_data4(connect_result, base::span<MockRead>(), |
| 4422 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4423 | socket_factory_->AddSocketDataProvider(&socket_data4); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4424 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4425 | // Connect the new network and cause migration to bad sockets, causing |
| 4426 | // sessions to close. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4427 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4428 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 4429 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4430 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 4431 | |
| 4432 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4433 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4434 | |
| 4435 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4436 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4437 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 4438 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 4439 | } |
| 4440 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4441 | // This test verifies that session attempts connection migration with signals |
| 4442 | // delivered in the following order (no alternate network is available): |
| 4443 | // - path degrading is detected: session attempts connection migration but no |
| 4444 | // alternate network is available, session caches path degrading signal in |
| 4445 | // connection and stays on the original network. |
| 4446 | // - original network backs up, request is served in the orignal network, |
| 4447 | // session is not marked as going away. |
| 4448 | TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { |
| 4449 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4450 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4451 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4452 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4453 | MockQuicData quic_data; |
| 4454 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4455 | quic_data.AddWrite(SYNCHRONOUS, |
| 4456 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4457 | quic_data.AddWrite(SYNCHRONOUS, |
| 4458 | ConstructGetRequestPacket( |
| 4459 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4460 | true, &header_stream_offset)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4461 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause for path degrading signal. |
| 4462 | |
| 4463 | // The rest of the data will still flow in the original socket as there is no |
| 4464 | // new network after path degrading. |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4465 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 4466 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4467 | false, false)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4468 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4469 | quic_data.AddWrite( |
| 4470 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4471 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4472 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4473 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4474 | |
| 4475 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4476 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4477 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4478 | request.Request( |
| 4479 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4480 | SocketTag(), |
| 4481 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4482 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4483 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4484 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4485 | EXPECT_TRUE(stream.get()); |
| 4486 | |
| 4487 | // Cause QUIC stream to be created. |
| 4488 | HttpRequestInfo request_info; |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4489 | request_info.method = "GET"; |
| 4490 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4491 | request_info.traffic_annotation = |
| 4492 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4493 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4494 | net_log_, CompletionOnceCallback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4495 | |
| 4496 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4497 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4498 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4499 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4500 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4501 | // Send GET request on stream. |
| 4502 | HttpResponseInfo response; |
| 4503 | HttpRequestHeaders request_headers; |
| 4504 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4505 | callback_.callback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4506 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4507 | // Trigger connection migration on path degrading. Since there are no networks |
| 4508 | // to migrate to, the session will remain on the original network, not marked |
| 4509 | // as going away. |
| 4510 | session->connection()->OnPathDegradingTimeout(); |
| 4511 | EXPECT_TRUE(session->connection()->IsPathDegrading()); |
| 4512 | |
| 4513 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4514 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4515 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4516 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4517 | |
| 4518 | // Resume so that rest of the data will flow in the original socket. |
| 4519 | quic_data.Resume(); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4520 | |
| 4521 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4522 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4523 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4524 | |
| 4525 | stream.reset(); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4526 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 4527 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4528 | } |
| 4529 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4530 | // This test verifies that session with non-migratable stream will probe the |
| 4531 | // alternate network on path degrading, and close the non-migratable streams |
| 4532 | // when probe is successful. |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 4533 | TEST_P(QuicStreamFactoryTest, |
| 4534 | MigrateSessionEarlyNonMigratableStream_DoNotMigrateIdleSessions) { |
| 4535 | TestMigrateSessionEarlyNonMigratableStream(false); |
| 4536 | } |
| 4537 | |
| 4538 | TEST_P(QuicStreamFactoryTest, |
| 4539 | MigrateSessionEarlyNonMigratableStream_MigrateIdleSessions) { |
| 4540 | TestMigrateSessionEarlyNonMigratableStream(true); |
| 4541 | } |
| 4542 | |
| 4543 | void QuicStreamFactoryTestBase::TestMigrateSessionEarlyNonMigratableStream( |
| 4544 | bool migrate_idle_sessions) { |
| 4545 | test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4546 | InitializeConnectionMigrationV2Test( |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4547 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4548 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4549 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4550 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4551 | MockQuicData socket_data; |
| 4552 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4553 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 4554 | if (!migrate_idle_sessions) { |
| 4555 | socket_data.AddWrite( |
| 4556 | SYNCHRONOUS, |
| 4557 | client_maker_.MakeRstAckAndConnectionClosePacket( |
| 4558 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4559 | quic::QUIC_STREAM_CANCELLED, |
| 4560 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 4561 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 4562 | "net error")); |
| 4563 | } |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4564 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4565 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4566 | // Set up the second socket data provider that is used for probing. |
| 4567 | MockQuicData quic_data1; |
| 4568 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4569 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4570 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4571 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4572 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4573 | quic_data1.AddRead(ASYNC, |
| 4574 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 4575 | if (migrate_idle_sessions) { |
| 4576 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 4577 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 4578 | quic_data1.AddWrite( |
| 4579 | SYNCHRONOUS, |
| 4580 | client_maker_.MakeRstPacket( |
| 4581 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4582 | quic::QUIC_STREAM_CANCELLED)); |
| 4583 | // Ping packet to send after migration is completed. |
| 4584 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4585 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4586 | } |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4587 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4588 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4589 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4590 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4591 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4592 | request.Request( |
| 4593 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4594 | SocketTag(), |
| 4595 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4596 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4597 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4598 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4599 | EXPECT_TRUE(stream.get()); |
| 4600 | |
| 4601 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 4602 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 4603 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4604 | request_info.traffic_annotation = |
| 4605 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4606 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4607 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4608 | |
| 4609 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4610 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4611 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4612 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4613 | |
| 4614 | // Trigger connection migration. Since there is a non-migratable stream, |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 4615 | // this should cause session to migrate. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4616 | session->OnPathDegrading(); |
| 4617 | |
| 4618 | // Run the message loop so that data queued in the new socket is read by the |
| 4619 | // packet reader. |
| 4620 | base::RunLoop().RunUntilIdle(); |
| 4621 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4622 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4623 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4624 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4625 | // Resume the data to read the connectivity probing response to declare probe |
| 4626 | // as successful. Non-migratable streams will be closed. |
| 4627 | quic_data1.Resume(); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 4628 | if (migrate_idle_sessions) |
| 4629 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 4630 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 4631 | EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4632 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4633 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4634 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4635 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4636 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4637 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4638 | } |
| 4639 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4640 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyConnectionMigrationDisabled) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4641 | InitializeConnectionMigrationV2Test( |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4642 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4643 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4644 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4645 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4646 | MockQuicData socket_data; |
| 4647 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4648 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 4649 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4650 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4651 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4652 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4653 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4654 | |
| 4655 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4656 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4657 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4658 | request.Request( |
| 4659 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4660 | SocketTag(), |
| 4661 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4662 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4663 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4664 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4665 | EXPECT_TRUE(stream.get()); |
| 4666 | |
| 4667 | // Cause QUIC stream to be created. |
| 4668 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4669 | request_info.traffic_annotation = |
| 4670 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4671 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4672 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4673 | |
| 4674 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4675 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4676 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4677 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4678 | |
| 4679 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4680 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 4681 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4682 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 4683 | |
| 4684 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4685 | // this should cause session to be continue without migrating. |
| 4686 | session->OnPathDegrading(); |
| 4687 | |
| 4688 | // Run the message loop so that data queued in the new socket is read by the |
| 4689 | // packet reader. |
| 4690 | base::RunLoop().RunUntilIdle(); |
| 4691 | |
| 4692 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4693 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4694 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4695 | |
| 4696 | stream.reset(); |
| 4697 | |
| 4698 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4699 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4700 | } |
| 4701 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4702 | // Regression test for http://crbug.com/791886. |
| 4703 | // This test verifies that the old packet writer which encountered an |
| 4704 | // asynchronous write error will be blocked during migration on write error. New |
| 4705 | // packets would not be written until the one with write error is rewritten on |
| 4706 | // the new network. |
| 4707 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { |
| 4708 | InitializeConnectionMigrationV2Test( |
| 4709 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4710 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4711 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4712 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4713 | |
| 4714 | // Using a testing task runner so that we can control time. |
| 4715 | // base::RunLoop() controls mocked socket writes and reads. |
| 4716 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4717 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4718 | |
| 4719 | MockQuicData socket_data; |
| 4720 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4721 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4722 | socket_data.AddWrite( |
| 4723 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4724 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4725 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4726 | |
| 4727 | // Set up second socket data provider that is used after |
| 4728 | // migration. The request is rewritten to this new socket, and the |
| 4729 | // response to the request is read on this new socket. |
| 4730 | MockQuicData socket_data1; |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4731 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4732 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4733 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4734 | true, &header_stream_offset)); |
| 4735 | socket_data1.AddWrite(SYNCHRONOUS, |
| 4736 | ConstructGetRequestPacket( |
| 4737 | 3, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4738 | GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4739 | true, &header_stream_offset)); |
| 4740 | socket_data1.AddRead( |
| 4741 | ASYNC, |
| 4742 | ConstructOkResponsePacket( |
| 4743 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 4744 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4745 | socket_data1.AddWrite( |
| 4746 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4747 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4748 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4749 | socket_data1.AddWrite( |
| 4750 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4751 | 5, false, GetNthClientInitiatedBidirectionalStreamId(1), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame] | 4752 | quic::QUIC_STREAM_CANCELLED, 0, |
| 4753 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4754 | |
| 4755 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4756 | |
| 4757 | // Create request #1 and QuicHttpStream. |
| 4758 | QuicStreamRequest request1(factory_.get()); |
| 4759 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4760 | request1.Request( |
| 4761 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4762 | SocketTag(), |
| 4763 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4764 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4765 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4766 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4767 | EXPECT_TRUE(stream1.get()); |
| 4768 | |
| 4769 | HttpRequestInfo request_info1; |
| 4770 | request_info1.method = "GET"; |
| 4771 | request_info1.url = GURL("https://www.example.org/"); |
| 4772 | request_info1.traffic_annotation = |
| 4773 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4774 | EXPECT_EQ(OK, |
| 4775 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4776 | net_log_, CompletionOnceCallback())); |
| 4777 | |
| 4778 | // Request #2 returns synchronously because it pools to existing session. |
| 4779 | TestCompletionCallback callback2; |
| 4780 | QuicStreamRequest request2(factory_.get()); |
| 4781 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 4782 | DEFAULT_PRIORITY, SocketTag(), |
| 4783 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4784 | &net_error_details_, |
| 4785 | failed_on_default_network_callback_, |
| 4786 | callback2.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4787 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 4788 | EXPECT_TRUE(stream2.get()); |
| 4789 | |
| 4790 | HttpRequestInfo request_info2; |
| 4791 | request_info2.method = "GET"; |
| 4792 | request_info2.url = GURL("https://www.example.org/"); |
| 4793 | request_info2.traffic_annotation = |
| 4794 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4795 | EXPECT_EQ(OK, |
| 4796 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 4797 | net_log_, CompletionOnceCallback())); |
| 4798 | |
| 4799 | // Ensure that session is alive and active. |
| 4800 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4801 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4802 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4803 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 4804 | |
| 4805 | // Send GET request on stream1. This should cause an async write error. |
| 4806 | HttpResponseInfo response; |
| 4807 | HttpRequestHeaders request_headers; |
| 4808 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4809 | callback_.callback())); |
| 4810 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4811 | |
| 4812 | // Run the message loop so that asynchronous write completes and a connection |
| 4813 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4814 | // runner. |
| 4815 | base::RunLoop().RunUntilIdle(); |
| 4816 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4817 | |
| 4818 | // Send GET request on stream. This will cause another write attempt before |
| 4819 | // migration on write error is exectued. |
| 4820 | HttpResponseInfo response2; |
| 4821 | HttpRequestHeaders request_headers2; |
| 4822 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4823 | callback2.callback())); |
| 4824 | |
| 4825 | // Run the task runner so that migration on write error is finally executed. |
| 4826 | task_runner->RunUntilIdle(); |
| 4827 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4828 | // Verify the session is still alive and not marked as going away. |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4829 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4830 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4831 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4832 | // There should be one task posted to migrate back to the default network in |
| 4833 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4834 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4835 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 4836 | task_runner->NextPendingTaskDelay()); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4837 | |
| 4838 | // Verify that response headers on the migrated socket were delivered to the |
| 4839 | // stream. |
| 4840 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4841 | EXPECT_EQ(200, response.headers->response_code()); |
| 4842 | |
| 4843 | stream1.reset(); |
| 4844 | stream2.reset(); |
| 4845 | |
| 4846 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4847 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4848 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4849 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4850 | } |
| 4851 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4852 | // Verify session is not marked as going away after connection migration on |
| 4853 | // write error and migrate back to default network logic is applied to bring the |
| 4854 | // migrated session back to the default network. Migration singals delivered |
| 4855 | // in the following order (alternate network is always availabe): |
| 4856 | // - session on the default network encountered a write error; |
| 4857 | // - session successfully migrated to the non-default network; |
| 4858 | // - session attempts to migrate back to default network post migration; |
| 4859 | // - migration back to the default network is successful. |
| 4860 | TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { |
| 4861 | InitializeConnectionMigrationV2Test( |
| 4862 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4863 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4864 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4865 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4866 | |
| 4867 | // Using a testing task runner so that we can control time. |
| 4868 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4869 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4870 | |
| 4871 | MockQuicData socket_data; |
| 4872 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4873 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4874 | socket_data.AddWrite( |
| 4875 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4876 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4877 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4878 | |
| 4879 | // Set up second socket data provider that is used after |
| 4880 | // migration. The request is rewritten to this new socket, and the |
| 4881 | // response to the request is read on this new socket. |
| 4882 | MockQuicData quic_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4883 | quic_data2.AddWrite( |
| 4884 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4885 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4886 | true, &header_stream_offset)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4887 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4888 | ASYNC, |
| 4889 | ConstructOkResponsePacket( |
| 4890 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4891 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4892 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4893 | |
| 4894 | // Create request QuicHttpStream. |
| 4895 | QuicStreamRequest request1(factory_.get()); |
| 4896 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4897 | request1.Request( |
| 4898 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4899 | SocketTag(), |
| 4900 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4901 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4902 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4903 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4904 | EXPECT_TRUE(stream1.get()); |
| 4905 | |
| 4906 | HttpRequestInfo request_info1; |
| 4907 | request_info1.method = "GET"; |
| 4908 | request_info1.url = GURL("https://www.example.org/"); |
| 4909 | request_info1.traffic_annotation = |
| 4910 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4911 | EXPECT_EQ(OK, |
| 4912 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4913 | net_log_, CompletionOnceCallback())); |
| 4914 | |
| 4915 | // Ensure that session is alive and active. |
| 4916 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4917 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4918 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4919 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4920 | |
| 4921 | // Send GET request. This should cause an async write error. |
| 4922 | HttpResponseInfo response; |
| 4923 | HttpRequestHeaders request_headers; |
| 4924 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4925 | callback_.callback())); |
| 4926 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4927 | |
| 4928 | // Run the message loop so that asynchronous write completes and a connection |
| 4929 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4930 | // runner. |
| 4931 | base::RunLoop().RunUntilIdle(); |
| 4932 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4933 | |
| 4934 | // Run the task runner so that migration on write error is finally executed. |
| 4935 | task_runner->RunUntilIdle(); |
| 4936 | |
| 4937 | // Verify the session is still alive and not marked as going away. |
| 4938 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4939 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4940 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4941 | // There should be one task posted to migrate back to the default network in |
| 4942 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4943 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4944 | base::TimeDelta expected_delay = |
| 4945 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 4946 | EXPECT_EQ(expected_delay, task_runner->NextPendingTaskDelay()); |
| 4947 | |
| 4948 | // Verify that response headers on the migrated socket were delivered to the |
| 4949 | // stream. |
| 4950 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4951 | EXPECT_EQ(200, response.headers->response_code()); |
| 4952 | |
| 4953 | // Set up the third socket data provider for migrate back to default network. |
| 4954 | MockQuicData quic_data3; |
| 4955 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4956 | quic_data3.AddWrite(SYNCHRONOUS, |
| 4957 | client_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4958 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4959 | quic_data3.AddRead(ASYNC, |
| 4960 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4961 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4962 | quic_data3.AddWrite(ASYNC, client_maker_.MakeAckPacket(4, 1, 2, 1, 1, true)); |
| 4963 | quic_data3.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4964 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4965 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame] | 4966 | quic::QUIC_STREAM_CANCELLED, 0, |
| 4967 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4968 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 4969 | |
| 4970 | // Fast forward to fire the migrate back timer and verify the session |
| 4971 | // successfully migrates back to the default network. |
| 4972 | task_runner->FastForwardBy(expected_delay); |
| 4973 | |
| 4974 | // Verify the session is still alive and not marked as going away. |
| 4975 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4976 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4977 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4978 | |
| 4979 | // There should be one task posted to one will resend a connectivity probe and |
| 4980 | // the other will retry migrate back, both are cancelled. |
| 4981 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4982 | task_runner->FastForwardBy( |
| 4983 | base::TimeDelta::FromSeconds(2 * kMinRetryTimeForDefaultNetworkSecs)); |
| 4984 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4985 | |
| 4986 | stream1.reset(); |
| 4987 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4988 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4989 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4990 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4991 | EXPECT_TRUE(quic_data3.AllReadDataConsumed()); |
| 4992 | EXPECT_TRUE(quic_data3.AllWriteDataConsumed()); |
| 4993 | } |
| 4994 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4995 | // This test verifies that the connection will not attempt connection migration |
| 4996 | // (send connectivity probes on alternate path) when path degrading is detected |
| 4997 | // and handshake is not confirmed. |
| 4998 | TEST_P(QuicStreamFactoryTest, |
| 4999 | NoMigrationOnPathDegradingBeforeHandshakeConfirmed) { |
| 5000 | InitializeConnectionMigrationV2Test( |
| 5001 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5002 | |
| 5003 | // Using a testing task runner. |
| 5004 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5005 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 5006 | |
| 5007 | // Use cold start mode to send crypto message for handshake. |
| 5008 | crypto_client_stream_factory_.set_handshake_mode( |
| 5009 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5010 | |
| 5011 | MockQuicData socket_data; |
| 5012 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5013 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 5014 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5015 | |
| 5016 | // Create request and QuicHttpStream. |
| 5017 | QuicStreamRequest request(factory_.get()); |
| 5018 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5019 | request.Request( |
| 5020 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5021 | SocketTag(), |
| 5022 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5023 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 5024 | |
| 5025 | base::RunLoop().RunUntilIdle(); |
| 5026 | |
| 5027 | // Ensure that session is alive but not active. |
| 5028 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5029 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5030 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5031 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5032 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5033 | |
| 5034 | // Cause the connection to report path degrading to the session. |
| 5035 | // Session will ignore the signal as handshake is not completed. |
| 5036 | session->connection()->OnPathDegradingTimeout(); |
| 5037 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5038 | |
| 5039 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5040 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 5041 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5042 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5043 | } |
| 5044 | |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 5045 | // This test verifies that if a connection is closed with |
| 5046 | // QUIC_NETWORK_IDLE_TIMEOUT before handshake is completed and there is no |
| 5047 | // alternate network, no new connection will be created. |
| 5048 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkBeforeHandshakeOnIdleTimeout) { |
| 5049 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 5050 | } |
| 5051 | |
| 5052 | // This test verifies that if a connection is closed with QUIC_HANDSHAKE_TIMEOUT |
| 5053 | // and there is no alternate network, no new connection will be created. |
| 5054 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkOnHandshakeTimeout) { |
| 5055 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_HANDSHAKE_TIMEOUT); |
| 5056 | } |
| 5057 | |
| 5058 | void QuicStreamFactoryTestBase::TestNoAlternateNetworkBeforeHandshake( |
| 5059 | quic::QuicErrorCode quic_error) { |
| 5060 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 5061 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 5062 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 5063 | |
| 5064 | // Using a testing task runner. |
| 5065 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5066 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 5067 | |
| 5068 | // Use cold start mode to send crypto message for handshake. |
| 5069 | crypto_client_stream_factory_.set_handshake_mode( |
| 5070 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5071 | |
| 5072 | MockQuicData socket_data; |
| 5073 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5074 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 5075 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5076 | |
| 5077 | // Create request. |
| 5078 | QuicStreamRequest request(factory_.get()); |
| 5079 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5080 | request.Request( |
| 5081 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5082 | SocketTag(), |
| 5083 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5084 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 5085 | |
| 5086 | base::RunLoop().RunUntilIdle(); |
| 5087 | |
| 5088 | // Ensure that session is alive but not active. |
| 5089 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5090 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5091 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5092 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5093 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5094 | |
| 5095 | // Cause the connection to report path degrading to the session. |
| 5096 | // Session will ignore the signal as handshake is not completed. |
| 5097 | session->connection()->OnPathDegradingTimeout(); |
| 5098 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5099 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5100 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5101 | |
| 5102 | // Cause the connection to close due to |quic_error| before handshake. |
| 5103 | quic::QuicString error_details; |
| 5104 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5105 | error_details = "No recent network activity."; |
| 5106 | } else { |
| 5107 | error_details = "Handshake timeout expired."; |
| 5108 | } |
| 5109 | session->connection()->CloseConnection( |
| 5110 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5111 | |
| 5112 | // A task will be posted to clean up the session in the factory. |
| 5113 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5114 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5115 | |
| 5116 | // No new session should be created as there is no alternate network. |
| 5117 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5118 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5119 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5120 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5121 | } |
| 5122 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5123 | TEST_P(QuicStreamFactoryTest, NewConnectionBeforeHandshakeAfterIdleTimeout) { |
| 5124 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 5125 | quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 5126 | } |
| 5127 | |
| 5128 | TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) { |
| 5129 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 5130 | quic::QUIC_HANDSHAKE_TIMEOUT); |
| 5131 | } |
| 5132 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5133 | // Sets up a test to verify that a new connection will be created on the |
| 5134 | // alternate network after the initial connection fails before handshake with |
| 5135 | // signals delivered in the following order (alternate network is available): |
| 5136 | // - the default network is not able to complete crypto handshake; |
| 5137 | // - the original connection is closed with |quic_error|; |
| 5138 | // - a new connection is created on the alternate network and is able to finish |
| 5139 | // crypto handshake; |
| 5140 | // - the new session on the alternate network attempts to migrate back to the |
| 5141 | // default network by sending probes; |
| 5142 | // - default network being disconnected is delivered: session will stop probing |
| 5143 | // the original network. |
| 5144 | // - alternate network is made by default. |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5145 | void QuicStreamFactoryTestBase:: |
| 5146 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 5147 | quic::QuicErrorCode quic_error) { |
| 5148 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 5149 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 5150 | test_params_.quic_retry_on_alternate_network_before_handshake = true; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5151 | InitializeConnectionMigrationV2Test( |
| 5152 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5153 | |
| 5154 | // Using a testing task runner. |
| 5155 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5156 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 5157 | |
| 5158 | // Use cold start mode to send crypto message for handshake. |
| 5159 | crypto_client_stream_factory_.set_handshake_mode( |
| 5160 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5161 | |
| 5162 | // Socket data for connection on the default network. |
| 5163 | MockQuicData socket_data; |
| 5164 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5165 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 5166 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5167 | |
| 5168 | // Socket data for connection on the alternate network. |
| 5169 | MockQuicData socket_data2; |
| 5170 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5171 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5172 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5173 | // Change the encryption level after handshake is confirmed. |
| 5174 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5175 | socket_data2.AddWrite( |
| 5176 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5177 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5178 | ASYNC, ConstructGetRequestPacket( |
| 5179 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5180 | &header_stream_offset)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5181 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5182 | ASYNC, |
| 5183 | ConstructOkResponsePacket( |
| 5184 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5185 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5186 | socket_data2.AddWrite( |
| 5187 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5188 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5189 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5190 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5191 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5192 | // Socket data for probing on the default network. |
| 5193 | MockQuicData probing_data; |
| 5194 | probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5195 | probing_data.AddWrite(SYNCHRONOUS, |
| 5196 | client_maker_.MakeConnectivityProbingPacket(4, false)); |
| 5197 | probing_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5198 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5199 | // Create request and QuicHttpStream. |
| 5200 | QuicStreamRequest request(factory_.get()); |
| 5201 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5202 | request.Request( |
| 5203 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5204 | SocketTag(), |
| 5205 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5206 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5207 | |
| 5208 | base::RunLoop().RunUntilIdle(); |
| 5209 | |
| 5210 | // Ensure that session is alive but not active. |
| 5211 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5212 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5213 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5214 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5215 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5216 | EXPECT_FALSE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5217 | |
| 5218 | quic::QuicString error_details; |
| 5219 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5220 | error_details = "No recent network activity."; |
| 5221 | } else { |
| 5222 | error_details = "Handshake timeout expired."; |
| 5223 | } |
| 5224 | session->connection()->CloseConnection( |
| 5225 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5226 | |
| 5227 | // A task will be posted to clean up the session in the factory. |
| 5228 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5229 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5230 | |
| 5231 | // Verify a new session is created on the alternate network. |
| 5232 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5233 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5234 | QuicChromiumClientSession* session2 = GetPendingSession(host_port_pair_); |
| 5235 | EXPECT_NE(session, session2); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5236 | EXPECT_TRUE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5237 | |
| 5238 | // Confirm the handshake on the alternate network. |
| 5239 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5240 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5241 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5242 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5243 | // Resume the data now so that data can be sent and read. |
| 5244 | socket_data2.Resume(); |
| 5245 | |
| 5246 | // Create the stream. |
| 5247 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5248 | EXPECT_TRUE(stream.get()); |
| 5249 | HttpRequestInfo request_info; |
| 5250 | request_info.method = "GET"; |
| 5251 | request_info.url = GURL("https://www.example.org/"); |
| 5252 | request_info.traffic_annotation = |
| 5253 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5254 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5255 | net_log_, CompletionOnceCallback())); |
| 5256 | // Send the request. |
| 5257 | HttpResponseInfo response; |
| 5258 | HttpRequestHeaders request_headers; |
| 5259 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5260 | callback_.callback())); |
| 5261 | // Run the message loop to finish asynchronous mock write. |
| 5262 | base::RunLoop().RunUntilIdle(); |
| 5263 | // Read the response. |
| 5264 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5265 | EXPECT_EQ(200, response.headers->response_code()); |
| 5266 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5267 | // There should be a new task posted to migrate back to the default network. |
| 5268 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5269 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5270 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 5271 | next_task_delay); |
| 5272 | task_runner->FastForwardBy(next_task_delay); |
| 5273 | |
| 5274 | // There should be two tasks posted. One will retry probing and the other |
| 5275 | // will retry migrate back. |
| 5276 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 5277 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5278 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 5279 | next_task_delay); |
| 5280 | |
| 5281 | // Deliver the signal that the default network is disconnected. |
| 5282 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5283 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 5284 | // Verify no connectivity probes will be sent as probing will be cancelled. |
| 5285 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5286 | // Deliver the signal that the alternate network is made default. |
| 5287 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5288 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 5289 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5290 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5291 | stream.reset(); |
| 5292 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5293 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5294 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5295 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5296 | } |
| 5297 | |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5298 | // Test that connection will be closed with PACKET_WRITE_ERROR if a write error |
| 5299 | // is triggered before handshake is confirmed and connection migration is turned |
| 5300 | // on. |
| 5301 | TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 5302 | DCHECK(!test_params_.quic_retry_on_alternate_network_before_handshake); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5303 | InitializeConnectionMigrationV2Test( |
| 5304 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5305 | |
| 5306 | // Use unmocked crypto stream to do crypto connect. |
| 5307 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 5308 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5309 | |
| 5310 | MockQuicData socket_data; |
| 5311 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5312 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5313 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5314 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5315 | |
| 5316 | // Create request, should fail after the write of the CHLO fails. |
| 5317 | QuicStreamRequest request(factory_.get()); |
| 5318 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5319 | request.Request( |
| 5320 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5321 | SocketTag(), |
| 5322 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5323 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5324 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 5325 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5326 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5327 | |
| 5328 | // Verify new requests can be sent normally. |
| 5329 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 5330 | MockCryptoClientStream::COLD_START); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5331 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5332 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5333 | MockQuicData socket_data2; |
| 5334 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5335 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 5336 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5337 | |
| 5338 | QuicStreamRequest request2(factory_.get()); |
| 5339 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5340 | request2.Request( |
| 5341 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5342 | SocketTag(), |
| 5343 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5344 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5345 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5346 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5347 | // Run the message loop to complete host resolution. |
| 5348 | base::RunLoop().RunUntilIdle(); |
| 5349 | |
| 5350 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 5351 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5352 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5353 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5354 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5355 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5356 | |
| 5357 | // Create QuicHttpStream. |
| 5358 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
| 5359 | EXPECT_TRUE(stream.get()); |
| 5360 | stream.reset(); |
| 5361 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5362 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5363 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5364 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5365 | } |
| 5366 | |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5367 | // Test that if the original connection is closed with QUIC_PACKET_WRITE_ERROR |
| 5368 | // before handshake is confirmed and new connection before handshake is turned |
| 5369 | // on, a new connection will be retried on the alternate network. |
| 5370 | TEST_P(QuicStreamFactoryTest, |
| 5371 | RetryConnectionOnWriteErrorBeforeHandshakeConfirmed) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 5372 | test_params_.quic_retry_on_alternate_network_before_handshake = true; |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5373 | InitializeConnectionMigrationV2Test( |
| 5374 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5375 | |
| 5376 | // Use unmocked crypto stream to do crypto connect. |
| 5377 | crypto_client_stream_factory_.set_handshake_mode( |
| 5378 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5379 | |
| 5380 | // Socket data for connection on the default network. |
| 5381 | MockQuicData socket_data; |
| 5382 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5383 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5384 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5385 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5386 | |
| 5387 | // Socket data for connection on the alternate network. |
| 5388 | MockQuicData socket_data2; |
| 5389 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5390 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5391 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5392 | // Change the encryption level after handshake is confirmed. |
| 5393 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5394 | socket_data2.AddWrite( |
| 5395 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5396 | socket_data2.AddWrite( |
| 5397 | ASYNC, ConstructGetRequestPacket( |
| 5398 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5399 | &header_stream_offset)); |
| 5400 | socket_data2.AddRead( |
| 5401 | ASYNC, |
| 5402 | ConstructOkResponsePacket( |
| 5403 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5404 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5405 | socket_data2.AddWrite( |
| 5406 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5407 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5408 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5409 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5410 | |
| 5411 | // Create request, should fail after the write of the CHLO fails. |
| 5412 | QuicStreamRequest request(factory_.get()); |
| 5413 | EXPECT_EQ(ERR_IO_PENDING, |
| 5414 | request.Request( |
| 5415 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5416 | SocketTag(), |
| 5417 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5418 | failed_on_default_network_callback_, callback_.callback())); |
| 5419 | // Ensure that the session is alive but not active. |
| 5420 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5421 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5422 | base::RunLoop().RunUntilIdle(); |
| 5423 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5424 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5425 | |
| 5426 | // Confirm the handshake on the alternate network. |
| 5427 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5428 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5429 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5430 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5431 | |
| 5432 | // Resume the data now so that data can be sent and read. |
| 5433 | socket_data2.Resume(); |
| 5434 | |
| 5435 | // Create the stream. |
| 5436 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5437 | EXPECT_TRUE(stream.get()); |
| 5438 | HttpRequestInfo request_info; |
| 5439 | request_info.method = "GET"; |
| 5440 | request_info.url = GURL("https://www.example.org/"); |
| 5441 | request_info.traffic_annotation = |
| 5442 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5443 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5444 | net_log_, CompletionOnceCallback())); |
| 5445 | // Send the request. |
| 5446 | HttpResponseInfo response; |
| 5447 | HttpRequestHeaders request_headers; |
| 5448 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5449 | callback_.callback())); |
| 5450 | // Run the message loop to finish asynchronous mock write. |
| 5451 | base::RunLoop().RunUntilIdle(); |
| 5452 | // Read the response. |
| 5453 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5454 | EXPECT_EQ(200, response.headers->response_code()); |
| 5455 | |
| 5456 | stream.reset(); |
| 5457 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5458 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5459 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5460 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5461 | } |
| 5462 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5463 | void QuicStreamFactoryTestBase::TestMigrationOnWriteError( |
| 5464 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5465 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5466 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5467 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5468 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5469 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5470 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 5471 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5472 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5473 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5474 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5475 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 5476 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5477 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5478 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5479 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5480 | |
| 5481 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5482 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5483 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5484 | request.Request( |
| 5485 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5486 | SocketTag(), |
| 5487 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5488 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5489 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5490 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5491 | EXPECT_TRUE(stream.get()); |
| 5492 | |
| 5493 | // Cause QUIC stream to be created. |
| 5494 | HttpRequestInfo request_info; |
| 5495 | request_info.method = "GET"; |
| 5496 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5497 | request_info.traffic_annotation = |
| 5498 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5499 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5500 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5501 | |
| 5502 | // Ensure that session is alive and active. |
| 5503 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5504 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5505 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5506 | |
| 5507 | // Set up second socket data provider that is used after |
| 5508 | // migration. The request is rewritten to this new socket, and the |
| 5509 | // response to the request is read on this new socket. |
| 5510 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5511 | socket_data1.AddWrite( |
| 5512 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5513 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5514 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5515 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5516 | ASYNC, |
| 5517 | ConstructOkResponsePacket( |
| 5518 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5519 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5520 | socket_data1.AddWrite( |
| 5521 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5522 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5523 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5524 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5525 | |
| 5526 | // Send GET request on stream. This should cause a write error, which triggers |
| 5527 | // a connection migration attempt. |
| 5528 | HttpResponseInfo response; |
| 5529 | HttpRequestHeaders request_headers; |
| 5530 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5531 | callback_.callback())); |
| 5532 | |
| 5533 | // Run the message loop so that the migration attempt is executed and |
| 5534 | // data queued in the new socket is read by the packet reader. |
| 5535 | base::RunLoop().RunUntilIdle(); |
| 5536 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5537 | // Verify that session is alive and not marked as going awya. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5538 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5539 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5540 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5541 | |
| 5542 | // Verify that response headers on the migrated socket were delivered to the |
| 5543 | // stream. |
| 5544 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5545 | EXPECT_EQ(200, response.headers->response_code()); |
| 5546 | |
| 5547 | stream.reset(); |
| 5548 | |
| 5549 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5550 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5551 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5552 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5553 | } |
| 5554 | |
| 5555 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 5556 | TestMigrationOnWriteError(SYNCHRONOUS); |
| 5557 | } |
| 5558 | |
| 5559 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 5560 | TestMigrationOnWriteError(ASYNC); |
| 5561 | } |
| 5562 | |
| 5563 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNoNewNetwork( |
| 5564 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5565 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5566 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5567 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5568 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5569 | // Use the test task runner, to force the migration alarm timeout later. |
| 5570 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 5571 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5572 | MockQuicData socket_data; |
| 5573 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5574 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5575 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5576 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5577 | |
| 5578 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5579 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5580 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5581 | request.Request( |
| 5582 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5583 | SocketTag(), |
| 5584 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5585 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5586 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5587 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5588 | EXPECT_TRUE(stream.get()); |
| 5589 | |
| 5590 | // Cause QUIC stream to be created. |
| 5591 | HttpRequestInfo request_info; |
| 5592 | request_info.method = "GET"; |
| 5593 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5594 | request_info.traffic_annotation = |
| 5595 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5596 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5597 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5598 | |
| 5599 | // Ensure that session is alive and active. |
| 5600 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5601 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5602 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5603 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5604 | // Send GET request on stream. This causes a write error, which triggers |
| 5605 | // a connection migration attempt. Since there are no networks |
| 5606 | // to migrate to, this causes the session to wait for a new network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5607 | HttpResponseInfo response; |
| 5608 | HttpRequestHeaders request_headers; |
| 5609 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5610 | callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5611 | |
| 5612 | // Complete any pending writes. Pending async MockQuicData writes |
| 5613 | // are run on the message loop, not on the test runner. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5614 | base::RunLoop().RunUntilIdle(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5615 | |
| 5616 | // Write error causes migration task to be posted. Spin the loop. |
| 5617 | if (write_error_mode == ASYNC) |
| 5618 | runner_->RunNextTask(); |
| 5619 | |
| 5620 | // Migration has not yet failed. The session should be alive and active. |
| 5621 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5622 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5623 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5624 | EXPECT_TRUE(session->connection()->writer()->IsWriteBlocked()); |
| 5625 | |
| 5626 | // The migration will not fail until the migration alarm timeout. |
| 5627 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5628 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5629 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5630 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 5631 | |
| 5632 | // Force migration alarm timeout to run. |
| 5633 | RunTestLoopUntilIdle(); |
| 5634 | |
| 5635 | // The connection should be closed. A request for response headers |
| 5636 | // should fail. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5637 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5638 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5639 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
| 5640 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 5641 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5642 | |
Zhongyi Shi | 59aaf07 | 2019-01-17 03:32:13 | [diff] [blame] | 5643 | NetErrorDetails error_details; |
| 5644 | stream->PopulateNetErrorDetails(&error_details); |
| 5645 | EXPECT_EQ(error_details.quic_connection_error, |
| 5646 | quic::QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
| 5647 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5648 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5649 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5650 | } |
| 5651 | |
| 5652 | TEST_P(QuicStreamFactoryTest, |
| 5653 | MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 5654 | TestMigrationOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 5655 | } |
| 5656 | |
| 5657 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 5658 | TestMigrationOnWriteErrorNoNewNetwork(ASYNC); |
| 5659 | } |
| 5660 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5661 | TEST_P(QuicStreamFactoryTest, |
| 5662 | MigrateSessionOnWriteErrorWithMultipleRequestsSync) { |
| 5663 | TestMigrationOnWriteErrorWithMultipleRequests(SYNCHRONOUS); |
| 5664 | } |
| 5665 | |
| 5666 | TEST_P(QuicStreamFactoryTest, |
| 5667 | MigrateSessionOnWriteErrorWithMultipleRequestsAsync) { |
| 5668 | TestMigrationOnWriteErrorWithMultipleRequests(ASYNC); |
| 5669 | } |
| 5670 | |
| 5671 | // Sets up a test which verifies that connection migration on write error can |
| 5672 | // eventually succeed and rewrite the packet on the new network with *multiple* |
| 5673 | // migratable streams. |
| 5674 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( |
| 5675 | IoMode write_error_mode) { |
| 5676 | InitializeConnectionMigrationV2Test( |
| 5677 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5678 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5679 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5680 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5681 | |
| 5682 | MockQuicData socket_data; |
| 5683 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5684 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5685 | socket_data.AddWrite( |
| 5686 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5687 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5688 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5689 | |
| 5690 | // Set up second socket data provider that is used after |
| 5691 | // migration. The request is rewritten to this new socket, and the |
| 5692 | // response to the request is read on this new socket. |
| 5693 | MockQuicData socket_data1; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5694 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5695 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5696 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5697 | true, &header_stream_offset)); |
| 5698 | socket_data1.AddRead( |
| 5699 | ASYNC, |
| 5700 | ConstructOkResponsePacket( |
| 5701 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5702 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5703 | socket_data1.AddWrite( |
| 5704 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5705 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5706 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5707 | socket_data1.AddWrite( |
| 5708 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 5709 | 4, false, GetNthClientInitiatedBidirectionalStreamId(1), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame] | 5710 | quic::QUIC_STREAM_CANCELLED, 0, |
| 5711 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5712 | |
| 5713 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5714 | |
| 5715 | // Create request #1 and QuicHttpStream. |
| 5716 | QuicStreamRequest request1(factory_.get()); |
| 5717 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5718 | request1.Request( |
| 5719 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5720 | SocketTag(), |
| 5721 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5722 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5723 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5724 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5725 | EXPECT_TRUE(stream1.get()); |
| 5726 | |
| 5727 | HttpRequestInfo request_info1; |
| 5728 | request_info1.method = "GET"; |
| 5729 | request_info1.url = GURL("https://www.example.org/"); |
| 5730 | request_info1.traffic_annotation = |
| 5731 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5732 | EXPECT_EQ(OK, |
| 5733 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5734 | net_log_, CompletionOnceCallback())); |
| 5735 | |
| 5736 | // Second request returns synchronously because it pools to existing session. |
| 5737 | TestCompletionCallback callback2; |
| 5738 | QuicStreamRequest request2(factory_.get()); |
| 5739 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5740 | DEFAULT_PRIORITY, SocketTag(), |
| 5741 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5742 | &net_error_details_, |
| 5743 | failed_on_default_network_callback_, |
| 5744 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5745 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5746 | EXPECT_TRUE(stream2.get()); |
| 5747 | HttpRequestInfo request_info2; |
| 5748 | request_info2.method = "GET"; |
| 5749 | request_info2.url = GURL("https://www.example.org/"); |
| 5750 | request_info2.traffic_annotation = |
| 5751 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5752 | EXPECT_EQ(OK, |
| 5753 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5754 | net_log_, CompletionOnceCallback())); |
| 5755 | |
| 5756 | // Ensure that session is alive and active. |
| 5757 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5758 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5759 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5760 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5761 | |
| 5762 | // Send GET request on stream. This should cause a write error, which triggers |
| 5763 | // a connection migration attempt. |
| 5764 | HttpResponseInfo response; |
| 5765 | HttpRequestHeaders request_headers; |
| 5766 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5767 | callback_.callback())); |
| 5768 | |
| 5769 | // Run the message loop so that the migration attempt is executed and |
| 5770 | // data queued in the new socket is read by the packet reader. |
| 5771 | base::RunLoop().RunUntilIdle(); |
| 5772 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5773 | // Verify session is still alive and not marked as going away. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5774 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5775 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5776 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5777 | |
| 5778 | // Verify that response headers on the migrated socket were delivered to the |
| 5779 | // stream. |
| 5780 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5781 | EXPECT_EQ(200, response.headers->response_code()); |
| 5782 | |
| 5783 | stream1.reset(); |
| 5784 | stream2.reset(); |
| 5785 | |
| 5786 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5787 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5788 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5789 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5790 | } |
| 5791 | |
| 5792 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsSync) { |
| 5793 | TestMigrationOnWriteErrorMixedStreams(SYNCHRONOUS); |
| 5794 | } |
| 5795 | |
| 5796 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsAsync) { |
| 5797 | TestMigrationOnWriteErrorMixedStreams(ASYNC); |
| 5798 | } |
| 5799 | |
| 5800 | // Sets up a test that verifies connection migration manages to migrate to |
| 5801 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5802 | // |write_error_mode| on the original network. |
| 5803 | // Note there are mixed types of unfinished requests before migration: one |
| 5804 | // migratable and one non-migratable. The *migratable* one triggers write |
| 5805 | // error. |
| 5806 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( |
| 5807 | IoMode write_error_mode) { |
| 5808 | InitializeConnectionMigrationV2Test( |
| 5809 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5810 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5811 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5812 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5813 | |
| 5814 | int packet_number = 1; |
| 5815 | MockQuicData socket_data; |
| 5816 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5817 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5818 | socket_data.AddWrite( |
| 5819 | SYNCHRONOUS, |
| 5820 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5821 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5822 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5823 | |
| 5824 | // Set up second socket data provider that is used after |
| 5825 | // migration. The request is rewritten to this new socket, and the |
| 5826 | // response to the request is read on this new socket. |
| 5827 | MockQuicData socket_data1; |
| 5828 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5829 | SYNCHRONOUS, |
| 5830 | ConstructGetRequestPacket(packet_number++, |
| 5831 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5832 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5833 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5834 | SYNCHRONOUS, |
| 5835 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5836 | GetNthClientInitiatedBidirectionalStreamId(1), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame] | 5837 | quic::QUIC_STREAM_CANCELLED, 0, |
| 5838 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5839 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5840 | ASYNC, |
| 5841 | ConstructOkResponsePacket( |
| 5842 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5843 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5844 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5845 | SYNCHRONOUS, |
| 5846 | client_maker_.MakeAckAndRstPacket( |
| 5847 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5848 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5849 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5850 | |
| 5851 | // Create request #1 and QuicHttpStream. |
| 5852 | QuicStreamRequest request1(factory_.get()); |
| 5853 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5854 | request1.Request( |
| 5855 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5856 | SocketTag(), |
| 5857 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5858 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5859 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5860 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5861 | EXPECT_TRUE(stream1.get()); |
| 5862 | |
| 5863 | HttpRequestInfo request_info1; |
| 5864 | request_info1.method = "GET"; |
| 5865 | request_info1.url = GURL("https://www.example.org/"); |
| 5866 | request_info1.traffic_annotation = |
| 5867 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5868 | EXPECT_EQ(OK, |
| 5869 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5870 | net_log_, CompletionOnceCallback())); |
| 5871 | |
| 5872 | // Second request returns synchronously because it pools to existing session. |
| 5873 | TestCompletionCallback callback2; |
| 5874 | QuicStreamRequest request2(factory_.get()); |
| 5875 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5876 | DEFAULT_PRIORITY, SocketTag(), |
| 5877 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5878 | &net_error_details_, |
| 5879 | failed_on_default_network_callback_, |
| 5880 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5881 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5882 | EXPECT_TRUE(stream2.get()); |
| 5883 | |
| 5884 | HttpRequestInfo request_info2; |
| 5885 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5886 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5887 | request_info2.url = GURL("https://www.example.org/"); |
| 5888 | request_info2.traffic_annotation = |
| 5889 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5890 | EXPECT_EQ(OK, |
| 5891 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5892 | net_log_, CompletionOnceCallback())); |
| 5893 | |
| 5894 | // Ensure that session is alive and active. |
| 5895 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5896 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5897 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5898 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5899 | |
| 5900 | // Send GET request on stream 1. This should cause a write error, which |
| 5901 | // triggers a connection migration attempt. |
| 5902 | HttpResponseInfo response; |
| 5903 | HttpRequestHeaders request_headers; |
| 5904 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5905 | callback_.callback())); |
| 5906 | |
| 5907 | // Run the message loop so that the migration attempt is executed and |
| 5908 | // data queued in the new socket is read by the packet reader. |
| 5909 | base::RunLoop().RunUntilIdle(); |
| 5910 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5911 | // Verify that the session is still alive and not marked as going away. |
| 5912 | // Non-migratable stream should be closed due to migration. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5913 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5914 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5915 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5916 | |
| 5917 | // Verify that response headers on the migrated socket were delivered to the |
| 5918 | // stream. |
| 5919 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5920 | EXPECT_EQ(200, response.headers->response_code()); |
| 5921 | |
| 5922 | stream1.reset(); |
| 5923 | |
| 5924 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5925 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5926 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5927 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5928 | } |
| 5929 | |
| 5930 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Sync) { |
| 5931 | TestMigrationOnWriteErrorMixedStreams2(SYNCHRONOUS); |
| 5932 | } |
| 5933 | |
| 5934 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Async) { |
| 5935 | TestMigrationOnWriteErrorMixedStreams2(ASYNC); |
| 5936 | } |
| 5937 | |
| 5938 | // The one triggers write error is a non-migratable stream. |
| 5939 | // Sets up a test that verifies connection migration manages to migrate to |
| 5940 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5941 | // |write_error_mode| on the original network. |
| 5942 | // Note there are mixed types of unfinished requests before migration: one |
| 5943 | // migratable and one non-migratable. The *non-migratable* one triggers write |
| 5944 | // error. |
| 5945 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( |
| 5946 | IoMode write_error_mode) { |
| 5947 | InitializeConnectionMigrationV2Test( |
| 5948 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5949 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5950 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5951 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5952 | |
| 5953 | int packet_number = 1; |
| 5954 | MockQuicData socket_data; |
| 5955 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5956 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5957 | socket_data.AddWrite( |
| 5958 | SYNCHRONOUS, |
| 5959 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5960 | socket_data.AddWrite(write_error_mode, |
| 5961 | ERR_ADDRESS_UNREACHABLE); // Write error. |
| 5962 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5963 | |
| 5964 | // Set up second socket data provider that is used after |
| 5965 | // migration. The request is rewritten to this new socket, and the |
| 5966 | // response to the request is read on this new socket. |
| 5967 | MockQuicData socket_data1; |
| 5968 | // The packet triggered writer error will be sent anyway even if the stream |
| 5969 | // will be cancelled later. |
| 5970 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5971 | SYNCHRONOUS, |
| 5972 | ConstructGetRequestPacket(packet_number++, |
| 5973 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5974 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5975 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5976 | SYNCHRONOUS, |
| 5977 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5978 | GetNthClientInitiatedBidirectionalStreamId(1), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame] | 5979 | quic::QUIC_STREAM_CANCELLED, 0, |
| 5980 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5981 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5982 | SYNCHRONOUS, |
| 5983 | ConstructGetRequestPacket(packet_number++, |
| 5984 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5985 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5986 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5987 | ASYNC, |
| 5988 | ConstructOkResponsePacket( |
| 5989 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5990 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5991 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5992 | SYNCHRONOUS, |
| 5993 | client_maker_.MakeAckAndRstPacket( |
| 5994 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5995 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5996 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5997 | |
| 5998 | // Create request #1 and QuicHttpStream. |
| 5999 | QuicStreamRequest request1(factory_.get()); |
| 6000 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6001 | request1.Request( |
| 6002 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6003 | SocketTag(), |
| 6004 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6005 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 6006 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6007 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 6008 | EXPECT_TRUE(stream1.get()); |
| 6009 | |
| 6010 | HttpRequestInfo request_info1; |
| 6011 | request_info1.method = "GET"; |
| 6012 | request_info1.url = GURL("https://www.example.org/"); |
| 6013 | request_info1.traffic_annotation = |
| 6014 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6015 | EXPECT_EQ(OK, |
| 6016 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 6017 | net_log_, CompletionOnceCallback())); |
| 6018 | |
| 6019 | // Second request returns synchronously because it pools to existing session. |
| 6020 | TestCompletionCallback callback2; |
| 6021 | QuicStreamRequest request2(factory_.get()); |
| 6022 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 6023 | DEFAULT_PRIORITY, SocketTag(), |
| 6024 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6025 | &net_error_details_, |
| 6026 | failed_on_default_network_callback_, |
| 6027 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 6028 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 6029 | EXPECT_TRUE(stream2.get()); |
| 6030 | |
| 6031 | HttpRequestInfo request_info2; |
| 6032 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 6033 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 6034 | request_info2.url = GURL("https://www.example.org/"); |
| 6035 | request_info2.traffic_annotation = |
| 6036 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6037 | EXPECT_EQ(OK, |
| 6038 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 6039 | net_log_, CompletionOnceCallback())); |
| 6040 | |
| 6041 | // Ensure that session is alive and active. |
| 6042 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6043 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6044 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6045 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 6046 | |
| 6047 | // Send GET request on stream 2 which is non-migratable. This should cause a |
| 6048 | // write error, which triggers a connection migration attempt. |
| 6049 | HttpResponseInfo response2; |
| 6050 | HttpRequestHeaders request_headers2; |
| 6051 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 6052 | callback2.callback())); |
| 6053 | |
| 6054 | // Run the message loop so that the migration attempt is executed and |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6055 | // data queued in the new socket is read by the packet reader. Session is |
| 6056 | // still alive and not marked as going away, non-migratable stream will be |
| 6057 | // closed. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 6058 | base::RunLoop().RunUntilIdle(); |
| 6059 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6060 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 6061 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6062 | |
| 6063 | // Send GET request on stream 1. |
| 6064 | HttpResponseInfo response; |
| 6065 | HttpRequestHeaders request_headers; |
| 6066 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 6067 | callback_.callback())); |
| 6068 | |
| 6069 | base::RunLoop().RunUntilIdle(); |
| 6070 | |
| 6071 | // Verify that response headers on the migrated socket were delivered to the |
| 6072 | // stream. |
| 6073 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 6074 | EXPECT_EQ(200, response.headers->response_code()); |
| 6075 | |
| 6076 | stream1.reset(); |
| 6077 | |
| 6078 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6079 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6080 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6081 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6082 | } |
| 6083 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 6084 | // This test verifies that when a connection encounters a packet write error, it |
| 6085 | // will cancel non-migratable streams, and migrate to the alternate network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6086 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 6087 | IoMode write_error_mode, |
| 6088 | bool migrate_idle_sessions) { |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 6089 | DVLOG(1) << "Write error mode: " |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6090 | << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 6091 | DVLOG(1) << "Migrate idle sessions: " << migrate_idle_sessions; |
| 6092 | test_params_.quic_migrate_idle_sessions = migrate_idle_sessions; |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6093 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6094 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6095 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6096 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6097 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 6098 | MockQuicData failed_socket_data; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6099 | MockQuicData socket_data; |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 6100 | if (migrate_idle_sessions) { |
| 6101 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6102 | // The socket data provider for the original socket before migration. |
| 6103 | failed_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6104 | failed_socket_data.AddWrite( |
| 6105 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6106 | failed_socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 6107 | failed_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6108 | |
| 6109 | // Set up second socket data provider that is used after migration. |
| 6110 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 6111 | // Although the write error occurs when writing a packet for the |
| 6112 | // non-migratable stream and the stream will be cancelled during migration, |
| 6113 | // the packet will still be retransimitted at the connection level. |
| 6114 | socket_data.AddWrite( |
| 6115 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6116 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6117 | true, &header_stream_offset)); |
| 6118 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 6119 | socket_data.AddWrite( |
| 6120 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 6121 | 3, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6122 | quic::QUIC_STREAM_CANCELLED)); |
| 6123 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6124 | } else { |
| 6125 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6126 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 6127 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 6128 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6129 | } |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6130 | |
| 6131 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6132 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6133 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6134 | request.Request( |
| 6135 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6136 | SocketTag(), |
| 6137 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6138 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6139 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6140 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6141 | EXPECT_TRUE(stream.get()); |
| 6142 | |
| 6143 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 6144 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 6145 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6146 | request_info.method = "GET"; |
| 6147 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6148 | request_info.traffic_annotation = |
| 6149 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6150 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6151 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6152 | |
| 6153 | // Ensure that session is alive and active. |
| 6154 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6155 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6156 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6157 | |
| 6158 | // Send GET request on stream. This should cause a write error, which triggers |
| 6159 | // a connection migration attempt. |
| 6160 | HttpResponseInfo response; |
| 6161 | HttpRequestHeaders request_headers; |
| 6162 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6163 | callback_.callback())); |
| 6164 | |
| 6165 | // Run message loop to execute migration attempt. |
| 6166 | base::RunLoop().RunUntilIdle(); |
| 6167 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 6168 | // Migration closes the non-migratable stream and: |
| 6169 | // if migrate idle session is enabled, it migrates to the alternate network |
| 6170 | // successfully; otherwise the connection is closed. |
| 6171 | EXPECT_EQ(migrate_idle_sessions, |
| 6172 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6173 | EXPECT_EQ(migrate_idle_sessions, HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6174 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 6175 | if (migrate_idle_sessions) { |
| 6176 | EXPECT_TRUE(failed_socket_data.AllReadDataConsumed()); |
| 6177 | EXPECT_TRUE(failed_socket_data.AllWriteDataConsumed()); |
| 6178 | } |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6179 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6180 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6181 | } |
| 6182 | |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 6183 | TEST_P( |
| 6184 | QuicStreamFactoryTest, |
| 6185 | MigrateSessionOnWriteErrorNonMigratableStreamSync_DoNotMigrateIdleSessions) { |
| 6186 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS, false); |
| 6187 | } |
| 6188 | |
| 6189 | TEST_P( |
| 6190 | QuicStreamFactoryTest, |
| 6191 | MigrateSessionOnWriteErrorNonMigratableStreamAsync_DoNotMigrateIdleSessions) { |
| 6192 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC, false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 6196 | MigrateSessionOnWriteErrorNonMigratableStreamSync_MigrateIdleSessions) { |
| 6197 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS, true); |
| 6198 | } |
| 6199 | |
| 6200 | TEST_P(QuicStreamFactoryTest, |
| 6201 | MigrateSessionOnWriteErrorNonMigratableStreamAsync_MigrateIdleSessions) { |
| 6202 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC, true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6203 | } |
| 6204 | |
| 6205 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( |
| 6206 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6207 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6208 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6209 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6210 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6211 | |
| 6212 | MockQuicData socket_data; |
| 6213 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6214 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6215 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6216 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6217 | |
| 6218 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6219 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6220 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6221 | request.Request( |
| 6222 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6223 | SocketTag(), |
| 6224 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6225 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6226 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6227 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6228 | EXPECT_TRUE(stream.get()); |
| 6229 | |
| 6230 | // Cause QUIC stream to be created. |
| 6231 | HttpRequestInfo request_info; |
| 6232 | request_info.method = "GET"; |
| 6233 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6234 | request_info.traffic_annotation = |
| 6235 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6236 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6237 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6238 | |
| 6239 | // Ensure that session is alive and active. |
| 6240 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6241 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6242 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6243 | |
| 6244 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6245 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 6246 | session->config()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6247 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 6248 | |
| 6249 | // Send GET request on stream. This should cause a write error, which triggers |
| 6250 | // a connection migration attempt. |
| 6251 | HttpResponseInfo response; |
| 6252 | HttpRequestHeaders request_headers; |
| 6253 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6254 | callback_.callback())); |
| 6255 | // Run message loop to execute migration attempt. |
| 6256 | base::RunLoop().RunUntilIdle(); |
| 6257 | // Migration fails, and session is closed and deleted. |
| 6258 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6259 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6260 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6261 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6262 | } |
| 6263 | |
| 6264 | TEST_P(QuicStreamFactoryTest, |
| 6265 | MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 6266 | TestMigrationOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 6267 | } |
| 6268 | |
| 6269 | TEST_P(QuicStreamFactoryTest, |
| 6270 | MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 6271 | TestMigrationOnWriteErrorMigrationDisabled(ASYNC); |
| 6272 | } |
| 6273 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6274 | // Sets up a test which verifies that connection migration on write error can |
| 6275 | // eventually succeed and rewrite the packet on the new network with singals |
| 6276 | // delivered in the following order (alternate network is always availabe): |
| 6277 | // - original network encounters a SYNC/ASYNC write error based on |
| 6278 | // |write_error_mode_on_old_network|, the packet failed to be written is |
| 6279 | // cached, session migrates immediately to the alternate network. |
| 6280 | // - an immediate SYNC/ASYNC write error based on |
| 6281 | // |write_error_mode_on_new_network| is encountered after migration to the |
| 6282 | // alternate network, session migrates immediately to the original network. |
| 6283 | // - an immediate SYNC/ASYNC write error based on |
| 6284 | // |write_error_mode_on_old_network| is encountered after migration to the |
| 6285 | // original network, session migrates immediately to the alternate network. |
| 6286 | // - finally, session successfully sends the packet and reads the response on |
| 6287 | // the alternate network. |
| 6288 | // TODO(zhongyi): once https://crbug.com/855666 is fixed, this test should be |
| 6289 | // modified to test that session is closed early if hopping between networks |
| 6290 | // with consecutive write errors is detected. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6291 | void QuicStreamFactoryTestBase::TestMigrationOnMultipleWriteErrors( |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6292 | IoMode write_error_mode_on_old_network, |
| 6293 | IoMode write_error_mode_on_new_network) { |
| 6294 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6295 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6296 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6297 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6298 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6299 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6300 | // Set up the socket data used by the original network, which encounters a |
| 6301 | // write erorr. |
| 6302 | MockQuicData socket_data1; |
| 6303 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6304 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6305 | socket_data1.AddWrite( |
| 6306 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6307 | socket_data1.AddWrite(write_error_mode_on_old_network, |
| 6308 | ERR_ADDRESS_UNREACHABLE); // Write Error |
| 6309 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6310 | |
| 6311 | // Set up the socket data used by the alternate network, which also |
| 6312 | // encounters a write error. |
| 6313 | MockQuicData failed_quic_data2; |
| 6314 | failed_quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6315 | failed_quic_data2.AddWrite(write_error_mode_on_new_network, ERR_FAILED); |
| 6316 | failed_quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 6317 | |
| 6318 | // Set up the third socket data used by original network, which encounters a |
| 6319 | // write error again. |
| 6320 | MockQuicData failed_quic_data1; |
| 6321 | failed_quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6322 | failed_quic_data1.AddWrite(write_error_mode_on_old_network, ERR_FAILED); |
| 6323 | failed_quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6324 | |
| 6325 | // Set up the last socket data used by the alternate network, which will |
| 6326 | // finish migration successfully. The request is rewritten to this new socket, |
| 6327 | // and the response to the request is read on this socket. |
| 6328 | MockQuicData socket_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6329 | socket_data2.AddWrite( |
| 6330 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6331 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6332 | true, &header_stream_offset)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6333 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6334 | ASYNC, |
| 6335 | ConstructOkResponsePacket( |
| 6336 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6337 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6338 | socket_data2.AddWrite( |
| 6339 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6340 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6341 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6342 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6343 | |
| 6344 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6345 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6346 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6347 | request.Request( |
| 6348 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6349 | SocketTag(), |
| 6350 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6351 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6352 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6353 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6354 | EXPECT_TRUE(stream.get()); |
| 6355 | |
| 6356 | // Cause QUIC stream to be created. |
| 6357 | HttpRequestInfo request_info; |
| 6358 | request_info.method = "GET"; |
| 6359 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6360 | request_info.traffic_annotation = |
| 6361 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6362 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6363 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6364 | |
| 6365 | // Ensure that session is alive and active. |
| 6366 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6367 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6368 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6369 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6370 | // Send GET request on stream. |
| 6371 | // This should encounter a write error on network 1, |
| 6372 | // then migrate to network 2, which encounters another write error, |
| 6373 | // and migrate again to network 1, which encoutners one more write error. |
| 6374 | // Finally the session migrates to network 2 successfully. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6375 | HttpResponseInfo response; |
| 6376 | HttpRequestHeaders request_headers; |
| 6377 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6378 | callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6379 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6380 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6381 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6382 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6383 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6384 | // Verify that response headers on the migrated socket were delivered to the |
| 6385 | // stream. |
| 6386 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6387 | EXPECT_EQ(200, response.headers->response_code()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6388 | |
| 6389 | stream.reset(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6390 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6391 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6392 | EXPECT_TRUE(failed_quic_data2.AllReadDataConsumed()); |
| 6393 | EXPECT_TRUE(failed_quic_data2.AllWriteDataConsumed()); |
| 6394 | EXPECT_TRUE(failed_quic_data1.AllReadDataConsumed()); |
| 6395 | EXPECT_TRUE(failed_quic_data1.AllWriteDataConsumed()); |
| 6396 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 6397 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6401 | TestMigrationOnMultipleWriteErrors( |
| 6402 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6403 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6407 | TestMigrationOnMultipleWriteErrors( |
| 6408 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6409 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6413 | TestMigrationOnMultipleWriteErrors( |
| 6414 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6415 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6416 | } |
| 6417 | |
| 6418 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6419 | TestMigrationOnMultipleWriteErrors( |
| 6420 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6421 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6422 | } |
| 6423 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6424 | // Verifies that a connection is closed when connection migration is triggered |
| 6425 | // on network being disconnected and the handshake is not confirmed. |
| 6426 | TEST_P(QuicStreamFactoryTest, NoMigrationBeforeHandshakeOnNetworkDisconnected) { |
| 6427 | InitializeConnectionMigrationV2Test( |
| 6428 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6429 | |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6430 | // 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] | 6431 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6432 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6433 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6434 | MockQuicData socket_data; |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6435 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5068bb0 | 2018-08-03 02:44:09 | [diff] [blame] | 6436 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6437 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6438 | |
| 6439 | // Create request and QuicHttpStream. |
| 6440 | QuicStreamRequest request(factory_.get()); |
| 6441 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6442 | request.Request( |
| 6443 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6444 | SocketTag(), |
| 6445 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6446 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6447 | // Deliver the network notification, which should cause the connection to be |
| 6448 | // closed. |
| 6449 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6450 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6451 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6452 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6453 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6454 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6455 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6456 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6457 | } |
| 6458 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6459 | // Sets up the connection migration test where network change notification is |
| 6460 | // queued BEFORE connection migration attempt on write error is posted. |
| 6461 | void QuicStreamFactoryTestBase:: |
| 6462 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6463 | bool disconnected) { |
| 6464 | InitializeConnectionMigrationV2Test( |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6465 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6466 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6467 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6468 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6469 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6470 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6471 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6472 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6473 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6474 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6475 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6476 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6477 | |
| 6478 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6479 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6480 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6481 | request.Request( |
| 6482 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6483 | SocketTag(), |
| 6484 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6485 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6486 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6487 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6488 | EXPECT_TRUE(stream.get()); |
| 6489 | |
| 6490 | // Cause QUIC stream to be created. |
| 6491 | HttpRequestInfo request_info; |
| 6492 | request_info.method = "GET"; |
| 6493 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6494 | request_info.traffic_annotation = |
| 6495 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6496 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6497 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6498 | |
| 6499 | // Ensure that session is alive and active. |
| 6500 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6501 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6502 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6503 | |
| 6504 | // Set up second socket data provider that is used after |
| 6505 | // migration. The request is rewritten to this new socket, and the |
| 6506 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6507 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6508 | socket_data1.AddWrite( |
| 6509 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6510 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6511 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6512 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6513 | ASYNC, |
| 6514 | ConstructOkResponsePacket( |
| 6515 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6516 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6517 | socket_data1.AddWrite( |
| 6518 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6519 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6520 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6521 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6522 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6523 | // First queue a network change notification in the message loop. |
| 6524 | if (disconnected) { |
| 6525 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6526 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6527 | } else { |
| 6528 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6529 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6530 | } |
| 6531 | // Send GET request on stream. This should cause a write error, |
| 6532 | // which triggers a connection migration attempt. This will queue a |
| 6533 | // migration attempt behind the notification in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6534 | HttpResponseInfo response; |
| 6535 | HttpRequestHeaders request_headers; |
| 6536 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6537 | callback_.callback())); |
| 6538 | |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6539 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6540 | // Verify the session is still alive and not marked as going away post |
| 6541 | // migration. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6542 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6543 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6544 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6545 | |
| 6546 | // Verify that response headers on the migrated socket were delivered to the |
| 6547 | // stream. |
| 6548 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6549 | EXPECT_EQ(200, response.headers->response_code()); |
| 6550 | |
| 6551 | stream.reset(); |
| 6552 | |
| 6553 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6554 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6555 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6556 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6557 | } |
| 6558 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6559 | // This test verifies that session attempts connection migration successfully |
| 6560 | // with signals delivered in the following order (alternate network is always |
| 6561 | // available): |
| 6562 | // - a notification that default network is disconnected is queued. |
| 6563 | // - write error is triggered: session posts a task to attempt connection |
| 6564 | // migration, |migration_pending_| set to true. |
| 6565 | // - default network disconnected is delivered: session immediately migrates to |
| 6566 | // the alternate network, |migration_pending_| set to false. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6567 | // - connection migration on write error attempt aborts: writer encountered |
| 6568 | // error is no longer in active use. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6569 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6570 | MigrateOnNetworkDisconnectedWithWriteErrorQueuedLater) { |
| 6571 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6572 | /*disconnected=*/true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6573 | } |
| 6574 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6575 | // This test verifies that session attempts connection migration successfully |
| 6576 | // with signals delivered in the following order (alternate network is always |
| 6577 | // available): |
| 6578 | // - a notification that alternate network is made default is queued. |
| 6579 | // - write error is triggered: session posts a task to attempt connection |
| 6580 | // migration, block future migrations. |
| 6581 | // - new default notification is delivered: migrate back timer spins and task is |
| 6582 | // posted to migrate to the new default network. |
| 6583 | // - connection migration on write error attempt proceeds successfully: session |
| 6584 | // is |
| 6585 | // marked as going away, future migrations unblocked. |
| 6586 | // - migrate back to default network task executed: session is already on the |
| 6587 | // default network, no-op. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6588 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6589 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedEarlier) { |
| 6590 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6591 | /*disconnected=*/false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6592 | } |
| 6593 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6594 | // Sets up the connection migration test where network change notification is |
| 6595 | // queued AFTER connection migration attempt on write error is posted. |
| 6596 | void QuicStreamFactoryTestBase:: |
| 6597 | TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6598 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6599 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6600 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6601 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6602 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6603 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6604 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6605 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6606 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6607 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6608 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6609 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6610 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6611 | |
| 6612 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6613 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6614 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6615 | request.Request( |
| 6616 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6617 | SocketTag(), |
| 6618 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6619 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6620 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6621 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6622 | EXPECT_TRUE(stream.get()); |
| 6623 | |
| 6624 | // Cause QUIC stream to be created. |
| 6625 | HttpRequestInfo request_info; |
| 6626 | request_info.method = "GET"; |
| 6627 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6628 | request_info.traffic_annotation = |
| 6629 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6630 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6631 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6632 | |
| 6633 | // Ensure that session is alive and active. |
| 6634 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6635 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6636 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6637 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6638 | // Set up second socket data provider that is used after |
| 6639 | // migration. The request is rewritten to this new socket, and the |
| 6640 | // response to the request is read on this new socket. |
| 6641 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6642 | socket_data1.AddWrite( |
| 6643 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6644 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6645 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6646 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6647 | ASYNC, |
| 6648 | ConstructOkResponsePacket( |
| 6649 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6650 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6651 | socket_data1.AddWrite( |
| 6652 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6653 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6654 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6655 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6656 | |
| 6657 | // Send GET request on stream. This should cause a write error, |
| 6658 | // which triggers a connection migration attempt. This will queue a |
| 6659 | // migration attempt in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6660 | HttpResponseInfo response; |
| 6661 | HttpRequestHeaders request_headers; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6662 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6663 | callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6664 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6665 | // Now queue a network change notification in the message loop behind |
| 6666 | // the migration attempt. |
| 6667 | if (disconnected) { |
| 6668 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6669 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6670 | } else { |
| 6671 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6672 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6673 | } |
| 6674 | |
| 6675 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6676 | // Verify session is still alive and not marked as going away. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6677 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6678 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6679 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6680 | |
| 6681 | // Verify that response headers on the migrated socket were delivered to the |
| 6682 | // stream. |
| 6683 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6684 | EXPECT_EQ(200, response.headers->response_code()); |
| 6685 | |
| 6686 | stream.reset(); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6687 | |
| 6688 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6689 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6690 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6691 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6692 | } |
| 6693 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6694 | // This test verifies that session attempts connection migration successfully |
| 6695 | // with signals delivered in the following order (alternate network is always |
| 6696 | // available): |
| 6697 | // - write error is triggered: session posts a task to complete connection |
| 6698 | // migration. |
| 6699 | // - a notification that alternate network is made default is queued. |
| 6700 | // - connection migration attempt proceeds successfully, session is marked as |
| 6701 | // going away. |
| 6702 | // - new default notification is delivered after connection migration has been |
| 6703 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6704 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6705 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedLater) { |
| 6706 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/false); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6707 | } |
| 6708 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6709 | // This test verifies that session attempts connection migration successfully |
| 6710 | // with signals delivered in the following order (alternate network is always |
| 6711 | // available): |
| 6712 | // - write error is triggered: session posts a task to complete connection |
| 6713 | // migration. |
| 6714 | // - a notification that default network is diconnected is queued. |
| 6715 | // - connection migration attempt proceeds successfully, session is marked as |
| 6716 | // going away. |
| 6717 | // - disconnect notification is delivered after connection migration has been |
| 6718 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6719 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6720 | MigrateOnWriteErrorWithNetworkDisconnectedQueuedLater) { |
| 6721 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/true); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6722 | } |
| 6723 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6724 | // This tests connection migration on write error with signals delivered in the |
| 6725 | // following order: |
| 6726 | // - a synchronous/asynchronous write error is triggered base on |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6727 | // |write_error_mode|: connection migration attempt is posted. |
| 6728 | // - old default network disconnects, migration waits for a new network. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6729 | // - after a pause, new network is connected: session will migrate to new |
| 6730 | // network immediately. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6731 | // - migration on writer error is exectued and aborts as writer passed in is no |
| 6732 | // longer active in use. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6733 | // - new network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6734 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorPauseBeforeConnected( |
| 6735 | IoMode write_error_mode) { |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6736 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6737 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6738 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6739 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6740 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6741 | // Use the test task runner. |
| 6742 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 6743 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6744 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6745 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6746 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6747 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6748 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6749 | socket_data.AddWrite(write_error_mode, ERR_FAILED); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6750 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6751 | |
| 6752 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6753 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6754 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6755 | request.Request( |
| 6756 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6757 | SocketTag(), |
| 6758 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6759 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6760 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6761 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6762 | EXPECT_TRUE(stream.get()); |
| 6763 | |
| 6764 | // Cause QUIC stream to be created. |
| 6765 | HttpRequestInfo request_info; |
| 6766 | request_info.method = "GET"; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6767 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6768 | request_info.traffic_annotation = |
| 6769 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6770 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6771 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6772 | |
| 6773 | // Ensure that session is alive and active. |
| 6774 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6775 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6776 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6777 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6778 | // Send GET request on stream. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6779 | HttpResponseInfo response; |
| 6780 | HttpRequestHeaders request_headers; |
| 6781 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6782 | callback_.callback())); |
| 6783 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6784 | // The connection should still be alive, not marked as going away. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6785 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6786 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6787 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6788 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6789 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6790 | // Set up second socket data provider that is used after migration. |
| 6791 | // The response to the earlier request is read on this new socket. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6792 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6793 | socket_data1.AddWrite( |
| 6794 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6795 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6796 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6797 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6798 | ASYNC, |
| 6799 | ConstructOkResponsePacket( |
| 6800 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6801 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6802 | socket_data1.AddWrite( |
| 6803 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6804 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6805 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6806 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6807 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6808 | // On a DISCONNECTED notification, nothing happens. |
| 6809 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6810 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6811 | // Add a new network and notify the stream factory of a new connected network. |
| 6812 | // This causes a PING packet to be sent over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6813 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6814 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 6815 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6816 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 6817 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6818 | // Ensure that the session is still alive. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6819 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6820 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6821 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6822 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6823 | // Run the message loop migration for write error can finish. |
| 6824 | runner_->RunUntilIdle(); |
| 6825 | |
| 6826 | // Response headers are received over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6827 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6828 | EXPECT_EQ(200, response.headers->response_code()); |
| 6829 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6830 | // Check that the session is still alive. |
| 6831 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6832 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6833 | |
| 6834 | // There should be no posted tasks not executed, no way to migrate back to |
| 6835 | // default network. |
| 6836 | EXPECT_TRUE(runner_->GetPostedTasks().empty()); |
| 6837 | |
| 6838 | // Receive signal to mark new network as default. |
| 6839 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6840 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6841 | |
| 6842 | stream.reset(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6843 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6844 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6845 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6846 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6847 | } |
| 6848 | |
| 6849 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6850 | MigrateSessionOnSyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6851 | TestMigrationOnWriteErrorPauseBeforeConnected(SYNCHRONOUS); |
| 6852 | } |
| 6853 | |
| 6854 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6855 | MigrateSessionOnAsyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6856 | TestMigrationOnWriteErrorPauseBeforeConnected(ASYNC); |
| 6857 | } |
| 6858 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6859 | // This test verifies that when session successfully migrate to the alternate |
| 6860 | // network, packet write error on the old writer will be ignored and will not |
| 6861 | // trigger connection migration on write error. |
| 6862 | TEST_P(QuicStreamFactoryTest, IgnoreWriteErrorFromOldWriterAfterMigration) { |
| 6863 | InitializeConnectionMigrationV2Test( |
| 6864 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6865 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6866 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6867 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6868 | |
| 6869 | // Using a testing task runner so that we can verify whether the migrate on |
| 6870 | // write error task is posted. |
| 6871 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6872 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6873 | |
| 6874 | MockQuicData socket_data; |
| 6875 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6876 | socket_data.AddWrite( |
| 6877 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6878 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6879 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6880 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6881 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6882 | |
| 6883 | // Create request and QuicHttpStream. |
| 6884 | QuicStreamRequest request(factory_.get()); |
| 6885 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6886 | request.Request( |
| 6887 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6888 | SocketTag(), |
| 6889 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6890 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6891 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6892 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6893 | EXPECT_TRUE(stream.get()); |
| 6894 | |
| 6895 | // Cause QUIC stream to be created. |
| 6896 | HttpRequestInfo request_info; |
| 6897 | request_info.method = "GET"; |
| 6898 | request_info.url = GURL("https://www.example.org/"); |
| 6899 | request_info.traffic_annotation = |
| 6900 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6901 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6902 | net_log_, CompletionOnceCallback())); |
| 6903 | |
| 6904 | // Ensure that session is alive and active. |
| 6905 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6906 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6907 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6908 | |
| 6909 | // Set up second socket data provider that is used after |
| 6910 | // migration. The response to the request is read on this new socket. |
| 6911 | MockQuicData socket_data1; |
| 6912 | socket_data1.AddWrite( |
| 6913 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 6914 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6915 | ASYNC, |
| 6916 | ConstructOkResponsePacket( |
| 6917 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6918 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6919 | socket_data1.AddWrite( |
| 6920 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6921 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6922 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6923 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6924 | |
| 6925 | // Send GET request on stream. |
| 6926 | HttpResponseInfo response; |
| 6927 | HttpRequestHeaders request_headers; |
| 6928 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6929 | callback_.callback())); |
| 6930 | |
| 6931 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6932 | // Now notify network is disconnected, cause the migration to complete |
| 6933 | // immediately. |
| 6934 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6935 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6936 | // There will be two pending task, one will complete migration with no delay |
| 6937 | // and the other will attempt to migrate back to the default network with |
| 6938 | // delay. |
| 6939 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6940 | |
| 6941 | // Complete migration. |
| 6942 | task_runner->RunUntilIdle(); |
| 6943 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6944 | |
| 6945 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6946 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6947 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6948 | |
| 6949 | // Verify that response headers on the migrated socket were delivered to the |
| 6950 | // stream. |
| 6951 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6952 | EXPECT_EQ(200, response.headers->response_code()); |
| 6953 | |
| 6954 | // Resume the old socket data, a write error will be delivered to the old |
| 6955 | // packet writer. Verify no additional task is posted. |
| 6956 | socket_data.Resume(); |
| 6957 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6958 | |
| 6959 | stream.reset(); |
| 6960 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6961 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6962 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6963 | } |
| 6964 | |
| 6965 | // This test verifies that when session successfully migrate to the alternate |
| 6966 | // network, packet read error on the old reader will be ignored and will not |
| 6967 | // close the connection. |
| 6968 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorFromOldReaderAfterMigration) { |
| 6969 | InitializeConnectionMigrationV2Test( |
| 6970 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6971 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6972 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6973 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6974 | |
| 6975 | // Using a testing task runner. |
| 6976 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6977 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6978 | |
| 6979 | MockQuicData socket_data; |
| 6980 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6981 | socket_data.AddWrite( |
| 6982 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6983 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6984 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6985 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6986 | |
| 6987 | // Create request and QuicHttpStream. |
| 6988 | QuicStreamRequest request(factory_.get()); |
| 6989 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6990 | request.Request( |
| 6991 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6992 | SocketTag(), |
| 6993 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6994 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6995 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6996 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6997 | EXPECT_TRUE(stream.get()); |
| 6998 | |
| 6999 | // Cause QUIC stream to be created. |
| 7000 | HttpRequestInfo request_info; |
| 7001 | request_info.method = "GET"; |
| 7002 | request_info.url = GURL("https://www.example.org/"); |
| 7003 | request_info.traffic_annotation = |
| 7004 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7005 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 7006 | net_log_, CompletionOnceCallback())); |
| 7007 | |
| 7008 | // Ensure that session is alive and active. |
| 7009 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7010 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7011 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7012 | |
| 7013 | // Set up second socket data provider that is used after |
| 7014 | // migration. The request is written to this new socket, and the |
| 7015 | // response to the request is read on this new socket. |
| 7016 | MockQuicData socket_data1; |
| 7017 | socket_data1.AddWrite( |
| 7018 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7019 | socket_data1.AddWrite( |
| 7020 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7021 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7022 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7023 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7024 | ASYNC, |
| 7025 | ConstructOkResponsePacket( |
| 7026 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7027 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7028 | socket_data1.AddWrite( |
| 7029 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7030 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7031 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7032 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7033 | |
| 7034 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7035 | // Now notify network is disconnected, cause the migration to complete |
| 7036 | // immediately. |
| 7037 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7038 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 7039 | // There will be two pending task, one will complete migration with no delay |
| 7040 | // and the other will attempt to migrate back to the default network with |
| 7041 | // delay. |
| 7042 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7043 | |
| 7044 | // Complete migration. |
| 7045 | task_runner->RunUntilIdle(); |
| 7046 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7047 | |
| 7048 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7049 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7050 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7051 | |
| 7052 | // Send GET request on stream. |
| 7053 | HttpResponseInfo response; |
| 7054 | HttpRequestHeaders request_headers; |
| 7055 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7056 | callback_.callback())); |
| 7057 | |
| 7058 | // Verify that response headers on the migrated socket were delivered to the |
| 7059 | // stream. |
| 7060 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7061 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7062 | EXPECT_EQ(200, response.headers->response_code()); |
| 7063 | |
| 7064 | // Resume the old socket data, a read error will be delivered to the old |
| 7065 | // packet reader. Verify that the session is not affected. |
| 7066 | socket_data.Resume(); |
| 7067 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7068 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7069 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7070 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7071 | |
| 7072 | stream.reset(); |
| 7073 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7074 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7075 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7076 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7077 | } |
| 7078 | |
| 7079 | // This test verifies that after migration on network is executed, packet |
| 7080 | // read error on the old reader will be ignored and will not close the |
| 7081 | // connection. |
| 7082 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorOnOldReaderDuringMigration) { |
| 7083 | InitializeConnectionMigrationV2Test( |
| 7084 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 7085 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7086 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7087 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7088 | |
| 7089 | // Using a testing task runner. |
| 7090 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7091 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7092 | |
| 7093 | MockQuicData socket_data; |
| 7094 | quic::QuicStreamOffset header_stream_offset = 0; |
| 7095 | socket_data.AddWrite( |
| 7096 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 7097 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 7098 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 7099 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7100 | |
| 7101 | // Create request and QuicHttpStream. |
| 7102 | QuicStreamRequest request(factory_.get()); |
| 7103 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7104 | request.Request( |
| 7105 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7106 | SocketTag(), |
| 7107 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7108 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7109 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7110 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7111 | EXPECT_TRUE(stream.get()); |
| 7112 | |
| 7113 | // Cause QUIC stream to be created. |
| 7114 | HttpRequestInfo request_info; |
| 7115 | request_info.method = "GET"; |
| 7116 | request_info.url = GURL("https://www.example.org/"); |
| 7117 | request_info.traffic_annotation = |
| 7118 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7119 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 7120 | net_log_, CompletionOnceCallback())); |
| 7121 | |
| 7122 | // Ensure that session is alive and active. |
| 7123 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7124 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7125 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7126 | |
| 7127 | // Set up second socket data provider that is used after |
| 7128 | // migration. The request is written to this new socket, and the |
| 7129 | // response to the request is read on this new socket. |
| 7130 | MockQuicData socket_data1; |
| 7131 | socket_data1.AddWrite( |
| 7132 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7133 | socket_data1.AddWrite( |
| 7134 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7135 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7136 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7137 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7138 | ASYNC, |
| 7139 | ConstructOkResponsePacket( |
| 7140 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7141 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7142 | socket_data1.AddWrite( |
| 7143 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7144 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7145 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7146 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7147 | |
| 7148 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7149 | // Now notify network is disconnected, cause the migration to complete |
| 7150 | // immediately. |
| 7151 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7152 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 7153 | // There will be two pending task, one will complete migration with no delay |
| 7154 | // and the other will attempt to migrate back to the default network with |
| 7155 | // delay. |
| 7156 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7157 | |
| 7158 | // Resume the old socket data, a read error will be delivered to the old |
| 7159 | // packet reader. Verify that the session is not affected. |
| 7160 | socket_data.Resume(); |
| 7161 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7162 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7163 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7164 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7165 | |
| 7166 | // Complete migration. |
| 7167 | task_runner->RunUntilIdle(); |
| 7168 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7169 | |
| 7170 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7171 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7172 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7173 | |
| 7174 | // Send GET request on stream. |
| 7175 | HttpResponseInfo response; |
| 7176 | HttpRequestHeaders request_headers; |
| 7177 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7178 | callback_.callback())); |
| 7179 | |
| 7180 | // Verify that response headers on the migrated socket were delivered to the |
| 7181 | // stream. |
| 7182 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7183 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7184 | EXPECT_EQ(200, response.headers->response_code()); |
| 7185 | |
| 7186 | stream.reset(); |
| 7187 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7188 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7189 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7190 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7191 | } |
| 7192 | |
| 7193 | // This test verifies that after migration on write error is posted, packet |
| 7194 | // read error on the old reader will be ignored and will not close the |
| 7195 | // connection. |
| 7196 | TEST_P(QuicStreamFactoryTest, |
| 7197 | IgnoreReadErrorOnOldReaderDuringPendingMigrationOnWriteError) { |
| 7198 | InitializeConnectionMigrationV2Test( |
| 7199 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 7200 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7201 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7202 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7203 | |
| 7204 | // Using a testing task runner. |
| 7205 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7206 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7207 | |
| 7208 | MockQuicData socket_data; |
| 7209 | quic::QuicStreamOffset header_stream_offset = 0; |
| 7210 | socket_data.AddWrite( |
| 7211 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 7212 | socket_data.AddWrite(ASYNC, ERR_FAILED); // Write error. |
| 7213 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); // Read error. |
| 7214 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7215 | |
| 7216 | // Create request and QuicHttpStream. |
| 7217 | QuicStreamRequest request(factory_.get()); |
| 7218 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7219 | request.Request( |
| 7220 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7221 | SocketTag(), |
| 7222 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7223 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7224 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7225 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7226 | EXPECT_TRUE(stream.get()); |
| 7227 | |
| 7228 | // Cause QUIC stream to be created. |
| 7229 | HttpRequestInfo request_info; |
| 7230 | request_info.method = "GET"; |
| 7231 | request_info.url = GURL("https://www.example.org/"); |
| 7232 | request_info.traffic_annotation = |
| 7233 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7234 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 7235 | net_log_, CompletionOnceCallback())); |
| 7236 | |
| 7237 | // Ensure that session is alive and active. |
| 7238 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7239 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7240 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7241 | |
| 7242 | // Set up second socket data provider that is used after |
| 7243 | // migration. The request is written to this new socket, and the |
| 7244 | // response to the request is read on this new socket. |
| 7245 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7246 | socket_data1.AddWrite( |
| 7247 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7248 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7249 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7250 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7251 | ASYNC, |
| 7252 | ConstructOkResponsePacket( |
| 7253 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7254 | |
| 7255 | socket_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 7256 | socket_data1.AddRead(ASYNC, ERR_FAILED); // Read error to close connection. |
| 7257 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7258 | |
| 7259 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7260 | // Send GET request on stream. |
| 7261 | HttpResponseInfo response; |
| 7262 | HttpRequestHeaders request_headers; |
| 7263 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7264 | callback_.callback())); |
| 7265 | // Run the message loop to complete asynchronous write and read with errors. |
| 7266 | base::RunLoop().RunUntilIdle(); |
| 7267 | // There will be one pending task to complete migration on write error. |
| 7268 | // Verify session is not closed with read error. |
| 7269 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7270 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7271 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7272 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7273 | |
| 7274 | // Complete migration. |
| 7275 | task_runner->RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7276 | // There will be one more task posted attempting to migrate back to the |
| 7277 | // default network. |
| 7278 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7279 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7280 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7281 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7282 | |
| 7283 | // Verify that response headers on the migrated socket were delivered to the |
| 7284 | // stream. |
| 7285 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7286 | EXPECT_EQ(200, response.headers->response_code()); |
| 7287 | |
| 7288 | // Resume to consume the read error on new socket, which will close |
| 7289 | // the connection. |
| 7290 | socket_data1.Resume(); |
| 7291 | |
| 7292 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7293 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7294 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7295 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7296 | } |
| 7297 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7298 | // Migrate on asynchronous write error, old network disconnects after alternate |
| 7299 | // network connects. |
| 7300 | TEST_P(QuicStreamFactoryTest, |
| 7301 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectAysnc) { |
| 7302 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7303 | ASYNC, /*disconnect_before_connect*/ false); |
| 7304 | } |
| 7305 | |
| 7306 | // Migrate on synchronous write error, old network disconnects after alternate |
| 7307 | // network connects. |
| 7308 | TEST_P(QuicStreamFactoryTest, |
| 7309 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectSync) { |
| 7310 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7311 | SYNCHRONOUS, /*disconnect_before_connect*/ false); |
| 7312 | } |
| 7313 | |
| 7314 | // Migrate on asynchronous write error, old network disconnects before alternate |
| 7315 | // network connects. |
| 7316 | TEST_P(QuicStreamFactoryTest, |
| 7317 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectAysnc) { |
| 7318 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7319 | ASYNC, /*disconnect_before_connect*/ true); |
| 7320 | } |
| 7321 | |
| 7322 | // Migrate on synchronous write error, old network disconnects before alternate |
| 7323 | // network connects. |
| 7324 | TEST_P(QuicStreamFactoryTest, |
| 7325 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectSync) { |
| 7326 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7327 | SYNCHRONOUS, /*disconnect_before_connect*/ true); |
| 7328 | } |
| 7329 | |
| 7330 | // Setps up test which verifies that session successfully migrate to alternate |
| 7331 | // network with signals delivered in the following order: |
| 7332 | // *NOTE* Signal (A) and (B) can reverse order based on |
| 7333 | // |disconnect_before_connect|. |
| 7334 | // - (No alternate network is connected) session connects to |
| 7335 | // kDefaultNetworkForTests. |
| 7336 | // - An async/sync write error is encountered based on |write_error_mode|: |
| 7337 | // session posted task to migrate session on write error. |
| 7338 | // - Posted task is executed, miration moves to pending state due to lack of |
| 7339 | // alternate network. |
| 7340 | // - (A) An alternate network is connected, pending migration completes. |
| 7341 | // - (B) Old default network disconnects, no migration will be attempted as |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7342 | // session has already migrate to the alternate network. |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7343 | // - The alternate network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7344 | void QuicStreamFactoryTestBase:: |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7345 | TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7346 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7347 | bool disconnect_before_connect) { |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7348 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7349 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7350 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7351 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7352 | |
| 7353 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7354 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7355 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7356 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7357 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7358 | socket_data.AddWrite(write_error_mode, ERR_FAILED); // Write error. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7359 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7360 | |
| 7361 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7362 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7363 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7364 | request.Request( |
| 7365 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7366 | SocketTag(), |
| 7367 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7368 | failed_on_default_network_callback_, callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7369 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7370 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7371 | EXPECT_TRUE(stream.get()); |
| 7372 | |
| 7373 | // Cause QUIC stream to be created. |
| 7374 | HttpRequestInfo request_info; |
| 7375 | request_info.method = "GET"; |
| 7376 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7377 | request_info.traffic_annotation = |
| 7378 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7379 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7380 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7381 | |
| 7382 | // Ensure that session is alive and active. |
| 7383 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7384 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7385 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7386 | |
| 7387 | // Send GET request on stream. This should cause a write error, which triggers |
| 7388 | // a connection migration attempt. |
| 7389 | HttpResponseInfo response; |
| 7390 | HttpRequestHeaders request_headers; |
| 7391 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7392 | callback_.callback())); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7393 | // Run the message loop so that posted task to migrate to socket will be |
| 7394 | // executed. A new task will be posted to wait for a new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7395 | base::RunLoop().RunUntilIdle(); |
| 7396 | |
| 7397 | // In this particular code path, the network will not yet be marked |
| 7398 | // as going away and the session will still be alive. |
| 7399 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7400 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7401 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7402 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7403 | |
| 7404 | // Set up second socket data provider that is used after |
| 7405 | // migration. The request is rewritten to this new socket, and the |
| 7406 | // response to the request is read on this new socket. |
| 7407 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7408 | socket_data1.AddWrite( |
| 7409 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7410 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7411 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7412 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7413 | ASYNC, |
| 7414 | ConstructOkResponsePacket( |
| 7415 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7416 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7417 | socket_data1.AddWrite( |
| 7418 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7419 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7420 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7421 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7422 | |
| 7423 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7424 | ->SetConnectedNetworksList( |
| 7425 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7426 | if (disconnect_before_connect) { |
| 7427 | // Now deliver a DISCONNECT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7428 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7429 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7430 | |
| 7431 | // Now deliver a CONNECTED notification and completes migration. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7432 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7433 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7434 | } else { |
| 7435 | // Now deliver a CONNECTED notification and completes migration. |
| 7436 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7437 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7438 | |
| 7439 | // Now deliver a DISCONNECT notification. |
| 7440 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7441 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7442 | } |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7443 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7444 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7445 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7446 | |
| 7447 | // This is the callback for the response headers that returned |
| 7448 | // pending previously, because no result was available. Check that |
| 7449 | // the result is now available due to the successful migration. |
| 7450 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7451 | EXPECT_EQ(200, response.headers->response_code()); |
| 7452 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7453 | // Deliver a MADEDEFAULT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7454 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7455 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7456 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7457 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7458 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 7459 | DEFAULT_PRIORITY, SocketTag(), |
| 7460 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7461 | &net_error_details_, |
| 7462 | failed_on_default_network_callback_, |
| 7463 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7464 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7465 | EXPECT_TRUE(stream2.get()); |
| 7466 | |
| 7467 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7468 | EXPECT_EQ(session, GetActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7469 | |
| 7470 | stream.reset(); |
| 7471 | stream2.reset(); |
| 7472 | |
| 7473 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7474 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7475 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7476 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7477 | } |
| 7478 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 7479 | // This test verifies after session migrates off the default network, it keeps |
| 7480 | // retrying migrate back to the default network until successfully gets on the |
| 7481 | // default network or the idle migration period threshold is exceeded. |
| 7482 | // The default threshold is 30s. |
| 7483 | TEST_P(QuicStreamFactoryTest, DefaultIdleMigrationPeriod) { |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 7484 | test_params_.quic_migrate_idle_sessions = true; |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 7485 | InitializeConnectionMigrationV2Test( |
| 7486 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 7487 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7488 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7489 | |
| 7490 | // Using a testing task runner and a test tick tock. |
| 7491 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7492 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7493 | QuicStreamFactoryPeer::SetTickClock(factory_.get(), |
| 7494 | task_runner->GetMockTickClock()); |
| 7495 | |
| 7496 | MockQuicData default_socket_data; |
| 7497 | default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 7498 | default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7499 | default_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7500 | |
| 7501 | // Set up second socket data provider that is used after migration. |
| 7502 | MockQuicData alternate_socket_data; |
| 7503 | alternate_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7504 | // Ping packet to send after migration. |
| 7505 | alternate_socket_data.AddWrite( |
| 7506 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 7507 | alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7508 | |
| 7509 | // Set up probing socket for migrating back to the default network. |
| 7510 | MockQuicData quic_data; // retry count: 0. |
| 7511 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7512 | quic_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7513 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7514 | |
| 7515 | MockQuicData quic_data1; // retry count: 1 |
| 7516 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7517 | quic_data1.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7518 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7519 | |
| 7520 | MockQuicData quic_data2; // retry count: 2 |
| 7521 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7522 | quic_data2.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7523 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 7524 | |
| 7525 | MockQuicData quic_data3; // retry count: 3 |
| 7526 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7527 | quic_data3.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7528 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 7529 | |
| 7530 | MockQuicData quic_data4; // retry count: 4 |
| 7531 | quic_data4.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7532 | quic_data4.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7533 | quic_data4.AddSocketDataToFactory(socket_factory_.get()); |
| 7534 | |
| 7535 | MockQuicData quic_data5; // retry count: 5 |
| 7536 | quic_data5.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7537 | quic_data5.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7538 | quic_data5.AddSocketDataToFactory(socket_factory_.get()); |
| 7539 | |
| 7540 | // Create request and QuicHttpStream. |
| 7541 | QuicStreamRequest request(factory_.get()); |
| 7542 | EXPECT_EQ(ERR_IO_PENDING, |
| 7543 | request.Request( |
| 7544 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7545 | SocketTag(), |
| 7546 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7547 | failed_on_default_network_callback_, callback_.callback())); |
| 7548 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7549 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7550 | EXPECT_TRUE(stream.get()); |
| 7551 | |
| 7552 | // Ensure that session is active. |
| 7553 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7554 | |
| 7555 | // Trigger connection migration. Since there are no active streams, |
| 7556 | // the session will be closed. |
| 7557 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7558 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 7559 | |
| 7560 | // The nearest task will complete migration. |
| 7561 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7562 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7563 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7564 | |
| 7565 | // The migrate back timer will fire. Due to default network |
| 7566 | // being disconnected, no attempt will be exercised to migrate back. |
| 7567 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7568 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 7569 | task_runner->NextPendingTaskDelay()); |
| 7570 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7571 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7572 | |
| 7573 | // Deliver the signal that the old default network now backs up. |
| 7574 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7575 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 7576 | |
| 7577 | // A task is posted to migrate back to the default network immediately. |
| 7578 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7579 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7580 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7581 | |
| 7582 | // Retry migrate back in 1, 2, 4, 8, 16s. |
| 7583 | // Session will be closed due to idle migration timeout. |
| 7584 | for (int i = 0; i < 5; i++) { |
| 7585 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7586 | // A task is posted to migrate back to the default network in 2^i seconds. |
| 7587 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7588 | EXPECT_EQ(base::TimeDelta::FromSeconds(UINT64_C(1) << i), |
| 7589 | task_runner->NextPendingTaskDelay()); |
| 7590 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7591 | } |
| 7592 | |
| 7593 | EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); |
| 7594 | EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); |
| 7595 | EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); |
| 7596 | EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); |
| 7597 | } |
| 7598 | |
| 7599 | TEST_P(QuicStreamFactoryTest, CustomIdleMigrationPeriod) { |
| 7600 | // The customized threshold is 15s. |
Zhongyi Shi | 32fe14d4 | 2019-02-28 00:25:36 | [diff] [blame^] | 7601 | test_params_.quic_migrate_idle_sessions = true; |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 7602 | test_params_.quic_idle_session_migration_period = |
| 7603 | base::TimeDelta::FromSeconds(15); |
| 7604 | InitializeConnectionMigrationV2Test( |
| 7605 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 7606 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7607 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7608 | |
| 7609 | // Using a testing task runner and a test tick tock. |
| 7610 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7611 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7612 | QuicStreamFactoryPeer::SetTickClock(factory_.get(), |
| 7613 | task_runner->GetMockTickClock()); |
| 7614 | |
| 7615 | MockQuicData default_socket_data; |
| 7616 | default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 7617 | default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7618 | default_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7619 | |
| 7620 | // Set up second socket data provider that is used after migration. |
| 7621 | MockQuicData alternate_socket_data; |
| 7622 | alternate_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7623 | // Ping packet to send after migration. |
| 7624 | alternate_socket_data.AddWrite( |
| 7625 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 7626 | alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7627 | |
| 7628 | // Set up probing socket for migrating back to the default network. |
| 7629 | MockQuicData quic_data; // retry count: 0. |
| 7630 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7631 | quic_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7632 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7633 | |
| 7634 | MockQuicData quic_data1; // retry count: 1 |
| 7635 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7636 | quic_data1.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7637 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7638 | |
| 7639 | MockQuicData quic_data2; // retry count: 2 |
| 7640 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7641 | quic_data2.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7642 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 7643 | |
| 7644 | MockQuicData quic_data3; // retry count: 3 |
| 7645 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7646 | quic_data3.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7647 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 7648 | |
| 7649 | MockQuicData quic_data4; // retry count: 4 |
| 7650 | quic_data4.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7651 | quic_data4.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7652 | quic_data4.AddSocketDataToFactory(socket_factory_.get()); |
| 7653 | |
| 7654 | // Create request and QuicHttpStream. |
| 7655 | QuicStreamRequest request(factory_.get()); |
| 7656 | EXPECT_EQ(ERR_IO_PENDING, |
| 7657 | request.Request( |
| 7658 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7659 | SocketTag(), |
| 7660 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7661 | failed_on_default_network_callback_, callback_.callback())); |
| 7662 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7663 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7664 | EXPECT_TRUE(stream.get()); |
| 7665 | |
| 7666 | // Ensure that session is active. |
| 7667 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7668 | |
| 7669 | // Trigger connection migration. Since there are no active streams, |
| 7670 | // the session will be closed. |
| 7671 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7672 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 7673 | |
| 7674 | // The nearest task will complete migration. |
| 7675 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7676 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7677 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7678 | |
| 7679 | // The migrate back timer will fire. Due to default network |
| 7680 | // being disconnected, no attempt will be exercised to migrate back. |
| 7681 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7682 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 7683 | task_runner->NextPendingTaskDelay()); |
| 7684 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7685 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7686 | |
| 7687 | // Deliver the signal that the old default network now backs up. |
| 7688 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7689 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 7690 | |
| 7691 | // A task is posted to migrate back to the default network immediately. |
| 7692 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7693 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7694 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7695 | |
| 7696 | // Retry migrate back in 1, 2, 4, 8s. |
| 7697 | // Session will be closed due to idle migration timeout. |
| 7698 | for (int i = 0; i < 4; i++) { |
| 7699 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7700 | // A task is posted to migrate back to the default network in 2^i seconds. |
| 7701 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7702 | EXPECT_EQ(base::TimeDelta::FromSeconds(UINT64_C(1) << i), |
| 7703 | task_runner->NextPendingTaskDelay()); |
| 7704 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7705 | } |
| 7706 | |
| 7707 | EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); |
| 7708 | EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); |
| 7709 | EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); |
| 7710 | EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); |
| 7711 | } |
| 7712 | |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7713 | TEST_P(QuicStreamFactoryTest, ServerMigration) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 7714 | test_params_.quic_allow_server_migration = true; |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7715 | Initialize(); |
| 7716 | |
| 7717 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7718 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7719 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7720 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7721 | MockQuicData socket_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7722 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7723 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7724 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7725 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7726 | socket_data1.AddWrite( |
| 7727 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7728 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7729 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7730 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7731 | |
| 7732 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7733 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7734 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7735 | request.Request( |
| 7736 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7737 | SocketTag(), |
| 7738 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7739 | failed_on_default_network_callback_, callback_.callback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7740 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7741 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7742 | EXPECT_TRUE(stream.get()); |
| 7743 | |
| 7744 | // Cause QUIC stream to be created. |
| 7745 | HttpRequestInfo request_info; |
| 7746 | request_info.method = "GET"; |
| 7747 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7748 | request_info.traffic_annotation = |
| 7749 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7750 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7751 | net_log_, CompletionOnceCallback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7752 | |
| 7753 | // Ensure that session is alive and active. |
| 7754 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7755 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7756 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7757 | |
| 7758 | // Send GET request on stream. |
| 7759 | HttpResponseInfo response; |
| 7760 | HttpRequestHeaders request_headers; |
| 7761 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7762 | callback_.callback())); |
| 7763 | |
| 7764 | IPEndPoint ip; |
| 7765 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7766 | DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 7767 | << ip.port(); |
| 7768 | |
| 7769 | // Set up second socket data provider that is used after |
| 7770 | // migration. The request is rewritten to this new socket, and the |
| 7771 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7772 | MockQuicData socket_data2; |
| 7773 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7774 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 7775 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7776 | ASYNC, |
| 7777 | ConstructOkResponsePacket( |
| 7778 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7779 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7780 | socket_data2.AddWrite( |
| 7781 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7782 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7783 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7784 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7785 | |
| 7786 | const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 7787 | const uint16_t kTestPort = 123; |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 7788 | session->Migrate(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 7789 | IPEndPoint(IPAddress(kTestIpAddress), kTestPort), true, |
| 7790 | net_log_); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7791 | |
| 7792 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7793 | DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 7794 | << ip.port(); |
| 7795 | |
| 7796 | // The session should be alive and active. |
| 7797 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7798 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7799 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7800 | |
| 7801 | // Run the message loop so that data queued in the new socket is read by the |
| 7802 | // packet reader. |
| 7803 | base::RunLoop().RunUntilIdle(); |
| 7804 | |
| 7805 | // Verify that response headers on the migrated socket were delivered to the |
| 7806 | // stream. |
| 7807 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7808 | EXPECT_EQ(200, response.headers->response_code()); |
| 7809 | |
| 7810 | stream.reset(); |
| 7811 | |
| 7812 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7813 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7814 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7815 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7816 | } |
| 7817 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7818 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv4) { |
| 7819 | // Add alternate IPv4 server address to config. |
| 7820 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7821 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7822 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7823 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7824 | VerifyServerMigration(config, alt_address); |
| 7825 | } |
| 7826 | |
| 7827 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv6) { |
| 7828 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7829 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7830 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7831 | // Add alternate IPv6 server address to config. |
| 7832 | IPEndPoint alt_address = IPEndPoint( |
| 7833 | 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] | 7834 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7835 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7836 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7837 | VerifyServerMigration(config, alt_address); |
| 7838 | } |
| 7839 | |
| 7840 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { |
| 7841 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7842 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7843 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7844 | // Add alternate IPv4 server address to config. |
| 7845 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7846 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7847 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7848 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7849 | IPEndPoint expected_address( |
| 7850 | ConvertIPv4ToIPv4MappedIPv6(alt_address.address()), alt_address.port()); |
| 7851 | VerifyServerMigration(config, expected_address); |
| 7852 | } |
| 7853 | |
| 7854 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 7855 | test_params_.quic_allow_server_migration = true; |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7856 | Initialize(); |
| 7857 | |
| 7858 | // Add a resolver rule to make initial connection to an IPv4 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7859 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), "1.2.3.4", |
| 7860 | ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7861 | // Add alternate IPv6 server address to config. |
| 7862 | IPEndPoint alt_address = IPEndPoint( |
| 7863 | 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] | 7864 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7865 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7866 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7867 | |
| 7868 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7869 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7870 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7871 | |
| 7872 | crypto_client_stream_factory_.SetConfig(config); |
| 7873 | |
| 7874 | // Set up only socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7875 | MockQuicData socket_data1; |
| 7876 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7877 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7878 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7879 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7880 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7881 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7882 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7883 | |
| 7884 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7885 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7886 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7887 | request.Request( |
| 7888 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7889 | SocketTag(), |
| 7890 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7891 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7892 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7893 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7894 | EXPECT_TRUE(stream.get()); |
| 7895 | |
| 7896 | // Cause QUIC stream to be created. |
| 7897 | HttpRequestInfo request_info; |
| 7898 | request_info.method = "GET"; |
| 7899 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7900 | request_info.traffic_annotation = |
| 7901 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7902 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7903 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7904 | |
| 7905 | // Ensure that session is alive and active. |
| 7906 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7907 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7908 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7909 | |
| 7910 | IPEndPoint actual_address; |
| 7911 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 7912 | // No migration should have happened. |
| 7913 | IPEndPoint expected_address = |
| 7914 | IPEndPoint(IPAddress(1, 2, 3, 4), kDefaultServerPort); |
| 7915 | EXPECT_EQ(actual_address, expected_address); |
| 7916 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 7917 | << " " << actual_address.port(); |
| 7918 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 7919 | << " " << expected_address.port(); |
| 7920 | |
| 7921 | stream.reset(); |
| 7922 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7923 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7924 | } |
| 7925 | |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 7926 | TEST_P(QuicStreamFactoryTest, OnCertDBChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7927 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7928 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7929 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7930 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7931 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7932 | MockQuicData socket_data; |
| 7933 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7934 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7935 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7936 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7937 | MockQuicData socket_data2; |
| 7938 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7939 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7940 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7941 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7942 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7943 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7944 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7945 | request.Request( |
| 7946 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7947 | SocketTag(), |
| 7948 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7949 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7950 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7951 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7952 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7953 | EXPECT_TRUE(stream); |
| 7954 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7955 | |
| 7956 | // Change the CA cert and verify that stream saw the event. |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 7957 | factory_->OnCertDBChanged(); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7958 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7959 | EXPECT_FALSE(factory_->require_confirmation()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7960 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7961 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7962 | |
| 7963 | // Now attempting to request a stream to the same origin should create |
| 7964 | // a new session. |
| 7965 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7966 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7967 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7968 | request2.Request( |
| 7969 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7970 | SocketTag(), |
| 7971 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7972 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7973 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7974 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7975 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 7976 | EXPECT_TRUE(stream2); |
| 7977 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 7978 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7979 | EXPECT_NE(session, session2); |
| 7980 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7981 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 7982 | |
| 7983 | stream2.reset(); |
| 7984 | stream.reset(); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7985 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7986 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7987 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7988 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7989 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7990 | } |
| 7991 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7992 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7993 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7994 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7995 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7996 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7997 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7998 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7999 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 8000 | string r1_host_name("r1"); |
| 8001 | string r2_host_name("r2"); |
| 8002 | r1_host_name.append(cannoncial_suffixes[i]); |
| 8003 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 8004 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 8005 | HostPortPair host_port_pair1(r1_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8006 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8007 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8008 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 8009 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8010 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 8011 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 8012 | EXPECT_FALSE(cached1->proof_valid()); |
| 8013 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 8014 | |
| 8015 | // Mutate the cached1 to have different data. |
| 8016 | // TODO(rtenneti): mutate other members of CachedState. |
| 8017 | cached1->set_source_address_token(r1_host_name); |
| 8018 | cached1->SetProofValid(); |
| 8019 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 8020 | HostPortPair host_port_pair2(r2_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8021 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 8022 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8023 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 8024 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 8025 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 8026 | EXPECT_TRUE(cached2->proof_valid()); |
| 8027 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 8028 | } |
| 8029 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 8030 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8031 | Initialize(); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8032 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 8033 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 8034 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 8035 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 8036 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 8037 | string r3_host_name("r3"); |
| 8038 | string r4_host_name("r4"); |
| 8039 | r3_host_name.append(cannoncial_suffixes[i]); |
| 8040 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 8041 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 8042 | HostPortPair host_port_pair1(r3_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8043 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8044 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8045 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 8046 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8047 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 8048 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 8049 | EXPECT_FALSE(cached1->proof_valid()); |
| 8050 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 8051 | |
| 8052 | // Mutate the cached1 to have different data. |
| 8053 | // TODO(rtenneti): mutate other members of CachedState. |
| 8054 | cached1->set_source_address_token(r3_host_name); |
| 8055 | cached1->SetProofInvalid(); |
| 8056 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 8057 | HostPortPair host_port_pair2(r4_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8058 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 8059 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8060 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 8061 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 8062 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 8063 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 8064 | EXPECT_FALSE(cached2->proof_valid()); |
| 8065 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 8066 | } |
| 8067 | |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 8068 | TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8069 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 8070 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 8071 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8072 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8073 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8074 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 8075 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8076 | MockQuicData socket_data; |
| 8077 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8078 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 8079 | |
| 8080 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8081 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8082 | host_resolver_->set_synchronous_mode(true); |
| 8083 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8084 | "192.168.0.1", ""); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 8085 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8086 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8087 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 8088 | DEFAULT_PRIORITY, SocketTag(), |
| 8089 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8090 | &net_error_details_, |
| 8091 | failed_on_default_network_callback_, |
| 8092 | callback_.callback())); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 8093 | |
| 8094 | // If we are waiting for disk cache, we would have posted a task. Verify that |
| 8095 | // the CancelWaitForDataReady task hasn't been posted. |
| 8096 | ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
| 8097 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8098 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 8099 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 8100 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8101 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 8102 | } |
| 8103 | |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 8104 | TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8105 | test_params_.quic_reduced_ping_timeout_seconds = 10; |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 8106 | Initialize(); |
| 8107 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8108 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8109 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8110 | |
| 8111 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8112 | |
| 8113 | MockQuicData socket_data; |
| 8114 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8115 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8116 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8117 | |
| 8118 | MockQuicData socket_data2; |
| 8119 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8120 | socket_data2.AddWrite(SYNCHRONOUS, |
| 8121 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8122 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8123 | |
| 8124 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
| 8125 | |
| 8126 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8127 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8128 | host_resolver_->set_synchronous_mode(true); |
| 8129 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8130 | "192.168.0.1", ""); |
| 8131 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8132 | |
| 8133 | // Quic should use default PING timeout when no previous connection times out |
| 8134 | // with open stream. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8135 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8136 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8137 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8138 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 8139 | DEFAULT_PRIORITY, SocketTag(), |
| 8140 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8141 | &net_error_details_, |
| 8142 | failed_on_default_network_callback_, |
| 8143 | callback_.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8144 | |
| 8145 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8146 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8147 | session->connection()->ping_timeout()); |
| 8148 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8149 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8150 | EXPECT_TRUE(stream.get()); |
| 8151 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 8152 | request_info.traffic_annotation = |
| 8153 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 8154 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 8155 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8156 | |
| 8157 | DVLOG(1) |
| 8158 | << "Created 1st session and initialized a stream. Now trigger timeout"; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8159 | session->connection()->CloseConnection( |
| 8160 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 8161 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8162 | // Need to spin the loop now to ensure that |
| 8163 | // QuicStreamFactory::OnSessionClosed() runs. |
| 8164 | base::RunLoop run_loop; |
| 8165 | run_loop.RunUntilIdle(); |
| 8166 | |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8167 | // The first connection times out with open stream, QUIC should reduce initial |
| 8168 | // PING time for subsequent connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8169 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8170 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 8171 | |
| 8172 | // Test two-in-a-row timeouts with open streams. |
| 8173 | DVLOG(1) << "Create 2nd session and timeout with open stream"; |
| 8174 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8175 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8176 | EXPECT_EQ(OK, |
| 8177 | request2.Request( |
| 8178 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8179 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 8180 | failed_on_default_network_callback_, callback2.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8181 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8182 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8183 | session2->connection()->ping_timeout()); |
| 8184 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8185 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8186 | EXPECT_TRUE(stream2.get()); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 8187 | EXPECT_EQ(OK, |
| 8188 | stream2->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 8189 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8190 | session2->connection()->CloseConnection( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8191 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 8192 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8193 | // Need to spin the loop now to ensure that |
| 8194 | // QuicStreamFactory::OnSessionClosed() runs. |
| 8195 | base::RunLoop run_loop2; |
| 8196 | run_loop2.RunUntilIdle(); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8197 | |
| 8198 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8199 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8200 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 8201 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 8202 | } |
| 8203 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 8204 | // Verifies that the QUIC stream factory is initialized correctly. |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 8205 | TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 8206 | VerifyInitialization(); |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 8207 | } |
| 8208 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8209 | TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 8210 | Initialize(); |
| 8211 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8212 | MockQuicData socket_data; |
| 8213 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8214 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8215 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8216 | |
| 8217 | // Save current state of |race_cert_verification|. |
| 8218 | bool race_cert_verification = |
| 8219 | QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 8220 | |
| 8221 | // Load server config. |
| 8222 | HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8223 | quic::QuicServerId quic_server_id(host_port_pair_.host(), |
| 8224 | host_port_pair_.port(), |
| 8225 | privacy_mode_ == PRIVACY_MODE_ENABLED); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8226 | QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 8227 | |
| 8228 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 8229 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 8230 | |
| 8231 | // Start CertVerifyJob. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8232 | quic::QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8233 | factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8234 | if (status == quic::QUIC_PENDING) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8235 | // Verify CertVerifierJob has started. |
| 8236 | EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 8237 | |
| 8238 | while (HasActiveCertVerifierJob(quic_server_id)) { |
| 8239 | base::RunLoop().RunUntilIdle(); |
| 8240 | } |
| 8241 | } |
| 8242 | // Verify CertVerifierJob has finished. |
| 8243 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 8244 | |
| 8245 | // Start a QUIC request. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8246 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8247 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8248 | request.Request( |
| 8249 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8250 | SocketTag(), |
| 8251 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8252 | failed_on_default_network_callback_, callback_.callback())); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8253 | |
| 8254 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 8255 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8256 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8257 | EXPECT_TRUE(stream.get()); |
| 8258 | |
| 8259 | // Restore |race_cert_verification|. |
| 8260 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 8261 | race_cert_verification); |
| 8262 | |
| 8263 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8264 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8265 | |
| 8266 | // Verify there are no outstanding CertVerifierJobs after request has |
| 8267 | // finished. |
| 8268 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 8269 | } |
| 8270 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8271 | TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8272 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 8273 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 8274 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8275 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8276 | QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8277 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8278 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 8279 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8280 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8281 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8282 | |
| 8283 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8284 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8285 | host_resolver_->set_synchronous_mode(true); |
| 8286 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8287 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8288 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8289 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 8290 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8291 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8292 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 8293 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8294 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8295 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8296 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 8297 | DEFAULT_PRIORITY, SocketTag(), |
| 8298 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8299 | &net_error_details_, |
| 8300 | failed_on_default_network_callback_, |
| 8301 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8302 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8303 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 8304 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8305 | base::RunLoop run_loop; |
| 8306 | run_loop.RunUntilIdle(); |
| 8307 | |
| 8308 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8309 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 8310 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8311 | EXPECT_EQ(1u, observer.executed_count()); |
| 8312 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8313 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 8314 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8315 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8316 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8317 | } |
| 8318 | |
| 8319 | TEST_P(QuicStreamFactoryTest, YieldAfterDuration) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8320 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 8321 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 8322 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8323 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8324 | QuicStreamFactoryPeer::SetYieldAfterDuration( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8325 | factory_.get(), quic::QuicTime::Delta::FromMilliseconds(-1)); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8326 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8327 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 8328 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8329 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8330 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8331 | |
| 8332 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8333 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8334 | host_resolver_->set_synchronous_mode(true); |
| 8335 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8336 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8337 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8338 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 8339 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8340 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8341 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 8342 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8343 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8344 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8345 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 8346 | DEFAULT_PRIORITY, SocketTag(), |
| 8347 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8348 | &net_error_details_, |
| 8349 | failed_on_default_network_callback_, |
| 8350 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8351 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8352 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 8353 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8354 | base::RunLoop run_loop; |
| 8355 | run_loop.RunUntilIdle(); |
| 8356 | |
| 8357 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8358 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 8359 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8360 | EXPECT_EQ(1u, observer.executed_count()); |
| 8361 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8362 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 8363 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8364 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8365 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8366 | } |
| 8367 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8368 | TEST_P(QuicStreamFactoryTest, ServerPushSessionAffinity) { |
| 8369 | Initialize(); |
| 8370 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8371 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8372 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8373 | MockQuicData socket_data; |
| 8374 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8375 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8376 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8377 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8378 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8379 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8380 | request.Request( |
| 8381 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8382 | SocketTag(), |
| 8383 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8384 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8385 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8386 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8387 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8388 | EXPECT_TRUE(stream.get()); |
| 8389 | |
| 8390 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 8391 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 8392 | string url = "https://www.example.org/"; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8393 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 8394 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8395 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8396 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 8397 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8398 | (*QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()) |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8399 | ->promised_by_url())[kDefaultUrl] = &promised; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8400 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8401 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8402 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8403 | DEFAULT_PRIORITY, SocketTag(), |
| 8404 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8405 | &net_error_details_, |
| 8406 | failed_on_default_network_callback_, |
| 8407 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8408 | |
| 8409 | EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 8410 | } |
| 8411 | |
| 8412 | TEST_P(QuicStreamFactoryTest, ServerPushPrivacyModeMismatch) { |
| 8413 | Initialize(); |
| 8414 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8415 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8416 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8417 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8418 | MockQuicData socket_data1; |
| 8419 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8420 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8421 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 8422 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 8423 | 2, true, GetNthServerInitiatedUnidirectionalStreamId(0), |
| 8424 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8425 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8426 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8427 | MockQuicData socket_data2; |
| 8428 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8429 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8430 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8431 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8432 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8433 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8434 | request.Request( |
| 8435 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8436 | SocketTag(), |
| 8437 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8438 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8439 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8440 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8441 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8442 | EXPECT_TRUE(stream.get()); |
| 8443 | |
| 8444 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 8445 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 8446 | string url = "https://www.example.org/"; |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 8447 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8448 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8449 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 8450 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8451 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8452 | quic::QuicClientPushPromiseIndex* index = |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8453 | QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()); |
| 8454 | |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8455 | (*index->promised_by_url())[kDefaultUrl] = &promised; |
| 8456 | EXPECT_EQ(index->GetPromised(kDefaultUrl), &promised); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8457 | |
| 8458 | // Doing the request should not use the push stream, but rather |
| 8459 | // cancel it because the privacy modes do not match. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8460 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8461 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8462 | request2.Request( |
| 8463 | host_port_pair_, version_, PRIVACY_MODE_ENABLED, |
| 8464 | DEFAULT_PRIORITY, SocketTag(), |
| 8465 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8466 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8467 | |
| 8468 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8469 | EXPECT_EQ(index->GetPromised(kDefaultUrl), nullptr); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8470 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8471 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8472 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8473 | EXPECT_TRUE(stream2.get()); |
| 8474 | |
| 8475 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 8476 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 8477 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 8478 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 8479 | } |
| 8480 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8481 | // Pool to existing session with matching quic::QuicServerId |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8482 | // even if destination is different. |
| 8483 | TEST_P(QuicStreamFactoryTest, PoolByOrigin) { |
| 8484 | Initialize(); |
| 8485 | |
| 8486 | HostPortPair destination1("first.example.com", 443); |
| 8487 | HostPortPair destination2("second.example.com", 443); |
| 8488 | |
| 8489 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8490 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8491 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8492 | MockQuicData socket_data; |
| 8493 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8494 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8495 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8496 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8497 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8498 | EXPECT_EQ( |
| 8499 | ERR_IO_PENDING, |
| 8500 | request1.Request( |
| 8501 | destination1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8502 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8503 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8504 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8505 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8506 | EXPECT_TRUE(stream1.get()); |
| 8507 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 8508 | |
| 8509 | // Second request returns synchronously because it pools to existing session. |
| 8510 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8511 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8512 | EXPECT_EQ(OK, request2.Request(destination2, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8513 | DEFAULT_PRIORITY, SocketTag(), |
| 8514 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8515 | &net_error_details_, |
| 8516 | failed_on_default_network_callback_, |
| 8517 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8518 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8519 | EXPECT_TRUE(stream2.get()); |
| 8520 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8521 | QuicChromiumClientSession::Handle* session1 = |
| 8522 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8523 | QuicChromiumClientSession::Handle* session2 = |
| 8524 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8525 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8526 | EXPECT_EQ(quic::QuicServerId(host_port_pair_.host(), host_port_pair_.port(), |
| 8527 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8528 | session1->server_id()); |
| 8529 | |
| 8530 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8531 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8532 | } |
| 8533 | |
| 8534 | class QuicStreamFactoryWithDestinationTest |
| 8535 | : public QuicStreamFactoryTestBase, |
| 8536 | public ::testing::TestWithParam<PoolingTestParams> { |
| 8537 | protected: |
| 8538 | QuicStreamFactoryWithDestinationTest() |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 8539 | : QuicStreamFactoryTestBase( |
| 8540 | GetParam().version, |
| 8541 | GetParam().client_headers_include_h2_stream_dependency), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8542 | destination_type_(GetParam().destination_type), |
| 8543 | hanging_read_(SYNCHRONOUS, ERR_IO_PENDING, 0) {} |
| 8544 | |
| 8545 | HostPortPair GetDestination() { |
| 8546 | switch (destination_type_) { |
| 8547 | case SAME_AS_FIRST: |
| 8548 | return origin1_; |
| 8549 | case SAME_AS_SECOND: |
| 8550 | return origin2_; |
| 8551 | case DIFFERENT: |
| 8552 | return HostPortPair(kDifferentHostname, 443); |
| 8553 | default: |
| 8554 | NOTREACHED(); |
| 8555 | return HostPortPair(); |
| 8556 | } |
| 8557 | } |
| 8558 | |
| 8559 | void AddHangingSocketData() { |
| 8560 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8561 | new SequencedSocketData(base::make_span(&hanging_read_, 1), |
| 8562 | base::span<MockWrite>())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8563 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8564 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8565 | } |
| 8566 | |
| 8567 | bool AllDataConsumed() { |
| 8568 | for (const auto& socket_data_ptr : sequenced_socket_data_vector_) { |
| 8569 | if (!socket_data_ptr->AllReadDataConsumed() || |
| 8570 | !socket_data_ptr->AllWriteDataConsumed()) { |
| 8571 | return false; |
| 8572 | } |
| 8573 | } |
| 8574 | return true; |
| 8575 | } |
| 8576 | |
| 8577 | DestinationType destination_type_; |
| 8578 | HostPortPair origin1_; |
| 8579 | HostPortPair origin2_; |
| 8580 | MockRead hanging_read_; |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8581 | std::vector<std::unique_ptr<SequencedSocketData>> |
| 8582 | sequenced_socket_data_vector_; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8583 | }; |
| 8584 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 8585 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 8586 | QuicStreamFactoryWithDestinationTest, |
| 8587 | ::testing::ValuesIn(GetPoolingTestParams())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8588 | |
| 8589 | // A single QUIC request fails because the certificate does not match the origin |
| 8590 | // hostname, regardless of whether it matches the alternative service hostname. |
| 8591 | TEST_P(QuicStreamFactoryWithDestinationTest, InvalidCertificate) { |
| 8592 | if (destination_type_ == DIFFERENT) |
| 8593 | return; |
| 8594 | |
| 8595 | Initialize(); |
| 8596 | |
| 8597 | GURL url("https://mail.example.com/"); |
| 8598 | origin1_ = HostPortPair::FromURL(url); |
| 8599 | |
| 8600 | // Not used for requests, but this provides a test case where the certificate |
| 8601 | // is valid for the hostname of the alternative service. |
| 8602 | origin2_ = HostPortPair("mail.example.org", 433); |
| 8603 | |
| 8604 | HostPortPair destination = GetDestination(); |
| 8605 | |
| 8606 | scoped_refptr<X509Certificate> cert( |
| 8607 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8608 | ASSERT_FALSE(cert->VerifyNameMatch(origin1_.host())); |
| 8609 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8610 | |
| 8611 | ProofVerifyDetailsChromium verify_details; |
| 8612 | verify_details.cert_verify_result.verified_cert = cert; |
| 8613 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8614 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8615 | |
| 8616 | AddHangingSocketData(); |
| 8617 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8618 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8619 | EXPECT_EQ( |
| 8620 | ERR_IO_PENDING, |
| 8621 | request.Request( |
| 8622 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8623 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 8624 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8625 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8626 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_QUIC_HANDSHAKE_FAILED)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8627 | |
| 8628 | EXPECT_TRUE(AllDataConsumed()); |
| 8629 | } |
| 8630 | |
| 8631 | // QuicStreamRequest is pooled based on |destination| if certificate matches. |
| 8632 | TEST_P(QuicStreamFactoryWithDestinationTest, SharedCertificate) { |
| 8633 | Initialize(); |
| 8634 | |
| 8635 | GURL url1("https://www.example.org/"); |
| 8636 | GURL url2("https://mail.example.org/"); |
| 8637 | origin1_ = HostPortPair::FromURL(url1); |
| 8638 | origin2_ = HostPortPair::FromURL(url2); |
| 8639 | |
| 8640 | HostPortPair destination = GetDestination(); |
| 8641 | |
| 8642 | scoped_refptr<X509Certificate> cert( |
| 8643 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8644 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8645 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8646 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8647 | |
| 8648 | ProofVerifyDetailsChromium verify_details; |
| 8649 | verify_details.cert_verify_result.verified_cert = cert; |
| 8650 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8651 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8652 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8653 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8654 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8655 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8656 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8657 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8658 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8659 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8660 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8661 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8662 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8663 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8664 | EXPECT_EQ( |
| 8665 | ERR_IO_PENDING, |
| 8666 | request1.Request( |
| 8667 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8668 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8669 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8670 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8671 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8672 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8673 | EXPECT_TRUE(stream1.get()); |
| 8674 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8675 | |
| 8676 | // Second request returns synchronously because it pools to existing session. |
| 8677 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8678 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8679 | EXPECT_EQ(OK, request2.Request(destination, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8680 | DEFAULT_PRIORITY, SocketTag(), |
| 8681 | /*cert_verify_flags=*/0, url2, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8682 | &net_error_details_, |
| 8683 | failed_on_default_network_callback_, |
| 8684 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8685 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8686 | EXPECT_TRUE(stream2.get()); |
| 8687 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8688 | QuicChromiumClientSession::Handle* session1 = |
| 8689 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8690 | QuicChromiumClientSession::Handle* session2 = |
| 8691 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8692 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8693 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8694 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8695 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8696 | session1->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8697 | |
| 8698 | EXPECT_TRUE(AllDataConsumed()); |
| 8699 | } |
| 8700 | |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8701 | // QuicStreamRequest is not pooled if PrivacyMode differs. |
| 8702 | TEST_P(QuicStreamFactoryWithDestinationTest, DifferentPrivacyMode) { |
| 8703 | Initialize(); |
| 8704 | |
| 8705 | GURL url1("https://www.example.org/"); |
| 8706 | GURL url2("https://mail.example.org/"); |
| 8707 | origin1_ = HostPortPair::FromURL(url1); |
| 8708 | origin2_ = HostPortPair::FromURL(url2); |
| 8709 | |
| 8710 | HostPortPair destination = GetDestination(); |
| 8711 | |
| 8712 | scoped_refptr<X509Certificate> cert( |
| 8713 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8714 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8715 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8716 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8717 | |
| 8718 | ProofVerifyDetailsChromium verify_details1; |
| 8719 | verify_details1.cert_verify_result.verified_cert = cert; |
| 8720 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8721 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8722 | |
| 8723 | ProofVerifyDetailsChromium verify_details2; |
| 8724 | verify_details2.cert_verify_result.verified_cert = cert; |
| 8725 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8726 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8727 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8728 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8729 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8730 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8731 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8732 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8733 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8734 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8735 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8736 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8737 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8738 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8739 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8740 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8741 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8742 | QuicStreamRequest request1(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8743 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8744 | request1.Request( |
| 8745 | destination, version_, PRIVACY_MODE_DISABLED, DEFAULT_PRIORITY, |
| 8746 | SocketTag(), |
| 8747 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8748 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8749 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8750 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8751 | EXPECT_TRUE(stream1.get()); |
| 8752 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8753 | |
| 8754 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8755 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8756 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8757 | request2.Request( |
| 8758 | destination, version_, PRIVACY_MODE_ENABLED, DEFAULT_PRIORITY, |
| 8759 | SocketTag(), |
| 8760 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8761 | failed_on_default_network_callback_, callback2.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8762 | EXPECT_EQ(OK, callback2.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8763 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8764 | EXPECT_TRUE(stream2.get()); |
| 8765 | |
| 8766 | // |request2| does not pool to the first session, because PrivacyMode does not |
| 8767 | // match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8768 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8769 | QuicChromiumClientSession::Handle* session1 = |
| 8770 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8771 | QuicChromiumClientSession::Handle* session2 = |
| 8772 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8773 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8774 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8775 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), false), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8776 | session1->server_id()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8777 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), true), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8778 | session2->server_id()); |
| 8779 | |
| 8780 | EXPECT_TRUE(AllDataConsumed()); |
| 8781 | } |
| 8782 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8783 | // QuicStreamRequest is not pooled if certificate does not match its origin. |
| 8784 | TEST_P(QuicStreamFactoryWithDestinationTest, DisjointCertificate) { |
| 8785 | Initialize(); |
| 8786 | |
| 8787 | GURL url1("https://news.example.org/"); |
| 8788 | GURL url2("https://mail.example.com/"); |
| 8789 | origin1_ = HostPortPair::FromURL(url1); |
| 8790 | origin2_ = HostPortPair::FromURL(url2); |
| 8791 | |
| 8792 | HostPortPair destination = GetDestination(); |
| 8793 | |
| 8794 | scoped_refptr<X509Certificate> cert1( |
| 8795 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8796 | ASSERT_TRUE(cert1->VerifyNameMatch(origin1_.host())); |
| 8797 | ASSERT_FALSE(cert1->VerifyNameMatch(origin2_.host())); |
| 8798 | ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8799 | |
| 8800 | ProofVerifyDetailsChromium verify_details1; |
| 8801 | verify_details1.cert_verify_result.verified_cert = cert1; |
| 8802 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8803 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8804 | |
| 8805 | scoped_refptr<X509Certificate> cert2( |
| 8806 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8807 | ASSERT_TRUE(cert2->VerifyNameMatch(origin2_.host())); |
| 8808 | ASSERT_FALSE(cert2->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8809 | |
| 8810 | ProofVerifyDetailsChromium verify_details2; |
| 8811 | verify_details2.cert_verify_result.verified_cert = cert2; |
| 8812 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8813 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8814 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8815 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8816 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8817 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8818 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8819 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8820 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8821 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8822 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8823 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8824 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8825 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8826 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8827 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8828 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8829 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8830 | EXPECT_EQ( |
| 8831 | ERR_IO_PENDING, |
| 8832 | request1.Request( |
| 8833 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8834 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8835 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8836 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8837 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8838 | EXPECT_TRUE(stream1.get()); |
| 8839 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8840 | |
| 8841 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8842 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8843 | EXPECT_EQ( |
| 8844 | ERR_IO_PENDING, |
| 8845 | request2.Request( |
| 8846 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8847 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8848 | failed_on_default_network_callback_, callback2.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8849 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8850 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8851 | EXPECT_TRUE(stream2.get()); |
| 8852 | |
| 8853 | // |request2| does not pool to the first session, because the certificate does |
| 8854 | // not match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8855 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8856 | QuicChromiumClientSession::Handle* session1 = |
| 8857 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8858 | QuicChromiumClientSession::Handle* session2 = |
| 8859 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8860 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8861 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8862 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8863 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8864 | session1->server_id()); |
| 8865 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), |
| 8866 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8867 | session2->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8868 | |
| 8869 | EXPECT_TRUE(AllDataConsumed()); |
| 8870 | } |
| 8871 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8872 | // This test verifies that QuicStreamFactory::ClearCachedStatesInCryptoConfig |
| 8873 | // correctly transform an origin filter to a ServerIdFilter. Whether the |
| 8874 | // deletion itself works correctly is tested in QuicCryptoClientConfigTest. |
| 8875 | TEST_P(QuicStreamFactoryTest, ClearCachedStatesInCryptoConfig) { |
| 8876 | Initialize(); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8877 | quic::QuicCryptoClientConfig* crypto_config = |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8878 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 8879 | |
| 8880 | struct TestCase { |
| 8881 | TestCase(const std::string& host, |
| 8882 | int port, |
| 8883 | PrivacyMode privacy_mode, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8884 | quic::QuicCryptoClientConfig* crypto_config) |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8885 | : server_id(host, port, privacy_mode), |
| 8886 | state(crypto_config->LookupOrCreate(server_id)) { |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8887 | std::vector<string> certs(1); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8888 | certs[0] = "cert"; |
| 8889 | state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); |
| 8890 | state->set_source_address_token("TOKEN"); |
| 8891 | state->SetProofValid(); |
| 8892 | |
| 8893 | EXPECT_FALSE(state->certs().empty()); |
| 8894 | } |
| 8895 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8896 | quic::QuicServerId server_id; |
| 8897 | quic::QuicCryptoClientConfig::CachedState* state; |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8898 | } test_cases[] = { |
| 8899 | TestCase("www.google.com", 443, privacy_mode_, crypto_config), |
| 8900 | TestCase("www.example.com", 443, privacy_mode_, crypto_config), |
| 8901 | TestCase("www.example.com", 4433, privacy_mode_, crypto_config)}; |
| 8902 | |
| 8903 | // Clear cached states for the origin https://www.example.com:4433. |
| 8904 | GURL origin("https://www.example.com:4433"); |
csharrison | ebeca8e | 2016-10-18 02:35:36 | [diff] [blame] | 8905 | factory_->ClearCachedStatesInCryptoConfig(base::Bind( |
| 8906 | static_cast<bool (*)(const GURL&, const GURL&)>(::operator==), origin)); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8907 | EXPECT_FALSE(test_cases[0].state->certs().empty()); |
| 8908 | EXPECT_FALSE(test_cases[1].state->certs().empty()); |
| 8909 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8910 | |
| 8911 | // Clear all cached states. |
| 8912 | factory_->ClearCachedStatesInCryptoConfig( |
| 8913 | base::Callback<bool(const GURL&)>()); |
| 8914 | EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 8915 | EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 8916 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8917 | } |
| 8918 | |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8919 | // Passes connection options and client connection options to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8920 | // then checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8921 | TEST_P(QuicStreamFactoryTest, ConfigConnectionOptions) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8922 | test_params_.quic_connection_options.push_back(quic::kTIME); |
| 8923 | test_params_.quic_connection_options.push_back(quic::kTBBR); |
| 8924 | test_params_.quic_connection_options.push_back(quic::kREJ); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8925 | |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8926 | test_params_.quic_client_connection_options.push_back(quic::kTBBR); |
| 8927 | test_params_.quic_client_connection_options.push_back(quic::k1RTT); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8928 | |
| 8929 | Initialize(); |
| 8930 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8931 | const quic::QuicConfig* config = |
| 8932 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8933 | EXPECT_EQ(test_params_.quic_connection_options, |
| 8934 | config->SendConnectionOptions()); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8935 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8936 | quic::kTBBR, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8937 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8938 | quic::k1RTT, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8939 | } |
| 8940 | |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8941 | // Verifies that the host resolver uses the request priority passed to |
| 8942 | // QuicStreamRequest::Request(). |
| 8943 | TEST_P(QuicStreamFactoryTest, HostResolverUsesRequestPriority) { |
| 8944 | Initialize(); |
| 8945 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8946 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8947 | |
| 8948 | MockQuicData socket_data; |
| 8949 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8950 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8951 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8952 | |
| 8953 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8954 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8955 | request.Request( |
| 8956 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8957 | SocketTag(), |
| 8958 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8959 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8960 | |
| 8961 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8962 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8963 | EXPECT_TRUE(stream.get()); |
| 8964 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8965 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8966 | |
| 8967 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8968 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8969 | } |
| 8970 | |
Lily Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 8971 | TEST_P(QuicStreamFactoryTest, HostResolverRequestReprioritizedOnSetPriority) { |
| 8972 | Initialize(); |
| 8973 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8974 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8975 | |
| 8976 | MockQuicData socket_data; |
| 8977 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8978 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8979 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8980 | |
| 8981 | QuicStreamRequest request(factory_.get()); |
| 8982 | EXPECT_EQ(ERR_IO_PENDING, |
| 8983 | request.Request( |
| 8984 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8985 | SocketTag(), |
| 8986 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8987 | failed_on_default_network_callback_, callback_.callback())); |
| 8988 | |
| 8989 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
| 8990 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->request_priority(1)); |
| 8991 | |
| 8992 | QuicStreamRequest request2(factory_.get()); |
| 8993 | EXPECT_EQ(ERR_IO_PENDING, |
| 8994 | request2.Request( |
| 8995 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8996 | SocketTag(), |
| 8997 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 8998 | failed_on_default_network_callback_, callback_.callback())); |
| 8999 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
| 9000 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 9001 | |
| 9002 | request.SetPriority(LOWEST); |
| 9003 | EXPECT_EQ(LOWEST, host_resolver_->request_priority(1)); |
| 9004 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 9005 | } |
| 9006 | |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9007 | // Passes |quic_max_time_before_crypto_handshake_seconds| and |
| 9008 | // |quic_max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 9009 | // checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 9010 | TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9011 | test_params_.quic_max_time_before_crypto_handshake_seconds = 11; |
| 9012 | test_params_.quic_max_idle_time_before_crypto_handshake_seconds = 13; |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 9013 | Initialize(); |
| 9014 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 9015 | const quic::QuicConfig* config = |
| 9016 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 9017 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(11), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 9018 | config->max_time_before_crypto_handshake()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 9019 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(13), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 9020 | config->max_idle_time_before_crypto_handshake()); |
| 9021 | } |
| 9022 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9023 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 9024 | // succeeds asynchronously, then crypto handshake fails synchronously. |
| 9025 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncSync) { |
| 9026 | Initialize(); |
| 9027 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9028 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9029 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9030 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9031 | |
| 9032 | MockQuicData socket_data; |
| 9033 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 9034 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 9035 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9036 | |
| 9037 | QuicStreamRequest request(factory_.get()); |
| 9038 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9039 | request.Request( |
| 9040 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9041 | SocketTag(), |
| 9042 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9043 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9044 | |
| 9045 | TestCompletionCallback host_resolution_callback; |
| 9046 | EXPECT_TRUE( |
| 9047 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9048 | |
| 9049 | // |host_resolver_| has not finished host resolution at this point, so |
| 9050 | // |host_resolution_callback| should not have a result. |
| 9051 | base::RunLoop().RunUntilIdle(); |
| 9052 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9053 | |
| 9054 | // Allow |host_resolver_| to finish host resolution. |
| 9055 | // Since the request fails immediately after host resolution (getting |
| 9056 | // ERR_FAILED from socket reads/writes), |host_resolution_callback| should be |
| 9057 | // called with ERR_QUIC_PROTOCOL_ERROR since that's the next result in |
| 9058 | // forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9059 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9060 | base::RunLoop().RunUntilIdle(); |
| 9061 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 9062 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, host_resolution_callback.WaitForResult()); |
| 9063 | |
| 9064 | // Calling WaitForHostResolution() a second time should return |
| 9065 | // false since host resolution has finished already. |
| 9066 | EXPECT_FALSE( |
| 9067 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9068 | |
| 9069 | EXPECT_TRUE(callback_.have_result()); |
| 9070 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 9071 | } |
| 9072 | |
| 9073 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 9074 | // succeeds asynchronously, then crypto handshake fails asynchronously. |
| 9075 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncAsync) { |
| 9076 | Initialize(); |
| 9077 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9078 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9079 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9080 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9081 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 9082 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9083 | factory_->set_require_confirmation(true); |
| 9084 | |
| 9085 | MockQuicData socket_data; |
| 9086 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 9087 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 9088 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 9089 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9090 | |
| 9091 | QuicStreamRequest request(factory_.get()); |
| 9092 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9093 | request.Request( |
| 9094 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9095 | SocketTag(), |
| 9096 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9097 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9098 | |
| 9099 | TestCompletionCallback host_resolution_callback; |
| 9100 | EXPECT_TRUE( |
| 9101 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9102 | |
| 9103 | // |host_resolver_| has not finished host resolution at this point, so |
| 9104 | // |host_resolution_callback| should not have a result. |
| 9105 | base::RunLoop().RunUntilIdle(); |
| 9106 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9107 | |
| 9108 | // Allow |host_resolver_| to finish host resolution. Since crypto handshake |
| 9109 | // will hang after host resolution, |host_resolution_callback| should run with |
| 9110 | // ERR_IO_PENDING since that's the next result in forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9111 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9112 | base::RunLoop().RunUntilIdle(); |
| 9113 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 9114 | EXPECT_EQ(ERR_IO_PENDING, host_resolution_callback.WaitForResult()); |
| 9115 | |
| 9116 | // Calling WaitForHostResolution() a second time should return |
| 9117 | // false since host resolution has finished already. |
| 9118 | EXPECT_FALSE( |
| 9119 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9120 | |
| 9121 | EXPECT_FALSE(callback_.have_result()); |
| 9122 | socket_data.GetSequencedSocketData()->Resume(); |
| 9123 | base::RunLoop().RunUntilIdle(); |
| 9124 | EXPECT_TRUE(callback_.have_result()); |
| 9125 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 9126 | } |
| 9127 | |
| 9128 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 9129 | // succeeds synchronously, then crypto handshake fails synchronously. |
| 9130 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncSync) { |
| 9131 | Initialize(); |
| 9132 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9133 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9134 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9135 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9136 | |
| 9137 | MockQuicData socket_data; |
| 9138 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 9139 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 9140 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9141 | |
| 9142 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9143 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9144 | request.Request( |
| 9145 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9146 | SocketTag(), |
| 9147 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9148 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9149 | |
| 9150 | // WaitForHostResolution() should return false since host |
| 9151 | // resolution has finished already. |
| 9152 | TestCompletionCallback host_resolution_callback; |
| 9153 | EXPECT_FALSE( |
| 9154 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9155 | base::RunLoop().RunUntilIdle(); |
| 9156 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9157 | EXPECT_FALSE(callback_.have_result()); |
| 9158 | } |
| 9159 | |
| 9160 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 9161 | // succeeds synchronously, then crypto handshake fails asynchronously. |
| 9162 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncAsync) { |
| 9163 | Initialize(); |
| 9164 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9165 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9166 | |
| 9167 | // Host resolution will succeed synchronously, but Request() as a whole |
| 9168 | // will fail asynchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9169 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9170 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 9171 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9172 | factory_->set_require_confirmation(true); |
| 9173 | |
| 9174 | MockQuicData socket_data; |
| 9175 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 9176 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 9177 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 9178 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9179 | |
| 9180 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9181 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9182 | request.Request( |
| 9183 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9184 | SocketTag(), |
| 9185 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9186 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9187 | |
| 9188 | // WaitForHostResolution() should return false since host |
| 9189 | // resolution has finished already. |
| 9190 | TestCompletionCallback host_resolution_callback; |
| 9191 | EXPECT_FALSE( |
| 9192 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9193 | base::RunLoop().RunUntilIdle(); |
| 9194 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9195 | |
| 9196 | EXPECT_FALSE(callback_.have_result()); |
| 9197 | socket_data.GetSequencedSocketData()->Resume(); |
| 9198 | base::RunLoop().RunUntilIdle(); |
| 9199 | EXPECT_TRUE(callback_.have_result()); |
| 9200 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 9201 | } |
| 9202 | |
| 9203 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 9204 | // synchronously. |
| 9205 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailSync) { |
| 9206 | Initialize(); |
| 9207 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9208 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9209 | |
| 9210 | // Host resolution will fail synchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9211 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9212 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9213 | |
| 9214 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9215 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9216 | request.Request( |
| 9217 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9218 | SocketTag(), |
| 9219 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9220 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9221 | |
| 9222 | // WaitForHostResolution() should return false since host |
| 9223 | // resolution has failed already. |
| 9224 | TestCompletionCallback host_resolution_callback; |
| 9225 | EXPECT_FALSE( |
| 9226 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9227 | base::RunLoop().RunUntilIdle(); |
| 9228 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9229 | } |
| 9230 | |
| 9231 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 9232 | // asynchronously. |
| 9233 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { |
| 9234 | Initialize(); |
| 9235 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9236 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9237 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9238 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9239 | |
| 9240 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9241 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9242 | request.Request( |
| 9243 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9244 | SocketTag(), |
| 9245 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9246 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9247 | |
| 9248 | TestCompletionCallback host_resolution_callback; |
| 9249 | EXPECT_TRUE( |
| 9250 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9251 | |
| 9252 | // Allow |host_resolver_| to fail host resolution. |host_resolution_callback| |
| 9253 | // Should run with ERR_NAME_NOT_RESOLVED since that's the error host |
| 9254 | // resolution failed with. |
| 9255 | base::RunLoop().RunUntilIdle(); |
| 9256 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 9257 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, host_resolution_callback.WaitForResult()); |
| 9258 | |
| 9259 | EXPECT_TRUE(callback_.have_result()); |
| 9260 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 9261 | } |
| 9262 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9263 | // With dns race experiment turned on, and DNS resolve succeeds synchronously, |
| 9264 | // the final connection is established through the resolved DNS. No racing |
| 9265 | // connection. |
| 9266 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9267 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9268 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9269 | Initialize(); |
| 9270 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9271 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9272 | |
| 9273 | // Set an address in resolver for synchronous return. |
| 9274 | host_resolver_->set_synchronous_mode(true); |
| 9275 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9276 | kNonCachedIPAddress, ""); |
| 9277 | |
| 9278 | // Set up a different address in stale resolver cache. |
| 9279 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9280 | HostCache::Entry entry(OK, |
| 9281 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9282 | HostCache::Entry::SOURCE_DNS); |
| 9283 | base::TimeDelta zero; |
| 9284 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9285 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9286 | // Expire the cache |
| 9287 | cache->OnNetworkChange(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9288 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9289 | MockQuicData quic_data; |
| 9290 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9291 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9292 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9293 | |
| 9294 | QuicStreamRequest request(factory_.get()); |
| 9295 | EXPECT_THAT(request.Request( |
| 9296 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9297 | SocketTag(), |
| 9298 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9299 | failed_on_default_network_callback_, callback_.callback()), |
| 9300 | IsOk()); |
| 9301 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9302 | EXPECT_TRUE(stream.get()); |
| 9303 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9304 | EXPECT_EQ( |
| 9305 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9306 | kNonCachedIPAddress); |
| 9307 | |
| 9308 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9309 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9310 | } |
| 9311 | |
| 9312 | // With dns race experiment on, DNS resolve returns async, no matching cache in |
| 9313 | // host resolver, connection should be successful and through resolved DNS. No |
| 9314 | // racing connection. |
| 9315 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9316 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9317 | Initialize(); |
| 9318 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9319 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9320 | |
| 9321 | // Set an address in resolver for asynchronous return. |
| 9322 | host_resolver_->set_ondemand_mode(true); |
| 9323 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9324 | kNonCachedIPAddress, ""); |
| 9325 | |
| 9326 | MockQuicData quic_data; |
| 9327 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9328 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9329 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9330 | |
| 9331 | QuicStreamRequest request(factory_.get()); |
| 9332 | EXPECT_EQ(ERR_IO_PENDING, |
| 9333 | request.Request( |
| 9334 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9335 | SocketTag(), |
| 9336 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9337 | failed_on_default_network_callback_, callback_.callback())); |
| 9338 | TestCompletionCallback host_resolution_callback; |
| 9339 | EXPECT_TRUE( |
| 9340 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9341 | base::RunLoop().RunUntilIdle(); |
| 9342 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9343 | |
| 9344 | // Cause the host resolution to return. |
| 9345 | host_resolver_->ResolveAllPending(); |
| 9346 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 9347 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9348 | |
| 9349 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9350 | EXPECT_TRUE(stream.get()); |
| 9351 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9352 | |
| 9353 | EXPECT_EQ( |
| 9354 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9355 | kNonCachedIPAddress); |
| 9356 | |
| 9357 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9358 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9359 | } |
| 9360 | |
| 9361 | // With dns race experiment on, DNS resolve returns async, stale dns used, |
| 9362 | // connects synchrounously, and then the resolved DNS matches. |
| 9363 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9364 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9365 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9366 | Initialize(); |
| 9367 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9368 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9369 | |
| 9370 | // Set an address in resolver for asynchronous return. |
| 9371 | host_resolver_->set_ondemand_mode(true); |
| 9372 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9373 | kCachedIPAddress.ToString(), ""); |
| 9374 | |
| 9375 | // Set up the same address in the stale resolver cache. |
| 9376 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9377 | HostCache::Entry entry(OK, |
| 9378 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9379 | HostCache::Entry::SOURCE_DNS); |
| 9380 | base::TimeDelta zero; |
| 9381 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9382 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9383 | // Expire the cache |
| 9384 | cache->OnNetworkChange(); |
| 9385 | |
| 9386 | MockQuicData quic_data; |
| 9387 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9388 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9389 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9390 | |
| 9391 | QuicStreamRequest request(factory_.get()); |
| 9392 | EXPECT_EQ(ERR_IO_PENDING, |
| 9393 | request.Request( |
| 9394 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9395 | SocketTag(), |
| 9396 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9397 | failed_on_default_network_callback_, callback_.callback())); |
| 9398 | |
| 9399 | // Check that the racing job is running. |
| 9400 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9401 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9402 | |
| 9403 | // Resolve dns and return. |
| 9404 | host_resolver_->ResolveAllPending(); |
| 9405 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9406 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9407 | EXPECT_TRUE(stream.get()); |
| 9408 | |
| 9409 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9410 | |
| 9411 | EXPECT_EQ( |
| 9412 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9413 | kCachedIPAddress.ToString()); |
| 9414 | |
| 9415 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9416 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9417 | } |
| 9418 | |
| 9419 | // With dns race experiment on, dns resolve async, stale dns used, connect |
| 9420 | // async, and then the result matches. |
| 9421 | TEST_P(QuicStreamFactoryTest, |
| 9422 | ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9423 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9424 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9425 | Initialize(); |
| 9426 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9427 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9428 | |
| 9429 | // Set an address in resolver for asynchronous return. |
| 9430 | host_resolver_->set_ondemand_mode(true); |
| 9431 | factory_->set_require_confirmation(true); |
| 9432 | crypto_client_stream_factory_.set_handshake_mode( |
| 9433 | MockCryptoClientStream::ZERO_RTT); |
| 9434 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9435 | kCachedIPAddress.ToString(), ""); |
| 9436 | |
| 9437 | // Set up the same address in the stale resolver cache. |
| 9438 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9439 | HostCache::Entry entry(OK, |
| 9440 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9441 | HostCache::Entry::SOURCE_DNS); |
| 9442 | base::TimeDelta zero; |
| 9443 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9444 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9445 | // Expire the cache |
| 9446 | cache->OnNetworkChange(); |
| 9447 | |
| 9448 | MockQuicData quic_data; |
| 9449 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9450 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9451 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9452 | |
| 9453 | QuicStreamRequest request(factory_.get()); |
| 9454 | EXPECT_EQ(ERR_IO_PENDING, |
| 9455 | request.Request( |
| 9456 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9457 | SocketTag(), |
| 9458 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9459 | failed_on_default_network_callback_, callback_.callback())); |
| 9460 | |
| 9461 | // Send Crypto handshake so connect will call back. |
| 9462 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9463 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9464 | base::RunLoop().RunUntilIdle(); |
| 9465 | |
| 9466 | // Check that the racing job is running. |
| 9467 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9468 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9469 | |
| 9470 | // Resolve dns and call back, make sure job finishes. |
| 9471 | host_resolver_->ResolveAllPending(); |
| 9472 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9473 | |
| 9474 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9475 | EXPECT_TRUE(stream.get()); |
| 9476 | |
| 9477 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9478 | |
| 9479 | EXPECT_EQ( |
| 9480 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9481 | kCachedIPAddress.ToString()); |
| 9482 | |
| 9483 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9484 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9485 | } |
| 9486 | |
| 9487 | // With dns race experiment on, dns resolve async, stale dns used, dns resolve |
| 9488 | // return, then connection finishes and matches with the result. |
| 9489 | TEST_P(QuicStreamFactoryTest, |
| 9490 | ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9491 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9492 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9493 | Initialize(); |
| 9494 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9495 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9496 | |
| 9497 | // Set an address in resolver for asynchronous return. |
| 9498 | host_resolver_->set_ondemand_mode(true); |
| 9499 | factory_->set_require_confirmation(true); |
| 9500 | crypto_client_stream_factory_.set_handshake_mode( |
| 9501 | MockCryptoClientStream::ZERO_RTT); |
| 9502 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9503 | kCachedIPAddress.ToString(), ""); |
| 9504 | |
| 9505 | // Set up the same address in the stale resolver cache. |
| 9506 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9507 | HostCache::Entry entry(OK, |
| 9508 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9509 | HostCache::Entry::SOURCE_DNS); |
| 9510 | base::TimeDelta zero; |
| 9511 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9512 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9513 | // Expire the cache |
| 9514 | cache->OnNetworkChange(); |
| 9515 | |
| 9516 | MockQuicData quic_data; |
| 9517 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9518 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9519 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9520 | |
| 9521 | QuicStreamRequest request(factory_.get()); |
| 9522 | EXPECT_EQ(ERR_IO_PENDING, |
| 9523 | request.Request( |
| 9524 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9525 | SocketTag(), |
| 9526 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9527 | failed_on_default_network_callback_, callback_.callback())); |
| 9528 | |
| 9529 | // Finish dns async, check we still need to wait for stale connection async. |
| 9530 | host_resolver_->ResolveAllPending(); |
| 9531 | base::RunLoop().RunUntilIdle(); |
| 9532 | EXPECT_FALSE(callback_.have_result()); |
| 9533 | |
| 9534 | // Finish stale connection async, and the stale connection should pass dns |
| 9535 | // validation. |
| 9536 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9537 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9538 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9539 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9540 | EXPECT_TRUE(stream.get()); |
| 9541 | |
| 9542 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9543 | EXPECT_EQ( |
| 9544 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9545 | kCachedIPAddress.ToString()); |
| 9546 | |
| 9547 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9548 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9549 | } |
| 9550 | |
| 9551 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9552 | // sync, but dns no match |
| 9553 | TEST_P(QuicStreamFactoryTest, |
| 9554 | ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9555 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9556 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9557 | Initialize(); |
| 9558 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9559 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9560 | |
| 9561 | // Set an address in resolver for asynchronous return. |
| 9562 | host_resolver_->set_ondemand_mode(true); |
| 9563 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9564 | kNonCachedIPAddress, ""); |
| 9565 | |
| 9566 | // Set up a different address in the stale resolver cache. |
| 9567 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9568 | HostCache::Entry entry(OK, |
| 9569 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9570 | HostCache::Entry::SOURCE_DNS); |
| 9571 | base::TimeDelta zero; |
| 9572 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9573 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9574 | // Expire the cache |
| 9575 | cache->OnNetworkChange(); |
| 9576 | |
| 9577 | // Socket for the stale connection which will invoke connection closure. |
| 9578 | MockQuicData quic_data; |
| 9579 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9580 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9581 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9582 | SYNCHRONOUS, |
| 9583 | client_maker_.MakeConnectionClosePacket( |
| 9584 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9585 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9586 | |
| 9587 | // Socket for the new connection. |
| 9588 | MockQuicData quic_data2; |
| 9589 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9590 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9591 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9592 | |
| 9593 | QuicStreamRequest request(factory_.get()); |
| 9594 | EXPECT_EQ(ERR_IO_PENDING, |
| 9595 | request.Request( |
| 9596 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9597 | SocketTag(), |
| 9598 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9599 | failed_on_default_network_callback_, callback_.callback())); |
| 9600 | |
| 9601 | // Check the stale connection is running. |
| 9602 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9603 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9604 | |
| 9605 | // Finish dns resolution and check the job has finished. |
| 9606 | host_resolver_->ResolveAllPending(); |
| 9607 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9608 | |
| 9609 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9610 | EXPECT_TRUE(stream.get()); |
| 9611 | |
| 9612 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9613 | |
| 9614 | EXPECT_EQ( |
| 9615 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9616 | kNonCachedIPAddress); |
| 9617 | |
| 9618 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9619 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9620 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9621 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9622 | } |
| 9623 | |
| 9624 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9625 | // async, finishes before dns, but no match |
| 9626 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9627 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9628 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9629 | Initialize(); |
| 9630 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9631 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9632 | |
| 9633 | // Set an address in resolver for asynchronous return. |
| 9634 | host_resolver_->set_ondemand_mode(true); |
| 9635 | factory_->set_require_confirmation(true); |
| 9636 | crypto_client_stream_factory_.set_handshake_mode( |
| 9637 | MockCryptoClientStream::ZERO_RTT); |
| 9638 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9639 | kNonCachedIPAddress, ""); |
| 9640 | |
| 9641 | // Set up a different address in the stale resolvercache. |
| 9642 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9643 | HostCache::Entry entry(OK, |
| 9644 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9645 | HostCache::Entry::SOURCE_DNS); |
| 9646 | base::TimeDelta zero; |
| 9647 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9648 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9649 | // Expire the cache |
| 9650 | cache->OnNetworkChange(); |
| 9651 | |
| 9652 | MockQuicData quic_data; |
| 9653 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9654 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9655 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9656 | SYNCHRONOUS, |
| 9657 | client_maker_.MakeConnectionClosePacket( |
| 9658 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9659 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9660 | |
| 9661 | MockQuicData quic_data2; |
| 9662 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9663 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9664 | |
| 9665 | QuicStreamRequest request(factory_.get()); |
| 9666 | EXPECT_EQ(ERR_IO_PENDING, |
| 9667 | request.Request( |
| 9668 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9669 | SocketTag(), |
| 9670 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9671 | failed_on_default_network_callback_, callback_.callback())); |
| 9672 | |
| 9673 | // Finish the stale connection. |
| 9674 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9675 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9676 | base::RunLoop().RunUntilIdle(); |
| 9677 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9678 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9679 | |
| 9680 | // Finish host resolution and check the job is done. |
| 9681 | host_resolver_->ResolveAllPending(); |
| 9682 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9683 | |
| 9684 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9685 | EXPECT_TRUE(stream.get()); |
| 9686 | |
| 9687 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9688 | EXPECT_EQ( |
| 9689 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9690 | kNonCachedIPAddress); |
| 9691 | |
| 9692 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9693 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9694 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9695 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9696 | } |
| 9697 | |
| 9698 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9699 | // async, dns finishes first, but no match |
| 9700 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9701 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9702 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9703 | Initialize(); |
| 9704 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9705 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9706 | |
| 9707 | // Set an address in resolver for asynchronous return. |
| 9708 | host_resolver_->set_ondemand_mode(true); |
| 9709 | factory_->set_require_confirmation(true); |
| 9710 | crypto_client_stream_factory_.set_handshake_mode( |
| 9711 | MockCryptoClientStream::ZERO_RTT); |
| 9712 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9713 | kNonCachedIPAddress, ""); |
| 9714 | |
| 9715 | // Set up a different address in the stale resolver cache. |
| 9716 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9717 | HostCache::Entry entry(OK, |
| 9718 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9719 | HostCache::Entry::SOURCE_DNS); |
| 9720 | base::TimeDelta zero; |
| 9721 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9722 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9723 | // Expire the cache |
| 9724 | cache->OnNetworkChange(); |
| 9725 | |
| 9726 | MockQuicData quic_data; |
| 9727 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9728 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9729 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9730 | SYNCHRONOUS, |
| 9731 | client_maker_.MakeConnectionClosePacket( |
| 9732 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9733 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9734 | |
| 9735 | MockQuicData quic_data2; |
| 9736 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9737 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 9738 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9739 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9740 | |
| 9741 | QuicStreamRequest request(factory_.get()); |
| 9742 | EXPECT_EQ(ERR_IO_PENDING, |
| 9743 | request.Request( |
| 9744 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9745 | SocketTag(), |
| 9746 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9747 | failed_on_default_network_callback_, callback_.callback())); |
| 9748 | // Finish dns resolution, but need to wait for stale connection. |
| 9749 | host_resolver_->ResolveAllPending(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9750 | base::RunLoop().RunUntilIdle(); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9751 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9752 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9753 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9754 | |
| 9755 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9756 | EXPECT_TRUE(stream.get()); |
| 9757 | |
| 9758 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9759 | EXPECT_EQ( |
| 9760 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9761 | kNonCachedIPAddress); |
| 9762 | |
| 9763 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9764 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9765 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9766 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9767 | } |
| 9768 | |
| 9769 | // With dns race experiment on, dns resolve returns error sync, same behavior |
| 9770 | // as experiment is not on |
| 9771 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9772 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9773 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9774 | Initialize(); |
| 9775 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9776 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9777 | |
| 9778 | // Set synchronous failure in resolver. |
| 9779 | host_resolver_->set_synchronous_mode(true); |
| 9780 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9781 | |
| 9782 | MockQuicData quic_data; |
| 9783 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9784 | QuicStreamRequest request(factory_.get()); |
| 9785 | |
| 9786 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 9787 | request.Request( |
| 9788 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9789 | SocketTag(), |
| 9790 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9791 | failed_on_default_network_callback_, callback_.callback())); |
| 9792 | } |
| 9793 | |
| 9794 | // With dns race experiment on, no cache available, dns resolve returns error |
| 9795 | // async |
| 9796 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9797 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9798 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9799 | Initialize(); |
| 9800 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9801 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9802 | |
| 9803 | // Set asynchronous failure in resolver. |
| 9804 | host_resolver_->set_ondemand_mode(true); |
| 9805 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9806 | |
| 9807 | MockQuicData quic_data; |
| 9808 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9809 | QuicStreamRequest request(factory_.get()); |
| 9810 | |
| 9811 | EXPECT_EQ(ERR_IO_PENDING, |
| 9812 | request.Request( |
| 9813 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9814 | SocketTag(), |
| 9815 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9816 | failed_on_default_network_callback_, callback_.callback())); |
| 9817 | |
| 9818 | // Resolve and expect result that shows the resolution error. |
| 9819 | host_resolver_->ResolveAllPending(); |
| 9820 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9821 | } |
| 9822 | |
| 9823 | // With dns race experiment on, dns resolve async, staled used and connects |
| 9824 | // sync, dns returns error and no connection is established. |
| 9825 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9826 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9827 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9828 | Initialize(); |
| 9829 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9830 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9831 | |
| 9832 | // Set asynchronous failure in resolver. |
| 9833 | host_resolver_->set_ondemand_mode(true); |
| 9834 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9835 | |
| 9836 | // Set up an address in the stale cache. |
| 9837 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9838 | HostCache::Entry entry(OK, |
| 9839 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9840 | HostCache::Entry::SOURCE_DNS); |
| 9841 | base::TimeDelta zero; |
| 9842 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9843 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9844 | // Expire the cache |
| 9845 | cache->OnNetworkChange(); |
| 9846 | |
| 9847 | // Socket for the stale connection which is supposed to disconnect. |
| 9848 | MockQuicData quic_data; |
| 9849 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9850 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9851 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9852 | SYNCHRONOUS, |
| 9853 | client_maker_.MakeConnectionClosePacket( |
| 9854 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9855 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9856 | |
| 9857 | QuicStreamRequest request(factory_.get()); |
| 9858 | EXPECT_EQ(ERR_IO_PENDING, |
| 9859 | request.Request( |
| 9860 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9861 | SocketTag(), |
| 9862 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9863 | failed_on_default_network_callback_, callback_.callback())); |
| 9864 | |
| 9865 | // Check that the stale connection is running. |
| 9866 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9867 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9868 | |
| 9869 | // Finish host resolution. |
| 9870 | host_resolver_->ResolveAllPending(); |
| 9871 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9872 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9873 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9874 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9875 | } |
| 9876 | |
| 9877 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9878 | // return error, then dns matches |
| 9879 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9880 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9881 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9882 | Initialize(); |
| 9883 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9884 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9885 | |
| 9886 | // Set an address in host resolver for asynchronous return. |
| 9887 | host_resolver_->set_ondemand_mode(true); |
| 9888 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9889 | kCachedIPAddress.ToString(), ""); |
| 9890 | |
| 9891 | // Set up the same address in the stale resolver cache. |
| 9892 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9893 | HostCache::Entry entry(OK, |
| 9894 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9895 | HostCache::Entry::SOURCE_DNS); |
| 9896 | base::TimeDelta zero; |
| 9897 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9898 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9899 | // Expire the cache |
| 9900 | cache->OnNetworkChange(); |
| 9901 | |
| 9902 | // Simulate synchronous connect failure. |
| 9903 | MockQuicData quic_data; |
| 9904 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9905 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9906 | |
| 9907 | MockQuicData quic_data2; |
| 9908 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9909 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9910 | |
| 9911 | QuicStreamRequest request(factory_.get()); |
| 9912 | EXPECT_EQ(ERR_IO_PENDING, |
| 9913 | request.Request( |
| 9914 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9915 | SocketTag(), |
| 9916 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9917 | failed_on_default_network_callback_, callback_.callback())); |
| 9918 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9919 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9920 | |
| 9921 | host_resolver_->ResolveAllPending(); |
| 9922 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9923 | } |
| 9924 | |
| 9925 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9926 | // returns error, dns no match, new connection is established |
| 9927 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9928 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9929 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9930 | Initialize(); |
| 9931 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9932 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9933 | |
| 9934 | // Set an address in host resolver. |
| 9935 | host_resolver_->set_ondemand_mode(true); |
| 9936 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9937 | kNonCachedIPAddress, ""); |
| 9938 | |
| 9939 | // Set up a different address in stale resolver cache. |
| 9940 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9941 | HostCache::Entry entry(OK, |
| 9942 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9943 | HostCache::Entry::SOURCE_DNS); |
| 9944 | base::TimeDelta zero; |
| 9945 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9946 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9947 | // Expire the cache |
| 9948 | cache->OnNetworkChange(); |
| 9949 | |
| 9950 | // Add failure for the stale connection. |
| 9951 | MockQuicData quic_data; |
| 9952 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9953 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9954 | |
| 9955 | MockQuicData quic_data2; |
| 9956 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9957 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9958 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9959 | |
| 9960 | QuicStreamRequest request(factory_.get()); |
| 9961 | EXPECT_EQ(ERR_IO_PENDING, |
| 9962 | request.Request( |
| 9963 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9964 | SocketTag(), |
| 9965 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9966 | failed_on_default_network_callback_, callback_.callback())); |
| 9967 | |
| 9968 | // Check that the stale connection fails. |
| 9969 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9970 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9971 | |
| 9972 | // Finish host resolution and check the job finishes ok. |
| 9973 | host_resolver_->ResolveAllPending(); |
| 9974 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9975 | |
| 9976 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9977 | EXPECT_TRUE(stream.get()); |
| 9978 | |
| 9979 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9980 | |
| 9981 | EXPECT_EQ( |
| 9982 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9983 | kNonCachedIPAddress); |
| 9984 | |
| 9985 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9986 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9987 | } |
| 9988 | |
| 9989 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9990 | // returns error, dns no match, new connection error |
| 9991 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9992 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9993 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9994 | Initialize(); |
| 9995 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9996 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9997 | |
| 9998 | // Set an address in host resolver asynchronously. |
| 9999 | host_resolver_->set_ondemand_mode(true); |
| 10000 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 10001 | kNonCachedIPAddress, ""); |
| 10002 | |
| 10003 | // Set up a different address in the stale cache. |
| 10004 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 10005 | HostCache::Entry entry(OK, |
| 10006 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 10007 | HostCache::Entry::SOURCE_DNS); |
| 10008 | base::TimeDelta zero; |
| 10009 | HostCache* cache = host_resolver_->GetHostCache(); |
| 10010 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 10011 | // Expire the cache |
| 10012 | cache->OnNetworkChange(); |
| 10013 | |
| 10014 | // Add failure for stale connection. |
| 10015 | MockQuicData quic_data; |
| 10016 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 10017 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 10018 | |
| 10019 | // Add failure for resolved dns connection. |
| 10020 | MockQuicData quic_data2; |
| 10021 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 10022 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 10023 | |
| 10024 | QuicStreamRequest request(factory_.get()); |
| 10025 | EXPECT_EQ(ERR_IO_PENDING, |
| 10026 | request.Request( |
| 10027 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 10028 | SocketTag(), |
| 10029 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10030 | failed_on_default_network_callback_, callback_.callback())); |
| 10031 | |
| 10032 | // Check the stale connection fails. |
| 10033 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 10034 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 10035 | |
| 10036 | // Check the resolved dns connection fails. |
| 10037 | host_resolver_->ResolveAllPending(); |
| 10038 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 10039 | } |
| 10040 | |
| 10041 | // With dns race experiment on, dns resolve async and stale connect async, dns |
| 10042 | // resolve returns error and then preconnect finishes |
| 10043 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 10044 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 10045 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 10046 | Initialize(); |
| 10047 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 10048 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 10049 | |
| 10050 | // Add asynchronous failure in host resolver. |
| 10051 | host_resolver_->set_ondemand_mode(true); |
| 10052 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 10053 | factory_->set_require_confirmation(true); |
| 10054 | crypto_client_stream_factory_.set_handshake_mode( |
| 10055 | MockCryptoClientStream::ZERO_RTT); |
| 10056 | |
| 10057 | // Set up an address in stale resolver cache. |
| 10058 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 10059 | HostCache::Entry entry(OK, |
| 10060 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 10061 | HostCache::Entry::SOURCE_DNS); |
| 10062 | base::TimeDelta zero; |
| 10063 | HostCache* cache = host_resolver_->GetHostCache(); |
| 10064 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 10065 | // Expire the cache |
| 10066 | cache->OnNetworkChange(); |
| 10067 | |
| 10068 | // Socket data for stale connection which is supposed to disconnect. |
| 10069 | MockQuicData quic_data; |
| 10070 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 10071 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 10072 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 10073 | SYNCHRONOUS, |
| 10074 | client_maker_.MakeConnectionClosePacket( |
| 10075 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 10076 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 10077 | |
| 10078 | QuicStreamRequest request(factory_.get()); |
| 10079 | EXPECT_EQ(ERR_IO_PENDING, |
| 10080 | request.Request( |
| 10081 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 10082 | SocketTag(), |
| 10083 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10084 | failed_on_default_network_callback_, callback_.callback())); |
| 10085 | |
| 10086 | // host resolution returned but stale connection hasn't finished yet. |
| 10087 | host_resolver_->ResolveAllPending(); |
| 10088 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 10089 | |
| 10090 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 10091 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 10092 | } |
| 10093 | |
| 10094 | // With dns race experiment on, dns resolve async and stale connect async, dns |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 10095 | // resolve returns error and then preconnect fails. |
| 10096 | TEST_P(QuicStreamFactoryTest, |
| 10097 | ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 10098 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 10099 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 10100 | Initialize(); |
| 10101 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 10102 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 10103 | |
| 10104 | // Add asynchronous failure to host resolver. |
| 10105 | host_resolver_->set_ondemand_mode(true); |
| 10106 | factory_->set_require_confirmation(true); |
| 10107 | crypto_client_stream_factory_.set_handshake_mode( |
| 10108 | MockCryptoClientStream::ZERO_RTT); |
| 10109 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 10110 | |
| 10111 | // Set up an address in stale resolver cache. |
| 10112 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 10113 | HostCache::Entry entry(OK, |
| 10114 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 10115 | HostCache::Entry::SOURCE_DNS); |
| 10116 | base::TimeDelta zero; |
| 10117 | HostCache* cache = host_resolver_->GetHostCache(); |
| 10118 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 10119 | // Expire the cache |
| 10120 | cache->OnNetworkChange(); |
| 10121 | |
| 10122 | MockQuicData quic_data; |
| 10123 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 10124 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 10125 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 10126 | SYNCHRONOUS, |
| 10127 | client_maker_.MakeConnectionClosePacket( |
| 10128 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 10129 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 10130 | |
| 10131 | QuicStreamRequest request(factory_.get()); |
| 10132 | EXPECT_EQ(ERR_IO_PENDING, |
| 10133 | request.Request( |
| 10134 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 10135 | SocketTag(), |
| 10136 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10137 | failed_on_default_network_callback_, callback_.callback())); |
| 10138 | |
| 10139 | // Host Resolution returns failure but stale connection hasn't finished. |
| 10140 | host_resolver_->ResolveAllPending(); |
| 10141 | |
| 10142 | // Check that the final error is on resolution failure. |
| 10143 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 10144 | |
| 10145 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 10146 | } |
| 10147 | |
| 10148 | // With dns race experiment on, test that host resolution callback behaves |
| 10149 | // normal as experiment is not on |
| 10150 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 10151 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 10152 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 10153 | Initialize(); |
| 10154 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 10155 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 10156 | |
| 10157 | host_resolver_->set_ondemand_mode(true); |
| 10158 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 10159 | kNonCachedIPAddress, ""); |
| 10160 | |
| 10161 | MockQuicData quic_data; |
| 10162 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 10163 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 10164 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 10165 | |
| 10166 | QuicStreamRequest request(factory_.get()); |
| 10167 | EXPECT_EQ(ERR_IO_PENDING, |
| 10168 | request.Request( |
| 10169 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 10170 | SocketTag(), |
| 10171 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10172 | failed_on_default_network_callback_, callback_.callback())); |
| 10173 | |
| 10174 | // Check that expect_on_host_resolution_ is properlly set. |
| 10175 | TestCompletionCallback host_resolution_callback; |
| 10176 | EXPECT_TRUE( |
| 10177 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 10178 | base::RunLoop().RunUntilIdle(); |
| 10179 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 10180 | |
| 10181 | host_resolver_->ResolveAllPending(); |
| 10182 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 10183 | |
| 10184 | // Check that expect_on_host_resolution_ is flipped back. |
| 10185 | EXPECT_FALSE( |
| 10186 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 10187 | |
| 10188 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 10189 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 10190 | } |
| 10191 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10192 | // Test that QuicStreamRequests with similar and different tags results in |
| 10193 | // reused and unique QUIC streams using appropriately tagged sockets. |
| 10194 | TEST_P(QuicStreamFactoryTest, Tag) { |
| 10195 | MockTaggingClientSocketFactory* socket_factory = |
| 10196 | new MockTaggingClientSocketFactory(); |
| 10197 | socket_factory_.reset(socket_factory); |
| 10198 | Initialize(); |
| 10199 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 10200 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 10201 | |
| 10202 | // Prepare to establish two QUIC sessions. |
| 10203 | MockQuicData socket_data; |
| 10204 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 10205 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10206 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 10207 | MockQuicData socket_data2; |
| 10208 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 10209 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10210 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 10211 | |
| 10212 | #if defined(OS_ANDROID) |
| 10213 | SocketTag tag1(SocketTag::UNSET_UID, 0x12345678); |
| 10214 | SocketTag tag2(getuid(), 0x87654321); |
| 10215 | #else |
| 10216 | // On non-Android platforms we can only use the default constructor. |
| 10217 | SocketTag tag1, tag2; |
| 10218 | #endif |
| 10219 | |
| 10220 | // Request a stream with |tag1|. |
| 10221 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 10222 | int rv = request1.Request( |
| 10223 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 10224 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10225 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10226 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 10227 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag1); |
| 10228 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 10229 | ->tagged_before_data_transferred()); |
| 10230 | std::unique_ptr<QuicChromiumClientSession::Handle> stream1 = |
| 10231 | request1.ReleaseSessionHandle(); |
| 10232 | EXPECT_TRUE(stream1); |
| 10233 | EXPECT_TRUE(stream1->IsConnected()); |
| 10234 | |
| 10235 | // Request a stream with |tag1| and verify underlying session is reused. |
| 10236 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 10237 | rv = request2.Request( |
| 10238 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 10239 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10240 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10241 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 10242 | std::unique_ptr<QuicChromiumClientSession::Handle> stream2 = |
| 10243 | request2.ReleaseSessionHandle(); |
| 10244 | EXPECT_TRUE(stream2); |
| 10245 | EXPECT_TRUE(stream2->IsConnected()); |
| 10246 | EXPECT_TRUE(stream2->SharesSameSession(*stream1)); |
| 10247 | |
| 10248 | // Request a stream with |tag2| and verify a new session is created. |
| 10249 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 10250 | rv = request3.Request( |
| 10251 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag2, |
| 10252 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10253 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10254 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 10255 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag2); |
| 10256 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 10257 | ->tagged_before_data_transferred()); |
| 10258 | std::unique_ptr<QuicChromiumClientSession::Handle> stream3 = |
| 10259 | request3.ReleaseSessionHandle(); |
| 10260 | EXPECT_TRUE(stream3); |
| 10261 | EXPECT_TRUE(stream3->IsConnected()); |
| 10262 | #if defined(OS_ANDROID) |
| 10263 | EXPECT_FALSE(stream3->SharesSameSession(*stream1)); |
| 10264 | #else |
| 10265 | // Same tag should reuse session. |
| 10266 | EXPECT_TRUE(stream3->SharesSameSession(*stream1)); |
| 10267 | #endif |
| 10268 | } |
| 10269 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 10270 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 10271 | } // namespace net |