[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, |
| 279 | test_params_.quic_max_time_before_crypto_handshake_seconds, |
| 280 | test_params_.quic_max_idle_time_before_crypto_handshake_seconds, |
| 281 | test_params_.quic_migrate_sessions_on_network_change_v2, |
| 282 | test_params_.quic_migrate_sessions_early_v2, |
| 283 | test_params_.quic_retry_on_alternate_network_before_handshake, |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 284 | test_params_.quic_idle_session_migration_period, |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 285 | test_params_.quic_max_time_on_non_default_network, |
| 286 | test_params_.quic_max_migrations_to_non_default_network_on_write_error, |
| 287 | test_params_ |
| 288 | .quic_max_migrations_to_non_default_network_on_path_degrading, |
| 289 | test_params_.quic_allow_server_migration, |
| 290 | test_params_.quic_race_stale_dns_on_connection, |
| 291 | test_params_.quic_go_away_on_path_degrading, |
| 292 | test_params_.quic_race_cert_verification, |
| 293 | test_params_.quic_estimate_initial_rtt, |
| 294 | test_params_.quic_headers_include_h2_stream_dependency, |
| 295 | test_params_.quic_connection_options, |
| 296 | test_params_.quic_client_connection_options, |
| 297 | test_params_.quic_enable_socket_recv_optimization)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 298 | } |
| 299 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 300 | void InitializeConnectionMigrationV2Test( |
| 301 | NetworkChangeNotifier::NetworkList connected_networks) { |
| 302 | scoped_mock_network_change_notifier_.reset( |
| 303 | new ScopedMockNetworkChangeNotifier()); |
| 304 | MockNetworkChangeNotifier* mock_ncn = |
| 305 | scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 306 | mock_ncn->ForceNetworkHandlesSupported(); |
| 307 | mock_ncn->SetConnectedNetworksList(connected_networks); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 308 | test_params_.quic_migrate_sessions_on_network_change_v2 = true; |
| 309 | test_params_.quic_migrate_sessions_early_v2 = true; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 310 | socket_factory_.reset(new TestConnectionMigrationSocketFactory); |
| 311 | Initialize(); |
| 312 | } |
| 313 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 314 | std::unique_ptr<HttpStream> CreateStream(QuicStreamRequest* request) { |
| 315 | std::unique_ptr<QuicChromiumClientSession::Handle> session = |
| 316 | request->ReleaseSessionHandle(); |
| 317 | if (!session || !session->IsConnected()) |
| 318 | return nullptr; |
| 319 | |
| 320 | return std::make_unique<QuicHttpStream>(std::move(session)); |
| 321 | } |
| 322 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 323 | bool HasActiveSession(const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 324 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 325 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 326 | return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 327 | } |
| 328 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 329 | bool HasLiveSession(const HostPortPair& host_port_pair) { |
| 330 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 331 | false); |
| 332 | return QuicStreamFactoryPeer::HasLiveSession(factory_.get(), host_port_pair, |
| 333 | server_id); |
| 334 | } |
| 335 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 336 | bool HasActiveJob(const HostPortPair& host_port_pair, |
| 337 | const PrivacyMode privacy_mode) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 338 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 339 | privacy_mode == PRIVACY_MODE_ENABLED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 340 | return QuicStreamFactoryPeer::HasActiveJob(factory_.get(), server_id); |
| 341 | } |
| 342 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 343 | bool HasActiveCertVerifierJob(const quic::QuicServerId& server_id) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 344 | return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 345 | server_id); |
| 346 | } |
| 347 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 348 | // Get the pending, not activated session, if there is only one session alive. |
| 349 | QuicChromiumClientSession* GetPendingSession( |
| 350 | const HostPortPair& host_port_pair) { |
| 351 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 352 | false); |
| 353 | return QuicStreamFactoryPeer::GetPendingSession(factory_.get(), server_id, |
| 354 | host_port_pair); |
| 355 | } |
| 356 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 357 | QuicChromiumClientSession* GetActiveSession( |
| 358 | const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 359 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 360 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 361 | return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 362 | } |
| 363 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 364 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 365 | return GetSourcePortForNewSessionInner(destination, false); |
| 366 | } |
| 367 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 368 | int GetSourcePortForNewSessionAndGoAway(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 369 | return GetSourcePortForNewSessionInner(destination, true); |
| 370 | } |
| 371 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 372 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 373 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 374 | // Should only be called if there is no active session for this destination. |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 375 | EXPECT_FALSE(HasActiveSession(destination)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 376 | size_t socket_count = socket_factory_->udp_client_socket_ports().size(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 377 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 378 | MockQuicData socket_data; |
| 379 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 380 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 381 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 382 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 383 | QuicStreamRequest request(factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 384 | GURL url("https://" + destination.host() + "/"); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 385 | EXPECT_EQ( |
| 386 | ERR_IO_PENDING, |
| 387 | request.Request( |
| 388 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 389 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 390 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 391 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 392 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 393 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 394 | EXPECT_TRUE(stream.get()); |
| 395 | stream.reset(); |
| 396 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 397 | QuicChromiumClientSession* session = GetActiveSession(destination); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 398 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 399 | if (socket_count + 1 != socket_factory_->udp_client_socket_ports().size()) { |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 400 | ADD_FAILURE(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 404 | if (goaway_received) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 405 | quic::QuicGoAwayFrame goaway(quic::kInvalidControlFrameId, |
| 406 | quic::QUIC_NO_ERROR, 1, ""); |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 407 | session->connection()->OnGoAwayFrame(goaway); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 408 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 409 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 410 | factory_->OnSessionClosed(session); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 411 | EXPECT_FALSE(HasActiveSession(destination)); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 412 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 413 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 414 | return socket_factory_->udp_client_socket_ports()[socket_count]; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 415 | } |
| 416 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 417 | std::unique_ptr<quic::QuicEncryptedPacket> |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 418 | ConstructClientConnectionClosePacket(uint64_t num) { |
Bin Wu | 5311aca | 2018-01-22 01:19:03 | [diff] [blame] | 419 | return client_maker_.MakeConnectionClosePacket( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 420 | num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 421 | } |
| 422 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 423 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 424 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 425 | quic::QuicRstStreamErrorCode error_code) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 426 | quic::QuicStreamId stream_id = |
| 427 | GetNthClientInitiatedBidirectionalStreamId(0); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 428 | return client_maker_.MakeRstPacket(packet_number, true, stream_id, |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 429 | error_code); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 430 | } |
| 431 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 432 | static ProofVerifyDetailsChromium DefaultProofVerifyDetails() { |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 433 | // Load a certificate that is valid for *.example.org |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 434 | scoped_refptr<X509Certificate> test_cert( |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 435 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 436 | EXPECT_TRUE(test_cert.get()); |
| 437 | ProofVerifyDetailsChromium verify_details; |
| 438 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 439 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 440 | return verify_details; |
| 441 | } |
| 442 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 443 | void NotifyIPAddressChanged() { |
| 444 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 445 | // Spin the message loop so the notification is delivered. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 446 | base::RunLoop().RunUntilIdle(); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 447 | } |
| 448 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 449 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 450 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 451 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 452 | bool should_include_version, |
| 453 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 454 | spdy::SpdyHeaderBlock headers = |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 455 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 456 | spdy::SpdyPriority priority = |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 457 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 458 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 459 | return client_maker_.MakeRequestHeadersPacket( |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 460 | packet_number, stream_id, should_include_version, fin, priority, |
Yixin Wang | 7a3f1b8d | 2018-01-17 21:40:48 | [diff] [blame] | 461 | std::move(headers), 0, &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 462 | } |
| 463 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 464 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 465 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 466 | quic::QuicStreamId stream_id, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 467 | quic::QuicStreamId parent_stream_id, |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 468 | bool should_include_version, |
| 469 | bool fin, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 470 | quic::QuicStreamOffset* offset) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 471 | spdy::SpdyHeaderBlock headers = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 472 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 473 | spdy::SpdyPriority priority = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 474 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 475 | size_t spdy_headers_frame_len; |
| 476 | return client_maker_.MakeRequestHeadersPacket( |
| 477 | packet_number, stream_id, should_include_version, fin, priority, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 478 | std::move(headers), parent_stream_id, &spdy_headers_frame_len, offset); |
| 479 | } |
| 480 | |
| 481 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 482 | uint64_t packet_number, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 483 | quic::QuicStreamId stream_id, |
| 484 | bool should_include_version, |
| 485 | bool fin, |
| 486 | quic::QuicStreamOffset* offset) { |
| 487 | return ConstructGetRequestPacket(packet_number, stream_id, |
| 488 | /*parent_stream_id=*/0, |
| 489 | should_include_version, fin, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 490 | } |
| 491 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 492 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 493 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 494 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 495 | bool should_include_version, |
| 496 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 497 | spdy::SpdyHeaderBlock headers = server_maker_.GetResponseHeaders("200 OK"); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 498 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 499 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 500 | packet_number, stream_id, should_include_version, fin, |
| 501 | std::move(headers), &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 502 | } |
| 503 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 504 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket() { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 505 | return client_maker_.MakeInitialSettingsPacket(1, nullptr); |
| 506 | } |
| 507 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 508 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 509 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 510 | quic::QuicStreamOffset* offset) { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 511 | return client_maker_.MakeInitialSettingsPacket(packet_number, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 512 | } |
| 513 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 514 | // Helper method for server migration tests. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 515 | void VerifyServerMigration(const quic::QuicConfig& config, |
bnc | 6a0348c | 2017-05-22 18:56:19 | [diff] [blame] | 516 | IPEndPoint expected_address) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 517 | test_params_.quic_allow_server_migration = true; |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 518 | Initialize(); |
| 519 | |
| 520 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 521 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 522 | crypto_client_stream_factory_.SetConfig(config); |
| 523 | |
| 524 | // Set up first socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 525 | MockQuicData socket_data1; |
| 526 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 527 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 528 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 529 | // Set up second socket data provider that is used after |
| 530 | // migration. |
| 531 | MockQuicData socket_data2; |
| 532 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 533 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 534 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 535 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 536 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 537 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 538 | 3, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 539 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 540 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 541 | |
| 542 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 543 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 544 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 545 | request.Request( |
| 546 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 547 | SocketTag(), |
| 548 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 549 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 550 | EXPECT_EQ(OK, callback_.WaitForResult()); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 551 | |
| 552 | // Run QuicChromiumClientSession::WriteToNewSocket() |
| 553 | // posted by QuicChromiumClientSession::MigrateToSocket(). |
| 554 | base::RunLoop().RunUntilIdle(); |
| 555 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 556 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 557 | EXPECT_TRUE(stream.get()); |
| 558 | |
| 559 | // Cause QUIC stream to be created. |
| 560 | HttpRequestInfo request_info; |
| 561 | request_info.method = "GET"; |
| 562 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 563 | request_info.traffic_annotation = |
| 564 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 565 | EXPECT_EQ(OK, |
| 566 | stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 567 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 568 | // Ensure that session is alive and active. |
| 569 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 570 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 571 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 572 | |
| 573 | IPEndPoint actual_address; |
| 574 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 575 | EXPECT_EQ(actual_address, expected_address); |
| 576 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 577 | << " " << actual_address.port(); |
| 578 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 579 | << " " << expected_address.port(); |
| 580 | |
| 581 | stream.reset(); |
| 582 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 583 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 584 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 585 | } |
| 586 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 587 | // Verifies that the QUIC stream factory is initialized correctly. |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 588 | void VerifyInitialization() { |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 589 | store_server_configs_in_properties_ = true; |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 590 | test_params_.quic_idle_connection_timeout_seconds = 500; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 591 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 592 | factory_->set_require_confirmation(false); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 593 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 594 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 595 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 596 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 597 | MockCryptoClientStream::ZERO_RTT); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 598 | const quic::QuicConfig* config = |
| 599 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
ckrasic | 32b17dcd | 2016-10-31 06:15:35 | [diff] [blame] | 600 | EXPECT_EQ(500, config->IdleNetworkTimeout().ToSeconds()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 601 | |
| 602 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 603 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 604 | const AlternativeService alternative_service1( |
| 605 | kProtoQUIC, host_port_pair_.host(), host_port_pair_.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 606 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 607 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 608 | alternative_service_info_vector.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 609 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 610 | alternative_service1, expiration, {version_})); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 611 | http_server_properties_.SetAlternativeServices( |
| 612 | url::SchemeHostPort(url_), alternative_service_info_vector); |
| 613 | |
| 614 | HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 615 | url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 616 | const AlternativeService alternative_service2( |
| 617 | kProtoQUIC, host_port_pair2.host(), host_port_pair2.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 618 | AlternativeServiceInfoVector alternative_service_info_vector2; |
| 619 | alternative_service_info_vector2.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 620 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 621 | alternative_service2, expiration, {version_})); |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 622 | |
| 623 | http_server_properties_.SetAlternativeServices( |
| 624 | server2, alternative_service_info_vector2); |
| 625 | // Verify that the properties of both QUIC servers are stored in the |
| 626 | // HTTP properties map. |
| 627 | EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 628 | |
| 629 | http_server_properties_.SetMaxServerConfigsStoredInProperties( |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 630 | kDefaultMaxQuicServerEntries); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 631 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 632 | quic::QuicServerId quic_server_id(kDefaultServerHostName, 443, |
| 633 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 634 | std::unique_ptr<QuicServerInfo> quic_server_info = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 635 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 636 | quic_server_id, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 637 | |
| 638 | // Update quic_server_info's server_config and persist it. |
| 639 | QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 640 | // Minimum SCFG that passes config validation checks. |
| 641 | const char scfg[] = {// SCFG |
| 642 | 0x53, 0x43, 0x46, 0x47, |
| 643 | // num entries |
| 644 | 0x01, 0x00, |
| 645 | // padding |
| 646 | 0x00, 0x00, |
| 647 | // EXPY |
| 648 | 0x45, 0x58, 0x50, 0x59, |
| 649 | // EXPY end offset |
| 650 | 0x08, 0x00, 0x00, 0x00, |
| 651 | // Value |
| 652 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 653 | |
| 654 | // Create temporary strings becasue Persist() clears string data in |state|. |
| 655 | string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 656 | string source_address_token("test_source_address_token"); |
| 657 | string cert_sct("test_cert_sct"); |
| 658 | string chlo_hash("test_chlo_hash"); |
| 659 | string signature("test_signature"); |
| 660 | string test_cert("test_cert"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 661 | std::vector<string> certs; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 662 | certs.push_back(test_cert); |
| 663 | state->server_config = server_config; |
| 664 | state->source_address_token = source_address_token; |
| 665 | state->cert_sct = cert_sct; |
| 666 | state->chlo_hash = chlo_hash; |
| 667 | state->server_config_sig = signature; |
| 668 | state->certs = certs; |
| 669 | |
| 670 | quic_server_info->Persist(); |
| 671 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 672 | quic::QuicServerId quic_server_id2(kServer2HostName, 443, |
| 673 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 674 | std::unique_ptr<QuicServerInfo> quic_server_info2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 675 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 676 | quic_server_id2, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 677 | // Update quic_server_info2's server_config and persist it. |
| 678 | QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 679 | |
| 680 | // Minimum SCFG that passes config validation checks. |
| 681 | const char scfg2[] = {// SCFG |
| 682 | 0x53, 0x43, 0x46, 0x47, |
| 683 | // num entries |
| 684 | 0x01, 0x00, |
| 685 | // padding |
| 686 | 0x00, 0x00, |
| 687 | // EXPY |
| 688 | 0x45, 0x58, 0x50, 0x59, |
| 689 | // EXPY end offset |
| 690 | 0x08, 0x00, 0x00, 0x00, |
| 691 | // Value |
| 692 | '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 693 | |
| 694 | // Create temporary strings becasue Persist() clears string data in |
| 695 | // |state2|. |
| 696 | string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 697 | string source_address_token2("test_source_address_token2"); |
| 698 | string cert_sct2("test_cert_sct2"); |
| 699 | string chlo_hash2("test_chlo_hash2"); |
| 700 | string signature2("test_signature2"); |
| 701 | string test_cert2("test_cert2"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 702 | std::vector<string> certs2; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 703 | certs2.push_back(test_cert2); |
| 704 | state2->server_config = server_config2; |
| 705 | state2->source_address_token = source_address_token2; |
| 706 | state2->cert_sct = cert_sct2; |
| 707 | state2->chlo_hash = chlo_hash2; |
| 708 | state2->server_config_sig = signature2; |
| 709 | state2->certs = certs2; |
| 710 | |
| 711 | quic_server_info2->Persist(); |
| 712 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 713 | // Verify the MRU order is maintained. |
| 714 | const QuicServerInfoMap& quic_server_info_map = |
| 715 | http_server_properties_.quic_server_info_map(); |
| 716 | EXPECT_EQ(2u, quic_server_info_map.size()); |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 717 | auto quic_server_info_map_it = quic_server_info_map.begin(); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 718 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 719 | ++quic_server_info_map_it; |
| 720 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 721 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 722 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 723 | "192.168.0.1", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 724 | |
| 725 | // Create a session and verify that the cached state is loaded. |
| 726 | MockQuicData socket_data; |
| 727 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 728 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 729 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 730 | QuicStreamRequest request(factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 731 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 732 | request.Request( |
| 733 | HostPortPair(quic_server_id.host(), quic_server_id.port()), |
| 734 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 735 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 736 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 737 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 738 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 739 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 740 | factory_.get(), quic_server_id)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 741 | quic::QuicCryptoClientConfig* crypto_config = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 742 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 743 | quic::QuicCryptoClientConfig::CachedState* cached = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 744 | crypto_config->LookupOrCreate(quic_server_id); |
| 745 | EXPECT_FALSE(cached->server_config().empty()); |
| 746 | EXPECT_TRUE(cached->GetServerConfig()); |
| 747 | EXPECT_EQ(server_config, cached->server_config()); |
| 748 | EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 749 | EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 750 | EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 751 | EXPECT_EQ(signature, cached->signature()); |
| 752 | ASSERT_EQ(1U, cached->certs().size()); |
| 753 | EXPECT_EQ(test_cert, cached->certs()[0]); |
| 754 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 755 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 756 | |
| 757 | // Create a session and verify that the cached state is loaded. |
| 758 | MockQuicData socket_data2; |
| 759 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 760 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 761 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 762 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 763 | "192.168.0.2", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 764 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 765 | QuicStreamRequest request2(factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 766 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 767 | request2.Request( |
| 768 | HostPortPair(quic_server_id2.host(), quic_server_id2.port()), |
| 769 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 770 | /*cert_verify_flags=*/0, GURL("https://mail.example.org/"), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 771 | net_log_, &net_error_details_, |
| 772 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 773 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 774 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 775 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 776 | factory_.get(), quic_server_id2)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 777 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 778 | crypto_config->LookupOrCreate(quic_server_id2); |
| 779 | EXPECT_FALSE(cached2->server_config().empty()); |
| 780 | EXPECT_TRUE(cached2->GetServerConfig()); |
| 781 | EXPECT_EQ(server_config2, cached2->server_config()); |
| 782 | EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 783 | EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 784 | EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 785 | EXPECT_EQ(signature2, cached2->signature()); |
| 786 | ASSERT_EQ(1U, cached->certs().size()); |
| 787 | EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 788 | } |
| 789 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 790 | void RunTestLoopUntilIdle() { |
| 791 | while (!runner_->GetPostedTasks().empty()) |
| 792 | runner_->RunNextTask(); |
| 793 | } |
| 794 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 795 | quic::QuicStreamId GetNthClientInitiatedBidirectionalStreamId(int n) { |
| 796 | return quic::test::GetNthClientInitiatedBidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 797 | } |
| 798 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 799 | quic::QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(int n) { |
| 800 | return quic::test::GetNthServerInitiatedUnidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 801 | } |
| 802 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 803 | void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } |
| 804 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 805 | // Helper methods for tests of connection migration on write error. |
| 806 | void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 807 | // Migratable stream triggers write error. |
| 808 | void TestMigrationOnWriteErrorMixedStreams(IoMode write_error_mode); |
| 809 | // Non-migratable stream triggers write error. |
| 810 | void TestMigrationOnWriteErrorMixedStreams2(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 811 | void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 812 | void TestMigrationOnWriteError(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 813 | void TestMigrationOnWriteErrorWithMultipleRequests(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 814 | void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 815 | void TestMigrationOnMultipleWriteErrors( |
| 816 | IoMode write_error_mode_on_old_network, |
| 817 | IoMode write_error_mode_on_new_network); |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 818 | void TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 819 | bool disconnected); |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 820 | void TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 821 | void TestMigrationOnNetworkDisconnected(bool async_write_before); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 822 | void TestMigrationOnNetworkMadeDefault(IoMode write_mode); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 823 | void TestMigrationOnPathDegrading(bool async_write_before); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 824 | void TestMigrateSessionWithDrainingStream( |
| 825 | IoMode write_mode_for_queued_packet); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 826 | void TestMigrationOnWriteErrorPauseBeforeConnected(IoMode write_error_mode); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 827 | void TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 828 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 829 | bool disconnect_before_connect); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 830 | void TestNoAlternateNetworkBeforeHandshake(quic::QuicErrorCode error); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 831 | void TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 832 | quic::QuicErrorCode error); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 833 | |
Jana Iyengar | f6b13d8 | 2017-09-04 02:09:10 | [diff] [blame] | 834 | QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 835 | std::unique_ptr<MockHostResolverBase> host_resolver_; |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 836 | std::unique_ptr<SSLConfigService> ssl_config_service_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 837 | std::unique_ptr<MockClientSocketFactory> socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 838 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 839 | quic::test::MockRandom random_generator_; |
| 840 | quic::MockClock clock_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 841 | scoped_refptr<TestTaskRunner> runner_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 842 | const quic::QuicTransportVersion version_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 843 | QuicTestPacketMaker client_maker_; |
| 844 | QuicTestPacketMaker server_maker_; |
rtenneti | ccab42b | 2015-10-09 06:38:16 | [diff] [blame] | 845 | HttpServerPropertiesImpl http_server_properties_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 846 | std::unique_ptr<CertVerifier> cert_verifier_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 847 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 848 | std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
Ryan Sleevi | 8a9c9c1 | 2018-05-09 02:36:23 | [diff] [blame] | 849 | DefaultCTPolicyEnforcer ct_policy_enforcer_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 850 | std::unique_ptr<ScopedMockNetworkChangeNotifier> |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 851 | scoped_mock_network_change_notifier_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 852 | std::unique_ptr<QuicStreamFactory> factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 853 | HostPortPair host_port_pair_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 854 | GURL url_; |
| 855 | GURL url2_; |
| 856 | GURL url3_; |
| 857 | GURL url4_; |
| 858 | |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 859 | PrivacyMode privacy_mode_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 860 | NetLogWithSource net_log_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 861 | TestCompletionCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 862 | const CompletionRepeatingCallback failed_on_default_network_callback_; |
| 863 | bool failed_on_default_network_; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 864 | NetErrorDetails net_error_details_; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 865 | |
| 866 | // Variables to configure QuicStreamFactory. |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 867 | HttpNetworkSession::Params test_params_; |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 868 | bool store_server_configs_in_properties_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 869 | }; |
| 870 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 871 | class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 872 | public ::testing::TestWithParam<TestParams> { |
| 873 | protected: |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 874 | QuicStreamFactoryTest() |
| 875 | : QuicStreamFactoryTestBase( |
| 876 | GetParam().version, |
| 877 | GetParam().client_headers_include_h2_stream_dependency) {} |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 878 | }; |
| 879 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 880 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 881 | QuicStreamFactoryTest, |
| 882 | ::testing::ValuesIn(GetTestParams())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 883 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 884 | TEST_P(QuicStreamFactoryTest, Create) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 885 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 886 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 887 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 888 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 889 | MockQuicData socket_data; |
| 890 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 891 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 892 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 893 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 894 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 895 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 896 | request.Request( |
| 897 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 898 | SocketTag(), |
| 899 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 900 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 901 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 902 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 903 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 904 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 905 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 906 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 907 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 908 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 909 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 910 | DEFAULT_PRIORITY, SocketTag(), |
| 911 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 912 | &net_error_details_, |
| 913 | failed_on_default_network_callback_, |
| 914 | callback_.callback())); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 915 | // Will reset stream 3. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 916 | stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 917 | |
| 918 | EXPECT_TRUE(stream.get()); |
| 919 | |
| 920 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 921 | // in streams on different sessions. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 922 | QuicStreamRequest request3(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 923 | EXPECT_EQ(OK, request3.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 924 | DEFAULT_PRIORITY, SocketTag(), |
| 925 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 926 | &net_error_details_, |
| 927 | failed_on_default_network_callback_, |
| 928 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 929 | stream = CreateStream(&request3); // Will reset stream 5. |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 930 | stream.reset(); // Will reset stream 7. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 931 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 932 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 933 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 934 | } |
| 935 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 936 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 937 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 938 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 939 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 940 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 941 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 942 | MockQuicData socket_data; |
| 943 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 944 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 945 | |
| 946 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 947 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 948 | host_resolver_->set_synchronous_mode(true); |
| 949 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 950 | "192.168.0.1", ""); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 951 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 952 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 953 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 954 | DEFAULT_PRIORITY, SocketTag(), |
| 955 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 956 | &net_error_details_, |
| 957 | failed_on_default_network_callback_, |
| 958 | callback_.callback())); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 959 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 960 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 961 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 962 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 963 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 964 | } |
| 965 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 966 | TEST_P(QuicStreamFactoryTest, DefaultInitialRtt) { |
| 967 | Initialize(); |
| 968 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 969 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 970 | |
| 971 | MockQuicData socket_data; |
| 972 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 973 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 974 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 975 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 976 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 977 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 978 | request.Request( |
| 979 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 980 | SocketTag(), |
| 981 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 982 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 983 | |
| 984 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 985 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 986 | EXPECT_TRUE(stream.get()); |
| 987 | |
| 988 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 989 | EXPECT_TRUE(session->require_confirmation()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 990 | EXPECT_EQ(100000u, session->connection()->GetStats().srtt_us); |
| 991 | ASSERT_FALSE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 992 | } |
| 993 | |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 994 | TEST_P(QuicStreamFactoryTest, FactoryDestroyedWhenJobPending) { |
| 995 | Initialize(); |
| 996 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 997 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 998 | |
| 999 | MockQuicData socket_data; |
| 1000 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1001 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1002 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1003 | |
| 1004 | auto request = std::make_unique<QuicStreamRequest>(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1005 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1006 | request->Request( |
| 1007 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1008 | SocketTag(), |
| 1009 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1010 | failed_on_default_network_callback_, callback_.callback())); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1011 | request.reset(); |
| 1012 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1013 | // Tearing down a QuicStreamFactory with a pending Job should not cause any |
| 1014 | // crash. crbug.com/768343. |
| 1015 | factory_.reset(); |
| 1016 | } |
| 1017 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1018 | TEST_P(QuicStreamFactoryTest, RequireConfirmation) { |
| 1019 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1020 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1021 | host_resolver_->set_synchronous_mode(true); |
| 1022 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1023 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1024 | Initialize(); |
| 1025 | factory_->set_require_confirmation(true); |
| 1026 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1027 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1028 | |
| 1029 | MockQuicData socket_data; |
| 1030 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1031 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1032 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1033 | |
| 1034 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1035 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1036 | request.Request( |
| 1037 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1038 | SocketTag(), |
| 1039 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1040 | failed_on_default_network_callback_, callback_.callback())); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1041 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1042 | IPAddress last_address; |
| 1043 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1044 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1045 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1046 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1047 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1048 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1049 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1050 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1051 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1052 | EXPECT_TRUE(stream.get()); |
| 1053 | |
| 1054 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1055 | EXPECT_TRUE(session->require_confirmation()); |
| 1056 | } |
| 1057 | |
| 1058 | TEST_P(QuicStreamFactoryTest, DontRequireConfirmationFromSameIP) { |
| 1059 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1060 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1061 | host_resolver_->set_synchronous_mode(true); |
| 1062 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1063 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1064 | Initialize(); |
| 1065 | factory_->set_require_confirmation(true); |
| 1066 | http_server_properties_.SetSupportsQuic(IPAddress(192, 0, 2, 33)); |
| 1067 | |
| 1068 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1069 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1070 | |
| 1071 | MockQuicData socket_data; |
| 1072 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1073 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1074 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1075 | |
| 1076 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1077 | EXPECT_THAT(request.Request( |
| 1078 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1079 | SocketTag(), |
| 1080 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1081 | failed_on_default_network_callback_, callback_.callback()), |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1082 | IsOk()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1083 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1084 | IPAddress last_address; |
| 1085 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1086 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1087 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1088 | EXPECT_TRUE(stream.get()); |
| 1089 | |
| 1090 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1091 | EXPECT_FALSE(session->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1092 | |
| 1093 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1094 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1095 | |
| 1096 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1097 | } |
| 1098 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1099 | TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { |
| 1100 | ServerNetworkStats stats; |
| 1101 | stats.srtt = base::TimeDelta::FromMilliseconds(10); |
| 1102 | http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), |
| 1103 | stats); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 1104 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1105 | |
| 1106 | Initialize(); |
| 1107 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1108 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1109 | |
| 1110 | MockQuicData socket_data; |
| 1111 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1112 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1113 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1114 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1115 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1116 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1117 | request.Request( |
| 1118 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1119 | SocketTag(), |
| 1120 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1121 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1122 | |
| 1123 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1124 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1125 | EXPECT_TRUE(stream.get()); |
| 1126 | |
| 1127 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1128 | EXPECT_EQ(10000u, session->connection()->GetStats().srtt_us); |
| 1129 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1130 | EXPECT_EQ(10000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1131 | } |
| 1132 | |
| 1133 | TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { |
| 1134 | ScopedMockNetworkChangeNotifier notifier; |
| 1135 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1136 | NetworkChangeNotifier::CONNECTION_2G); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 1137 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1138 | |
| 1139 | Initialize(); |
| 1140 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1141 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1142 | |
| 1143 | MockQuicData socket_data; |
| 1144 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1145 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1146 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1147 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1148 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1149 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1150 | request.Request( |
| 1151 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1152 | SocketTag(), |
| 1153 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1154 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1155 | |
| 1156 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1157 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1158 | EXPECT_TRUE(stream.get()); |
| 1159 | |
| 1160 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1161 | EXPECT_EQ(1200000u, session->connection()->GetStats().srtt_us); |
| 1162 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1163 | EXPECT_EQ(1200000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1164 | } |
| 1165 | |
| 1166 | TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { |
| 1167 | ScopedMockNetworkChangeNotifier notifier; |
| 1168 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1169 | NetworkChangeNotifier::CONNECTION_3G); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 1170 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1171 | |
| 1172 | Initialize(); |
| 1173 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1174 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1175 | |
| 1176 | MockQuicData socket_data; |
| 1177 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1178 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1179 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1180 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1181 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1182 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1183 | request.Request( |
| 1184 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1185 | SocketTag(), |
| 1186 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1187 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1188 | |
| 1189 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1190 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1191 | EXPECT_TRUE(stream.get()); |
| 1192 | |
| 1193 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1194 | EXPECT_EQ(400000u, session->connection()->GetStats().srtt_us); |
| 1195 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1196 | EXPECT_EQ(400000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1197 | } |
| 1198 | |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1199 | TEST_P(QuicStreamFactoryTest, GoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1200 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1201 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1202 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1203 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1204 | MockQuicData socket_data; |
| 1205 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1206 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1207 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1208 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1209 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1210 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1211 | request.Request( |
| 1212 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1213 | SocketTag(), |
| 1214 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1215 | failed_on_default_network_callback_, callback_.callback())); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1216 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1217 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1218 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1219 | EXPECT_TRUE(stream.get()); |
| 1220 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1221 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1222 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1223 | session->OnGoAway(quic::QuicGoAwayFrame()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1224 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1225 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1226 | |
| 1227 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1228 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1229 | } |
| 1230 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1231 | TEST_P(QuicStreamFactoryTest, GoAwayForConnectionMigrationWithPortOnly) { |
| 1232 | Initialize(); |
| 1233 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1234 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1235 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1236 | MockQuicData socket_data; |
| 1237 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1238 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1239 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1240 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1241 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1242 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1243 | request.Request( |
| 1244 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1245 | SocketTag(), |
| 1246 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1247 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1248 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1249 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1250 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1251 | EXPECT_TRUE(stream.get()); |
| 1252 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1253 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1254 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1255 | session->OnGoAway(quic::QuicGoAwayFrame( |
| 1256 | quic::kInvalidControlFrameId, quic::QUIC_ERROR_MIGRATING_PORT, 0, |
| 1257 | "peer connection migration due to port change only")); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1258 | NetErrorDetails details; |
| 1259 | EXPECT_FALSE(details.quic_port_migration_detected); |
| 1260 | session->PopulateNetErrorDetails(&details); |
| 1261 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1262 | details.quic_port_migration_detected = false; |
| 1263 | stream->PopulateNetErrorDetails(&details); |
| 1264 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1265 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1266 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1267 | |
| 1268 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1269 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1270 | } |
| 1271 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1272 | TEST_P(QuicStreamFactoryTest, Pooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1273 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1274 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1275 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1276 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1277 | MockQuicData socket_data; |
| 1278 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1279 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1280 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1281 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1282 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1283 | host_resolver_->set_synchronous_mode(true); |
| 1284 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1285 | "192.168.0.1", ""); |
| 1286 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1287 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1288 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1289 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1290 | DEFAULT_PRIORITY, SocketTag(), |
| 1291 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1292 | &net_error_details_, |
| 1293 | failed_on_default_network_callback_, |
| 1294 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1295 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1296 | EXPECT_TRUE(stream.get()); |
| 1297 | |
| 1298 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1299 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1300 | EXPECT_EQ(OK, |
| 1301 | request2.Request( |
| 1302 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1303 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1304 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1305 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1306 | EXPECT_TRUE(stream2.get()); |
| 1307 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1308 | EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1309 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1310 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1311 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1312 | } |
| 1313 | |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1314 | TEST_P(QuicStreamFactoryTest, PoolingWithServerMigration) { |
| 1315 | // Set up session to migrate. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1316 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1317 | "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1318 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 443); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1319 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 1320 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1321 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1322 | |
| 1323 | VerifyServerMigration(config, alt_address); |
| 1324 | |
| 1325 | // Close server-migrated session. |
| 1326 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1327 | session->CloseSessionOnError(0u, quic::QUIC_NO_ERROR, |
| 1328 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1329 | |
| 1330 | // Set up server IP, socket, proof, and config for new session. |
| 1331 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1332 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1333 | |
| 1334 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1335 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 1336 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 1337 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 1338 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1339 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1340 | SequencedSocketData socket_data(reads, writes); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1341 | socket_factory_->AddSocketDataProvider(&socket_data); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1342 | |
| 1343 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1344 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1345 | quic::QuicConfig config2; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1346 | crypto_client_stream_factory_.SetConfig(config2); |
| 1347 | |
| 1348 | // Create new request to cause new session creation. |
| 1349 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1350 | QuicStreamRequest request2(factory_.get()); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1351 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1352 | request2.Request( |
| 1353 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1354 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1355 | failed_on_default_network_callback_, callback.callback())); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1356 | EXPECT_EQ(OK, callback.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1357 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1358 | EXPECT_TRUE(stream2.get()); |
| 1359 | |
| 1360 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1361 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1362 | // EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
| 1363 | } |
| 1364 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1365 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1366 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1367 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1368 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1369 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1370 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1371 | MockQuicData socket_data1; |
| 1372 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1373 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1374 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1375 | MockQuicData socket_data2; |
| 1376 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1377 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1378 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1379 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1380 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1381 | host_resolver_->set_synchronous_mode(true); |
| 1382 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1383 | "192.168.0.1", ""); |
| 1384 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1385 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1386 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1387 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1388 | DEFAULT_PRIORITY, SocketTag(), |
| 1389 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1390 | &net_error_details_, |
| 1391 | failed_on_default_network_callback_, |
| 1392 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1393 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1394 | EXPECT_TRUE(stream.get()); |
| 1395 | |
| 1396 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1397 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1398 | EXPECT_EQ(OK, |
| 1399 | request2.Request( |
| 1400 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1401 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1402 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1403 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1404 | EXPECT_TRUE(stream2.get()); |
| 1405 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1406 | factory_->OnSessionGoingAway(GetActiveSession(host_port_pair_)); |
| 1407 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1408 | EXPECT_FALSE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1409 | |
| 1410 | TestCompletionCallback callback3; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1411 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1412 | EXPECT_EQ(OK, |
| 1413 | request3.Request( |
| 1414 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1415 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1416 | failed_on_default_network_callback_, callback3.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1417 | std::unique_ptr<HttpStream> stream3 = CreateStream(&request3); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1418 | EXPECT_TRUE(stream3.get()); |
| 1419 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1420 | EXPECT_TRUE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1421 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1422 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1423 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1424 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1425 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1426 | } |
| 1427 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1428 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1429 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1430 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1431 | MockQuicData socket_data; |
| 1432 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1433 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1434 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1435 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1436 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1437 | HostPortPair server2(kServer2HostName, 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1438 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1439 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1440 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1441 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1442 | host_resolver_->set_synchronous_mode(true); |
| 1443 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1444 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1445 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1446 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1447 | EXPECT_EQ(OK, |
| 1448 | request.Request( |
| 1449 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1450 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1451 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1452 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1453 | EXPECT_TRUE(stream.get()); |
| 1454 | |
| 1455 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1456 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1457 | EXPECT_EQ(OK, |
| 1458 | request2.Request( |
| 1459 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1460 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1461 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1462 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1463 | EXPECT_TRUE(stream2.get()); |
| 1464 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1465 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1466 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1467 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1468 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1469 | } |
| 1470 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1471 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1472 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1473 | MockQuicData socket_data; |
| 1474 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1475 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1476 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1477 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1478 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1479 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1480 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1481 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1482 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1483 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1484 | EXPECT_TRUE(primary_pin.FromString( |
| 1485 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1486 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1487 | verify_details.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1488 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1489 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1490 | host_resolver_->set_synchronous_mode(true); |
| 1491 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1492 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1493 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1494 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1495 | EXPECT_EQ(OK, |
| 1496 | request.Request( |
| 1497 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1498 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1499 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1500 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1501 | EXPECT_TRUE(stream.get()); |
| 1502 | |
| 1503 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1504 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1505 | EXPECT_EQ(OK, |
| 1506 | request2.Request( |
| 1507 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1508 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1509 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1510 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1511 | EXPECT_TRUE(stream2.get()); |
| 1512 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1513 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1514 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1515 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1516 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1520 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1521 | |
| 1522 | MockQuicData socket_data1; |
| 1523 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1524 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1525 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1526 | MockQuicData socket_data2; |
| 1527 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1528 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1529 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1530 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1531 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1532 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1533 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1534 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1535 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1536 | ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1537 | uint8_t bad_pin = 3; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1538 | verify_details1.cert_verify_result.public_key_hashes.push_back( |
| 1539 | test::GetTestHashValue(bad_pin)); |
| 1540 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 1541 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1542 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1543 | EXPECT_TRUE(primary_pin.FromString( |
| 1544 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1545 | ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1546 | verify_details2.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1547 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1548 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1549 | host_resolver_->set_synchronous_mode(true); |
| 1550 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1551 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1552 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1553 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1554 | EXPECT_EQ(OK, |
| 1555 | request.Request( |
| 1556 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1557 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1558 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1559 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1560 | EXPECT_TRUE(stream.get()); |
| 1561 | |
| 1562 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1563 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1564 | EXPECT_EQ(OK, |
| 1565 | request2.Request( |
| 1566 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1567 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1568 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1569 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1570 | EXPECT_TRUE(stream2.get()); |
| 1571 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1572 | EXPECT_NE(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1573 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1574 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1575 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1576 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1577 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1578 | } |
| 1579 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1580 | TEST_P(QuicStreamFactoryTest, Goaway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1581 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1582 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1583 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1584 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1585 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1586 | MockQuicData socket_data; |
| 1587 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1588 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1589 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1590 | MockQuicData socket_data2; |
| 1591 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1592 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1593 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1594 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1595 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1596 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1597 | request.Request( |
| 1598 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1599 | SocketTag(), |
| 1600 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1601 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1602 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1603 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1604 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1605 | EXPECT_TRUE(stream.get()); |
| 1606 | |
| 1607 | // Mark the session as going away. Ensure that while it is still alive |
| 1608 | // that it is no longer active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1609 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1610 | factory_->OnSessionGoingAway(session); |
| 1611 | EXPECT_EQ(true, |
| 1612 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1613 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1614 | |
| 1615 | // Create a new request for the same destination and verify that a |
| 1616 | // new session is created. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1617 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1618 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1619 | request2.Request( |
| 1620 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1621 | SocketTag(), |
| 1622 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1623 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1624 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1625 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1626 | EXPECT_TRUE(stream2.get()); |
| 1627 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1628 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1629 | EXPECT_NE(session, GetActiveSession(host_port_pair_)); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1630 | EXPECT_EQ(true, |
| 1631 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1632 | |
| 1633 | stream2.reset(); |
| 1634 | stream.reset(); |
| 1635 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1636 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1637 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1638 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1639 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1640 | } |
| 1641 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1642 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1643 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1644 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1645 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1646 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1647 | quic::QuicStreamId stream_id = GetNthClientInitiatedBidirectionalStreamId(0); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1648 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1649 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1650 | if (version_ == quic::QUIC_VERSION_99) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1651 | socket_data.AddWrite( |
| 1652 | SYNCHRONOUS, |
| 1653 | client_maker_.MakeStreamIdBlockedPacket( |
| 1654 | 2, true, GetNthClientInitiatedBidirectionalStreamId(49))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1655 | socket_data.AddWrite( |
| 1656 | SYNCHRONOUS, client_maker_.MakeRstPacket(3, true, stream_id, |
| 1657 | quic::QUIC_STREAM_CANCELLED)); |
| 1658 | socket_data.AddRead( |
| 1659 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1660 | quic::QUIC_STREAM_CANCELLED)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1661 | socket_data.AddRead( |
| 1662 | ASYNC, server_maker_.MakeMaxStreamIdPacket( |
| 1663 | 4, true, GetNthClientInitiatedBidirectionalStreamId(50))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1664 | } else { |
| 1665 | socket_data.AddWrite( |
| 1666 | SYNCHRONOUS, client_maker_.MakeRstPacket(2, true, stream_id, |
| 1667 | quic::QUIC_STREAM_CANCELLED)); |
| 1668 | socket_data.AddRead( |
| 1669 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1670 | quic::QUIC_STREAM_CANCELLED)); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1671 | } |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1672 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1673 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1674 | |
| 1675 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1676 | request_info.traffic_annotation = |
| 1677 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1678 | |
xunjieli | 1d2b427 | 2017-04-25 22:37:17 | [diff] [blame] | 1679 | std::vector<std::unique_ptr<HttpStream>> streams; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1680 | // The MockCryptoClientStream sets max_open_streams to be |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1681 | // quic::kDefaultMaxStreamsPerConnection / 2. |
| 1682 | for (size_t i = 0; i < quic::kDefaultMaxStreamsPerConnection / 2; i++) { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1683 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1684 | int rv = request.Request( |
| 1685 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1686 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1687 | failed_on_default_network_callback_, callback_.callback()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1688 | if (i == 0) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1690 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1691 | } else { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1692 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1693 | } |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1694 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1695 | EXPECT_TRUE(stream); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1696 | EXPECT_EQ(OK, |
| 1697 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1698 | net_log_, CompletionOnceCallback())); |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 1699 | streams.push_back(std::move(stream)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1700 | } |
| 1701 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1702 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1703 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1704 | DEFAULT_PRIORITY, SocketTag(), |
| 1705 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1706 | &net_error_details_, |
| 1707 | failed_on_default_network_callback_, |
| 1708 | CompletionOnceCallback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1709 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1710 | EXPECT_TRUE(stream); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1711 | EXPECT_EQ(ERR_IO_PENDING, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1712 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
| 1713 | net_log_, callback_.callback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1714 | |
| 1715 | // Close the first stream. |
| 1716 | streams.front()->Close(false); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1717 | // Trigger exchange of RSTs that in turn allow progress for the last |
| 1718 | // stream. |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1719 | base::RunLoop().RunUntilIdle(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1720 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1721 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1722 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1723 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1724 | |
| 1725 | // Force close of the connection to suppress the generation of RST |
| 1726 | // packets when streams are torn down, which wouldn't be relevant to |
| 1727 | // this test anyway. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1728 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1729 | session->connection()->CloseConnection( |
| 1730 | quic::QUIC_PUBLIC_RESET, "test", |
| 1731 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1732 | } |
| 1733 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1734 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1735 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1736 | MockQuicData socket_data; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1737 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1738 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1739 | host_resolver_->rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1740 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1741 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1742 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1743 | request.Request( |
| 1744 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1745 | SocketTag(), |
| 1746 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1747 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1748 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1749 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1750 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1751 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1752 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1753 | } |
| 1754 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1755 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1756 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1757 | |
| 1758 | MockQuicData socket_data; |
| 1759 | socket_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1760 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1761 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1762 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1763 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1764 | request.Request( |
| 1765 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1766 | SocketTag(), |
| 1767 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1768 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1769 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1770 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1771 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1772 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1773 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1774 | } |
| 1775 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1776 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1777 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1778 | MockQuicData socket_data; |
| 1779 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1780 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1781 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1782 | { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1783 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1784 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1785 | request.Request( |
| 1786 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1787 | SocketTag(), |
| 1788 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1789 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1790 | } |
| 1791 | |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 1792 | base::RunLoop().RunUntilIdle(); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1793 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1794 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 1795 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1796 | DEFAULT_PRIORITY, SocketTag(), |
| 1797 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1798 | &net_error_details_, |
| 1799 | failed_on_default_network_callback_, |
| 1800 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1801 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 1802 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1803 | EXPECT_TRUE(stream.get()); |
| 1804 | stream.reset(); |
| 1805 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1806 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1807 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1808 | } |
| 1809 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1810 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1811 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1812 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1813 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1814 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1815 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1816 | MockQuicData socket_data; |
| 1817 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1818 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1819 | socket_data.AddWrite( |
| 1820 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1821 | socket_data.AddWrite(SYNCHRONOUS, |
| 1822 | client_maker_.MakeConnectionClosePacket( |
| 1823 | 3, true, quic::QUIC_INTERNAL_ERROR, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1824 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1825 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1826 | MockQuicData socket_data2; |
| 1827 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1828 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1829 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1830 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1831 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1832 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1833 | request.Request( |
| 1834 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1835 | SocketTag(), |
| 1836 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1837 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1838 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1839 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1840 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1841 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1842 | request_info.traffic_annotation = |
| 1843 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1844 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1845 | net_log_, CompletionOnceCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1846 | |
| 1847 | // Close the session and verify that stream saw the error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1848 | factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, |
| 1849 | quic::QUIC_INTERNAL_ERROR); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1850 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1851 | stream->ReadResponseHeaders(callback_.callback())); |
| 1852 | |
| 1853 | // Now attempting to request a stream to the same origin should create |
| 1854 | // a new session. |
| 1855 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1856 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1857 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1858 | request2.Request( |
| 1859 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1860 | SocketTag(), |
| 1861 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1862 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1863 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1864 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1865 | stream = CreateStream(&request2); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1866 | stream.reset(); // Will reset stream 3. |
| 1867 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1868 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1869 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1870 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1871 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1872 | } |
| 1873 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1874 | // Regression test for crbug.com/700617. Test a write error during the |
| 1875 | // crypto handshake will not hang QuicStreamFactory::Job and should |
| 1876 | // report QUIC_HANDSHAKE_FAILED to upper layers. Subsequent |
| 1877 | // QuicStreamRequest should succeed without hanging. |
| 1878 | TEST_P(QuicStreamFactoryTest, |
| 1879 | WriteErrorInCryptoConnectWithAsyncHostResolution) { |
| 1880 | Initialize(); |
| 1881 | // Use unmocked crypto stream to do crypto connect. |
| 1882 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1883 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1884 | |
| 1885 | MockQuicData socket_data; |
| 1886 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1887 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1888 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1889 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1890 | |
| 1891 | // Create request, should fail after the write of the CHLO fails. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1892 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1893 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1894 | request.Request( |
| 1895 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1896 | SocketTag(), |
| 1897 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1898 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1899 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 1900 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1901 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1902 | |
| 1903 | // Verify new requests can be sent normally without hanging. |
| 1904 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1905 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1906 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1907 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1908 | MockQuicData socket_data2; |
| 1909 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1910 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1911 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1912 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1913 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1914 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1915 | request2.Request( |
| 1916 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1917 | SocketTag(), |
| 1918 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1919 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1920 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1921 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1922 | // Run the message loop to complete host resolution. |
| 1923 | base::RunLoop().RunUntilIdle(); |
| 1924 | |
| 1925 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 1926 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1927 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1928 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1929 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1930 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1931 | |
| 1932 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1933 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1934 | EXPECT_TRUE(stream.get()); |
| 1935 | stream.reset(); |
| 1936 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1937 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1938 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1939 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1940 | } |
| 1941 | |
| 1942 | TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { |
| 1943 | Initialize(); |
| 1944 | // Use unmocked crypto stream to do crypto connect. |
| 1945 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1946 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1947 | host_resolver_->set_synchronous_mode(true); |
| 1948 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1949 | "192.168.0.1", ""); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1950 | |
| 1951 | MockQuicData socket_data; |
| 1952 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1953 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1954 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1955 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1956 | |
| 1957 | // Create request, should fail immediately. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1958 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1959 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1960 | request.Request( |
| 1961 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1962 | SocketTag(), |
| 1963 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1964 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1965 | // Check no active session, or active jobs left for this server. |
| 1966 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1967 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1968 | |
| 1969 | // Verify new requests can be sent normally without hanging. |
| 1970 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1971 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1972 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1973 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1974 | MockQuicData socket_data2; |
| 1975 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1976 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1977 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1978 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1979 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1980 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1981 | request2.Request( |
| 1982 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1983 | SocketTag(), |
| 1984 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1985 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1986 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1987 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1988 | |
| 1989 | // Complete handshake. |
| 1990 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1991 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1992 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1993 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1994 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1995 | |
| 1996 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1997 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1998 | EXPECT_TRUE(stream.get()); |
| 1999 | stream.reset(); |
| 2000 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2001 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2002 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2003 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2004 | } |
| 2005 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2006 | TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 2007 | test_params_.quic_close_sessions_on_ip_change = true; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2008 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 2009 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2010 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2011 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2012 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2013 | MockQuicData socket_data; |
| 2014 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2015 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2016 | socket_data.AddWrite( |
| 2017 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2018 | socket_data.AddWrite( |
| 2019 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 2020 | 3, true, quic::QUIC_IP_ADDRESS_CHANGED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2021 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2022 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2023 | MockQuicData socket_data2; |
| 2024 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2025 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2026 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2027 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2028 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2029 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2030 | request.Request( |
| 2031 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2032 | SocketTag(), |
| 2033 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2034 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2035 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2036 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2037 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 2038 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2039 | request_info.traffic_annotation = |
| 2040 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2041 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2042 | net_log_, CompletionOnceCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2043 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2044 | // Check an active session exisits for the destination. |
| 2045 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2046 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2047 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2048 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2049 | IPAddress last_address; |
| 2050 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2051 | // Change the IP address and verify that stream saw the error and the active |
| 2052 | // session is closed. |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2053 | NotifyIPAddressChanged(); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2054 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 2055 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2056 | EXPECT_TRUE(factory_->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2057 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2058 | // Check no active session exists for the destination. |
| 2059 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2060 | |
| 2061 | // Now attempting to request a stream to the same origin should create |
| 2062 | // a new session. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2063 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2064 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2065 | request2.Request( |
| 2066 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2067 | SocketTag(), |
| 2068 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2069 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2070 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2071 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2072 | stream = CreateStream(&request2); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2073 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2074 | // Check a new active session exisits for the destination and the old session |
| 2075 | // is no longer live. |
| 2076 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2077 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2078 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2079 | |
| 2080 | stream.reset(); // Will reset stream 3. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2081 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2082 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2083 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2084 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2085 | } |
| 2086 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2087 | // Test that if goaway_session_on_ip_change is set, old sessions will be marked |
| 2088 | // as going away on IP address change instead of being closed. New requests will |
| 2089 | // go to a new connection. |
| 2090 | TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 2091 | test_params_.quic_goaway_sessions_on_ip_change = true; |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2092 | Initialize(); |
| 2093 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2094 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2095 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2096 | |
| 2097 | MockQuicData quic_data1; |
| 2098 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2099 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2100 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2101 | quic_data1.AddWrite( |
| 2102 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2103 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2104 | true, &header_stream_offset)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2105 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2106 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2107 | ASYNC, |
| 2108 | ConstructOkResponsePacket( |
| 2109 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2110 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2111 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2112 | |
| 2113 | MockQuicData quic_data2; |
| 2114 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 2115 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2116 | quic_data2.AddWrite( |
| 2117 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 2118 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2119 | |
| 2120 | // Create request and QuicHttpStream. |
| 2121 | QuicStreamRequest request(factory_.get()); |
| 2122 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2123 | request.Request( |
| 2124 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2125 | SocketTag(), |
| 2126 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2127 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2128 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2129 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2130 | EXPECT_TRUE(stream.get()); |
| 2131 | |
| 2132 | // Cause QUIC stream to be created. |
| 2133 | HttpRequestInfo request_info; |
| 2134 | request_info.method = "GET"; |
| 2135 | request_info.url = url_; |
| 2136 | request_info.traffic_annotation = |
| 2137 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2138 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2139 | net_log_, CompletionOnceCallback())); |
| 2140 | |
| 2141 | // Ensure that session is alive and active. |
| 2142 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2143 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2144 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2145 | |
| 2146 | // Send GET request on stream. |
| 2147 | HttpResponseInfo response; |
| 2148 | HttpRequestHeaders request_headers; |
| 2149 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2150 | callback_.callback())); |
| 2151 | |
| 2152 | // Receive an IP address change notification. |
| 2153 | NotifyIPAddressChanged(); |
| 2154 | |
| 2155 | // The connection should still be alive, but marked as going away. |
| 2156 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2157 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2158 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2159 | |
| 2160 | // Resume the data, response should be read from the original connection. |
| 2161 | quic_data1.Resume(); |
| 2162 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2163 | EXPECT_EQ(200, response.headers->response_code()); |
| 2164 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2165 | |
| 2166 | // Second request should be sent on a new connection. |
| 2167 | QuicStreamRequest request2(factory_.get()); |
| 2168 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2169 | request2.Request( |
| 2170 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2171 | SocketTag(), |
| 2172 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2173 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2174 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2175 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 2176 | EXPECT_TRUE(stream2.get()); |
| 2177 | |
| 2178 | // Check an active session exisits for the destination. |
| 2179 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2180 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2181 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2182 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2183 | |
| 2184 | stream.reset(); |
| 2185 | stream2.reset(); |
| 2186 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2187 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2188 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2189 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2190 | } |
| 2191 | |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2192 | TEST_P(QuicStreamFactoryTest, OnIPAddressChangedWithConnectionMigration) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 2193 | InitializeConnectionMigrationV2Test( |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2194 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2195 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2196 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2197 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2198 | |
| 2199 | MockQuicData socket_data; |
| 2200 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2201 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2202 | socket_data.AddWrite( |
| 2203 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2204 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2205 | |
| 2206 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2207 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2208 | request.Request( |
| 2209 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2210 | SocketTag(), |
| 2211 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2212 | failed_on_default_network_callback_, callback_.callback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2213 | |
| 2214 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2215 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2216 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2217 | request_info.traffic_annotation = |
| 2218 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2219 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2220 | net_log_, CompletionOnceCallback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2221 | |
| 2222 | IPAddress last_address; |
| 2223 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2224 | |
| 2225 | // Change the IP address and verify that the connection is unaffected. |
| 2226 | NotifyIPAddressChanged(); |
| 2227 | EXPECT_FALSE(factory_->require_confirmation()); |
| 2228 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2229 | |
| 2230 | // Attempting a new request to the same origin uses the same connection. |
| 2231 | QuicStreamRequest request2(factory_.get()); |
| 2232 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2233 | DEFAULT_PRIORITY, SocketTag(), |
| 2234 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2235 | &net_error_details_, |
| 2236 | failed_on_default_network_callback_, |
| 2237 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2238 | stream = CreateStream(&request2); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2239 | |
| 2240 | stream.reset(); |
| 2241 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2242 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2243 | } |
| 2244 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2245 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithSynchronousWrite) { |
| 2246 | TestMigrationOnNetworkMadeDefault(SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2247 | } |
| 2248 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2249 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithAsyncWrite) { |
| 2250 | TestMigrationOnNetworkMadeDefault(ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2251 | } |
| 2252 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2253 | // Sets up a test which attempts connection migration successfully after probing |
| 2254 | // when a new network is made as default and the old default is still available. |
| 2255 | // |write_mode| specifies the write mode for the last write before |
| 2256 | // OnNetworkMadeDefault is delivered to session. |
| 2257 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkMadeDefault( |
| 2258 | IoMode write_mode) { |
| 2259 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2260 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2261 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2262 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2263 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2264 | // Using a testing task runner so that we can control time. |
| 2265 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2266 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2267 | |
| 2268 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2269 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2270 | |
| 2271 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2272 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2273 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2274 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2275 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2276 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2277 | write_mode, ConstructGetRequestPacket( |
| 2278 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2279 | true, &header_stream_offset)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2280 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2281 | |
| 2282 | // Set up the second socket data provider that is used after migration. |
| 2283 | // The response to the earlier request is read on the new socket. |
| 2284 | MockQuicData quic_data2; |
| 2285 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2286 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2287 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2288 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2289 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2290 | quic_data2.AddRead(ASYNC, |
| 2291 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2292 | // Ping packet to send after migration is completed. |
| 2293 | quic_data2.AddWrite(ASYNC, |
| 2294 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2295 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2296 | ASYNC, |
| 2297 | ConstructOkResponsePacket( |
| 2298 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2299 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2300 | quic_data2.AddWrite( |
| 2301 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2302 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2303 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2304 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2305 | |
| 2306 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2307 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2308 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2309 | request.Request( |
| 2310 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2311 | SocketTag(), |
| 2312 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2313 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2314 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2315 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2316 | EXPECT_TRUE(stream.get()); |
| 2317 | |
| 2318 | // Cause QUIC stream to be created. |
| 2319 | HttpRequestInfo request_info; |
| 2320 | request_info.method = "GET"; |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 2321 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2322 | request_info.traffic_annotation = |
| 2323 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2324 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2325 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2326 | |
| 2327 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2328 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2329 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2330 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2331 | |
| 2332 | // Send GET request on stream. |
| 2333 | HttpResponseInfo response; |
| 2334 | HttpRequestHeaders request_headers; |
| 2335 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2336 | callback_.callback())); |
| 2337 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2338 | // Deliver a signal that a alternate network is connected now, this should |
| 2339 | // cause the connection to start early migration on path degrading. |
| 2340 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2341 | ->SetConnectedNetworksList( |
| 2342 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2343 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2344 | ->NotifyNetworkConnected(kNewNetworkForTests); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2345 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2346 | // Cause the connection to report path degrading to the session. |
| 2347 | // Due to lack of alternate network, session will not mgirate connection. |
| 2348 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2349 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2350 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2351 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2352 | // A task will be posted to migrate to the new default network. |
| 2353 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2354 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2355 | |
| 2356 | // Execute the posted task to migrate back to the default network. |
| 2357 | task_runner->RunUntilIdle(); |
| 2358 | // Another task to try send a new connectivity probe is posted. And a task to |
| 2359 | // retry migrate back to default network is scheduled. |
| 2360 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2361 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2362 | // kDefaultRTTMilliSecs. |
| 2363 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2364 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2365 | next_task_delay); |
| 2366 | |
| 2367 | // The connection should still be alive, and not marked as going away. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2368 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2369 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2370 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2371 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2372 | |
| 2373 | // Resume quic data and a connectivity probe response will be read on the new |
| 2374 | // socket, declare probing as successful. And a new task to WriteToNewSocket |
| 2375 | // will be posted to complete migration. |
| 2376 | quic_data2.Resume(); |
| 2377 | |
| 2378 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2379 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2380 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2381 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2382 | // There should be three pending tasks, the nearest one will complete |
| 2383 | // migration to the new network. |
| 2384 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2385 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2386 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 2387 | task_runner->FastForwardBy(next_task_delay); |
| 2388 | |
| 2389 | // Response headers are received over the new network. |
| 2390 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2391 | EXPECT_EQ(200, response.headers->response_code()); |
| 2392 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2393 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 2394 | // probe and has been cancelled due to successful migration. |
| 2395 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2396 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2397 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2398 | next_task_delay); |
| 2399 | task_runner->FastForwardBy(next_task_delay); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2400 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2401 | // There's one more task to mgirate back to the default network in 0.4s, which |
| 2402 | // is also cancelled due to the success migration on the previous trial. |
| 2403 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2404 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2405 | base::TimeDelta expected_delay = |
| 2406 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2407 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2408 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2409 | task_runner->FastForwardBy(next_task_delay); |
| 2410 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2411 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2412 | // Verify that the session is still alive. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2413 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2414 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2415 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2416 | stream.reset(); |
| 2417 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2418 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2419 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2420 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2421 | } |
| 2422 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2423 | // Regression test for http://859674. |
| 2424 | // This test veries that a writer will not attempt to write packets until being |
| 2425 | // unblocked on both socket level and network level. In this test, a probing |
| 2426 | // writer is used to send two connectivity probes to the peer: where the first |
| 2427 | // one completes successfully, while a connectivity response is received before |
| 2428 | // completes sending the second one. The connection migration attempt will |
| 2429 | // proceed while the probing writer is blocked at the socket level, which will |
| 2430 | // block the writer on the network level. Once connection migration completes |
| 2431 | // successfully, the probing writer will be unblocked on the network level, it |
| 2432 | // will not attempt to write new packets until the socket level is unblocked. |
| 2433 | TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { |
| 2434 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 2435 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2436 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2437 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2438 | |
| 2439 | // Using a testing task runner so that we can control time. |
| 2440 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2441 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2442 | |
| 2443 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2444 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2445 | |
| 2446 | MockQuicData quic_data1; |
| 2447 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2448 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2449 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2450 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2451 | quic_data1.AddWrite( |
| 2452 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2453 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2454 | true, &header_stream_offset)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2455 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2456 | |
| 2457 | // Set up the second socket data provider that is used after migration. |
| 2458 | // The response to the earlier request is read on the new socket. |
| 2459 | MockQuicData quic_data2; |
| 2460 | // First connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2461 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2462 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2463 | quic_data2.AddRead(ASYNC, |
| 2464 | ERR_IO_PENDING); // Pause so that we can control time. |
| 2465 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2466 | quic_data2.AddRead(ASYNC, |
| 2467 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2468 | // Second connectivity probe which will complete asynchronously. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2469 | quic_data2.AddWrite(ASYNC, |
| 2470 | client_maker_.MakeConnectivityProbingPacket(4, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2471 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2472 | ASYNC, |
| 2473 | ConstructOkResponsePacket( |
| 2474 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2475 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2476 | quic_data2.AddWrite(ASYNC, |
| 2477 | client_maker_.MakeAckAndPingPacket(5, false, 1, 1, 1)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2478 | quic_data2.AddWrite( |
| 2479 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2480 | 6, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2481 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2482 | |
| 2483 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2484 | |
| 2485 | // Create request and QuicHttpStream. |
| 2486 | QuicStreamRequest request(factory_.get()); |
| 2487 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2488 | request.Request( |
| 2489 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2490 | SocketTag(), |
| 2491 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2492 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2493 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2494 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2495 | EXPECT_TRUE(stream.get()); |
| 2496 | |
| 2497 | // Cause QUIC stream to be created. |
| 2498 | HttpRequestInfo request_info; |
| 2499 | request_info.method = "GET"; |
| 2500 | request_info.url = url_; |
| 2501 | request_info.traffic_annotation = |
| 2502 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2503 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2504 | net_log_, CompletionOnceCallback())); |
| 2505 | |
| 2506 | // Ensure that session is alive and active. |
| 2507 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2508 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2509 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2510 | |
| 2511 | // Send GET request on stream. |
| 2512 | HttpResponseInfo response; |
| 2513 | HttpRequestHeaders request_headers; |
| 2514 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2515 | callback_.callback())); |
| 2516 | |
| 2517 | // Deliver a signal that a alternate network is connected now, this should |
| 2518 | // cause the connection to start early migration on path degrading. |
| 2519 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2520 | ->SetConnectedNetworksList( |
| 2521 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2522 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2523 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 2524 | |
| 2525 | // Cause the connection to report path degrading to the session. |
| 2526 | // Due to lack of alternate network, session will not mgirate connection. |
| 2527 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2528 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2529 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2530 | |
| 2531 | // A task will be posted to migrate to the new default network. |
| 2532 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2533 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2534 | |
| 2535 | // Execute the posted task to migrate back to the default network. |
| 2536 | task_runner->RunUntilIdle(); |
| 2537 | // Another task to resend a new connectivity probe is posted. And a task to |
| 2538 | // retry migrate back to default network is scheduled. |
| 2539 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2540 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2541 | // kDefaultRTTMilliSecs. |
| 2542 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2543 | base::TimeDelta expected_delay = |
| 2544 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2545 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2546 | |
| 2547 | // Fast forward to send the second connectivity probe. The write will be |
| 2548 | // asynchronous and complete after the read completes. |
| 2549 | task_runner->FastForwardBy(next_task_delay); |
| 2550 | |
| 2551 | // Resume quic data and a connectivity probe response will be read on the new |
| 2552 | // socket, declare probing as successful. |
| 2553 | quic_data2.Resume(); |
| 2554 | |
| 2555 | // The connection should still be alive, and not marked as going away. |
| 2556 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2557 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2558 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2559 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2560 | |
| 2561 | // There should be three pending tasks, the nearest one will complete |
| 2562 | // migration to the new network. Second task will retry migrate back to |
| 2563 | // default but cancelled, and the third task will retry send connectivity |
| 2564 | // probe but also cancelled. |
| 2565 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2566 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2567 | task_runner->RunUntilIdle(); |
| 2568 | |
| 2569 | // Response headers are received over the new network. |
| 2570 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2571 | EXPECT_EQ(200, response.headers->response_code()); |
| 2572 | |
| 2573 | // Run the message loop to complete the asynchronous write of ack and ping. |
| 2574 | base::RunLoop().RunUntilIdle(); |
| 2575 | |
| 2576 | // Now there are two pending tasks, the nearest one was to retry migrate back |
| 2577 | // to default network and has been cancelled due to successful migration. |
| 2578 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2579 | expected_delay = |
| 2580 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2581 | expected_delay; |
| 2582 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2583 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2584 | task_runner->FastForwardBy(next_task_delay); |
| 2585 | |
| 2586 | // There's one more task to retry sending connectivity probe in 0.4s and has |
| 2587 | // also been cancelled due to the successful probing. |
| 2588 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2589 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2590 | expected_delay = |
| 2591 | base::TimeDelta::FromMilliseconds(3 * 2 * kDefaultRTTMilliSecs) - |
| 2592 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 2593 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2594 | task_runner->FastForwardBy(next_task_delay); |
| 2595 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2596 | |
| 2597 | // Verify that the session is still alive. |
| 2598 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2599 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2600 | |
| 2601 | stream.reset(); |
| 2602 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2603 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2604 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2605 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2606 | } |
| 2607 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2608 | // This test verifies that session times out connection migration attempt |
| 2609 | // with signals delivered in the following order (no alternate network is |
| 2610 | // available): |
| 2611 | // - default network disconnected is delivered: session attempts connection |
| 2612 | // migration but found not alternate network. Session waits for a new network |
| 2613 | // comes up in the next kWaitTimeForNewNetworkSecs seonds. |
| 2614 | // - no new network is connected, migration times out. Session is closed. |
| 2615 | TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { |
| 2616 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2617 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2618 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2619 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2620 | // Using a testing task runner so that we can control time. |
| 2621 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2622 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2623 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2624 | MockQuicData socket_data; |
| 2625 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2626 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2627 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2628 | |
| 2629 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2630 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2631 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2632 | request.Request( |
| 2633 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2634 | SocketTag(), |
| 2635 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2636 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2637 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2638 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2639 | EXPECT_TRUE(stream.get()); |
| 2640 | |
| 2641 | // Cause QUIC stream to be created. |
| 2642 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2643 | request_info.traffic_annotation = |
| 2644 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2645 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2646 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2647 | |
| 2648 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2649 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2650 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2651 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2652 | |
| 2653 | // Trigger connection migration. Since there are no networks |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2654 | // to migrate to, this should cause the session to wait for a new network. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2655 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2656 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2657 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2658 | // The migration will not fail until the migration alarm timeout. |
| 2659 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2660 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2661 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2662 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2663 | EXPECT_EQ(true, session->connection()->writer()->IsWriteBlocked()); |
| 2664 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2665 | // Migration will be timed out after kWaitTimeForNewNetwokSecs. |
| 2666 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2667 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2668 | EXPECT_EQ(base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs), |
| 2669 | next_task_delay); |
| 2670 | task_runner->FastForwardBy(next_task_delay); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2671 | |
| 2672 | // The connection should now be closed. A request for response |
| 2673 | // headers should fail. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2674 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2675 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2676 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2677 | |
| 2678 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2679 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2680 | } |
| 2681 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2682 | // This test verifies that connectivity probes will be sent even if there is |
| 2683 | // a non-migratable stream. However, when connection migrates to the |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2684 | // successfully probed path, any non-migratable streams will be reset. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2685 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2686 | InitializeConnectionMigrationV2Test( |
| 2687 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2688 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2689 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2690 | |
| 2691 | MockQuicData socket_data; |
| 2692 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2693 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2694 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2695 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2696 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2697 | // Set up the second socket data provider that is used for probing. |
| 2698 | MockQuicData quic_data1; |
| 2699 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2700 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2701 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2702 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2703 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2704 | quic_data1.AddRead(ASYNC, |
| 2705 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2706 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2707 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 2708 | quic_data1.AddWrite( |
| 2709 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2710 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2711 | quic::QUIC_STREAM_CANCELLED)); |
| 2712 | // Ping packet to send after migration is completed. |
| 2713 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2714 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2715 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2716 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2717 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2718 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2719 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2720 | request.Request( |
| 2721 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2722 | SocketTag(), |
| 2723 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2724 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2725 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2726 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2727 | EXPECT_TRUE(stream.get()); |
| 2728 | |
| 2729 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2730 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2731 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2732 | request_info.traffic_annotation = |
| 2733 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2734 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2735 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2736 | |
| 2737 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2738 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2739 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2740 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2741 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2742 | // Trigger connection migration. Session will start to probe the alternative |
| 2743 | // network. Although there is a non-migratable stream, session will still be |
| 2744 | // active until probing is declared as successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2745 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2746 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2747 | |
| 2748 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2749 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2750 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2751 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2752 | // Resume data to read a connectivity probing response, which will cause |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2753 | // non-migtable streams to be closed. |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2754 | quic_data1.Resume(); |
| 2755 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2756 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2757 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2758 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2759 | base::RunLoop().RunUntilIdle(); |
| 2760 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2761 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2762 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2763 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2764 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2765 | } |
| 2766 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2767 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2768 | InitializeConnectionMigrationV2Test( |
| 2769 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2770 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2771 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2772 | |
| 2773 | MockQuicData socket_data; |
| 2774 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2775 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2776 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2777 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2778 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2779 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2780 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2781 | |
| 2782 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2783 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2784 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2785 | request.Request( |
| 2786 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2787 | SocketTag(), |
| 2788 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2789 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2790 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2791 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2792 | EXPECT_TRUE(stream.get()); |
| 2793 | |
| 2794 | // Cause QUIC stream to be created. |
| 2795 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2796 | request_info.traffic_annotation = |
| 2797 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2798 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2799 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2800 | |
| 2801 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2802 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2803 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2804 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2805 | |
| 2806 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2807 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2808 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2809 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2810 | |
| 2811 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2812 | // this should cause session to continue but be marked as going away. |
| 2813 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2814 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2815 | |
| 2816 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2817 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2818 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2819 | |
| 2820 | stream.reset(); |
| 2821 | |
| 2822 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2823 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2824 | } |
| 2825 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2826 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2827 | InitializeConnectionMigrationV2Test( |
| 2828 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2829 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2830 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2831 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2832 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2833 | MockQuicData failed_socket_data; |
| 2834 | failed_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2835 | failed_socket_data.AddWrite( |
| 2836 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2837 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 2838 | failed_socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2839 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2840 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2841 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2842 | failed_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2843 | |
| 2844 | // Set up second socket data provider that is used after migration. |
| 2845 | MockQuicData socket_data; |
| 2846 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2847 | // Ping packet to send after migration. |
| 2848 | socket_data.AddWrite( |
| 2849 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2850 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2851 | |
| 2852 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2853 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2854 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2855 | request.Request( |
| 2856 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2857 | SocketTag(), |
| 2858 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2859 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2860 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2861 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2862 | EXPECT_TRUE(stream.get()); |
| 2863 | |
| 2864 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2865 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2866 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2867 | request_info.traffic_annotation = |
| 2868 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2869 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2870 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2871 | |
| 2872 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2873 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2874 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2875 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2876 | |
| 2877 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2878 | // this should cause a RST_STREAM frame to be emitted with |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2879 | // quic::QUIC_STREAM_CANCELLED error code. |
| 2880 | // The connection will then be migrated to the alternate network. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2881 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2882 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2883 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2884 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2885 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2886 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2887 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2888 | base::RunLoop().RunUntilIdle(); |
| 2889 | |
| 2890 | EXPECT_TRUE(failed_socket_data.AllReadDataConsumed()); |
| 2891 | EXPECT_TRUE(failed_socket_data.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2892 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2893 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2894 | } |
| 2895 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2896 | TEST_P(QuicStreamFactoryTest, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2897 | OnNetworkDisconnectedConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2898 | InitializeConnectionMigrationV2Test( |
| 2899 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2900 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2901 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2902 | |
| 2903 | MockQuicData socket_data; |
| 2904 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2905 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2906 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2907 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2908 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2909 | quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2910 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2911 | |
| 2912 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2913 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2914 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2915 | request.Request( |
| 2916 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2917 | SocketTag(), |
| 2918 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2919 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2920 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2921 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2922 | EXPECT_TRUE(stream.get()); |
| 2923 | |
| 2924 | // Cause QUIC stream to be created. |
| 2925 | HttpRequestInfo request_info; |
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 | 9c54157 | 2016-03-29 17:51:48 | [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 | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2933 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2934 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2935 | |
| 2936 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2937 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2938 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2939 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2940 | |
| 2941 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2942 | // this should cause a RST_STREAM frame to be emitted with |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2943 | // quic::QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2944 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2945 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2946 | |
| 2947 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2948 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2949 | |
| 2950 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2951 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2952 | } |
| 2953 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2954 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2955 | InitializeConnectionMigrationV2Test( |
| 2956 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2957 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2958 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2959 | |
| 2960 | MockQuicData socket_data; |
| 2961 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2962 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2963 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2964 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2965 | // Set up the second socket data provider that is used for probing. |
| 2966 | MockQuicData quic_data1; |
| 2967 | // Connectivity probe to be sent on the new path. |
| 2968 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2969 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
| 2970 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2971 | // Connectivity probe to receive from the server. |
| 2972 | quic_data1.AddRead(ASYNC, |
| 2973 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 2974 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2975 | // Ping packet to send after migration is completed. |
| 2976 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2977 | client_maker_.MakeAckAndPingPacket(3, false, 1, 1, 1)); |
| 2978 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2979 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2980 | // Create request and QuicHttpStream. |
| 2981 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2982 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2983 | request.Request( |
| 2984 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2985 | SocketTag(), |
| 2986 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2987 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2988 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2989 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2990 | EXPECT_TRUE(stream.get()); |
| 2991 | |
| 2992 | // Ensure that session is alive and active. |
| 2993 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2994 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2995 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 2996 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2997 | EXPECT_EQ(0u, session->GetNumDrainingStreams()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2998 | |
| 2999 | // Trigger connection migration. |
| 3000 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3001 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3002 | // Verify that the session is still active. |
| 3003 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3004 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3005 | quic_data1.Resume(); |
| 3006 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3007 | |
| 3008 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3009 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3010 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3011 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3012 | } |
| 3013 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 3014 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3015 | InitializeConnectionMigrationV2Test( |
| 3016 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3017 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3018 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3019 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3020 | MockQuicData default_socket_data; |
| 3021 | default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3022 | default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 3023 | default_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3024 | |
| 3025 | // Set up second socket data provider that is used after migration. |
| 3026 | MockQuicData alternate_socket_data; |
| 3027 | alternate_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3028 | // Ping packet to send after migration. |
| 3029 | alternate_socket_data.AddWrite( |
| 3030 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 3031 | alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3032 | |
| 3033 | // Create request and QuicHttpStream. |
| 3034 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3035 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3036 | request.Request( |
| 3037 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3038 | SocketTag(), |
| 3039 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3040 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3041 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3042 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3043 | EXPECT_TRUE(stream.get()); |
| 3044 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3045 | // Ensure that session is active. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3046 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3047 | |
| 3048 | // Trigger connection migration. Since there are no active streams, |
| 3049 | // the session will be closed. |
| 3050 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3051 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3052 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3053 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3054 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 3055 | EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); |
| 3056 | EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); |
| 3057 | EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); |
| 3058 | EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3059 | } |
| 3060 | |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3061 | // This test verifies session migrates to the alternate network immediately when |
| 3062 | // default network disconnects with a synchronous write before migration. |
| 3063 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedSync) { |
| 3064 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ false); |
| 3065 | } |
| 3066 | |
| 3067 | // This test verifies session migrates to the alternate network immediately when |
| 3068 | // default network disconnects with an asynchronously write before migration. |
| 3069 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedAsync) { |
| 3070 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ true); |
| 3071 | } |
| 3072 | |
| 3073 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkDisconnected( |
| 3074 | bool async_write_before) { |
| 3075 | InitializeConnectionMigrationV2Test( |
| 3076 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3077 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3078 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 3079 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3080 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3081 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3082 | |
| 3083 | // Use the test task runner. |
| 3084 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3085 | |
| 3086 | int packet_number = 1; |
| 3087 | MockQuicData socket_data; |
| 3088 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3089 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3090 | socket_data.AddWrite( |
| 3091 | SYNCHRONOUS, |
| 3092 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 3093 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3094 | SYNCHRONOUS, |
| 3095 | ConstructGetRequestPacket(packet_number++, |
| 3096 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3097 | true, true, &header_stream_offset)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3098 | if (async_write_before) { |
| 3099 | socket_data.AddWrite(ASYNC, OK); |
| 3100 | packet_number++; |
| 3101 | } |
| 3102 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3103 | |
| 3104 | // Create request and QuicHttpStream. |
| 3105 | QuicStreamRequest request(factory_.get()); |
| 3106 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3107 | request.Request( |
| 3108 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3109 | SocketTag(), |
| 3110 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3111 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3112 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3113 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3114 | EXPECT_TRUE(stream.get()); |
| 3115 | |
| 3116 | // Cause QUIC stream to be created. |
| 3117 | HttpRequestInfo request_info; |
| 3118 | request_info.method = "GET"; |
| 3119 | request_info.url = url_; |
| 3120 | request_info.traffic_annotation = |
| 3121 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3122 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3123 | net_log_, CompletionOnceCallback())); |
| 3124 | |
| 3125 | // Ensure that session is alive and active. |
| 3126 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3127 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3128 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3129 | |
| 3130 | // Send GET request on stream. |
| 3131 | HttpResponseInfo response; |
| 3132 | HttpRequestHeaders request_headers; |
| 3133 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3134 | callback_.callback())); |
| 3135 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3136 | if (async_write_before) |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3137 | session->SendPing(); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3138 | |
| 3139 | // Set up second socket data provider that is used after migration. |
| 3140 | // The response to the earlier request is read on this new socket. |
| 3141 | MockQuicData socket_data1; |
| 3142 | socket_data1.AddWrite( |
| 3143 | SYNCHRONOUS, |
| 3144 | client_maker_.MakePingPacket(packet_number++, /*include_version=*/true)); |
| 3145 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3146 | ASYNC, |
| 3147 | ConstructOkResponsePacket( |
| 3148 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3149 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3150 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3151 | SYNCHRONOUS, |
| 3152 | client_maker_.MakeAckAndRstPacket( |
| 3153 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3154 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3155 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3156 | |
| 3157 | // Trigger connection migration. |
| 3158 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3159 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3160 | |
| 3161 | // The connection should still be alive, not marked as going away. |
| 3162 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3163 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3164 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3165 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3166 | |
| 3167 | // Ensure that the session is still alive. |
| 3168 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3169 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3170 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3171 | |
| 3172 | // Run the message loop so that data queued in the new socket is read by the |
| 3173 | // packet reader. |
| 3174 | runner_->RunNextTask(); |
| 3175 | |
| 3176 | // Response headers are received over the new network. |
| 3177 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3178 | EXPECT_EQ(200, response.headers->response_code()); |
| 3179 | |
| 3180 | // Check that the session is still alive. |
| 3181 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3182 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3183 | |
| 3184 | // There should be posted tasks not executed, which is to migrate back to |
| 3185 | // default network. |
| 3186 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3187 | |
| 3188 | // Receive signal to mark new network as default. |
| 3189 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3190 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3191 | |
| 3192 | stream.reset(); |
| 3193 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3194 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3195 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3196 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3197 | } |
| 3198 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3199 | // This test receives NCN signals in the following order: |
| 3200 | // - default network disconnected |
| 3201 | // - after a pause, new network is connected. |
| 3202 | // - new network is made default. |
| 3203 | TEST_P(QuicStreamFactoryTest, NewNetworkConnectedAfterNoNetwork) { |
| 3204 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 3205 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3206 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3207 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3208 | |
| 3209 | // Use the test task runner. |
| 3210 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3211 | |
| 3212 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3213 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3214 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3215 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3216 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3217 | socket_data.AddWrite( |
| 3218 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3219 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3220 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3221 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3222 | |
| 3223 | // Create request and QuicHttpStream. |
| 3224 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3225 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3226 | request.Request( |
| 3227 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3228 | SocketTag(), |
| 3229 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3230 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3231 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3232 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3233 | EXPECT_TRUE(stream.get()); |
| 3234 | |
| 3235 | // Cause QUIC stream to be created. |
| 3236 | HttpRequestInfo request_info; |
| 3237 | request_info.method = "GET"; |
| 3238 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 3239 | request_info.traffic_annotation = |
| 3240 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 3241 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 3242 | net_log_, CompletionOnceCallback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3243 | |
| 3244 | // Ensure that session is alive and active. |
| 3245 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3246 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3247 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3248 | |
| 3249 | // Send GET request on stream. |
| 3250 | HttpResponseInfo response; |
| 3251 | HttpRequestHeaders request_headers; |
| 3252 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3253 | callback_.callback())); |
| 3254 | |
| 3255 | // Trigger connection migration. Since there are no networks |
| 3256 | // to migrate to, this should cause the session to wait for a new network. |
| 3257 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3258 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3259 | |
| 3260 | // The connection should still be alive, not marked as going away. |
| 3261 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3262 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3263 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3264 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3265 | |
| 3266 | // Set up second socket data provider that is used after migration. |
| 3267 | // The response to the earlier request is read on this new socket. |
| 3268 | MockQuicData socket_data1; |
| 3269 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3270 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 3271 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3272 | ASYNC, |
| 3273 | ConstructOkResponsePacket( |
| 3274 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3275 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3276 | socket_data1.AddWrite( |
| 3277 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3278 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3279 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3280 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3281 | |
| 3282 | // Add a new network and notify the stream factory of a new connected network. |
| 3283 | // This causes a PING packet to be sent over the new network. |
| 3284 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3285 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 3286 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3287 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 3288 | |
| 3289 | // Ensure that the session is still alive. |
| 3290 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3291 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3292 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3293 | |
| 3294 | // Run the message loop so that data queued in the new socket is read by the |
| 3295 | // packet reader. |
| 3296 | runner_->RunNextTask(); |
| 3297 | |
| 3298 | // Response headers are received over the new network. |
| 3299 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3300 | EXPECT_EQ(200, response.headers->response_code()); |
| 3301 | |
| 3302 | // Check that the session is still alive. |
| 3303 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3304 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3305 | |
| 3306 | // There should posted tasks not executed, which is to migrate back to default |
| 3307 | // network. |
| 3308 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3309 | |
| 3310 | // Receive signal to mark new network as default. |
| 3311 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3312 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3313 | |
| 3314 | stream.reset(); |
| 3315 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3316 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3317 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3318 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3319 | } |
| 3320 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3321 | // Regression test for http://crbug.com/872011. |
| 3322 | // This test verifies that migrate to the probing socket will not trigger |
| 3323 | // new packets being read synchronously and generate ACK frame while |
| 3324 | // processing the initial connectivity probe response, which may cause a |
| 3325 | // connection being closed with INTERNAL_ERROR as pending ACK frame is not |
| 3326 | // allowed when processing a new packet. |
Zhongyi Shi | 6a7323b | 2018-12-07 01:26:32 | [diff] [blame] | 3327 | TEST_P(QuicStreamFactoryTest, MigrateToProbingSocket) { |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3328 | InitializeConnectionMigrationV2Test( |
| 3329 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3330 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3331 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3332 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3333 | |
| 3334 | // Using a testing task runner so that we can control time. |
| 3335 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3336 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3337 | |
| 3338 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3339 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3340 | |
| 3341 | int packet_number = 1; |
| 3342 | MockQuicData quic_data1; |
| 3343 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3344 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 3345 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3346 | packet_number++, &header_stream_offset)); |
| 3347 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3348 | SYNCHRONOUS, |
| 3349 | ConstructGetRequestPacket(packet_number++, |
| 3350 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3351 | true, true, &header_stream_offset)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3352 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3353 | |
| 3354 | // Set up the second socket data provider that is used for probing on the |
| 3355 | // alternate network. |
| 3356 | MockQuicData quic_data2; |
| 3357 | // Connectivity probe to be sent on the new path. |
| 3358 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
| 3359 | packet_number++, true)); |
| 3360 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3361 | // First connectivity probe to receive from the server, which will complete |
| 3362 | // connection migraiton on path degrading. |
| 3363 | quic_data2.AddRead(ASYNC, |
| 3364 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3365 | // Read multiple connectivity probes synchronously. |
| 3366 | quic_data2.AddRead(SYNCHRONOUS, |
| 3367 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
| 3368 | quic_data2.AddRead(SYNCHRONOUS, |
| 3369 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
| 3370 | quic_data2.AddRead(SYNCHRONOUS, |
| 3371 | server_maker_.MakeConnectivityProbingPacket(4, false)); |
| 3372 | quic_data2.AddWrite( |
| 3373 | ASYNC, client_maker_.MakeAckPacket(packet_number++, 1, 4, 1, 1, true)); |
| 3374 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3375 | ASYNC, |
| 3376 | ConstructOkResponsePacket( |
| 3377 | 5, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3378 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3379 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3380 | SYNCHRONOUS, |
| 3381 | client_maker_.MakeAckAndRstPacket( |
| 3382 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3383 | quic::QUIC_STREAM_CANCELLED, 5, 1, 1, true)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3384 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3385 | |
| 3386 | // Create request and QuicHttpStream. |
| 3387 | QuicStreamRequest request(factory_.get()); |
| 3388 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3389 | request.Request( |
| 3390 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3391 | SocketTag(), |
| 3392 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3393 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3394 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3395 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3396 | EXPECT_TRUE(stream.get()); |
| 3397 | |
| 3398 | // Cause QUIC stream to be created. |
| 3399 | HttpRequestInfo request_info; |
| 3400 | request_info.method = "GET"; |
| 3401 | request_info.url = url_; |
| 3402 | request_info.traffic_annotation = |
| 3403 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3404 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3405 | net_log_, CompletionOnceCallback())); |
| 3406 | |
| 3407 | // Ensure that session is alive and active. |
| 3408 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3409 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3410 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3411 | |
| 3412 | // Send GET request on stream. |
| 3413 | HttpResponseInfo response; |
| 3414 | HttpRequestHeaders request_headers; |
| 3415 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3416 | callback_.callback())); |
| 3417 | |
| 3418 | // Cause the connection to report path degrading to the session. |
| 3419 | // Session will start to probe the alternate network. |
| 3420 | session->connection()->OnPathDegradingTimeout(); |
| 3421 | |
| 3422 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3423 | // kDefaultRTTMilliSecs. |
| 3424 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3425 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3426 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3427 | next_task_delay); |
| 3428 | |
| 3429 | // The connection should still be alive, and not marked as going away. |
| 3430 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3431 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3432 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3433 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3434 | |
| 3435 | // Resume quic data and a connectivity probe response will be read on the new |
| 3436 | // socket. |
| 3437 | quic_data2.Resume(); |
| 3438 | |
| 3439 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3440 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3441 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3442 | |
| 3443 | // There should be three pending tasks, the nearest one will complete |
| 3444 | // migration to the new network. |
| 3445 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3446 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3447 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3448 | task_runner->FastForwardBy(next_task_delay); |
| 3449 | |
| 3450 | // Response headers are received over the new network. |
| 3451 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3452 | EXPECT_EQ(200, response.headers->response_code()); |
| 3453 | |
| 3454 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3455 | // probe and has been cancelled due to successful migration. |
| 3456 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3457 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3458 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3459 | next_task_delay); |
| 3460 | task_runner->FastForwardBy(next_task_delay); |
| 3461 | |
| 3462 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3463 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3464 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3465 | base::TimeDelta expected_delay = |
| 3466 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3467 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3468 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3469 | |
| 3470 | // Deliver a signal that the alternate network now becomes default to session, |
| 3471 | // this will cancel mgirate back to default network timer. |
| 3472 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3473 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3474 | |
| 3475 | task_runner->FastForwardBy(next_task_delay); |
| 3476 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3477 | |
| 3478 | // Verify that the session is still alive. |
| 3479 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3480 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3481 | |
| 3482 | stream.reset(); |
| 3483 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3484 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3485 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3486 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3487 | } |
| 3488 | |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3489 | // This test verifies that the connection migrates to the alternate network |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3490 | // early when path degrading is detected with an ASYNCHRONOUS write before |
| 3491 | // migration. |
| 3492 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingAysnc) { |
| 3493 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ true); |
| 3494 | } |
| 3495 | |
| 3496 | // This test verifies that the connection migrates to the alternate network |
| 3497 | // early when path degrading is detected with a SYNCHRONOUS write before |
| 3498 | // migration. |
| 3499 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingSync) { |
| 3500 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ false); |
| 3501 | } |
| 3502 | |
| 3503 | void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( |
| 3504 | bool async_write_before) { |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3505 | InitializeConnectionMigrationV2Test( |
| 3506 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3507 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3508 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3509 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3510 | |
| 3511 | // Using a testing task runner so that we can control time. |
| 3512 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3513 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3514 | |
| 3515 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3516 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3517 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3518 | int packet_number = 1; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3519 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3520 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3521 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3522 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3523 | packet_number++, &header_stream_offset)); |
| 3524 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3525 | SYNCHRONOUS, |
| 3526 | ConstructGetRequestPacket(packet_number++, |
| 3527 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3528 | true, true, &header_stream_offset)); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3529 | if (async_write_before) { |
| 3530 | quic_data1.AddWrite(ASYNC, OK); |
| 3531 | packet_number++; |
| 3532 | } |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3533 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3534 | |
| 3535 | // Set up the second socket data provider that is used after migration. |
| 3536 | // The response to the earlier request is read on the new socket. |
| 3537 | MockQuicData quic_data2; |
| 3538 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3539 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3540 | packet_number++, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3541 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3542 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3543 | quic_data2.AddRead(ASYNC, |
| 3544 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3545 | // Ping packet to send after migration is completed. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3546 | quic_data2.AddWrite(ASYNC, client_maker_.MakeAckAndPingPacket( |
| 3547 | packet_number++, false, 1, 1, 1)); |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 3548 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3549 | ASYNC, |
| 3550 | ConstructOkResponsePacket( |
| 3551 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3552 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3553 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3554 | SYNCHRONOUS, |
| 3555 | client_maker_.MakeAckAndRstPacket( |
| 3556 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3557 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3558 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3559 | |
| 3560 | // Create request and QuicHttpStream. |
| 3561 | QuicStreamRequest request(factory_.get()); |
| 3562 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3563 | request.Request( |
| 3564 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3565 | SocketTag(), |
| 3566 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3567 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3568 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3569 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3570 | EXPECT_TRUE(stream.get()); |
| 3571 | |
| 3572 | // Cause QUIC stream to be created. |
| 3573 | HttpRequestInfo request_info; |
| 3574 | request_info.method = "GET"; |
| 3575 | request_info.url = url_; |
| 3576 | request_info.traffic_annotation = |
| 3577 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3578 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3579 | net_log_, CompletionOnceCallback())); |
| 3580 | |
| 3581 | // Ensure that session is alive and active. |
| 3582 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3583 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3584 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3585 | |
| 3586 | // Send GET request on stream. |
| 3587 | HttpResponseInfo response; |
| 3588 | HttpRequestHeaders request_headers; |
| 3589 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3590 | callback_.callback())); |
| 3591 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3592 | if (async_write_before) |
| 3593 | session->SendPing(); |
| 3594 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 3595 | // Cause the connection to report path degrading to the session. |
| 3596 | // Session will start to probe the alternate network. |
| 3597 | session->connection()->OnPathDegradingTimeout(); |
| 3598 | |
| 3599 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3600 | // kDefaultRTTMilliSecs. |
| 3601 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3602 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3603 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3604 | next_task_delay); |
| 3605 | |
| 3606 | // The connection should still be alive, and not marked as going away. |
| 3607 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3608 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3609 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3610 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3611 | |
| 3612 | // Resume quic data and a connectivity probe response will be read on the new |
| 3613 | // socket. |
| 3614 | quic_data2.Resume(); |
| 3615 | |
| 3616 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3617 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3618 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3619 | |
| 3620 | // There should be three pending tasks, the nearest one will complete |
| 3621 | // migration to the new network. |
| 3622 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3623 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3624 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3625 | task_runner->FastForwardBy(next_task_delay); |
| 3626 | |
| 3627 | // Response headers are received over the new network. |
| 3628 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3629 | EXPECT_EQ(200, response.headers->response_code()); |
| 3630 | |
| 3631 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3632 | // probe and has been cancelled due to successful migration. |
| 3633 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3634 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3635 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3636 | next_task_delay); |
| 3637 | task_runner->FastForwardBy(next_task_delay); |
| 3638 | |
| 3639 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3640 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3641 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3642 | base::TimeDelta expected_delay = |
| 3643 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3644 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3645 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3646 | |
| 3647 | // Deliver a signal that the alternate network now becomes default to session, |
| 3648 | // this will cancel mgirate back to default network timer. |
| 3649 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3650 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3651 | |
| 3652 | task_runner->FastForwardBy(next_task_delay); |
| 3653 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3654 | |
| 3655 | // Verify that the session is still alive. |
| 3656 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3657 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3658 | |
| 3659 | stream.reset(); |
| 3660 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3661 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3662 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3663 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3664 | } |
| 3665 | |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3666 | // This test verifies that the session marks itself GOAWAY on path degrading |
| 3667 | // and it does not receive any new request |
| 3668 | TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 3669 | test_params_.quic_go_away_on_path_degrading = true; |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3670 | Initialize(); |
| 3671 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3672 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3673 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3674 | |
| 3675 | MockQuicData quic_data1; |
| 3676 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3677 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3678 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3679 | quic_data1.AddWrite( |
| 3680 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3681 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3682 | true, &header_stream_offset)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3683 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3684 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3685 | ASYNC, |
| 3686 | ConstructOkResponsePacket( |
| 3687 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3688 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3689 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3690 | |
| 3691 | MockQuicData quic_data2; |
| 3692 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 3693 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3694 | quic_data2.AddWrite( |
| 3695 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 3696 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3697 | |
| 3698 | // Creat request and QuicHttpStream. |
| 3699 | QuicStreamRequest request(factory_.get()); |
| 3700 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3701 | request.Request( |
| 3702 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3703 | SocketTag(), |
| 3704 | /*cerf_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3705 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3706 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3707 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3708 | EXPECT_TRUE(stream.get()); |
| 3709 | |
| 3710 | // Cause QUIC stream to be created. |
| 3711 | HttpRequestInfo request_info; |
| 3712 | request_info.method = "GET"; |
| 3713 | request_info.url = url_; |
| 3714 | request_info.traffic_annotation = |
| 3715 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3716 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3717 | net_log_, CompletionOnceCallback())); |
| 3718 | |
| 3719 | // Ensure that session is alive and active. |
| 3720 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3721 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3722 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3723 | |
| 3724 | // Send GET request on stream. |
| 3725 | HttpResponseInfo response; |
| 3726 | HttpRequestHeaders request_headers; |
| 3727 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3728 | callback_.callback())); |
| 3729 | |
| 3730 | // Trigger the connection to report path degrading to the session. |
| 3731 | // Session will mark itself GOAWAY. |
| 3732 | session->connection()->OnPathDegradingTimeout(); |
| 3733 | |
| 3734 | // The connection should still be alive, but marked as going away. |
| 3735 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3736 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3737 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3738 | |
| 3739 | // Second request should be sent on a new connection. |
| 3740 | QuicStreamRequest request2(factory_.get()); |
| 3741 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3742 | request2.Request( |
| 3743 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3744 | SocketTag(), |
| 3745 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3746 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3747 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3748 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 3749 | EXPECT_TRUE(stream2.get()); |
| 3750 | |
| 3751 | // Resume the data, verify old request can read response on the old session |
| 3752 | // successfully. |
| 3753 | quic_data1.Resume(); |
| 3754 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 3755 | EXPECT_EQ(200, response.headers->response_code()); |
| 3756 | EXPECT_EQ(0U, session->GetNumActiveStreams()); |
| 3757 | |
| 3758 | // Check an active session exists for the destination. |
| 3759 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3760 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3761 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 3762 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 3763 | EXPECT_NE(session, session2); |
| 3764 | |
| 3765 | stream.reset(); |
| 3766 | stream2.reset(); |
| 3767 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3768 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3769 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3770 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3771 | } |
| 3772 | |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3773 | // This test verifies that the connection will not migrate to a bad socket |
| 3774 | // when path degrading is detected. |
| 3775 | TEST_P(QuicStreamFactoryTest, DoNotMigrateToBadSocketOnPathDegrading) { |
| 3776 | InitializeConnectionMigrationV2Test( |
| 3777 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3778 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3779 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3780 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3781 | |
| 3782 | // Using a testing task runner so that we can control time. |
| 3783 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3784 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3785 | |
| 3786 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3787 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3788 | |
| 3789 | MockQuicData quic_data; |
| 3790 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3791 | quic_data.AddWrite(SYNCHRONOUS, |
| 3792 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3793 | quic_data.AddWrite(SYNCHRONOUS, |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3794 | ConstructGetRequestPacket( |
| 3795 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3796 | true, &header_stream_offset)); |
| 3797 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3798 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 3799 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3800 | false, false)); |
| 3801 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3802 | quic_data.AddWrite( |
| 3803 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3804 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3805 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3806 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3807 | |
| 3808 | // Set up second socket that will immediately return disconnected. |
| 3809 | // The stream factory will abort probe the alternate network. |
| 3810 | MockConnect bad_connect = MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
| 3811 | SequencedSocketData socket_data(bad_connect, base::span<MockRead>(), |
| 3812 | base::span<MockWrite>()); |
| 3813 | socket_factory_->AddSocketDataProvider(&socket_data); |
| 3814 | |
| 3815 | // Create request and QuicHttpStream. |
| 3816 | QuicStreamRequest request(factory_.get()); |
| 3817 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3818 | request.Request( |
| 3819 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3820 | SocketTag(), |
| 3821 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3822 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3823 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3824 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3825 | EXPECT_TRUE(stream.get()); |
| 3826 | |
| 3827 | // Cause QUIC stream to be created. |
| 3828 | HttpRequestInfo request_info; |
| 3829 | request_info.method = "GET"; |
| 3830 | request_info.url = url_; |
| 3831 | request_info.traffic_annotation = |
| 3832 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3833 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3834 | net_log_, CompletionOnceCallback())); |
| 3835 | |
| 3836 | // Ensure that session is alive and active. |
| 3837 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3838 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3839 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3840 | |
| 3841 | // Send GET request on stream. |
| 3842 | HttpResponseInfo response; |
| 3843 | HttpRequestHeaders request_headers; |
| 3844 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3845 | callback_.callback())); |
| 3846 | |
| 3847 | // Cause the connection to report path degrading to the session. |
| 3848 | // Session will start to probe the alternate network. |
| 3849 | session->connection()->OnPathDegradingTimeout(); |
| 3850 | |
| 3851 | // The connection should still be alive, and not marked as going away. |
| 3852 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3853 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3854 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3855 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3856 | |
| 3857 | // Resume the data, and response header is received over the original network. |
| 3858 | quic_data.Resume(); |
| 3859 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3860 | EXPECT_EQ(200, response.headers->response_code()); |
| 3861 | |
| 3862 | // Verify there is no pending task as probing alternate network is halted. |
| 3863 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3864 | |
| 3865 | // Verify that the session is still alive. |
| 3866 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3867 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3868 | |
| 3869 | stream.reset(); |
| 3870 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 3871 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 3872 | } |
| 3873 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3874 | // Regression test for http://crbug.com/847569. |
| 3875 | // This test verifies that the connection migrates to the alternate network |
| 3876 | // early when there is no active stream but a draining stream. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3877 | // The first packet being written after migration is a synchrnous write, which |
| 3878 | // will cause a PING packet being sent. |
| 3879 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamSync) { |
| 3880 | TestMigrateSessionWithDrainingStream(SYNCHRONOUS); |
| 3881 | } |
| 3882 | |
| 3883 | // Regression test for http://crbug.com/847569. |
| 3884 | // This test verifies that the connection migrates to the alternate network |
| 3885 | // early when there is no active stream but a draining stream. |
| 3886 | // The first packet being written after migration is an asynchronous write, no |
| 3887 | // PING packet will be sent. |
| 3888 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamAsync) { |
| 3889 | TestMigrateSessionWithDrainingStream(ASYNC); |
| 3890 | } |
| 3891 | |
| 3892 | void QuicStreamFactoryTestBase::TestMigrateSessionWithDrainingStream( |
| 3893 | IoMode write_mode_for_queued_packet) { |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3894 | InitializeConnectionMigrationV2Test( |
| 3895 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3896 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3897 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3898 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3899 | |
| 3900 | // Using a testing task runner so that we can control time. |
| 3901 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3902 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3903 | |
| 3904 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3905 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3906 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3907 | int packet_number = 1; |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3908 | MockQuicData quic_data1; |
| 3909 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3910 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3911 | packet_number++, &header_stream_offset)); |
| 3912 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3913 | SYNCHRONOUS, |
| 3914 | ConstructGetRequestPacket(packet_number++, |
| 3915 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3916 | true, true, &header_stream_offset)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3917 | // Read an out of order packet with FIN to drain the stream. |
| 3918 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3919 | ASYNC, ConstructOkResponsePacket( |
| 3920 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, |
| 3921 | true)); // keep sending version. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3922 | quic_data1.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3923 | packet_number++, 2, 2, 2, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3924 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3925 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3926 | |
| 3927 | // Set up the second socket data provider that is used after migration. |
| 3928 | MockQuicData quic_data2; |
| 3929 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3930 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3931 | packet_number++, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3932 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3933 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3934 | quic_data2.AddRead(ASYNC, |
| 3935 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3936 | // Ping packet to send after migration is completed. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3937 | quic_data2.AddWrite( |
| 3938 | write_mode_for_queued_packet, |
| 3939 | client_maker_.MakeAckPacket(packet_number++, 2, 3, 3, 1, true)); |
| 3940 | if (write_mode_for_queued_packet == SYNCHRONOUS) { |
| 3941 | quic_data2.AddWrite(ASYNC, |
| 3942 | client_maker_.MakePingPacket(packet_number++, false)); |
| 3943 | } |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3944 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3945 | ASYNC, |
| 3946 | ConstructOkResponsePacket( |
| 3947 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3948 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3949 | packet_number++, 1, 3, 1, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3950 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3951 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3952 | |
| 3953 | // Create request and QuicHttpStream. |
| 3954 | QuicStreamRequest request(factory_.get()); |
| 3955 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3956 | request.Request( |
| 3957 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3958 | SocketTag(), |
| 3959 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3960 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3961 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3962 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3963 | EXPECT_TRUE(stream.get()); |
| 3964 | |
| 3965 | // Cause QUIC stream to be created. |
| 3966 | HttpRequestInfo request_info; |
| 3967 | request_info.method = "GET"; |
| 3968 | request_info.url = url_; |
| 3969 | request_info.traffic_annotation = |
| 3970 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3971 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3972 | net_log_, CompletionOnceCallback())); |
| 3973 | |
| 3974 | // Ensure that session is alive and active. |
| 3975 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3976 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3977 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3978 | |
| 3979 | // Send GET request on stream. |
| 3980 | HttpResponseInfo response; |
| 3981 | HttpRequestHeaders request_headers; |
| 3982 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3983 | callback_.callback())); |
| 3984 | |
| 3985 | // Run the message loop to receive the out of order packet which contains a |
| 3986 | // FIN and drains the stream. |
| 3987 | base::RunLoop().RunUntilIdle(); |
| 3988 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3989 | |
| 3990 | // Cause the connection to report path degrading to the session. |
| 3991 | // Session should still start to probe the alternate network. |
| 3992 | session->connection()->OnPathDegradingTimeout(); |
| 3993 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3994 | |
| 3995 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3996 | // kDefaultRTTMilliSecs. |
| 3997 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3998 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3999 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4000 | next_task_delay); |
| 4001 | |
| 4002 | // The connection should still be alive, and not marked as going away. |
| 4003 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4004 | |
| 4005 | // Resume quic data and a connectivity probe response will be read on the new |
| 4006 | // socket. |
| 4007 | quic_data2.Resume(); |
| 4008 | |
| 4009 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4010 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4011 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 4012 | EXPECT_EQ(1u, session->GetNumDrainingStreams()); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4013 | |
| 4014 | // There should be three pending tasks, the nearest one will complete |
| 4015 | // migration to the new network. |
| 4016 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4017 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4018 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4019 | task_runner->FastForwardBy(next_task_delay); |
| 4020 | |
| 4021 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4022 | // probe and has been cancelled due to successful migration. |
| 4023 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4024 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4025 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4026 | next_task_delay); |
| 4027 | task_runner->FastForwardBy(next_task_delay); |
| 4028 | |
| 4029 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4030 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4031 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4032 | base::TimeDelta expected_delay = |
| 4033 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4034 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4035 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4036 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4037 | base::RunLoop().RunUntilIdle(); |
| 4038 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4039 | // Deliver a signal that the alternate network now becomes default to session, |
| 4040 | // this will cancel mgirate back to default network timer. |
| 4041 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4042 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4043 | |
| 4044 | task_runner->FastForwardBy(next_task_delay); |
| 4045 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4046 | |
| 4047 | // Verify that the session is still alive. |
| 4048 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4049 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4050 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4051 | |
| 4052 | stream.reset(); |
| 4053 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4054 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4055 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4056 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4057 | } |
| 4058 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4059 | // Regression test for http://crbug.com/835444. |
| 4060 | // This test verifies that the connection migrates to the alternate network |
| 4061 | // when the alternate network is connected after path has been degrading. |
| 4062 | TEST_P(QuicStreamFactoryTest, MigrateOnNewNetworkConnectAfterPathDegrading) { |
| 4063 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4064 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4065 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4066 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4067 | |
| 4068 | // Using a testing task runner so that we can control time. |
| 4069 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4070 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4071 | |
| 4072 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4073 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4074 | |
| 4075 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4076 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4077 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 4078 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4079 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4080 | quic_data1.AddWrite( |
| 4081 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4082 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4083 | true, &header_stream_offset)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4084 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4085 | |
| 4086 | // Set up the second socket data provider that is used after migration. |
| 4087 | // The response to the earlier request is read on the new socket. |
| 4088 | MockQuicData quic_data2; |
| 4089 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4090 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4091 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4092 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4093 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4094 | quic_data2.AddRead(ASYNC, |
| 4095 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4096 | // Ping packet to send after migration is completed. |
| 4097 | quic_data2.AddWrite(ASYNC, |
| 4098 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4099 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4100 | ASYNC, |
| 4101 | ConstructOkResponsePacket( |
| 4102 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4103 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4104 | quic_data2.AddWrite( |
| 4105 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4106 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4107 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4108 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4109 | |
| 4110 | // Create request and QuicHttpStream. |
| 4111 | QuicStreamRequest request(factory_.get()); |
| 4112 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4113 | request.Request( |
| 4114 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4115 | SocketTag(), |
| 4116 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4117 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4118 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4119 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4120 | EXPECT_TRUE(stream.get()); |
| 4121 | |
| 4122 | // Cause QUIC stream to be created. |
| 4123 | HttpRequestInfo request_info; |
| 4124 | request_info.method = "GET"; |
| 4125 | request_info.url = url_; |
| 4126 | request_info.traffic_annotation = |
| 4127 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4128 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4129 | net_log_, CompletionOnceCallback())); |
| 4130 | |
| 4131 | // Ensure that session is alive and active. |
| 4132 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4133 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4134 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4135 | |
| 4136 | // Send GET request on stream. |
| 4137 | HttpResponseInfo response; |
| 4138 | HttpRequestHeaders request_headers; |
| 4139 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4140 | callback_.callback())); |
| 4141 | |
| 4142 | // Cause the connection to report path degrading to the session. |
| 4143 | // Due to lack of alternate network, session will not mgirate connection. |
| 4144 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4145 | session->connection()->OnPathDegradingTimeout(); |
| 4146 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4147 | |
| 4148 | // Deliver a signal that a alternate network is connected now, this should |
| 4149 | // cause the connection to start early migration on path degrading. |
| 4150 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4151 | ->SetConnectedNetworksList( |
| 4152 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4153 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4154 | ->NotifyNetworkConnected(kNewNetworkForTests); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 4155 | |
| 4156 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4157 | // kDefaultRTTMilliSecs. |
| 4158 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4159 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4160 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4161 | next_task_delay); |
| 4162 | |
| 4163 | // The connection should still be alive, and not marked as going away. |
| 4164 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4165 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4166 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4167 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4168 | |
| 4169 | // Resume quic data and a connectivity probe response will be read on the new |
| 4170 | // socket. |
| 4171 | quic_data2.Resume(); |
| 4172 | |
| 4173 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4174 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4175 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4176 | |
| 4177 | // There should be three pending tasks, the nearest one will complete |
| 4178 | // migration to the new network. |
| 4179 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4180 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4181 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4182 | task_runner->FastForwardBy(next_task_delay); |
| 4183 | |
| 4184 | // Response headers are received over the new network. |
| 4185 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4186 | EXPECT_EQ(200, response.headers->response_code()); |
| 4187 | |
| 4188 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4189 | // probe and has been cancelled due to successful migration. |
| 4190 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4191 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4192 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4193 | next_task_delay); |
| 4194 | task_runner->FastForwardBy(next_task_delay); |
| 4195 | |
| 4196 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4197 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4198 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4199 | base::TimeDelta expected_delay = |
| 4200 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4201 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4202 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4203 | |
| 4204 | // Deliver a signal that the alternate network now becomes default to session, |
| 4205 | // this will cancel mgirate back to default network timer. |
| 4206 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4207 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4208 | |
| 4209 | task_runner->FastForwardBy(next_task_delay); |
| 4210 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4211 | |
| 4212 | // Verify that the session is still alive. |
| 4213 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4214 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4215 | |
| 4216 | stream.reset(); |
| 4217 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4218 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4219 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4220 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4221 | } |
| 4222 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4223 | // This test verifies that multiple sessions are migrated on connection |
| 4224 | // migration signal. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4225 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4226 | MigrateMultipleSessionsToBadSocketsAfterDisconnected) { |
| 4227 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4228 | |
| 4229 | MockQuicData socket_data1; |
| 4230 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4231 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4232 | socket_data1.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4233 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4234 | MockQuicData socket_data2; |
| 4235 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4236 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4237 | socket_data2.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4238 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4239 | |
| 4240 | HostPortPair server1(kDefaultServerHostName, 443); |
| 4241 | HostPortPair server2(kServer2HostName, 443); |
| 4242 | |
| 4243 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4244 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4245 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4246 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 4247 | host_resolver_->set_synchronous_mode(true); |
| 4248 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 4249 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.2", ""); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4250 | |
| 4251 | // Create request and QuicHttpStream to create session1. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4252 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4253 | EXPECT_EQ(OK, |
| 4254 | request1.Request( |
| 4255 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4256 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4257 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4258 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4259 | EXPECT_TRUE(stream1.get()); |
| 4260 | |
| 4261 | // Create request and QuicHttpStream to create session2. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4262 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4263 | EXPECT_EQ(OK, |
| 4264 | request2.Request( |
| 4265 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4266 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 4267 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4268 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4269 | EXPECT_TRUE(stream2.get()); |
| 4270 | |
| 4271 | QuicChromiumClientSession* session1 = GetActiveSession(server1); |
| 4272 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 4273 | EXPECT_NE(session1, session2); |
| 4274 | |
| 4275 | // Cause QUIC stream to be created and send GET so session1 has an open |
| 4276 | // stream. |
| 4277 | HttpRequestInfo request_info1; |
| 4278 | request_info1.method = "GET"; |
| 4279 | request_info1.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4280 | request_info1.traffic_annotation = |
| 4281 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4282 | EXPECT_EQ(OK, |
| 4283 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4284 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4285 | HttpResponseInfo response1; |
| 4286 | HttpRequestHeaders request_headers1; |
| 4287 | EXPECT_EQ(OK, stream1->SendRequest(request_headers1, &response1, |
| 4288 | callback_.callback())); |
| 4289 | |
| 4290 | // Cause QUIC stream to be created and send GET so session2 has an open |
| 4291 | // stream. |
| 4292 | HttpRequestInfo request_info2; |
| 4293 | request_info2.method = "GET"; |
| 4294 | request_info2.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4295 | request_info2.traffic_annotation = |
| 4296 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4297 | EXPECT_EQ(OK, |
| 4298 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4299 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4300 | HttpResponseInfo response2; |
| 4301 | HttpRequestHeaders request_headers2; |
| 4302 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4303 | callback_.callback())); |
| 4304 | |
| 4305 | // Cause both sessions to be paused due to DISCONNECTED. |
| 4306 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4307 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 4308 | |
| 4309 | // Ensure that both sessions are paused but alive. |
| 4310 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4311 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4312 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4313 | // Add new sockets to use post migration. Those are bad sockets and will cause |
| 4314 | // migration to fail. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4315 | MockConnect connect_result = |
| 4316 | MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4317 | SequencedSocketData socket_data3(connect_result, base::span<MockRead>(), |
| 4318 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4319 | socket_factory_->AddSocketDataProvider(&socket_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4320 | SequencedSocketData socket_data4(connect_result, base::span<MockRead>(), |
| 4321 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4322 | socket_factory_->AddSocketDataProvider(&socket_data4); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4323 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4324 | // Connect the new network and cause migration to bad sockets, causing |
| 4325 | // sessions to close. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4326 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4327 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 4328 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4329 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 4330 | |
| 4331 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4332 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4333 | |
| 4334 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4335 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4336 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 4337 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 4338 | } |
| 4339 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4340 | // This test verifies that session attempts connection migration with signals |
| 4341 | // delivered in the following order (no alternate network is available): |
| 4342 | // - path degrading is detected: session attempts connection migration but no |
| 4343 | // alternate network is available, session caches path degrading signal in |
| 4344 | // connection and stays on the original network. |
| 4345 | // - original network backs up, request is served in the orignal network, |
| 4346 | // session is not marked as going away. |
| 4347 | TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { |
| 4348 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4349 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4350 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4351 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4352 | MockQuicData quic_data; |
| 4353 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4354 | quic_data.AddWrite(SYNCHRONOUS, |
| 4355 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4356 | quic_data.AddWrite(SYNCHRONOUS, |
| 4357 | ConstructGetRequestPacket( |
| 4358 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4359 | true, &header_stream_offset)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4360 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause for path degrading signal. |
| 4361 | |
| 4362 | // The rest of the data will still flow in the original socket as there is no |
| 4363 | // new network after path degrading. |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4364 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 4365 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4366 | false, false)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4367 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4368 | quic_data.AddWrite( |
| 4369 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4370 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4371 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4372 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4373 | |
| 4374 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4375 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4376 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4377 | request.Request( |
| 4378 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4379 | SocketTag(), |
| 4380 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4381 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4382 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4383 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4384 | EXPECT_TRUE(stream.get()); |
| 4385 | |
| 4386 | // Cause QUIC stream to be created. |
| 4387 | HttpRequestInfo request_info; |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4388 | request_info.method = "GET"; |
| 4389 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4390 | request_info.traffic_annotation = |
| 4391 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4392 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4393 | net_log_, CompletionOnceCallback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4394 | |
| 4395 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4396 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4397 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4398 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4399 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4400 | // Send GET request on stream. |
| 4401 | HttpResponseInfo response; |
| 4402 | HttpRequestHeaders request_headers; |
| 4403 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4404 | callback_.callback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4405 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4406 | // Trigger connection migration on path degrading. Since there are no networks |
| 4407 | // to migrate to, the session will remain on the original network, not marked |
| 4408 | // as going away. |
| 4409 | session->connection()->OnPathDegradingTimeout(); |
| 4410 | EXPECT_TRUE(session->connection()->IsPathDegrading()); |
| 4411 | |
| 4412 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4413 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4414 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4415 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4416 | |
| 4417 | // Resume so that rest of the data will flow in the original socket. |
| 4418 | quic_data.Resume(); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4419 | |
| 4420 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4421 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4422 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4423 | |
| 4424 | stream.reset(); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4425 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 4426 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4427 | } |
| 4428 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4429 | // This test verifies that session with non-migratable stream will probe the |
| 4430 | // alternate network on path degrading, and close the non-migratable streams |
| 4431 | // when probe is successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4432 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4433 | InitializeConnectionMigrationV2Test( |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4434 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4435 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4436 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4437 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4438 | MockQuicData socket_data; |
| 4439 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4440 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4441 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4442 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4443 | // Set up the second socket data provider that is used for probing. |
| 4444 | MockQuicData quic_data1; |
| 4445 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4446 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4447 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4448 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4449 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4450 | quic_data1.AddRead(ASYNC, |
| 4451 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 4452 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 4453 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 4454 | quic_data1.AddWrite( |
| 4455 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4456 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4457 | quic::QUIC_STREAM_CANCELLED)); |
| 4458 | // Ping packet to send after migration is completed. |
| 4459 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4460 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4461 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4462 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4463 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4464 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4465 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4466 | request.Request( |
| 4467 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4468 | SocketTag(), |
| 4469 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4470 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4471 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4472 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4473 | EXPECT_TRUE(stream.get()); |
| 4474 | |
| 4475 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 4476 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 4477 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4478 | request_info.traffic_annotation = |
| 4479 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4480 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4481 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4482 | |
| 4483 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4484 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4485 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4486 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4487 | |
| 4488 | // Trigger connection migration. Since there is a non-migratable stream, |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 4489 | // this should cause session to migrate. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4490 | session->OnPathDegrading(); |
| 4491 | |
| 4492 | // Run the message loop so that data queued in the new socket is read by the |
| 4493 | // packet reader. |
| 4494 | base::RunLoop().RunUntilIdle(); |
| 4495 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4496 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4497 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4498 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4499 | // Resume the data to read the connectivity probing response to declare probe |
| 4500 | // as successful. Non-migratable streams will be closed. |
| 4501 | quic_data1.Resume(); |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 4502 | base::RunLoop().RunUntilIdle(); |
| 4503 | |
| 4504 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4505 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4506 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4507 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4508 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4509 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4510 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4511 | } |
| 4512 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4513 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyConnectionMigrationDisabled) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4514 | InitializeConnectionMigrationV2Test( |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4515 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4516 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4517 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4518 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4519 | MockQuicData socket_data; |
| 4520 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4521 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 4522 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4523 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4524 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4525 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4526 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4527 | |
| 4528 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4529 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4530 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4531 | request.Request( |
| 4532 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4533 | SocketTag(), |
| 4534 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4535 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4536 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4537 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4538 | EXPECT_TRUE(stream.get()); |
| 4539 | |
| 4540 | // Cause QUIC stream to be created. |
| 4541 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4542 | request_info.traffic_annotation = |
| 4543 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4544 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4545 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4546 | |
| 4547 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4548 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4549 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4550 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4551 | |
| 4552 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4553 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 4554 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4555 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 4556 | |
| 4557 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4558 | // this should cause session to be continue without migrating. |
| 4559 | session->OnPathDegrading(); |
| 4560 | |
| 4561 | // Run the message loop so that data queued in the new socket is read by the |
| 4562 | // packet reader. |
| 4563 | base::RunLoop().RunUntilIdle(); |
| 4564 | |
| 4565 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4566 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4567 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4568 | |
| 4569 | stream.reset(); |
| 4570 | |
| 4571 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4572 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4573 | } |
| 4574 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4575 | // Regression test for http://crbug.com/791886. |
| 4576 | // This test verifies that the old packet writer which encountered an |
| 4577 | // asynchronous write error will be blocked during migration on write error. New |
| 4578 | // packets would not be written until the one with write error is rewritten on |
| 4579 | // the new network. |
| 4580 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { |
| 4581 | InitializeConnectionMigrationV2Test( |
| 4582 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4583 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4584 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4585 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4586 | |
| 4587 | // Using a testing task runner so that we can control time. |
| 4588 | // base::RunLoop() controls mocked socket writes and reads. |
| 4589 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4590 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4591 | |
| 4592 | MockQuicData socket_data; |
| 4593 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4594 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4595 | socket_data.AddWrite( |
| 4596 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4597 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4598 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4599 | |
| 4600 | // Set up second socket data provider that is used after |
| 4601 | // migration. The request is rewritten to this new socket, and the |
| 4602 | // response to the request is read on this new socket. |
| 4603 | MockQuicData socket_data1; |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4604 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4605 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4606 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4607 | true, &header_stream_offset)); |
| 4608 | socket_data1.AddWrite(SYNCHRONOUS, |
| 4609 | ConstructGetRequestPacket( |
| 4610 | 3, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4611 | GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4612 | true, &header_stream_offset)); |
| 4613 | socket_data1.AddRead( |
| 4614 | ASYNC, |
| 4615 | ConstructOkResponsePacket( |
| 4616 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 4617 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4618 | socket_data1.AddWrite( |
| 4619 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4620 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4621 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4622 | socket_data1.AddWrite( |
| 4623 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4624 | 5, false, GetNthClientInitiatedBidirectionalStreamId(1), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame^] | 4625 | quic::QUIC_STREAM_CANCELLED, 0, |
| 4626 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4627 | |
| 4628 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4629 | |
| 4630 | // Create request #1 and QuicHttpStream. |
| 4631 | QuicStreamRequest request1(factory_.get()); |
| 4632 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4633 | request1.Request( |
| 4634 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4635 | SocketTag(), |
| 4636 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4637 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4638 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4639 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4640 | EXPECT_TRUE(stream1.get()); |
| 4641 | |
| 4642 | HttpRequestInfo request_info1; |
| 4643 | request_info1.method = "GET"; |
| 4644 | request_info1.url = GURL("https://www.example.org/"); |
| 4645 | request_info1.traffic_annotation = |
| 4646 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4647 | EXPECT_EQ(OK, |
| 4648 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4649 | net_log_, CompletionOnceCallback())); |
| 4650 | |
| 4651 | // Request #2 returns synchronously because it pools to existing session. |
| 4652 | TestCompletionCallback callback2; |
| 4653 | QuicStreamRequest request2(factory_.get()); |
| 4654 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 4655 | DEFAULT_PRIORITY, SocketTag(), |
| 4656 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4657 | &net_error_details_, |
| 4658 | failed_on_default_network_callback_, |
| 4659 | callback2.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4660 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 4661 | EXPECT_TRUE(stream2.get()); |
| 4662 | |
| 4663 | HttpRequestInfo request_info2; |
| 4664 | request_info2.method = "GET"; |
| 4665 | request_info2.url = GURL("https://www.example.org/"); |
| 4666 | request_info2.traffic_annotation = |
| 4667 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4668 | EXPECT_EQ(OK, |
| 4669 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 4670 | net_log_, CompletionOnceCallback())); |
| 4671 | |
| 4672 | // Ensure that session is alive and active. |
| 4673 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4674 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4675 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4676 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 4677 | |
| 4678 | // Send GET request on stream1. This should cause an async write error. |
| 4679 | HttpResponseInfo response; |
| 4680 | HttpRequestHeaders request_headers; |
| 4681 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4682 | callback_.callback())); |
| 4683 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4684 | |
| 4685 | // Run the message loop so that asynchronous write completes and a connection |
| 4686 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4687 | // runner. |
| 4688 | base::RunLoop().RunUntilIdle(); |
| 4689 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4690 | |
| 4691 | // Send GET request on stream. This will cause another write attempt before |
| 4692 | // migration on write error is exectued. |
| 4693 | HttpResponseInfo response2; |
| 4694 | HttpRequestHeaders request_headers2; |
| 4695 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4696 | callback2.callback())); |
| 4697 | |
| 4698 | // Run the task runner so that migration on write error is finally executed. |
| 4699 | task_runner->RunUntilIdle(); |
| 4700 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4701 | // Verify the session is still alive and not marked as going away. |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4702 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4703 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4704 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4705 | // There should be one task posted to migrate back to the default network in |
| 4706 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4707 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4708 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 4709 | task_runner->NextPendingTaskDelay()); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4710 | |
| 4711 | // Verify that response headers on the migrated socket were delivered to the |
| 4712 | // stream. |
| 4713 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4714 | EXPECT_EQ(200, response.headers->response_code()); |
| 4715 | |
| 4716 | stream1.reset(); |
| 4717 | stream2.reset(); |
| 4718 | |
| 4719 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4720 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4721 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4722 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4723 | } |
| 4724 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4725 | // Verify session is not marked as going away after connection migration on |
| 4726 | // write error and migrate back to default network logic is applied to bring the |
| 4727 | // migrated session back to the default network. Migration singals delivered |
| 4728 | // in the following order (alternate network is always availabe): |
| 4729 | // - session on the default network encountered a write error; |
| 4730 | // - session successfully migrated to the non-default network; |
| 4731 | // - session attempts to migrate back to default network post migration; |
| 4732 | // - migration back to the default network is successful. |
| 4733 | TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { |
| 4734 | InitializeConnectionMigrationV2Test( |
| 4735 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4736 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4737 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4738 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4739 | |
| 4740 | // Using a testing task runner so that we can control time. |
| 4741 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4742 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4743 | |
| 4744 | MockQuicData socket_data; |
| 4745 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4746 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4747 | socket_data.AddWrite( |
| 4748 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4749 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4750 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4751 | |
| 4752 | // Set up second socket data provider that is used after |
| 4753 | // migration. The request is rewritten to this new socket, and the |
| 4754 | // response to the request is read on this new socket. |
| 4755 | MockQuicData quic_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4756 | quic_data2.AddWrite( |
| 4757 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4758 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4759 | true, &header_stream_offset)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4760 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4761 | ASYNC, |
| 4762 | ConstructOkResponsePacket( |
| 4763 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4764 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4765 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4766 | |
| 4767 | // Create request QuicHttpStream. |
| 4768 | QuicStreamRequest request1(factory_.get()); |
| 4769 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4770 | request1.Request( |
| 4771 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4772 | SocketTag(), |
| 4773 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4774 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4775 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4776 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4777 | EXPECT_TRUE(stream1.get()); |
| 4778 | |
| 4779 | HttpRequestInfo request_info1; |
| 4780 | request_info1.method = "GET"; |
| 4781 | request_info1.url = GURL("https://www.example.org/"); |
| 4782 | request_info1.traffic_annotation = |
| 4783 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4784 | EXPECT_EQ(OK, |
| 4785 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4786 | net_log_, CompletionOnceCallback())); |
| 4787 | |
| 4788 | // Ensure that session is alive and active. |
| 4789 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4790 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4791 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4792 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4793 | |
| 4794 | // Send GET request. This should cause an async write error. |
| 4795 | HttpResponseInfo response; |
| 4796 | HttpRequestHeaders request_headers; |
| 4797 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4798 | callback_.callback())); |
| 4799 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4800 | |
| 4801 | // Run the message loop so that asynchronous write completes and a connection |
| 4802 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4803 | // runner. |
| 4804 | base::RunLoop().RunUntilIdle(); |
| 4805 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4806 | |
| 4807 | // Run the task runner so that migration on write error is finally executed. |
| 4808 | task_runner->RunUntilIdle(); |
| 4809 | |
| 4810 | // Verify the session is still alive and not marked as going away. |
| 4811 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4812 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4813 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4814 | // There should be one task posted to migrate back to the default network in |
| 4815 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4816 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4817 | base::TimeDelta expected_delay = |
| 4818 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 4819 | EXPECT_EQ(expected_delay, task_runner->NextPendingTaskDelay()); |
| 4820 | |
| 4821 | // Verify that response headers on the migrated socket were delivered to the |
| 4822 | // stream. |
| 4823 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4824 | EXPECT_EQ(200, response.headers->response_code()); |
| 4825 | |
| 4826 | // Set up the third socket data provider for migrate back to default network. |
| 4827 | MockQuicData quic_data3; |
| 4828 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4829 | quic_data3.AddWrite(SYNCHRONOUS, |
| 4830 | client_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4831 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4832 | quic_data3.AddRead(ASYNC, |
| 4833 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4834 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4835 | quic_data3.AddWrite(ASYNC, client_maker_.MakeAckPacket(4, 1, 2, 1, 1, true)); |
| 4836 | quic_data3.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4837 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4838 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame^] | 4839 | quic::QUIC_STREAM_CANCELLED, 0, |
| 4840 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4841 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 4842 | |
| 4843 | // Fast forward to fire the migrate back timer and verify the session |
| 4844 | // successfully migrates back to the default network. |
| 4845 | task_runner->FastForwardBy(expected_delay); |
| 4846 | |
| 4847 | // Verify the session is still alive and not marked as going away. |
| 4848 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4849 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4850 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4851 | |
| 4852 | // There should be one task posted to one will resend a connectivity probe and |
| 4853 | // the other will retry migrate back, both are cancelled. |
| 4854 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4855 | task_runner->FastForwardBy( |
| 4856 | base::TimeDelta::FromSeconds(2 * kMinRetryTimeForDefaultNetworkSecs)); |
| 4857 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4858 | |
| 4859 | stream1.reset(); |
| 4860 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4861 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4862 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4863 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4864 | EXPECT_TRUE(quic_data3.AllReadDataConsumed()); |
| 4865 | EXPECT_TRUE(quic_data3.AllWriteDataConsumed()); |
| 4866 | } |
| 4867 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4868 | // This test verifies that the connection will not attempt connection migration |
| 4869 | // (send connectivity probes on alternate path) when path degrading is detected |
| 4870 | // and handshake is not confirmed. |
| 4871 | TEST_P(QuicStreamFactoryTest, |
| 4872 | NoMigrationOnPathDegradingBeforeHandshakeConfirmed) { |
| 4873 | InitializeConnectionMigrationV2Test( |
| 4874 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4875 | |
| 4876 | // Using a testing task runner. |
| 4877 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4878 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4879 | |
| 4880 | // Use cold start mode to send crypto message for handshake. |
| 4881 | crypto_client_stream_factory_.set_handshake_mode( |
| 4882 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4883 | |
| 4884 | MockQuicData socket_data; |
| 4885 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4886 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4887 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4888 | |
| 4889 | // Create request and QuicHttpStream. |
| 4890 | QuicStreamRequest request(factory_.get()); |
| 4891 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4892 | request.Request( |
| 4893 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4894 | SocketTag(), |
| 4895 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4896 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4897 | |
| 4898 | base::RunLoop().RunUntilIdle(); |
| 4899 | |
| 4900 | // Ensure that session is alive but not active. |
| 4901 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4902 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4903 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4904 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4905 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4906 | |
| 4907 | // Cause the connection to report path degrading to the session. |
| 4908 | // Session will ignore the signal as handshake is not completed. |
| 4909 | session->connection()->OnPathDegradingTimeout(); |
| 4910 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4911 | |
| 4912 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4913 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4914 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4915 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4916 | } |
| 4917 | |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4918 | // This test verifies that if a connection is closed with |
| 4919 | // QUIC_NETWORK_IDLE_TIMEOUT before handshake is completed and there is no |
| 4920 | // alternate network, no new connection will be created. |
| 4921 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkBeforeHandshakeOnIdleTimeout) { |
| 4922 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4923 | } |
| 4924 | |
| 4925 | // This test verifies that if a connection is closed with QUIC_HANDSHAKE_TIMEOUT |
| 4926 | // and there is no alternate network, no new connection will be created. |
| 4927 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkOnHandshakeTimeout) { |
| 4928 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4929 | } |
| 4930 | |
| 4931 | void QuicStreamFactoryTestBase::TestNoAlternateNetworkBeforeHandshake( |
| 4932 | quic::QuicErrorCode quic_error) { |
| 4933 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4934 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4935 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4936 | |
| 4937 | // Using a testing task runner. |
| 4938 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4939 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4940 | |
| 4941 | // Use cold start mode to send crypto message for handshake. |
| 4942 | crypto_client_stream_factory_.set_handshake_mode( |
| 4943 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4944 | |
| 4945 | MockQuicData socket_data; |
| 4946 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4947 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4948 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4949 | |
| 4950 | // Create request. |
| 4951 | QuicStreamRequest request(factory_.get()); |
| 4952 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4953 | request.Request( |
| 4954 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4955 | SocketTag(), |
| 4956 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4957 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4958 | |
| 4959 | base::RunLoop().RunUntilIdle(); |
| 4960 | |
| 4961 | // Ensure that session is alive but not active. |
| 4962 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4963 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4964 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4965 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4966 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4967 | |
| 4968 | // Cause the connection to report path degrading to the session. |
| 4969 | // Session will ignore the signal as handshake is not completed. |
| 4970 | session->connection()->OnPathDegradingTimeout(); |
| 4971 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4972 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4973 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4974 | |
| 4975 | // Cause the connection to close due to |quic_error| before handshake. |
| 4976 | quic::QuicString error_details; |
| 4977 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 4978 | error_details = "No recent network activity."; |
| 4979 | } else { |
| 4980 | error_details = "Handshake timeout expired."; |
| 4981 | } |
| 4982 | session->connection()->CloseConnection( |
| 4983 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 4984 | |
| 4985 | // A task will be posted to clean up the session in the factory. |
| 4986 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4987 | task_runner->FastForwardUntilNoTasksRemain(); |
| 4988 | |
| 4989 | // No new session should be created as there is no alternate network. |
| 4990 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4991 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4992 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4993 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4994 | } |
| 4995 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4996 | TEST_P(QuicStreamFactoryTest, NewConnectionBeforeHandshakeAfterIdleTimeout) { |
| 4997 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4998 | quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4999 | } |
| 5000 | |
| 5001 | TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) { |
| 5002 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 5003 | quic::QUIC_HANDSHAKE_TIMEOUT); |
| 5004 | } |
| 5005 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5006 | // Sets up a test to verify that a new connection will be created on the |
| 5007 | // alternate network after the initial connection fails before handshake with |
| 5008 | // signals delivered in the following order (alternate network is available): |
| 5009 | // - the default network is not able to complete crypto handshake; |
| 5010 | // - the original connection is closed with |quic_error|; |
| 5011 | // - a new connection is created on the alternate network and is able to finish |
| 5012 | // crypto handshake; |
| 5013 | // - the new session on the alternate network attempts to migrate back to the |
| 5014 | // default network by sending probes; |
| 5015 | // - default network being disconnected is delivered: session will stop probing |
| 5016 | // the original network. |
| 5017 | // - alternate network is made by default. |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5018 | void QuicStreamFactoryTestBase:: |
| 5019 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 5020 | quic::QuicErrorCode quic_error) { |
| 5021 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 5022 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 5023 | test_params_.quic_retry_on_alternate_network_before_handshake = true; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5024 | InitializeConnectionMigrationV2Test( |
| 5025 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5026 | |
| 5027 | // Using a testing task runner. |
| 5028 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5029 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 5030 | |
| 5031 | // Use cold start mode to send crypto message for handshake. |
| 5032 | crypto_client_stream_factory_.set_handshake_mode( |
| 5033 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5034 | |
| 5035 | // Socket data for connection on the default network. |
| 5036 | MockQuicData socket_data; |
| 5037 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5038 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 5039 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5040 | |
| 5041 | // Socket data for connection on the alternate network. |
| 5042 | MockQuicData socket_data2; |
| 5043 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5044 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5045 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5046 | // Change the encryption level after handshake is confirmed. |
| 5047 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5048 | socket_data2.AddWrite( |
| 5049 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5050 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5051 | ASYNC, ConstructGetRequestPacket( |
| 5052 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5053 | &header_stream_offset)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5054 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5055 | ASYNC, |
| 5056 | ConstructOkResponsePacket( |
| 5057 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5058 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5059 | socket_data2.AddWrite( |
| 5060 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5061 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5062 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5063 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5064 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5065 | // Socket data for probing on the default network. |
| 5066 | MockQuicData probing_data; |
| 5067 | probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5068 | probing_data.AddWrite(SYNCHRONOUS, |
| 5069 | client_maker_.MakeConnectivityProbingPacket(4, false)); |
| 5070 | probing_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5071 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5072 | // Create request and QuicHttpStream. |
| 5073 | QuicStreamRequest request(factory_.get()); |
| 5074 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5075 | request.Request( |
| 5076 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5077 | SocketTag(), |
| 5078 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5079 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5080 | |
| 5081 | base::RunLoop().RunUntilIdle(); |
| 5082 | |
| 5083 | // Ensure that session is alive but not active. |
| 5084 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5085 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5086 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5087 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5088 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5089 | EXPECT_FALSE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5090 | |
| 5091 | quic::QuicString error_details; |
| 5092 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5093 | error_details = "No recent network activity."; |
| 5094 | } else { |
| 5095 | error_details = "Handshake timeout expired."; |
| 5096 | } |
| 5097 | session->connection()->CloseConnection( |
| 5098 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5099 | |
| 5100 | // A task will be posted to clean up the session in the factory. |
| 5101 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5102 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5103 | |
| 5104 | // Verify a new session is created on the alternate network. |
| 5105 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5106 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5107 | QuicChromiumClientSession* session2 = GetPendingSession(host_port_pair_); |
| 5108 | EXPECT_NE(session, session2); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5109 | EXPECT_TRUE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5110 | |
| 5111 | // Confirm the handshake on the alternate network. |
| 5112 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5113 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5114 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5115 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5116 | // Resume the data now so that data can be sent and read. |
| 5117 | socket_data2.Resume(); |
| 5118 | |
| 5119 | // Create the stream. |
| 5120 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5121 | EXPECT_TRUE(stream.get()); |
| 5122 | HttpRequestInfo request_info; |
| 5123 | request_info.method = "GET"; |
| 5124 | request_info.url = GURL("https://www.example.org/"); |
| 5125 | request_info.traffic_annotation = |
| 5126 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5127 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5128 | net_log_, CompletionOnceCallback())); |
| 5129 | // Send the request. |
| 5130 | HttpResponseInfo response; |
| 5131 | HttpRequestHeaders request_headers; |
| 5132 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5133 | callback_.callback())); |
| 5134 | // Run the message loop to finish asynchronous mock write. |
| 5135 | base::RunLoop().RunUntilIdle(); |
| 5136 | // Read the response. |
| 5137 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5138 | EXPECT_EQ(200, response.headers->response_code()); |
| 5139 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5140 | // There should be a new task posted to migrate back to the default network. |
| 5141 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5142 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5143 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 5144 | next_task_delay); |
| 5145 | task_runner->FastForwardBy(next_task_delay); |
| 5146 | |
| 5147 | // There should be two tasks posted. One will retry probing and the other |
| 5148 | // will retry migrate back. |
| 5149 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 5150 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5151 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 5152 | next_task_delay); |
| 5153 | |
| 5154 | // Deliver the signal that the default network is disconnected. |
| 5155 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5156 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 5157 | // Verify no connectivity probes will be sent as probing will be cancelled. |
| 5158 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5159 | // Deliver the signal that the alternate network is made default. |
| 5160 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5161 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 5162 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5163 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5164 | stream.reset(); |
| 5165 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5166 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5167 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5168 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5169 | } |
| 5170 | |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5171 | // Test that connection will be closed with PACKET_WRITE_ERROR if a write error |
| 5172 | // is triggered before handshake is confirmed and connection migration is turned |
| 5173 | // on. |
| 5174 | TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 5175 | DCHECK(!test_params_.quic_retry_on_alternate_network_before_handshake); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5176 | InitializeConnectionMigrationV2Test( |
| 5177 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5178 | |
| 5179 | // Use unmocked crypto stream to do crypto connect. |
| 5180 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 5181 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5182 | |
| 5183 | MockQuicData socket_data; |
| 5184 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5185 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5186 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5187 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5188 | |
| 5189 | // Create request, should fail after the write of the CHLO fails. |
| 5190 | QuicStreamRequest request(factory_.get()); |
| 5191 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5192 | request.Request( |
| 5193 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5194 | SocketTag(), |
| 5195 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5196 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5197 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 5198 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5199 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5200 | |
| 5201 | // Verify new requests can be sent normally. |
| 5202 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 5203 | MockCryptoClientStream::COLD_START); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5204 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5205 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5206 | MockQuicData socket_data2; |
| 5207 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5208 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 5209 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5210 | |
| 5211 | QuicStreamRequest request2(factory_.get()); |
| 5212 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5213 | request2.Request( |
| 5214 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5215 | SocketTag(), |
| 5216 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5217 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5218 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5219 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5220 | // Run the message loop to complete host resolution. |
| 5221 | base::RunLoop().RunUntilIdle(); |
| 5222 | |
| 5223 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 5224 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5225 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5226 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5227 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5228 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5229 | |
| 5230 | // Create QuicHttpStream. |
| 5231 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
| 5232 | EXPECT_TRUE(stream.get()); |
| 5233 | stream.reset(); |
| 5234 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5235 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5236 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5237 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5238 | } |
| 5239 | |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5240 | // Test that if the original connection is closed with QUIC_PACKET_WRITE_ERROR |
| 5241 | // before handshake is confirmed and new connection before handshake is turned |
| 5242 | // on, a new connection will be retried on the alternate network. |
| 5243 | TEST_P(QuicStreamFactoryTest, |
| 5244 | RetryConnectionOnWriteErrorBeforeHandshakeConfirmed) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 5245 | test_params_.quic_retry_on_alternate_network_before_handshake = true; |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5246 | InitializeConnectionMigrationV2Test( |
| 5247 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5248 | |
| 5249 | // Use unmocked crypto stream to do crypto connect. |
| 5250 | crypto_client_stream_factory_.set_handshake_mode( |
| 5251 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5252 | |
| 5253 | // Socket data for connection on the default network. |
| 5254 | MockQuicData socket_data; |
| 5255 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5256 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5257 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5258 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5259 | |
| 5260 | // Socket data for connection on the alternate network. |
| 5261 | MockQuicData socket_data2; |
| 5262 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5263 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5264 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5265 | // Change the encryption level after handshake is confirmed. |
| 5266 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5267 | socket_data2.AddWrite( |
| 5268 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5269 | socket_data2.AddWrite( |
| 5270 | ASYNC, ConstructGetRequestPacket( |
| 5271 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5272 | &header_stream_offset)); |
| 5273 | socket_data2.AddRead( |
| 5274 | ASYNC, |
| 5275 | ConstructOkResponsePacket( |
| 5276 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5277 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5278 | socket_data2.AddWrite( |
| 5279 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5280 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5281 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5282 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5283 | |
| 5284 | // Create request, should fail after the write of the CHLO fails. |
| 5285 | QuicStreamRequest request(factory_.get()); |
| 5286 | EXPECT_EQ(ERR_IO_PENDING, |
| 5287 | request.Request( |
| 5288 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5289 | SocketTag(), |
| 5290 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5291 | failed_on_default_network_callback_, callback_.callback())); |
| 5292 | // Ensure that the session is alive but not active. |
| 5293 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5294 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5295 | base::RunLoop().RunUntilIdle(); |
| 5296 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5297 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5298 | |
| 5299 | // Confirm the handshake on the alternate network. |
| 5300 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5301 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5302 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5303 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5304 | |
| 5305 | // Resume the data now so that data can be sent and read. |
| 5306 | socket_data2.Resume(); |
| 5307 | |
| 5308 | // Create the stream. |
| 5309 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5310 | EXPECT_TRUE(stream.get()); |
| 5311 | HttpRequestInfo request_info; |
| 5312 | request_info.method = "GET"; |
| 5313 | request_info.url = GURL("https://www.example.org/"); |
| 5314 | request_info.traffic_annotation = |
| 5315 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5316 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5317 | net_log_, CompletionOnceCallback())); |
| 5318 | // Send the request. |
| 5319 | HttpResponseInfo response; |
| 5320 | HttpRequestHeaders request_headers; |
| 5321 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5322 | callback_.callback())); |
| 5323 | // Run the message loop to finish asynchronous mock write. |
| 5324 | base::RunLoop().RunUntilIdle(); |
| 5325 | // Read the response. |
| 5326 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5327 | EXPECT_EQ(200, response.headers->response_code()); |
| 5328 | |
| 5329 | stream.reset(); |
| 5330 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5331 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5332 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5333 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5334 | } |
| 5335 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5336 | void QuicStreamFactoryTestBase::TestMigrationOnWriteError( |
| 5337 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5338 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5339 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5340 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5341 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5342 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5343 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 5344 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5345 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5346 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5347 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5348 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 5349 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5350 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5351 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5352 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5353 | |
| 5354 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5355 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5356 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5357 | request.Request( |
| 5358 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5359 | SocketTag(), |
| 5360 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5361 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5362 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5363 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5364 | EXPECT_TRUE(stream.get()); |
| 5365 | |
| 5366 | // Cause QUIC stream to be created. |
| 5367 | HttpRequestInfo request_info; |
| 5368 | request_info.method = "GET"; |
| 5369 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5370 | request_info.traffic_annotation = |
| 5371 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5372 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5373 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5374 | |
| 5375 | // Ensure that session is alive and active. |
| 5376 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5377 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5378 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5379 | |
| 5380 | // Set up second socket data provider that is used after |
| 5381 | // migration. The request is rewritten to this new socket, and the |
| 5382 | // response to the request is read on this new socket. |
| 5383 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5384 | socket_data1.AddWrite( |
| 5385 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5386 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5387 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5388 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5389 | ASYNC, |
| 5390 | ConstructOkResponsePacket( |
| 5391 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5392 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5393 | socket_data1.AddWrite( |
| 5394 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5395 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5396 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5397 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5398 | |
| 5399 | // Send GET request on stream. This should cause a write error, which triggers |
| 5400 | // a connection migration attempt. |
| 5401 | HttpResponseInfo response; |
| 5402 | HttpRequestHeaders request_headers; |
| 5403 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5404 | callback_.callback())); |
| 5405 | |
| 5406 | // Run the message loop so that the migration attempt is executed and |
| 5407 | // data queued in the new socket is read by the packet reader. |
| 5408 | base::RunLoop().RunUntilIdle(); |
| 5409 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5410 | // Verify that session is alive and not marked as going awya. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5411 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5412 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5413 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5414 | |
| 5415 | // Verify that response headers on the migrated socket were delivered to the |
| 5416 | // stream. |
| 5417 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5418 | EXPECT_EQ(200, response.headers->response_code()); |
| 5419 | |
| 5420 | stream.reset(); |
| 5421 | |
| 5422 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5423 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5424 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5425 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5426 | } |
| 5427 | |
| 5428 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 5429 | TestMigrationOnWriteError(SYNCHRONOUS); |
| 5430 | } |
| 5431 | |
| 5432 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 5433 | TestMigrationOnWriteError(ASYNC); |
| 5434 | } |
| 5435 | |
| 5436 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNoNewNetwork( |
| 5437 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5438 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5439 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5440 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5441 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5442 | // Use the test task runner, to force the migration alarm timeout later. |
| 5443 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 5444 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5445 | MockQuicData socket_data; |
| 5446 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5447 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5448 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5449 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5450 | |
| 5451 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5452 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5453 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5454 | request.Request( |
| 5455 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5456 | SocketTag(), |
| 5457 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5458 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5459 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5460 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5461 | EXPECT_TRUE(stream.get()); |
| 5462 | |
| 5463 | // Cause QUIC stream to be created. |
| 5464 | HttpRequestInfo request_info; |
| 5465 | request_info.method = "GET"; |
| 5466 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5467 | request_info.traffic_annotation = |
| 5468 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5469 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5470 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5471 | |
| 5472 | // Ensure that session is alive and active. |
| 5473 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5474 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5475 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5476 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5477 | // Send GET request on stream. This causes a write error, which triggers |
| 5478 | // a connection migration attempt. Since there are no networks |
| 5479 | // to migrate to, this causes the session to wait for a new network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5480 | HttpResponseInfo response; |
| 5481 | HttpRequestHeaders request_headers; |
| 5482 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5483 | callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5484 | |
| 5485 | // Complete any pending writes. Pending async MockQuicData writes |
| 5486 | // are run on the message loop, not on the test runner. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5487 | base::RunLoop().RunUntilIdle(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5488 | |
| 5489 | // Write error causes migration task to be posted. Spin the loop. |
| 5490 | if (write_error_mode == ASYNC) |
| 5491 | runner_->RunNextTask(); |
| 5492 | |
| 5493 | // Migration has not yet failed. The session should be alive and active. |
| 5494 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5495 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5496 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5497 | EXPECT_TRUE(session->connection()->writer()->IsWriteBlocked()); |
| 5498 | |
| 5499 | // The migration will not fail until the migration alarm timeout. |
| 5500 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5501 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5502 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5503 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 5504 | |
| 5505 | // Force migration alarm timeout to run. |
| 5506 | RunTestLoopUntilIdle(); |
| 5507 | |
| 5508 | // The connection should be closed. A request for response headers |
| 5509 | // should fail. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5510 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5511 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5512 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
| 5513 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 5514 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5515 | |
Zhongyi Shi | 59aaf07 | 2019-01-17 03:32:13 | [diff] [blame] | 5516 | NetErrorDetails error_details; |
| 5517 | stream->PopulateNetErrorDetails(&error_details); |
| 5518 | EXPECT_EQ(error_details.quic_connection_error, |
| 5519 | quic::QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
| 5520 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5521 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5522 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5523 | } |
| 5524 | |
| 5525 | TEST_P(QuicStreamFactoryTest, |
| 5526 | MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 5527 | TestMigrationOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 5528 | } |
| 5529 | |
| 5530 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 5531 | TestMigrationOnWriteErrorNoNewNetwork(ASYNC); |
| 5532 | } |
| 5533 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5534 | TEST_P(QuicStreamFactoryTest, |
| 5535 | MigrateSessionOnWriteErrorWithMultipleRequestsSync) { |
| 5536 | TestMigrationOnWriteErrorWithMultipleRequests(SYNCHRONOUS); |
| 5537 | } |
| 5538 | |
| 5539 | TEST_P(QuicStreamFactoryTest, |
| 5540 | MigrateSessionOnWriteErrorWithMultipleRequestsAsync) { |
| 5541 | TestMigrationOnWriteErrorWithMultipleRequests(ASYNC); |
| 5542 | } |
| 5543 | |
| 5544 | // Sets up a test which verifies that connection migration on write error can |
| 5545 | // eventually succeed and rewrite the packet on the new network with *multiple* |
| 5546 | // migratable streams. |
| 5547 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( |
| 5548 | IoMode write_error_mode) { |
| 5549 | InitializeConnectionMigrationV2Test( |
| 5550 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5551 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5552 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5553 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5554 | |
| 5555 | MockQuicData socket_data; |
| 5556 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5557 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5558 | socket_data.AddWrite( |
| 5559 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5560 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5561 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5562 | |
| 5563 | // Set up second socket data provider that is used after |
| 5564 | // migration. The request is rewritten to this new socket, and the |
| 5565 | // response to the request is read on this new socket. |
| 5566 | MockQuicData socket_data1; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5567 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5568 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5569 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5570 | true, &header_stream_offset)); |
| 5571 | socket_data1.AddRead( |
| 5572 | ASYNC, |
| 5573 | ConstructOkResponsePacket( |
| 5574 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5575 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5576 | socket_data1.AddWrite( |
| 5577 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5578 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5579 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5580 | socket_data1.AddWrite( |
| 5581 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 5582 | 4, false, GetNthClientInitiatedBidirectionalStreamId(1), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame^] | 5583 | quic::QUIC_STREAM_CANCELLED, 0, |
| 5584 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5585 | |
| 5586 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5587 | |
| 5588 | // Create request #1 and QuicHttpStream. |
| 5589 | QuicStreamRequest request1(factory_.get()); |
| 5590 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5591 | request1.Request( |
| 5592 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5593 | SocketTag(), |
| 5594 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5595 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5596 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5597 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5598 | EXPECT_TRUE(stream1.get()); |
| 5599 | |
| 5600 | HttpRequestInfo request_info1; |
| 5601 | request_info1.method = "GET"; |
| 5602 | request_info1.url = GURL("https://www.example.org/"); |
| 5603 | request_info1.traffic_annotation = |
| 5604 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5605 | EXPECT_EQ(OK, |
| 5606 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5607 | net_log_, CompletionOnceCallback())); |
| 5608 | |
| 5609 | // Second request returns synchronously because it pools to existing session. |
| 5610 | TestCompletionCallback callback2; |
| 5611 | QuicStreamRequest request2(factory_.get()); |
| 5612 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5613 | DEFAULT_PRIORITY, SocketTag(), |
| 5614 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5615 | &net_error_details_, |
| 5616 | failed_on_default_network_callback_, |
| 5617 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5618 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5619 | EXPECT_TRUE(stream2.get()); |
| 5620 | HttpRequestInfo request_info2; |
| 5621 | request_info2.method = "GET"; |
| 5622 | request_info2.url = GURL("https://www.example.org/"); |
| 5623 | request_info2.traffic_annotation = |
| 5624 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5625 | EXPECT_EQ(OK, |
| 5626 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5627 | net_log_, CompletionOnceCallback())); |
| 5628 | |
| 5629 | // Ensure that session is alive and active. |
| 5630 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5631 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5632 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5633 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5634 | |
| 5635 | // Send GET request on stream. This should cause a write error, which triggers |
| 5636 | // a connection migration attempt. |
| 5637 | HttpResponseInfo response; |
| 5638 | HttpRequestHeaders request_headers; |
| 5639 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5640 | callback_.callback())); |
| 5641 | |
| 5642 | // Run the message loop so that the migration attempt is executed and |
| 5643 | // data queued in the new socket is read by the packet reader. |
| 5644 | base::RunLoop().RunUntilIdle(); |
| 5645 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5646 | // Verify session is still alive and not marked as going away. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5647 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5648 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5649 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5650 | |
| 5651 | // Verify that response headers on the migrated socket were delivered to the |
| 5652 | // stream. |
| 5653 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5654 | EXPECT_EQ(200, response.headers->response_code()); |
| 5655 | |
| 5656 | stream1.reset(); |
| 5657 | stream2.reset(); |
| 5658 | |
| 5659 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5660 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5661 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5662 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5663 | } |
| 5664 | |
| 5665 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsSync) { |
| 5666 | TestMigrationOnWriteErrorMixedStreams(SYNCHRONOUS); |
| 5667 | } |
| 5668 | |
| 5669 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsAsync) { |
| 5670 | TestMigrationOnWriteErrorMixedStreams(ASYNC); |
| 5671 | } |
| 5672 | |
| 5673 | // Sets up a test that verifies connection migration manages to migrate to |
| 5674 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5675 | // |write_error_mode| on the original network. |
| 5676 | // Note there are mixed types of unfinished requests before migration: one |
| 5677 | // migratable and one non-migratable. The *migratable* one triggers write |
| 5678 | // error. |
| 5679 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( |
| 5680 | IoMode write_error_mode) { |
| 5681 | InitializeConnectionMigrationV2Test( |
| 5682 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5683 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5684 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5685 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5686 | |
| 5687 | int packet_number = 1; |
| 5688 | MockQuicData socket_data; |
| 5689 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5690 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5691 | socket_data.AddWrite( |
| 5692 | SYNCHRONOUS, |
| 5693 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5694 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5695 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5696 | |
| 5697 | // Set up second socket data provider that is used after |
| 5698 | // migration. The request is rewritten to this new socket, and the |
| 5699 | // response to the request is read on this new socket. |
| 5700 | MockQuicData socket_data1; |
| 5701 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5702 | SYNCHRONOUS, |
| 5703 | ConstructGetRequestPacket(packet_number++, |
| 5704 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5705 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5706 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5707 | SYNCHRONOUS, |
| 5708 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5709 | 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 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5713 | ASYNC, |
| 5714 | ConstructOkResponsePacket( |
| 5715 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5716 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5717 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5718 | SYNCHRONOUS, |
| 5719 | client_maker_.MakeAckAndRstPacket( |
| 5720 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5721 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5722 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5723 | |
| 5724 | // Create request #1 and QuicHttpStream. |
| 5725 | QuicStreamRequest request1(factory_.get()); |
| 5726 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5727 | request1.Request( |
| 5728 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5729 | SocketTag(), |
| 5730 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5731 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5732 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5733 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5734 | EXPECT_TRUE(stream1.get()); |
| 5735 | |
| 5736 | HttpRequestInfo request_info1; |
| 5737 | request_info1.method = "GET"; |
| 5738 | request_info1.url = GURL("https://www.example.org/"); |
| 5739 | request_info1.traffic_annotation = |
| 5740 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5741 | EXPECT_EQ(OK, |
| 5742 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5743 | net_log_, CompletionOnceCallback())); |
| 5744 | |
| 5745 | // Second request returns synchronously because it pools to existing session. |
| 5746 | TestCompletionCallback callback2; |
| 5747 | QuicStreamRequest request2(factory_.get()); |
| 5748 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5749 | DEFAULT_PRIORITY, SocketTag(), |
| 5750 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5751 | &net_error_details_, |
| 5752 | failed_on_default_network_callback_, |
| 5753 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5754 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5755 | EXPECT_TRUE(stream2.get()); |
| 5756 | |
| 5757 | HttpRequestInfo request_info2; |
| 5758 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5759 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5760 | request_info2.url = GURL("https://www.example.org/"); |
| 5761 | request_info2.traffic_annotation = |
| 5762 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5763 | EXPECT_EQ(OK, |
| 5764 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5765 | net_log_, CompletionOnceCallback())); |
| 5766 | |
| 5767 | // Ensure that session is alive and active. |
| 5768 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5769 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5770 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5771 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5772 | |
| 5773 | // Send GET request on stream 1. This should cause a write error, which |
| 5774 | // triggers a connection migration attempt. |
| 5775 | HttpResponseInfo response; |
| 5776 | HttpRequestHeaders request_headers; |
| 5777 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5778 | callback_.callback())); |
| 5779 | |
| 5780 | // Run the message loop so that the migration attempt is executed and |
| 5781 | // data queued in the new socket is read by the packet reader. |
| 5782 | base::RunLoop().RunUntilIdle(); |
| 5783 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5784 | // Verify that the session is still alive and not marked as going away. |
| 5785 | // Non-migratable stream should be closed due to migration. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5786 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5787 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5788 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5789 | |
| 5790 | // Verify that response headers on the migrated socket were delivered to the |
| 5791 | // stream. |
| 5792 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5793 | EXPECT_EQ(200, response.headers->response_code()); |
| 5794 | |
| 5795 | stream1.reset(); |
| 5796 | |
| 5797 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5798 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5799 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5800 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5801 | } |
| 5802 | |
| 5803 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Sync) { |
| 5804 | TestMigrationOnWriteErrorMixedStreams2(SYNCHRONOUS); |
| 5805 | } |
| 5806 | |
| 5807 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Async) { |
| 5808 | TestMigrationOnWriteErrorMixedStreams2(ASYNC); |
| 5809 | } |
| 5810 | |
| 5811 | // The one triggers write error is a non-migratable stream. |
| 5812 | // Sets up a test that verifies connection migration manages to migrate to |
| 5813 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5814 | // |write_error_mode| on the original network. |
| 5815 | // Note there are mixed types of unfinished requests before migration: one |
| 5816 | // migratable and one non-migratable. The *non-migratable* one triggers write |
| 5817 | // error. |
| 5818 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( |
| 5819 | IoMode write_error_mode) { |
| 5820 | InitializeConnectionMigrationV2Test( |
| 5821 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5822 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5823 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5824 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5825 | |
| 5826 | int packet_number = 1; |
| 5827 | MockQuicData socket_data; |
| 5828 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5829 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5830 | socket_data.AddWrite( |
| 5831 | SYNCHRONOUS, |
| 5832 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5833 | socket_data.AddWrite(write_error_mode, |
| 5834 | ERR_ADDRESS_UNREACHABLE); // Write error. |
| 5835 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5836 | |
| 5837 | // Set up second socket data provider that is used after |
| 5838 | // migration. The request is rewritten to this new socket, and the |
| 5839 | // response to the request is read on this new socket. |
| 5840 | MockQuicData socket_data1; |
| 5841 | // The packet triggered writer error will be sent anyway even if the stream |
| 5842 | // will be cancelled later. |
| 5843 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5844 | SYNCHRONOUS, |
| 5845 | ConstructGetRequestPacket(packet_number++, |
| 5846 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5847 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5848 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5849 | SYNCHRONOUS, |
| 5850 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5851 | GetNthClientInitiatedBidirectionalStreamId(1), |
Frank Kastenholz | 684ea41 | 2019-02-13 18:48:18 | [diff] [blame^] | 5852 | quic::QUIC_STREAM_CANCELLED, 0, |
| 5853 | /*include_stop_sending_if_v99=*/true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5854 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5855 | SYNCHRONOUS, |
| 5856 | ConstructGetRequestPacket(packet_number++, |
| 5857 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5858 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5859 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5860 | ASYNC, |
| 5861 | ConstructOkResponsePacket( |
| 5862 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5863 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5864 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5865 | SYNCHRONOUS, |
| 5866 | client_maker_.MakeAckAndRstPacket( |
| 5867 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5868 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5869 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5870 | |
| 5871 | // Create request #1 and QuicHttpStream. |
| 5872 | QuicStreamRequest request1(factory_.get()); |
| 5873 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5874 | request1.Request( |
| 5875 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5876 | SocketTag(), |
| 5877 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5878 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5879 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5880 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5881 | EXPECT_TRUE(stream1.get()); |
| 5882 | |
| 5883 | HttpRequestInfo request_info1; |
| 5884 | request_info1.method = "GET"; |
| 5885 | request_info1.url = GURL("https://www.example.org/"); |
| 5886 | request_info1.traffic_annotation = |
| 5887 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5888 | EXPECT_EQ(OK, |
| 5889 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5890 | net_log_, CompletionOnceCallback())); |
| 5891 | |
| 5892 | // Second request returns synchronously because it pools to existing session. |
| 5893 | TestCompletionCallback callback2; |
| 5894 | QuicStreamRequest request2(factory_.get()); |
| 5895 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5896 | DEFAULT_PRIORITY, SocketTag(), |
| 5897 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5898 | &net_error_details_, |
| 5899 | failed_on_default_network_callback_, |
| 5900 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5901 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5902 | EXPECT_TRUE(stream2.get()); |
| 5903 | |
| 5904 | HttpRequestInfo request_info2; |
| 5905 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5906 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5907 | request_info2.url = GURL("https://www.example.org/"); |
| 5908 | request_info2.traffic_annotation = |
| 5909 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5910 | EXPECT_EQ(OK, |
| 5911 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5912 | net_log_, CompletionOnceCallback())); |
| 5913 | |
| 5914 | // Ensure that session is alive and active. |
| 5915 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5916 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5917 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5918 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5919 | |
| 5920 | // Send GET request on stream 2 which is non-migratable. This should cause a |
| 5921 | // write error, which triggers a connection migration attempt. |
| 5922 | HttpResponseInfo response2; |
| 5923 | HttpRequestHeaders request_headers2; |
| 5924 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 5925 | callback2.callback())); |
| 5926 | |
| 5927 | // Run the message loop so that the migration attempt is executed and |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5928 | // data queued in the new socket is read by the packet reader. Session is |
| 5929 | // still alive and not marked as going away, non-migratable stream will be |
| 5930 | // closed. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5931 | base::RunLoop().RunUntilIdle(); |
| 5932 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5933 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5934 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5935 | |
| 5936 | // Send GET request on stream 1. |
| 5937 | HttpResponseInfo response; |
| 5938 | HttpRequestHeaders request_headers; |
| 5939 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5940 | callback_.callback())); |
| 5941 | |
| 5942 | base::RunLoop().RunUntilIdle(); |
| 5943 | |
| 5944 | // Verify that response headers on the migrated socket were delivered to the |
| 5945 | // stream. |
| 5946 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5947 | EXPECT_EQ(200, response.headers->response_code()); |
| 5948 | |
| 5949 | stream1.reset(); |
| 5950 | |
| 5951 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5952 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5953 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5954 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5955 | } |
| 5956 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 5957 | // This test verifies that when a connection encounters a packet write error, it |
| 5958 | // will cancel non-migratable streams, and migrate to the alternate network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5959 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( |
| 5960 | IoMode write_error_mode) { |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 5961 | DVLOG(1) << "Write error mode: " |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5962 | << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5963 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5964 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5965 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5966 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5967 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 5968 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5969 | // The socket data provider for the original socket before migration. |
| 5970 | MockQuicData failed_socket_data; |
| 5971 | failed_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5972 | failed_socket_data.AddWrite( |
| 5973 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5974 | failed_socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5975 | failed_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5976 | |
| 5977 | // Set up second socket data provider that is used after migration. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5978 | MockQuicData socket_data; |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 5979 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5980 | // Although the write error occurs when writing a packet for the |
| 5981 | // non-migratable stream and the stream will be cancelled during migration, |
| 5982 | // the packet will still be retransimitted at the connection level. |
| 5983 | socket_data.AddWrite( |
| 5984 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5985 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5986 | true, &header_stream_offset)); |
| 5987 | // A RESET will be sent to the peer to cancel the non-migratable stream. |
| 5988 | socket_data.AddWrite( |
| 5989 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 5990 | 3, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5991 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5992 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5993 | |
| 5994 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5995 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5996 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5997 | request.Request( |
| 5998 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5999 | SocketTag(), |
| 6000 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6001 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6002 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6003 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6004 | EXPECT_TRUE(stream.get()); |
| 6005 | |
| 6006 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 6007 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 6008 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6009 | request_info.method = "GET"; |
| 6010 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6011 | request_info.traffic_annotation = |
| 6012 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6013 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6014 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6015 | |
| 6016 | // Ensure that session is alive and active. |
| 6017 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6018 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6019 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6020 | |
| 6021 | // Send GET request on stream. This should cause a write error, which triggers |
| 6022 | // a connection migration attempt. |
| 6023 | HttpResponseInfo response; |
| 6024 | HttpRequestHeaders request_headers; |
| 6025 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6026 | callback_.callback())); |
| 6027 | |
| 6028 | // Run message loop to execute migration attempt. |
| 6029 | base::RunLoop().RunUntilIdle(); |
| 6030 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 6031 | // Migration closes the non-migratable stream and then migrates to the |
| 6032 | // alternate network successfully.. |
| 6033 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6034 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6035 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 6036 | EXPECT_TRUE(failed_socket_data.AllReadDataConsumed()); |
| 6037 | EXPECT_TRUE(failed_socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6038 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6039 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6040 | } |
| 6041 | |
| 6042 | TEST_P(QuicStreamFactoryTest, |
| 6043 | MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { |
| 6044 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS); |
| 6045 | } |
| 6046 | |
| 6047 | TEST_P(QuicStreamFactoryTest, |
| 6048 | MigrateSessionOnWriteErrorNonMigratableStreamAsync) { |
| 6049 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC); |
| 6050 | } |
| 6051 | |
| 6052 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( |
| 6053 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6054 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6055 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6056 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6057 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6058 | |
| 6059 | MockQuicData socket_data; |
| 6060 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6061 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6062 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6063 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6064 | |
| 6065 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6066 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6067 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6068 | request.Request( |
| 6069 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6070 | SocketTag(), |
| 6071 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6072 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6073 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6074 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6075 | EXPECT_TRUE(stream.get()); |
| 6076 | |
| 6077 | // Cause QUIC stream to be created. |
| 6078 | HttpRequestInfo request_info; |
| 6079 | request_info.method = "GET"; |
| 6080 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6081 | request_info.traffic_annotation = |
| 6082 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6083 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6084 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6085 | |
| 6086 | // Ensure that session is alive and active. |
| 6087 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6088 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6089 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6090 | |
| 6091 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6092 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 6093 | session->config()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6094 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 6095 | |
| 6096 | // Send GET request on stream. This should cause a write error, which triggers |
| 6097 | // a connection migration attempt. |
| 6098 | HttpResponseInfo response; |
| 6099 | HttpRequestHeaders request_headers; |
| 6100 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6101 | callback_.callback())); |
| 6102 | // Run message loop to execute migration attempt. |
| 6103 | base::RunLoop().RunUntilIdle(); |
| 6104 | // Migration fails, and session is closed and deleted. |
| 6105 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6106 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6107 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6108 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6109 | } |
| 6110 | |
| 6111 | TEST_P(QuicStreamFactoryTest, |
| 6112 | MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 6113 | TestMigrationOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 6114 | } |
| 6115 | |
| 6116 | TEST_P(QuicStreamFactoryTest, |
| 6117 | MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 6118 | TestMigrationOnWriteErrorMigrationDisabled(ASYNC); |
| 6119 | } |
| 6120 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6121 | // Sets up a test which verifies that connection migration on write error can |
| 6122 | // eventually succeed and rewrite the packet on the new network with singals |
| 6123 | // delivered in the following order (alternate network is always availabe): |
| 6124 | // - original network encounters a SYNC/ASYNC write error based on |
| 6125 | // |write_error_mode_on_old_network|, the packet failed to be written is |
| 6126 | // cached, session migrates immediately to the alternate network. |
| 6127 | // - an immediate SYNC/ASYNC write error based on |
| 6128 | // |write_error_mode_on_new_network| is encountered after migration to the |
| 6129 | // alternate network, session migrates immediately to the original network. |
| 6130 | // - an immediate SYNC/ASYNC write error based on |
| 6131 | // |write_error_mode_on_old_network| is encountered after migration to the |
| 6132 | // original network, session migrates immediately to the alternate network. |
| 6133 | // - finally, session successfully sends the packet and reads the response on |
| 6134 | // the alternate network. |
| 6135 | // TODO(zhongyi): once https://crbug.com/855666 is fixed, this test should be |
| 6136 | // modified to test that session is closed early if hopping between networks |
| 6137 | // with consecutive write errors is detected. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6138 | void QuicStreamFactoryTestBase::TestMigrationOnMultipleWriteErrors( |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6139 | IoMode write_error_mode_on_old_network, |
| 6140 | IoMode write_error_mode_on_new_network) { |
| 6141 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6142 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6143 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6144 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6145 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6146 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6147 | // Set up the socket data used by the original network, which encounters a |
| 6148 | // write erorr. |
| 6149 | MockQuicData socket_data1; |
| 6150 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6151 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6152 | socket_data1.AddWrite( |
| 6153 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6154 | socket_data1.AddWrite(write_error_mode_on_old_network, |
| 6155 | ERR_ADDRESS_UNREACHABLE); // Write Error |
| 6156 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6157 | |
| 6158 | // Set up the socket data used by the alternate network, which also |
| 6159 | // encounters a write error. |
| 6160 | MockQuicData failed_quic_data2; |
| 6161 | failed_quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6162 | failed_quic_data2.AddWrite(write_error_mode_on_new_network, ERR_FAILED); |
| 6163 | failed_quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 6164 | |
| 6165 | // Set up the third socket data used by original network, which encounters a |
| 6166 | // write error again. |
| 6167 | MockQuicData failed_quic_data1; |
| 6168 | failed_quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6169 | failed_quic_data1.AddWrite(write_error_mode_on_old_network, ERR_FAILED); |
| 6170 | failed_quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6171 | |
| 6172 | // Set up the last socket data used by the alternate network, which will |
| 6173 | // finish migration successfully. The request is rewritten to this new socket, |
| 6174 | // and the response to the request is read on this socket. |
| 6175 | MockQuicData socket_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6176 | socket_data2.AddWrite( |
| 6177 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6178 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6179 | true, &header_stream_offset)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6180 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6181 | ASYNC, |
| 6182 | ConstructOkResponsePacket( |
| 6183 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6184 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6185 | socket_data2.AddWrite( |
| 6186 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6187 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6188 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6189 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6190 | |
| 6191 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6192 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6193 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6194 | request.Request( |
| 6195 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6196 | SocketTag(), |
| 6197 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6198 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6199 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6200 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6201 | EXPECT_TRUE(stream.get()); |
| 6202 | |
| 6203 | // Cause QUIC stream to be created. |
| 6204 | HttpRequestInfo request_info; |
| 6205 | request_info.method = "GET"; |
| 6206 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6207 | request_info.traffic_annotation = |
| 6208 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6209 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6210 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6211 | |
| 6212 | // Ensure that session is alive and active. |
| 6213 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6214 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6215 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6216 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6217 | // Send GET request on stream. |
| 6218 | // This should encounter a write error on network 1, |
| 6219 | // then migrate to network 2, which encounters another write error, |
| 6220 | // and migrate again to network 1, which encoutners one more write error. |
| 6221 | // Finally the session migrates to network 2 successfully. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6222 | HttpResponseInfo response; |
| 6223 | HttpRequestHeaders request_headers; |
| 6224 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6225 | callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6226 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6227 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6228 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6229 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6230 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6231 | // Verify that response headers on the migrated socket were delivered to the |
| 6232 | // stream. |
| 6233 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6234 | EXPECT_EQ(200, response.headers->response_code()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6235 | |
| 6236 | stream.reset(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6237 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6238 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6239 | EXPECT_TRUE(failed_quic_data2.AllReadDataConsumed()); |
| 6240 | EXPECT_TRUE(failed_quic_data2.AllWriteDataConsumed()); |
| 6241 | EXPECT_TRUE(failed_quic_data1.AllReadDataConsumed()); |
| 6242 | EXPECT_TRUE(failed_quic_data1.AllWriteDataConsumed()); |
| 6243 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 6244 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6248 | TestMigrationOnMultipleWriteErrors( |
| 6249 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6250 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6254 | TestMigrationOnMultipleWriteErrors( |
| 6255 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6256 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6260 | TestMigrationOnMultipleWriteErrors( |
| 6261 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6262 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6266 | TestMigrationOnMultipleWriteErrors( |
| 6267 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6268 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6269 | } |
| 6270 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6271 | // Verifies that a connection is closed when connection migration is triggered |
| 6272 | // on network being disconnected and the handshake is not confirmed. |
| 6273 | TEST_P(QuicStreamFactoryTest, NoMigrationBeforeHandshakeOnNetworkDisconnected) { |
| 6274 | InitializeConnectionMigrationV2Test( |
| 6275 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6276 | |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6277 | // 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] | 6278 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6279 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6280 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6281 | MockQuicData socket_data; |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6282 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5068bb0 | 2018-08-03 02:44:09 | [diff] [blame] | 6283 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6284 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6285 | |
| 6286 | // Create request and QuicHttpStream. |
| 6287 | QuicStreamRequest request(factory_.get()); |
| 6288 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6289 | request.Request( |
| 6290 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6291 | SocketTag(), |
| 6292 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6293 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6294 | // Deliver the network notification, which should cause the connection to be |
| 6295 | // closed. |
| 6296 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6297 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6298 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6299 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6300 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6301 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6302 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6303 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6304 | } |
| 6305 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6306 | // Sets up the connection migration test where network change notification is |
| 6307 | // queued BEFORE connection migration attempt on write error is posted. |
| 6308 | void QuicStreamFactoryTestBase:: |
| 6309 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6310 | bool disconnected) { |
| 6311 | InitializeConnectionMigrationV2Test( |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6312 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6313 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6314 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6315 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6316 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6317 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6318 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6319 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6320 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6321 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6322 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6323 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6324 | |
| 6325 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6326 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6327 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6328 | request.Request( |
| 6329 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6330 | SocketTag(), |
| 6331 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6332 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6333 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6334 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6335 | EXPECT_TRUE(stream.get()); |
| 6336 | |
| 6337 | // Cause QUIC stream to be created. |
| 6338 | HttpRequestInfo request_info; |
| 6339 | request_info.method = "GET"; |
| 6340 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6341 | request_info.traffic_annotation = |
| 6342 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6343 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6344 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6345 | |
| 6346 | // Ensure that session is alive and active. |
| 6347 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6348 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6349 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6350 | |
| 6351 | // Set up second socket data provider that is used after |
| 6352 | // migration. The request is rewritten to this new socket, and the |
| 6353 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6354 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6355 | socket_data1.AddWrite( |
| 6356 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6357 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6358 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6359 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6360 | ASYNC, |
| 6361 | ConstructOkResponsePacket( |
| 6362 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6363 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6364 | socket_data1.AddWrite( |
| 6365 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6366 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6367 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6368 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6369 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6370 | // First queue a network change notification in the message loop. |
| 6371 | if (disconnected) { |
| 6372 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6373 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6374 | } else { |
| 6375 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6376 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6377 | } |
| 6378 | // Send GET request on stream. This should cause a write error, |
| 6379 | // which triggers a connection migration attempt. This will queue a |
| 6380 | // migration attempt behind the notification in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6381 | HttpResponseInfo response; |
| 6382 | HttpRequestHeaders request_headers; |
| 6383 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6384 | callback_.callback())); |
| 6385 | |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6386 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6387 | // Verify the session is still alive and not marked as going away post |
| 6388 | // migration. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6389 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6390 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6391 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6392 | |
| 6393 | // Verify that response headers on the migrated socket were delivered to the |
| 6394 | // stream. |
| 6395 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6396 | EXPECT_EQ(200, response.headers->response_code()); |
| 6397 | |
| 6398 | stream.reset(); |
| 6399 | |
| 6400 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6401 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6402 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6403 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6404 | } |
| 6405 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6406 | // This test verifies that session attempts connection migration successfully |
| 6407 | // with signals delivered in the following order (alternate network is always |
| 6408 | // available): |
| 6409 | // - a notification that default network is disconnected is queued. |
| 6410 | // - write error is triggered: session posts a task to attempt connection |
| 6411 | // migration, |migration_pending_| set to true. |
| 6412 | // - default network disconnected is delivered: session immediately migrates to |
| 6413 | // the alternate network, |migration_pending_| set to false. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6414 | // - connection migration on write error attempt aborts: writer encountered |
| 6415 | // error is no longer in active use. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6416 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6417 | MigrateOnNetworkDisconnectedWithWriteErrorQueuedLater) { |
| 6418 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6419 | /*disconnected=*/true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6420 | } |
| 6421 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6422 | // This test verifies that session attempts connection migration successfully |
| 6423 | // with signals delivered in the following order (alternate network is always |
| 6424 | // available): |
| 6425 | // - a notification that alternate network is made default is queued. |
| 6426 | // - write error is triggered: session posts a task to attempt connection |
| 6427 | // migration, block future migrations. |
| 6428 | // - new default notification is delivered: migrate back timer spins and task is |
| 6429 | // posted to migrate to the new default network. |
| 6430 | // - connection migration on write error attempt proceeds successfully: session |
| 6431 | // is |
| 6432 | // marked as going away, future migrations unblocked. |
| 6433 | // - migrate back to default network task executed: session is already on the |
| 6434 | // default network, no-op. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6435 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6436 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedEarlier) { |
| 6437 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6438 | /*disconnected=*/false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6439 | } |
| 6440 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6441 | // Sets up the connection migration test where network change notification is |
| 6442 | // queued AFTER connection migration attempt on write error is posted. |
| 6443 | void QuicStreamFactoryTestBase:: |
| 6444 | TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6445 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6446 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6447 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6448 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6449 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6450 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6451 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6452 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6453 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6454 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6455 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6456 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6457 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6458 | |
| 6459 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6460 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6461 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6462 | request.Request( |
| 6463 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6464 | SocketTag(), |
| 6465 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6466 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6467 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6468 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6469 | EXPECT_TRUE(stream.get()); |
| 6470 | |
| 6471 | // Cause QUIC stream to be created. |
| 6472 | HttpRequestInfo request_info; |
| 6473 | request_info.method = "GET"; |
| 6474 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6475 | request_info.traffic_annotation = |
| 6476 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6477 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6478 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6479 | |
| 6480 | // Ensure that session is alive and active. |
| 6481 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6482 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6483 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6484 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6485 | // Set up second socket data provider that is used after |
| 6486 | // migration. The request is rewritten to this new socket, and the |
| 6487 | // response to the request is read on this new socket. |
| 6488 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6489 | socket_data1.AddWrite( |
| 6490 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6491 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6492 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6493 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6494 | ASYNC, |
| 6495 | ConstructOkResponsePacket( |
| 6496 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6497 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6498 | socket_data1.AddWrite( |
| 6499 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6500 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6501 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6502 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6503 | |
| 6504 | // Send GET request on stream. This should cause a write error, |
| 6505 | // which triggers a connection migration attempt. This will queue a |
| 6506 | // migration attempt in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6507 | HttpResponseInfo response; |
| 6508 | HttpRequestHeaders request_headers; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6509 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6510 | callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6511 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6512 | // Now queue a network change notification in the message loop behind |
| 6513 | // the migration attempt. |
| 6514 | if (disconnected) { |
| 6515 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6516 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6517 | } else { |
| 6518 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6519 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6520 | } |
| 6521 | |
| 6522 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6523 | // Verify session is still alive and not marked as going away. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6524 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6525 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6526 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6527 | |
| 6528 | // Verify that response headers on the migrated socket were delivered to the |
| 6529 | // stream. |
| 6530 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6531 | EXPECT_EQ(200, response.headers->response_code()); |
| 6532 | |
| 6533 | stream.reset(); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6534 | |
| 6535 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6536 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6537 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6538 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6539 | } |
| 6540 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6541 | // This test verifies that session attempts connection migration successfully |
| 6542 | // with signals delivered in the following order (alternate network is always |
| 6543 | // available): |
| 6544 | // - write error is triggered: session posts a task to complete connection |
| 6545 | // migration. |
| 6546 | // - a notification that alternate network is made default is queued. |
| 6547 | // - connection migration attempt proceeds successfully, session is marked as |
| 6548 | // going away. |
| 6549 | // - new default notification is delivered after connection migration has been |
| 6550 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6551 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6552 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedLater) { |
| 6553 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/false); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6554 | } |
| 6555 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6556 | // This test verifies that session attempts connection migration successfully |
| 6557 | // with signals delivered in the following order (alternate network is always |
| 6558 | // available): |
| 6559 | // - write error is triggered: session posts a task to complete connection |
| 6560 | // migration. |
| 6561 | // - a notification that default network is diconnected is queued. |
| 6562 | // - connection migration attempt proceeds successfully, session is marked as |
| 6563 | // going away. |
| 6564 | // - disconnect notification is delivered after connection migration has been |
| 6565 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6566 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6567 | MigrateOnWriteErrorWithNetworkDisconnectedQueuedLater) { |
| 6568 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/true); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6569 | } |
| 6570 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6571 | // This tests connection migration on write error with signals delivered in the |
| 6572 | // following order: |
| 6573 | // - a synchronous/asynchronous write error is triggered base on |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6574 | // |write_error_mode|: connection migration attempt is posted. |
| 6575 | // - old default network disconnects, migration waits for a new network. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6576 | // - after a pause, new network is connected: session will migrate to new |
| 6577 | // network immediately. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6578 | // - migration on writer error is exectued and aborts as writer passed in is no |
| 6579 | // longer active in use. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6580 | // - new network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6581 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorPauseBeforeConnected( |
| 6582 | IoMode write_error_mode) { |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6583 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6584 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6585 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6586 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6587 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6588 | // Use the test task runner. |
| 6589 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 6590 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6591 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6592 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6593 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6594 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6595 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6596 | socket_data.AddWrite(write_error_mode, ERR_FAILED); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6597 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6598 | |
| 6599 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6600 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6601 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6602 | request.Request( |
| 6603 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6604 | SocketTag(), |
| 6605 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6606 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6607 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6608 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6609 | EXPECT_TRUE(stream.get()); |
| 6610 | |
| 6611 | // Cause QUIC stream to be created. |
| 6612 | HttpRequestInfo request_info; |
| 6613 | request_info.method = "GET"; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6614 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6615 | request_info.traffic_annotation = |
| 6616 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6617 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6618 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6619 | |
| 6620 | // Ensure that session is alive and active. |
| 6621 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6622 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6623 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6624 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6625 | // Send GET request on stream. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6626 | HttpResponseInfo response; |
| 6627 | HttpRequestHeaders request_headers; |
| 6628 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6629 | callback_.callback())); |
| 6630 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6631 | // The connection should still be alive, not marked as going away. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6632 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6633 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6634 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6635 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6636 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6637 | // Set up second socket data provider that is used after migration. |
| 6638 | // The response to the earlier request is read on this new socket. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6639 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6640 | socket_data1.AddWrite( |
| 6641 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6642 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6643 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6644 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6645 | ASYNC, |
| 6646 | ConstructOkResponsePacket( |
| 6647 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6648 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6649 | socket_data1.AddWrite( |
| 6650 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6651 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6652 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6653 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6654 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6655 | // On a DISCONNECTED notification, nothing happens. |
| 6656 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6657 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6658 | // Add a new network and notify the stream factory of a new connected network. |
| 6659 | // This causes a PING packet to be sent over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6660 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6661 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 6662 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6663 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 6664 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6665 | // Ensure that the session is still alive. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6666 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6667 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6668 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6669 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6670 | // Run the message loop migration for write error can finish. |
| 6671 | runner_->RunUntilIdle(); |
| 6672 | |
| 6673 | // Response headers are received over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6674 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6675 | EXPECT_EQ(200, response.headers->response_code()); |
| 6676 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6677 | // Check that the session is still alive. |
| 6678 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6679 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6680 | |
| 6681 | // There should be no posted tasks not executed, no way to migrate back to |
| 6682 | // default network. |
| 6683 | EXPECT_TRUE(runner_->GetPostedTasks().empty()); |
| 6684 | |
| 6685 | // Receive signal to mark new network as default. |
| 6686 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6687 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6688 | |
| 6689 | stream.reset(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6690 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6691 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6692 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6693 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6694 | } |
| 6695 | |
| 6696 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6697 | MigrateSessionOnSyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6698 | TestMigrationOnWriteErrorPauseBeforeConnected(SYNCHRONOUS); |
| 6699 | } |
| 6700 | |
| 6701 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6702 | MigrateSessionOnAsyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6703 | TestMigrationOnWriteErrorPauseBeforeConnected(ASYNC); |
| 6704 | } |
| 6705 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6706 | // This test verifies that when session successfully migrate to the alternate |
| 6707 | // network, packet write error on the old writer will be ignored and will not |
| 6708 | // trigger connection migration on write error. |
| 6709 | TEST_P(QuicStreamFactoryTest, IgnoreWriteErrorFromOldWriterAfterMigration) { |
| 6710 | InitializeConnectionMigrationV2Test( |
| 6711 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6712 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6713 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6714 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6715 | |
| 6716 | // Using a testing task runner so that we can verify whether the migrate on |
| 6717 | // write error task is posted. |
| 6718 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6719 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6720 | |
| 6721 | MockQuicData socket_data; |
| 6722 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6723 | socket_data.AddWrite( |
| 6724 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6725 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6726 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6727 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6728 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6729 | |
| 6730 | // Create request and QuicHttpStream. |
| 6731 | QuicStreamRequest request(factory_.get()); |
| 6732 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6733 | request.Request( |
| 6734 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6735 | SocketTag(), |
| 6736 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6737 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6738 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6739 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6740 | EXPECT_TRUE(stream.get()); |
| 6741 | |
| 6742 | // Cause QUIC stream to be created. |
| 6743 | HttpRequestInfo request_info; |
| 6744 | request_info.method = "GET"; |
| 6745 | request_info.url = GURL("https://www.example.org/"); |
| 6746 | request_info.traffic_annotation = |
| 6747 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6748 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6749 | net_log_, CompletionOnceCallback())); |
| 6750 | |
| 6751 | // Ensure that session is alive and active. |
| 6752 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6753 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6754 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6755 | |
| 6756 | // Set up second socket data provider that is used after |
| 6757 | // migration. The response to the request is read on this new socket. |
| 6758 | MockQuicData socket_data1; |
| 6759 | socket_data1.AddWrite( |
| 6760 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 6761 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6762 | ASYNC, |
| 6763 | ConstructOkResponsePacket( |
| 6764 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6765 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6766 | socket_data1.AddWrite( |
| 6767 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6768 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6769 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6770 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6771 | |
| 6772 | // Send GET request on stream. |
| 6773 | HttpResponseInfo response; |
| 6774 | HttpRequestHeaders request_headers; |
| 6775 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6776 | callback_.callback())); |
| 6777 | |
| 6778 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6779 | // Now notify network is disconnected, cause the migration to complete |
| 6780 | // immediately. |
| 6781 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6782 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6783 | // There will be two pending task, one will complete migration with no delay |
| 6784 | // and the other will attempt to migrate back to the default network with |
| 6785 | // delay. |
| 6786 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6787 | |
| 6788 | // Complete migration. |
| 6789 | task_runner->RunUntilIdle(); |
| 6790 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6791 | |
| 6792 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6793 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6794 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6795 | |
| 6796 | // Verify that response headers on the migrated socket were delivered to the |
| 6797 | // stream. |
| 6798 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6799 | EXPECT_EQ(200, response.headers->response_code()); |
| 6800 | |
| 6801 | // Resume the old socket data, a write error will be delivered to the old |
| 6802 | // packet writer. Verify no additional task is posted. |
| 6803 | socket_data.Resume(); |
| 6804 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6805 | |
| 6806 | stream.reset(); |
| 6807 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6808 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6809 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6810 | } |
| 6811 | |
| 6812 | // This test verifies that when session successfully migrate to the alternate |
| 6813 | // network, packet read error on the old reader will be ignored and will not |
| 6814 | // close the connection. |
| 6815 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorFromOldReaderAfterMigration) { |
| 6816 | InitializeConnectionMigrationV2Test( |
| 6817 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6818 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6819 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6820 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6821 | |
| 6822 | // Using a testing task runner. |
| 6823 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6824 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6825 | |
| 6826 | MockQuicData socket_data; |
| 6827 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6828 | socket_data.AddWrite( |
| 6829 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6830 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6831 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6832 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6833 | |
| 6834 | // Create request and QuicHttpStream. |
| 6835 | QuicStreamRequest request(factory_.get()); |
| 6836 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6837 | request.Request( |
| 6838 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6839 | SocketTag(), |
| 6840 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6841 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6842 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6843 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6844 | EXPECT_TRUE(stream.get()); |
| 6845 | |
| 6846 | // Cause QUIC stream to be created. |
| 6847 | HttpRequestInfo request_info; |
| 6848 | request_info.method = "GET"; |
| 6849 | request_info.url = GURL("https://www.example.org/"); |
| 6850 | request_info.traffic_annotation = |
| 6851 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6852 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6853 | net_log_, CompletionOnceCallback())); |
| 6854 | |
| 6855 | // Ensure that session is alive and active. |
| 6856 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6857 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6858 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6859 | |
| 6860 | // Set up second socket data provider that is used after |
| 6861 | // migration. The request is written to this new socket, and the |
| 6862 | // response to the request is read on this new socket. |
| 6863 | MockQuicData socket_data1; |
| 6864 | socket_data1.AddWrite( |
| 6865 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6866 | socket_data1.AddWrite( |
| 6867 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6868 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6869 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6870 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6871 | ASYNC, |
| 6872 | ConstructOkResponsePacket( |
| 6873 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6874 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6875 | socket_data1.AddWrite( |
| 6876 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6877 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6878 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6879 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6880 | |
| 6881 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6882 | // Now notify network is disconnected, cause the migration to complete |
| 6883 | // immediately. |
| 6884 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6885 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6886 | // There will be two pending task, one will complete migration with no delay |
| 6887 | // and the other will attempt to migrate back to the default network with |
| 6888 | // delay. |
| 6889 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6890 | |
| 6891 | // Complete migration. |
| 6892 | task_runner->RunUntilIdle(); |
| 6893 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6894 | |
| 6895 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6896 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6897 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6898 | |
| 6899 | // Send GET request on stream. |
| 6900 | HttpResponseInfo response; |
| 6901 | HttpRequestHeaders request_headers; |
| 6902 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6903 | callback_.callback())); |
| 6904 | |
| 6905 | // Verify that response headers on the migrated socket were delivered to the |
| 6906 | // stream. |
| 6907 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6908 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6909 | EXPECT_EQ(200, response.headers->response_code()); |
| 6910 | |
| 6911 | // Resume the old socket data, a read error will be delivered to the old |
| 6912 | // packet reader. Verify that the session is not affected. |
| 6913 | socket_data.Resume(); |
| 6914 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6915 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6916 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6917 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6918 | |
| 6919 | stream.reset(); |
| 6920 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6921 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6922 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6923 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6924 | } |
| 6925 | |
| 6926 | // This test verifies that after migration on network is executed, packet |
| 6927 | // read error on the old reader will be ignored and will not close the |
| 6928 | // connection. |
| 6929 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorOnOldReaderDuringMigration) { |
| 6930 | InitializeConnectionMigrationV2Test( |
| 6931 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6932 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6933 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6934 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6935 | |
| 6936 | // Using a testing task runner. |
| 6937 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6938 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6939 | |
| 6940 | MockQuicData socket_data; |
| 6941 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6942 | socket_data.AddWrite( |
| 6943 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6944 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6945 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6946 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6947 | |
| 6948 | // Create request and QuicHttpStream. |
| 6949 | QuicStreamRequest request(factory_.get()); |
| 6950 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6951 | request.Request( |
| 6952 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6953 | SocketTag(), |
| 6954 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6955 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6956 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6957 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6958 | EXPECT_TRUE(stream.get()); |
| 6959 | |
| 6960 | // Cause QUIC stream to be created. |
| 6961 | HttpRequestInfo request_info; |
| 6962 | request_info.method = "GET"; |
| 6963 | request_info.url = GURL("https://www.example.org/"); |
| 6964 | request_info.traffic_annotation = |
| 6965 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6966 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6967 | net_log_, CompletionOnceCallback())); |
| 6968 | |
| 6969 | // Ensure that session is alive and active. |
| 6970 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6971 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6972 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6973 | |
| 6974 | // Set up second socket data provider that is used after |
| 6975 | // migration. The request is written to this new socket, and the |
| 6976 | // response to the request is read on this new socket. |
| 6977 | MockQuicData socket_data1; |
| 6978 | socket_data1.AddWrite( |
| 6979 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6980 | socket_data1.AddWrite( |
| 6981 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6982 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6983 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6984 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6985 | ASYNC, |
| 6986 | ConstructOkResponsePacket( |
| 6987 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6988 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6989 | socket_data1.AddWrite( |
| 6990 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6991 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6992 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6993 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6994 | |
| 6995 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6996 | // Now notify network is disconnected, cause the migration to complete |
| 6997 | // immediately. |
| 6998 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6999 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 7000 | // There will be two pending task, one will complete migration with no delay |
| 7001 | // and the other will attempt to migrate back to the default network with |
| 7002 | // delay. |
| 7003 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7004 | |
| 7005 | // Resume the old socket data, a read error will be delivered to the old |
| 7006 | // packet reader. Verify that the session is not affected. |
| 7007 | socket_data.Resume(); |
| 7008 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7009 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7010 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7011 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7012 | |
| 7013 | // Complete migration. |
| 7014 | task_runner->RunUntilIdle(); |
| 7015 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7016 | |
| 7017 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7018 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7019 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7020 | |
| 7021 | // Send GET request on stream. |
| 7022 | HttpResponseInfo response; |
| 7023 | HttpRequestHeaders request_headers; |
| 7024 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7025 | callback_.callback())); |
| 7026 | |
| 7027 | // Verify that response headers on the migrated socket were delivered to the |
| 7028 | // stream. |
| 7029 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7030 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7031 | EXPECT_EQ(200, response.headers->response_code()); |
| 7032 | |
| 7033 | stream.reset(); |
| 7034 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7035 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7036 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7037 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7038 | } |
| 7039 | |
| 7040 | // This test verifies that after migration on write error is posted, packet |
| 7041 | // read error on the old reader will be ignored and will not close the |
| 7042 | // connection. |
| 7043 | TEST_P(QuicStreamFactoryTest, |
| 7044 | IgnoreReadErrorOnOldReaderDuringPendingMigrationOnWriteError) { |
| 7045 | InitializeConnectionMigrationV2Test( |
| 7046 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 7047 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7048 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7049 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7050 | |
| 7051 | // Using a testing task runner. |
| 7052 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7053 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7054 | |
| 7055 | MockQuicData socket_data; |
| 7056 | quic::QuicStreamOffset header_stream_offset = 0; |
| 7057 | socket_data.AddWrite( |
| 7058 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 7059 | socket_data.AddWrite(ASYNC, ERR_FAILED); // Write error. |
| 7060 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); // Read error. |
| 7061 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7062 | |
| 7063 | // Create request and QuicHttpStream. |
| 7064 | QuicStreamRequest request(factory_.get()); |
| 7065 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7066 | request.Request( |
| 7067 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7068 | SocketTag(), |
| 7069 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7070 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7071 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7072 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7073 | EXPECT_TRUE(stream.get()); |
| 7074 | |
| 7075 | // Cause QUIC stream to be created. |
| 7076 | HttpRequestInfo request_info; |
| 7077 | request_info.method = "GET"; |
| 7078 | request_info.url = GURL("https://www.example.org/"); |
| 7079 | request_info.traffic_annotation = |
| 7080 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7081 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 7082 | net_log_, CompletionOnceCallback())); |
| 7083 | |
| 7084 | // Ensure that session is alive and active. |
| 7085 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7086 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7087 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7088 | |
| 7089 | // Set up second socket data provider that is used after |
| 7090 | // migration. The request is written to this new socket, and the |
| 7091 | // response to the request is read on this new socket. |
| 7092 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7093 | socket_data1.AddWrite( |
| 7094 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7095 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7096 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7097 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7098 | ASYNC, |
| 7099 | ConstructOkResponsePacket( |
| 7100 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7101 | |
| 7102 | socket_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 7103 | socket_data1.AddRead(ASYNC, ERR_FAILED); // Read error to close connection. |
| 7104 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7105 | |
| 7106 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7107 | // Send GET request on stream. |
| 7108 | HttpResponseInfo response; |
| 7109 | HttpRequestHeaders request_headers; |
| 7110 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7111 | callback_.callback())); |
| 7112 | // Run the message loop to complete asynchronous write and read with errors. |
| 7113 | base::RunLoop().RunUntilIdle(); |
| 7114 | // There will be one pending task to complete migration on write error. |
| 7115 | // Verify session is not closed with read error. |
| 7116 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7117 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7118 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7119 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7120 | |
| 7121 | // Complete migration. |
| 7122 | task_runner->RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7123 | // There will be one more task posted attempting to migrate back to the |
| 7124 | // default network. |
| 7125 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7126 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7127 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7128 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7129 | |
| 7130 | // Verify that response headers on the migrated socket were delivered to the |
| 7131 | // stream. |
| 7132 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7133 | EXPECT_EQ(200, response.headers->response_code()); |
| 7134 | |
| 7135 | // Resume to consume the read error on new socket, which will close |
| 7136 | // the connection. |
| 7137 | socket_data1.Resume(); |
| 7138 | |
| 7139 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7140 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7141 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7142 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7143 | } |
| 7144 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7145 | // Migrate on asynchronous write error, old network disconnects after alternate |
| 7146 | // network connects. |
| 7147 | TEST_P(QuicStreamFactoryTest, |
| 7148 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectAysnc) { |
| 7149 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7150 | ASYNC, /*disconnect_before_connect*/ false); |
| 7151 | } |
| 7152 | |
| 7153 | // Migrate on synchronous write error, old network disconnects after alternate |
| 7154 | // network connects. |
| 7155 | TEST_P(QuicStreamFactoryTest, |
| 7156 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectSync) { |
| 7157 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7158 | SYNCHRONOUS, /*disconnect_before_connect*/ false); |
| 7159 | } |
| 7160 | |
| 7161 | // Migrate on asynchronous write error, old network disconnects before alternate |
| 7162 | // network connects. |
| 7163 | TEST_P(QuicStreamFactoryTest, |
| 7164 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectAysnc) { |
| 7165 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7166 | ASYNC, /*disconnect_before_connect*/ true); |
| 7167 | } |
| 7168 | |
| 7169 | // Migrate on synchronous write error, old network disconnects before alternate |
| 7170 | // network connects. |
| 7171 | TEST_P(QuicStreamFactoryTest, |
| 7172 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectSync) { |
| 7173 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7174 | SYNCHRONOUS, /*disconnect_before_connect*/ true); |
| 7175 | } |
| 7176 | |
| 7177 | // Setps up test which verifies that session successfully migrate to alternate |
| 7178 | // network with signals delivered in the following order: |
| 7179 | // *NOTE* Signal (A) and (B) can reverse order based on |
| 7180 | // |disconnect_before_connect|. |
| 7181 | // - (No alternate network is connected) session connects to |
| 7182 | // kDefaultNetworkForTests. |
| 7183 | // - An async/sync write error is encountered based on |write_error_mode|: |
| 7184 | // session posted task to migrate session on write error. |
| 7185 | // - Posted task is executed, miration moves to pending state due to lack of |
| 7186 | // alternate network. |
| 7187 | // - (A) An alternate network is connected, pending migration completes. |
| 7188 | // - (B) Old default network disconnects, no migration will be attempted as |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7189 | // session has already migrate to the alternate network. |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7190 | // - The alternate network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7191 | void QuicStreamFactoryTestBase:: |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7192 | TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7193 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7194 | bool disconnect_before_connect) { |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7195 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7196 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7197 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7198 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7199 | |
| 7200 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7201 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7202 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7203 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7204 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7205 | socket_data.AddWrite(write_error_mode, ERR_FAILED); // Write error. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7206 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7207 | |
| 7208 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7209 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7210 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7211 | request.Request( |
| 7212 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7213 | SocketTag(), |
| 7214 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7215 | failed_on_default_network_callback_, callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7216 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7217 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7218 | EXPECT_TRUE(stream.get()); |
| 7219 | |
| 7220 | // Cause QUIC stream to be created. |
| 7221 | HttpRequestInfo request_info; |
| 7222 | request_info.method = "GET"; |
| 7223 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7224 | request_info.traffic_annotation = |
| 7225 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7226 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7227 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7228 | |
| 7229 | // Ensure that session is alive and active. |
| 7230 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7231 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7232 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7233 | |
| 7234 | // Send GET request on stream. This should cause a write error, which triggers |
| 7235 | // a connection migration attempt. |
| 7236 | HttpResponseInfo response; |
| 7237 | HttpRequestHeaders request_headers; |
| 7238 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7239 | callback_.callback())); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7240 | // Run the message loop so that posted task to migrate to socket will be |
| 7241 | // executed. A new task will be posted to wait for a new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7242 | base::RunLoop().RunUntilIdle(); |
| 7243 | |
| 7244 | // In this particular code path, the network will not yet be marked |
| 7245 | // as going away and the session will still be alive. |
| 7246 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7247 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7248 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7249 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7250 | |
| 7251 | // Set up second socket data provider that is used after |
| 7252 | // migration. The request is rewritten to this new socket, and the |
| 7253 | // response to the request is read on this new socket. |
| 7254 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7255 | socket_data1.AddWrite( |
| 7256 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7257 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7258 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7259 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7260 | ASYNC, |
| 7261 | ConstructOkResponsePacket( |
| 7262 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7263 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7264 | socket_data1.AddWrite( |
| 7265 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7266 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7267 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7268 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7269 | |
| 7270 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7271 | ->SetConnectedNetworksList( |
| 7272 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7273 | if (disconnect_before_connect) { |
| 7274 | // Now deliver a DISCONNECT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7275 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7276 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7277 | |
| 7278 | // Now deliver a CONNECTED notification and completes migration. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7279 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7280 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7281 | } else { |
| 7282 | // Now deliver a CONNECTED notification and completes migration. |
| 7283 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7284 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7285 | |
| 7286 | // Now deliver a DISCONNECT notification. |
| 7287 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7288 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7289 | } |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7290 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7291 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7292 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7293 | |
| 7294 | // This is the callback for the response headers that returned |
| 7295 | // pending previously, because no result was available. Check that |
| 7296 | // the result is now available due to the successful migration. |
| 7297 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7298 | EXPECT_EQ(200, response.headers->response_code()); |
| 7299 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7300 | // Deliver a MADEDEFAULT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7301 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7302 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7303 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7304 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7305 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 7306 | DEFAULT_PRIORITY, SocketTag(), |
| 7307 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7308 | &net_error_details_, |
| 7309 | failed_on_default_network_callback_, |
| 7310 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7311 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7312 | EXPECT_TRUE(stream2.get()); |
| 7313 | |
| 7314 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7315 | EXPECT_EQ(session, GetActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7316 | |
| 7317 | stream.reset(); |
| 7318 | stream2.reset(); |
| 7319 | |
| 7320 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7321 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7322 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7323 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7324 | } |
| 7325 | |
Zhongyi Shi | c16b410 | 2019-02-12 00:37:40 | [diff] [blame] | 7326 | // This test verifies after session migrates off the default network, it keeps |
| 7327 | // retrying migrate back to the default network until successfully gets on the |
| 7328 | // default network or the idle migration period threshold is exceeded. |
| 7329 | // The default threshold is 30s. |
| 7330 | TEST_P(QuicStreamFactoryTest, DefaultIdleMigrationPeriod) { |
| 7331 | InitializeConnectionMigrationV2Test( |
| 7332 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 7333 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7334 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7335 | |
| 7336 | // Using a testing task runner and a test tick tock. |
| 7337 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7338 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7339 | QuicStreamFactoryPeer::SetTickClock(factory_.get(), |
| 7340 | task_runner->GetMockTickClock()); |
| 7341 | |
| 7342 | MockQuicData default_socket_data; |
| 7343 | default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 7344 | default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7345 | default_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7346 | |
| 7347 | // Set up second socket data provider that is used after migration. |
| 7348 | MockQuicData alternate_socket_data; |
| 7349 | alternate_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7350 | // Ping packet to send after migration. |
| 7351 | alternate_socket_data.AddWrite( |
| 7352 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 7353 | alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7354 | |
| 7355 | // Set up probing socket for migrating back to the default network. |
| 7356 | MockQuicData quic_data; // retry count: 0. |
| 7357 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7358 | quic_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7359 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7360 | |
| 7361 | MockQuicData quic_data1; // retry count: 1 |
| 7362 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7363 | quic_data1.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7364 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7365 | |
| 7366 | MockQuicData quic_data2; // retry count: 2 |
| 7367 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7368 | quic_data2.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7369 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 7370 | |
| 7371 | MockQuicData quic_data3; // retry count: 3 |
| 7372 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7373 | quic_data3.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7374 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 7375 | |
| 7376 | MockQuicData quic_data4; // retry count: 4 |
| 7377 | quic_data4.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7378 | quic_data4.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7379 | quic_data4.AddSocketDataToFactory(socket_factory_.get()); |
| 7380 | |
| 7381 | MockQuicData quic_data5; // retry count: 5 |
| 7382 | quic_data5.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7383 | quic_data5.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7384 | quic_data5.AddSocketDataToFactory(socket_factory_.get()); |
| 7385 | |
| 7386 | // Create request and QuicHttpStream. |
| 7387 | QuicStreamRequest request(factory_.get()); |
| 7388 | EXPECT_EQ(ERR_IO_PENDING, |
| 7389 | request.Request( |
| 7390 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7391 | SocketTag(), |
| 7392 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7393 | failed_on_default_network_callback_, callback_.callback())); |
| 7394 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7395 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7396 | EXPECT_TRUE(stream.get()); |
| 7397 | |
| 7398 | // Ensure that session is active. |
| 7399 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7400 | |
| 7401 | // Trigger connection migration. Since there are no active streams, |
| 7402 | // the session will be closed. |
| 7403 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7404 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 7405 | |
| 7406 | // The nearest task will complete migration. |
| 7407 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7408 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7409 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7410 | |
| 7411 | // The migrate back timer will fire. Due to default network |
| 7412 | // being disconnected, no attempt will be exercised to migrate back. |
| 7413 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7414 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 7415 | task_runner->NextPendingTaskDelay()); |
| 7416 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7417 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7418 | |
| 7419 | // Deliver the signal that the old default network now backs up. |
| 7420 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7421 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 7422 | |
| 7423 | // A task is posted to migrate back to the default network immediately. |
| 7424 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7425 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7426 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7427 | |
| 7428 | // Retry migrate back in 1, 2, 4, 8, 16s. |
| 7429 | // Session will be closed due to idle migration timeout. |
| 7430 | for (int i = 0; i < 5; i++) { |
| 7431 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7432 | // A task is posted to migrate back to the default network in 2^i seconds. |
| 7433 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7434 | EXPECT_EQ(base::TimeDelta::FromSeconds(UINT64_C(1) << i), |
| 7435 | task_runner->NextPendingTaskDelay()); |
| 7436 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7437 | } |
| 7438 | |
| 7439 | EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); |
| 7440 | EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); |
| 7441 | EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); |
| 7442 | EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); |
| 7443 | } |
| 7444 | |
| 7445 | TEST_P(QuicStreamFactoryTest, CustomIdleMigrationPeriod) { |
| 7446 | // The customized threshold is 15s. |
| 7447 | test_params_.quic_idle_session_migration_period = |
| 7448 | base::TimeDelta::FromSeconds(15); |
| 7449 | InitializeConnectionMigrationV2Test( |
| 7450 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 7451 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7452 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7453 | |
| 7454 | // Using a testing task runner and a test tick tock. |
| 7455 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7456 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7457 | QuicStreamFactoryPeer::SetTickClock(factory_.get(), |
| 7458 | task_runner->GetMockTickClock()); |
| 7459 | |
| 7460 | MockQuicData default_socket_data; |
| 7461 | default_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 7462 | default_socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7463 | default_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7464 | |
| 7465 | // Set up second socket data provider that is used after migration. |
| 7466 | MockQuicData alternate_socket_data; |
| 7467 | alternate_socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7468 | // Ping packet to send after migration. |
| 7469 | alternate_socket_data.AddWrite( |
| 7470 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 7471 | alternate_socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7472 | |
| 7473 | // Set up probing socket for migrating back to the default network. |
| 7474 | MockQuicData quic_data; // retry count: 0. |
| 7475 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7476 | quic_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7477 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7478 | |
| 7479 | MockQuicData quic_data1; // retry count: 1 |
| 7480 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7481 | quic_data1.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7482 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7483 | |
| 7484 | MockQuicData quic_data2; // retry count: 2 |
| 7485 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7486 | quic_data2.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7487 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 7488 | |
| 7489 | MockQuicData quic_data3; // retry count: 3 |
| 7490 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7491 | quic_data3.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7492 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 7493 | |
| 7494 | MockQuicData quic_data4; // retry count: 4 |
| 7495 | quic_data4.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 7496 | quic_data4.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 7497 | quic_data4.AddSocketDataToFactory(socket_factory_.get()); |
| 7498 | |
| 7499 | // Create request and QuicHttpStream. |
| 7500 | QuicStreamRequest request(factory_.get()); |
| 7501 | EXPECT_EQ(ERR_IO_PENDING, |
| 7502 | request.Request( |
| 7503 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7504 | SocketTag(), |
| 7505 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7506 | failed_on_default_network_callback_, callback_.callback())); |
| 7507 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7508 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7509 | EXPECT_TRUE(stream.get()); |
| 7510 | |
| 7511 | // Ensure that session is active. |
| 7512 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7513 | |
| 7514 | // Trigger connection migration. Since there are no active streams, |
| 7515 | // the session will be closed. |
| 7516 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7517 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 7518 | |
| 7519 | // The nearest task will complete migration. |
| 7520 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 7521 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7522 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7523 | |
| 7524 | // The migrate back timer will fire. Due to default network |
| 7525 | // being disconnected, no attempt will be exercised to migrate back. |
| 7526 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7527 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 7528 | task_runner->NextPendingTaskDelay()); |
| 7529 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7530 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7531 | |
| 7532 | // Deliver the signal that the old default network now backs up. |
| 7533 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7534 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 7535 | |
| 7536 | // A task is posted to migrate back to the default network immediately. |
| 7537 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7538 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 7539 | task_runner->FastForwardBy(base::TimeDelta()); |
| 7540 | |
| 7541 | // Retry migrate back in 1, 2, 4, 8s. |
| 7542 | // Session will be closed due to idle migration timeout. |
| 7543 | for (int i = 0; i < 4; i++) { |
| 7544 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7545 | // A task is posted to migrate back to the default network in 2^i seconds. |
| 7546 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7547 | EXPECT_EQ(base::TimeDelta::FromSeconds(UINT64_C(1) << i), |
| 7548 | task_runner->NextPendingTaskDelay()); |
| 7549 | task_runner->FastForwardBy(task_runner->NextPendingTaskDelay()); |
| 7550 | } |
| 7551 | |
| 7552 | EXPECT_TRUE(default_socket_data.AllReadDataConsumed()); |
| 7553 | EXPECT_TRUE(default_socket_data.AllWriteDataConsumed()); |
| 7554 | EXPECT_TRUE(alternate_socket_data.AllReadDataConsumed()); |
| 7555 | EXPECT_TRUE(alternate_socket_data.AllWriteDataConsumed()); |
| 7556 | } |
| 7557 | |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7558 | TEST_P(QuicStreamFactoryTest, ServerMigration) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 7559 | test_params_.quic_allow_server_migration = true; |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7560 | Initialize(); |
| 7561 | |
| 7562 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7563 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7564 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7565 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7566 | MockQuicData socket_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7567 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7568 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7569 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7570 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7571 | socket_data1.AddWrite( |
| 7572 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7573 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7574 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7575 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7576 | |
| 7577 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7578 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7579 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7580 | request.Request( |
| 7581 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7582 | SocketTag(), |
| 7583 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7584 | failed_on_default_network_callback_, callback_.callback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7585 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7586 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7587 | EXPECT_TRUE(stream.get()); |
| 7588 | |
| 7589 | // Cause QUIC stream to be created. |
| 7590 | HttpRequestInfo request_info; |
| 7591 | request_info.method = "GET"; |
| 7592 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7593 | request_info.traffic_annotation = |
| 7594 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7595 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7596 | net_log_, CompletionOnceCallback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7597 | |
| 7598 | // Ensure that session is alive and active. |
| 7599 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7600 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7601 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7602 | |
| 7603 | // Send GET request on stream. |
| 7604 | HttpResponseInfo response; |
| 7605 | HttpRequestHeaders request_headers; |
| 7606 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7607 | callback_.callback())); |
| 7608 | |
| 7609 | IPEndPoint ip; |
| 7610 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7611 | DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 7612 | << ip.port(); |
| 7613 | |
| 7614 | // Set up second socket data provider that is used after |
| 7615 | // migration. The request is rewritten to this new socket, and the |
| 7616 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7617 | MockQuicData socket_data2; |
| 7618 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7619 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 7620 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7621 | ASYNC, |
| 7622 | ConstructOkResponsePacket( |
| 7623 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7624 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7625 | socket_data2.AddWrite( |
| 7626 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7627 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7628 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7629 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7630 | |
| 7631 | const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 7632 | const uint16_t kTestPort = 123; |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 7633 | session->Migrate(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 7634 | IPEndPoint(IPAddress(kTestIpAddress), kTestPort), true, |
| 7635 | net_log_); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7636 | |
| 7637 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7638 | DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 7639 | << ip.port(); |
| 7640 | |
| 7641 | // The session should be alive and active. |
| 7642 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7643 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7644 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7645 | |
| 7646 | // Run the message loop so that data queued in the new socket is read by the |
| 7647 | // packet reader. |
| 7648 | base::RunLoop().RunUntilIdle(); |
| 7649 | |
| 7650 | // Verify that response headers on the migrated socket were delivered to the |
| 7651 | // stream. |
| 7652 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7653 | EXPECT_EQ(200, response.headers->response_code()); |
| 7654 | |
| 7655 | stream.reset(); |
| 7656 | |
| 7657 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7658 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7659 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7660 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7661 | } |
| 7662 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7663 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv4) { |
| 7664 | // Add alternate IPv4 server address to config. |
| 7665 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7666 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7667 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7668 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7669 | VerifyServerMigration(config, alt_address); |
| 7670 | } |
| 7671 | |
| 7672 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv6) { |
| 7673 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7674 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7675 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7676 | // Add alternate IPv6 server address to config. |
| 7677 | IPEndPoint alt_address = IPEndPoint( |
| 7678 | 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] | 7679 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7680 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7681 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7682 | VerifyServerMigration(config, alt_address); |
| 7683 | } |
| 7684 | |
| 7685 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { |
| 7686 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7687 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7688 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7689 | // Add alternate IPv4 server address to config. |
| 7690 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7691 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7692 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7693 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7694 | IPEndPoint expected_address( |
| 7695 | ConvertIPv4ToIPv4MappedIPv6(alt_address.address()), alt_address.port()); |
| 7696 | VerifyServerMigration(config, expected_address); |
| 7697 | } |
| 7698 | |
| 7699 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 7700 | test_params_.quic_allow_server_migration = true; |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7701 | Initialize(); |
| 7702 | |
| 7703 | // Add a resolver rule to make initial connection to an IPv4 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7704 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), "1.2.3.4", |
| 7705 | ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7706 | // Add alternate IPv6 server address to config. |
| 7707 | IPEndPoint alt_address = IPEndPoint( |
| 7708 | 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] | 7709 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7710 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7711 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7712 | |
| 7713 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7714 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7715 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7716 | |
| 7717 | crypto_client_stream_factory_.SetConfig(config); |
| 7718 | |
| 7719 | // Set up only socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7720 | MockQuicData socket_data1; |
| 7721 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7722 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7723 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7724 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7725 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7726 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7727 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7728 | |
| 7729 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7730 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7731 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7732 | request.Request( |
| 7733 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7734 | SocketTag(), |
| 7735 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7736 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7737 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7738 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7739 | EXPECT_TRUE(stream.get()); |
| 7740 | |
| 7741 | // Cause QUIC stream to be created. |
| 7742 | HttpRequestInfo request_info; |
| 7743 | request_info.method = "GET"; |
| 7744 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7745 | request_info.traffic_annotation = |
| 7746 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7747 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7748 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7749 | |
| 7750 | // Ensure that session is alive and active. |
| 7751 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7752 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7753 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7754 | |
| 7755 | IPEndPoint actual_address; |
| 7756 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 7757 | // No migration should have happened. |
| 7758 | IPEndPoint expected_address = |
| 7759 | IPEndPoint(IPAddress(1, 2, 3, 4), kDefaultServerPort); |
| 7760 | EXPECT_EQ(actual_address, expected_address); |
| 7761 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 7762 | << " " << actual_address.port(); |
| 7763 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 7764 | << " " << expected_address.port(); |
| 7765 | |
| 7766 | stream.reset(); |
| 7767 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7768 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7769 | } |
| 7770 | |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 7771 | TEST_P(QuicStreamFactoryTest, OnCertDBChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7772 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7773 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7774 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7775 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7776 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7777 | MockQuicData socket_data; |
| 7778 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7779 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7780 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7781 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7782 | MockQuicData socket_data2; |
| 7783 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7784 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7785 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7786 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7787 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7788 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7789 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7790 | request.Request( |
| 7791 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7792 | SocketTag(), |
| 7793 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7794 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7795 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7796 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7797 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7798 | EXPECT_TRUE(stream); |
| 7799 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7800 | |
| 7801 | // Change the CA cert and verify that stream saw the event. |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 7802 | factory_->OnCertDBChanged(); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7803 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7804 | EXPECT_FALSE(factory_->require_confirmation()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7805 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7806 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7807 | |
| 7808 | // Now attempting to request a stream to the same origin should create |
| 7809 | // a new session. |
| 7810 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7811 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7812 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7813 | request2.Request( |
| 7814 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7815 | SocketTag(), |
| 7816 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7817 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7818 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7819 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7820 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 7821 | EXPECT_TRUE(stream2); |
| 7822 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 7823 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7824 | EXPECT_NE(session, session2); |
| 7825 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7826 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 7827 | |
| 7828 | stream2.reset(); |
| 7829 | stream.reset(); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7830 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7831 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7832 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7833 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7834 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7835 | } |
| 7836 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7837 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7838 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7839 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7840 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7841 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7842 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7843 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7844 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7845 | string r1_host_name("r1"); |
| 7846 | string r2_host_name("r2"); |
| 7847 | r1_host_name.append(cannoncial_suffixes[i]); |
| 7848 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7849 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7850 | HostPortPair host_port_pair1(r1_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7851 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7852 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7853 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7854 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7855 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7856 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7857 | EXPECT_FALSE(cached1->proof_valid()); |
| 7858 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7859 | |
| 7860 | // Mutate the cached1 to have different data. |
| 7861 | // TODO(rtenneti): mutate other members of CachedState. |
| 7862 | cached1->set_source_address_token(r1_host_name); |
| 7863 | cached1->SetProofValid(); |
| 7864 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7865 | HostPortPair host_port_pair2(r2_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7866 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7867 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7868 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7869 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7870 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 7871 | EXPECT_TRUE(cached2->proof_valid()); |
| 7872 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7873 | } |
| 7874 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7875 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7876 | Initialize(); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7877 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7878 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7879 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7880 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7881 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7882 | string r3_host_name("r3"); |
| 7883 | string r4_host_name("r4"); |
| 7884 | r3_host_name.append(cannoncial_suffixes[i]); |
| 7885 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7886 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7887 | HostPortPair host_port_pair1(r3_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7888 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7889 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7890 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7891 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7892 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7893 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7894 | EXPECT_FALSE(cached1->proof_valid()); |
| 7895 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7896 | |
| 7897 | // Mutate the cached1 to have different data. |
| 7898 | // TODO(rtenneti): mutate other members of CachedState. |
| 7899 | cached1->set_source_address_token(r3_host_name); |
| 7900 | cached1->SetProofInvalid(); |
| 7901 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7902 | HostPortPair host_port_pair2(r4_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7903 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7904 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7905 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7906 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7907 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 7908 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 7909 | EXPECT_FALSE(cached2->proof_valid()); |
| 7910 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7911 | } |
| 7912 | |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7913 | TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7914 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7915 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7916 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7917 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7918 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7919 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7920 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7921 | MockQuicData socket_data; |
| 7922 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7923 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7924 | |
| 7925 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7926 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7927 | host_resolver_->set_synchronous_mode(true); |
| 7928 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7929 | "192.168.0.1", ""); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7930 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7931 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7932 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7933 | DEFAULT_PRIORITY, SocketTag(), |
| 7934 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7935 | &net_error_details_, |
| 7936 | failed_on_default_network_callback_, |
| 7937 | callback_.callback())); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7938 | |
| 7939 | // If we are waiting for disk cache, we would have posted a task. Verify that |
| 7940 | // the CancelWaitForDataReady task hasn't been posted. |
| 7941 | ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
| 7942 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7943 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7944 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7945 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7946 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7947 | } |
| 7948 | |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7949 | TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 7950 | test_params_.quic_reduced_ping_timeout_seconds = 10; |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7951 | Initialize(); |
| 7952 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7953 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7954 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7955 | |
| 7956 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7957 | |
| 7958 | MockQuicData socket_data; |
| 7959 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7960 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7961 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7962 | |
| 7963 | MockQuicData socket_data2; |
| 7964 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7965 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7966 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7967 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7968 | |
| 7969 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
| 7970 | |
| 7971 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7972 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7973 | host_resolver_->set_synchronous_mode(true); |
| 7974 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7975 | "192.168.0.1", ""); |
| 7976 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7977 | |
| 7978 | // Quic should use default PING timeout when no previous connection times out |
| 7979 | // with open stream. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7980 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7981 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7982 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7983 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7984 | DEFAULT_PRIORITY, SocketTag(), |
| 7985 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7986 | &net_error_details_, |
| 7987 | failed_on_default_network_callback_, |
| 7988 | callback_.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7989 | |
| 7990 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7991 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7992 | session->connection()->ping_timeout()); |
| 7993 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7994 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7995 | EXPECT_TRUE(stream.get()); |
| 7996 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7997 | request_info.traffic_annotation = |
| 7998 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7999 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 8000 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8001 | |
| 8002 | DVLOG(1) |
| 8003 | << "Created 1st session and initialized a stream. Now trigger timeout"; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8004 | session->connection()->CloseConnection( |
| 8005 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 8006 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8007 | // Need to spin the loop now to ensure that |
| 8008 | // QuicStreamFactory::OnSessionClosed() runs. |
| 8009 | base::RunLoop run_loop; |
| 8010 | run_loop.RunUntilIdle(); |
| 8011 | |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8012 | // The first connection times out with open stream, QUIC should reduce initial |
| 8013 | // PING time for subsequent connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8014 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8015 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 8016 | |
| 8017 | // Test two-in-a-row timeouts with open streams. |
| 8018 | DVLOG(1) << "Create 2nd session and timeout with open stream"; |
| 8019 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8020 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8021 | EXPECT_EQ(OK, |
| 8022 | request2.Request( |
| 8023 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8024 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 8025 | failed_on_default_network_callback_, callback2.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8026 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8027 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8028 | session2->connection()->ping_timeout()); |
| 8029 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8030 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8031 | EXPECT_TRUE(stream2.get()); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 8032 | EXPECT_EQ(OK, |
| 8033 | stream2->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 8034 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8035 | session2->connection()->CloseConnection( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8036 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 8037 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8038 | // Need to spin the loop now to ensure that |
| 8039 | // QuicStreamFactory::OnSessionClosed() runs. |
| 8040 | base::RunLoop run_loop2; |
| 8041 | run_loop2.RunUntilIdle(); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 8042 | |
| 8043 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8044 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8045 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 8046 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 8047 | } |
| 8048 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 8049 | // Verifies that the QUIC stream factory is initialized correctly. |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 8050 | TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 8051 | VerifyInitialization(); |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 8052 | } |
| 8053 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8054 | TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 8055 | Initialize(); |
| 8056 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8057 | MockQuicData socket_data; |
| 8058 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8059 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8060 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8061 | |
| 8062 | // Save current state of |race_cert_verification|. |
| 8063 | bool race_cert_verification = |
| 8064 | QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 8065 | |
| 8066 | // Load server config. |
| 8067 | HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8068 | quic::QuicServerId quic_server_id(host_port_pair_.host(), |
| 8069 | host_port_pair_.port(), |
| 8070 | privacy_mode_ == PRIVACY_MODE_ENABLED); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8071 | QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 8072 | |
| 8073 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 8074 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 8075 | |
| 8076 | // Start CertVerifyJob. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8077 | quic::QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8078 | factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8079 | if (status == quic::QUIC_PENDING) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8080 | // Verify CertVerifierJob has started. |
| 8081 | EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 8082 | |
| 8083 | while (HasActiveCertVerifierJob(quic_server_id)) { |
| 8084 | base::RunLoop().RunUntilIdle(); |
| 8085 | } |
| 8086 | } |
| 8087 | // Verify CertVerifierJob has finished. |
| 8088 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 8089 | |
| 8090 | // Start a QUIC request. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8091 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8092 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8093 | request.Request( |
| 8094 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8095 | SocketTag(), |
| 8096 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8097 | failed_on_default_network_callback_, callback_.callback())); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8098 | |
| 8099 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 8100 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8101 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 8102 | EXPECT_TRUE(stream.get()); |
| 8103 | |
| 8104 | // Restore |race_cert_verification|. |
| 8105 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 8106 | race_cert_verification); |
| 8107 | |
| 8108 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8109 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8110 | |
| 8111 | // Verify there are no outstanding CertVerifierJobs after request has |
| 8112 | // finished. |
| 8113 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 8114 | } |
| 8115 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8116 | TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8117 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 8118 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 8119 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8120 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8121 | QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8122 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8123 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 8124 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8125 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8126 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8127 | |
| 8128 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8129 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8130 | host_resolver_->set_synchronous_mode(true); |
| 8131 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8132 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8133 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8134 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 8135 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8136 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8137 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 8138 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8139 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8140 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8141 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 8142 | DEFAULT_PRIORITY, SocketTag(), |
| 8143 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8144 | &net_error_details_, |
| 8145 | failed_on_default_network_callback_, |
| 8146 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8147 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8148 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 8149 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8150 | base::RunLoop run_loop; |
| 8151 | run_loop.RunUntilIdle(); |
| 8152 | |
| 8153 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8154 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 8155 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8156 | EXPECT_EQ(1u, observer.executed_count()); |
| 8157 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8158 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 8159 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8160 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8161 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8162 | } |
| 8163 | |
| 8164 | TEST_P(QuicStreamFactoryTest, YieldAfterDuration) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 8165 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 8166 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 8167 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8168 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8169 | QuicStreamFactoryPeer::SetYieldAfterDuration( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8170 | factory_.get(), quic::QuicTime::Delta::FromMilliseconds(-1)); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8171 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8172 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 8173 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8174 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8175 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8176 | |
| 8177 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8178 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8179 | host_resolver_->set_synchronous_mode(true); |
| 8180 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8181 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8182 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8183 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 8184 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8185 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8186 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 8187 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8188 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8189 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8190 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 8191 | DEFAULT_PRIORITY, SocketTag(), |
| 8192 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8193 | &net_error_details_, |
| 8194 | failed_on_default_network_callback_, |
| 8195 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8196 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8197 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 8198 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8199 | base::RunLoop run_loop; |
| 8200 | run_loop.RunUntilIdle(); |
| 8201 | |
| 8202 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 8203 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 8204 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8205 | EXPECT_EQ(1u, observer.executed_count()); |
| 8206 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8207 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 8208 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 8209 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8210 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8211 | } |
| 8212 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8213 | TEST_P(QuicStreamFactoryTest, ServerPushSessionAffinity) { |
| 8214 | Initialize(); |
| 8215 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8216 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8217 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8218 | MockQuicData socket_data; |
| 8219 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8220 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8221 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8222 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8223 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8224 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8225 | request.Request( |
| 8226 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8227 | SocketTag(), |
| 8228 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8229 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8230 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8231 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8232 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8233 | EXPECT_TRUE(stream.get()); |
| 8234 | |
| 8235 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 8236 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 8237 | string url = "https://www.example.org/"; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8238 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 8239 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8240 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8241 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 8242 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8243 | (*QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()) |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8244 | ->promised_by_url())[kDefaultUrl] = &promised; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8245 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8246 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8247 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8248 | DEFAULT_PRIORITY, SocketTag(), |
| 8249 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8250 | &net_error_details_, |
| 8251 | failed_on_default_network_callback_, |
| 8252 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8253 | |
| 8254 | EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 8255 | } |
| 8256 | |
| 8257 | TEST_P(QuicStreamFactoryTest, ServerPushPrivacyModeMismatch) { |
| 8258 | Initialize(); |
| 8259 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8260 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8261 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8262 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8263 | MockQuicData socket_data1; |
| 8264 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8265 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8266 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 8267 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 8268 | 2, true, GetNthServerInitiatedUnidirectionalStreamId(0), |
| 8269 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8270 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8271 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8272 | MockQuicData socket_data2; |
| 8273 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8274 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8275 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8276 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8277 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8278 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8279 | request.Request( |
| 8280 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8281 | SocketTag(), |
| 8282 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8283 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8284 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8285 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8286 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8287 | EXPECT_TRUE(stream.get()); |
| 8288 | |
| 8289 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 8290 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 8291 | string url = "https://www.example.org/"; |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 8292 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8293 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8294 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 8295 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8296 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8297 | quic::QuicClientPushPromiseIndex* index = |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8298 | QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()); |
| 8299 | |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8300 | (*index->promised_by_url())[kDefaultUrl] = &promised; |
| 8301 | EXPECT_EQ(index->GetPromised(kDefaultUrl), &promised); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8302 | |
| 8303 | // Doing the request should not use the push stream, but rather |
| 8304 | // cancel it because the privacy modes do not match. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8305 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8306 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8307 | request2.Request( |
| 8308 | host_port_pair_, version_, PRIVACY_MODE_ENABLED, |
| 8309 | DEFAULT_PRIORITY, SocketTag(), |
| 8310 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8311 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8312 | |
| 8313 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8314 | EXPECT_EQ(index->GetPromised(kDefaultUrl), nullptr); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8315 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8316 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8317 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8318 | EXPECT_TRUE(stream2.get()); |
| 8319 | |
| 8320 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 8321 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 8322 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 8323 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 8324 | } |
| 8325 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8326 | // Pool to existing session with matching quic::QuicServerId |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8327 | // even if destination is different. |
| 8328 | TEST_P(QuicStreamFactoryTest, PoolByOrigin) { |
| 8329 | Initialize(); |
| 8330 | |
| 8331 | HostPortPair destination1("first.example.com", 443); |
| 8332 | HostPortPair destination2("second.example.com", 443); |
| 8333 | |
| 8334 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8335 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8336 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8337 | MockQuicData socket_data; |
| 8338 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8339 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8340 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8341 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8342 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8343 | EXPECT_EQ( |
| 8344 | ERR_IO_PENDING, |
| 8345 | request1.Request( |
| 8346 | destination1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8347 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8348 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8349 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8350 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8351 | EXPECT_TRUE(stream1.get()); |
| 8352 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 8353 | |
| 8354 | // Second request returns synchronously because it pools to existing session. |
| 8355 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8356 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8357 | EXPECT_EQ(OK, request2.Request(destination2, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8358 | DEFAULT_PRIORITY, SocketTag(), |
| 8359 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8360 | &net_error_details_, |
| 8361 | failed_on_default_network_callback_, |
| 8362 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8363 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8364 | EXPECT_TRUE(stream2.get()); |
| 8365 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8366 | QuicChromiumClientSession::Handle* session1 = |
| 8367 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8368 | QuicChromiumClientSession::Handle* session2 = |
| 8369 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8370 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8371 | EXPECT_EQ(quic::QuicServerId(host_port_pair_.host(), host_port_pair_.port(), |
| 8372 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8373 | session1->server_id()); |
| 8374 | |
| 8375 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8376 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8377 | } |
| 8378 | |
| 8379 | class QuicStreamFactoryWithDestinationTest |
| 8380 | : public QuicStreamFactoryTestBase, |
| 8381 | public ::testing::TestWithParam<PoolingTestParams> { |
| 8382 | protected: |
| 8383 | QuicStreamFactoryWithDestinationTest() |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 8384 | : QuicStreamFactoryTestBase( |
| 8385 | GetParam().version, |
| 8386 | GetParam().client_headers_include_h2_stream_dependency), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8387 | destination_type_(GetParam().destination_type), |
| 8388 | hanging_read_(SYNCHRONOUS, ERR_IO_PENDING, 0) {} |
| 8389 | |
| 8390 | HostPortPair GetDestination() { |
| 8391 | switch (destination_type_) { |
| 8392 | case SAME_AS_FIRST: |
| 8393 | return origin1_; |
| 8394 | case SAME_AS_SECOND: |
| 8395 | return origin2_; |
| 8396 | case DIFFERENT: |
| 8397 | return HostPortPair(kDifferentHostname, 443); |
| 8398 | default: |
| 8399 | NOTREACHED(); |
| 8400 | return HostPortPair(); |
| 8401 | } |
| 8402 | } |
| 8403 | |
| 8404 | void AddHangingSocketData() { |
| 8405 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8406 | new SequencedSocketData(base::make_span(&hanging_read_, 1), |
| 8407 | base::span<MockWrite>())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8408 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8409 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8410 | } |
| 8411 | |
| 8412 | bool AllDataConsumed() { |
| 8413 | for (const auto& socket_data_ptr : sequenced_socket_data_vector_) { |
| 8414 | if (!socket_data_ptr->AllReadDataConsumed() || |
| 8415 | !socket_data_ptr->AllWriteDataConsumed()) { |
| 8416 | return false; |
| 8417 | } |
| 8418 | } |
| 8419 | return true; |
| 8420 | } |
| 8421 | |
| 8422 | DestinationType destination_type_; |
| 8423 | HostPortPair origin1_; |
| 8424 | HostPortPair origin2_; |
| 8425 | MockRead hanging_read_; |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8426 | std::vector<std::unique_ptr<SequencedSocketData>> |
| 8427 | sequenced_socket_data_vector_; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8428 | }; |
| 8429 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 8430 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 8431 | QuicStreamFactoryWithDestinationTest, |
| 8432 | ::testing::ValuesIn(GetPoolingTestParams())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8433 | |
| 8434 | // A single QUIC request fails because the certificate does not match the origin |
| 8435 | // hostname, regardless of whether it matches the alternative service hostname. |
| 8436 | TEST_P(QuicStreamFactoryWithDestinationTest, InvalidCertificate) { |
| 8437 | if (destination_type_ == DIFFERENT) |
| 8438 | return; |
| 8439 | |
| 8440 | Initialize(); |
| 8441 | |
| 8442 | GURL url("https://mail.example.com/"); |
| 8443 | origin1_ = HostPortPair::FromURL(url); |
| 8444 | |
| 8445 | // Not used for requests, but this provides a test case where the certificate |
| 8446 | // is valid for the hostname of the alternative service. |
| 8447 | origin2_ = HostPortPair("mail.example.org", 433); |
| 8448 | |
| 8449 | HostPortPair destination = GetDestination(); |
| 8450 | |
| 8451 | scoped_refptr<X509Certificate> cert( |
| 8452 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8453 | ASSERT_FALSE(cert->VerifyNameMatch(origin1_.host())); |
| 8454 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8455 | |
| 8456 | ProofVerifyDetailsChromium verify_details; |
| 8457 | verify_details.cert_verify_result.verified_cert = cert; |
| 8458 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8459 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8460 | |
| 8461 | AddHangingSocketData(); |
| 8462 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8463 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8464 | EXPECT_EQ( |
| 8465 | ERR_IO_PENDING, |
| 8466 | request.Request( |
| 8467 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8468 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 8469 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8470 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8471 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_QUIC_HANDSHAKE_FAILED)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8472 | |
| 8473 | EXPECT_TRUE(AllDataConsumed()); |
| 8474 | } |
| 8475 | |
| 8476 | // QuicStreamRequest is pooled based on |destination| if certificate matches. |
| 8477 | TEST_P(QuicStreamFactoryWithDestinationTest, SharedCertificate) { |
| 8478 | Initialize(); |
| 8479 | |
| 8480 | GURL url1("https://www.example.org/"); |
| 8481 | GURL url2("https://mail.example.org/"); |
| 8482 | origin1_ = HostPortPair::FromURL(url1); |
| 8483 | origin2_ = HostPortPair::FromURL(url2); |
| 8484 | |
| 8485 | HostPortPair destination = GetDestination(); |
| 8486 | |
| 8487 | scoped_refptr<X509Certificate> cert( |
| 8488 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8489 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8490 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8491 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8492 | |
| 8493 | ProofVerifyDetailsChromium verify_details; |
| 8494 | verify_details.cert_verify_result.verified_cert = cert; |
| 8495 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8496 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8497 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8498 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8499 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8500 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8501 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8502 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8503 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8504 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8505 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8506 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8507 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8508 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8509 | EXPECT_EQ( |
| 8510 | ERR_IO_PENDING, |
| 8511 | request1.Request( |
| 8512 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8513 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8514 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8515 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8516 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8517 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8518 | EXPECT_TRUE(stream1.get()); |
| 8519 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8520 | |
| 8521 | // Second request returns synchronously because it pools to existing session. |
| 8522 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8523 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8524 | EXPECT_EQ(OK, request2.Request(destination, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8525 | DEFAULT_PRIORITY, SocketTag(), |
| 8526 | /*cert_verify_flags=*/0, url2, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8527 | &net_error_details_, |
| 8528 | failed_on_default_network_callback_, |
| 8529 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8530 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8531 | EXPECT_TRUE(stream2.get()); |
| 8532 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8533 | QuicChromiumClientSession::Handle* session1 = |
| 8534 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8535 | QuicChromiumClientSession::Handle* session2 = |
| 8536 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8537 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8538 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8539 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8540 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8541 | session1->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8542 | |
| 8543 | EXPECT_TRUE(AllDataConsumed()); |
| 8544 | } |
| 8545 | |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8546 | // QuicStreamRequest is not pooled if PrivacyMode differs. |
| 8547 | TEST_P(QuicStreamFactoryWithDestinationTest, DifferentPrivacyMode) { |
| 8548 | Initialize(); |
| 8549 | |
| 8550 | GURL url1("https://www.example.org/"); |
| 8551 | GURL url2("https://mail.example.org/"); |
| 8552 | origin1_ = HostPortPair::FromURL(url1); |
| 8553 | origin2_ = HostPortPair::FromURL(url2); |
| 8554 | |
| 8555 | HostPortPair destination = GetDestination(); |
| 8556 | |
| 8557 | scoped_refptr<X509Certificate> cert( |
| 8558 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8559 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8560 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8561 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8562 | |
| 8563 | ProofVerifyDetailsChromium verify_details1; |
| 8564 | verify_details1.cert_verify_result.verified_cert = cert; |
| 8565 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8566 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8567 | |
| 8568 | ProofVerifyDetailsChromium verify_details2; |
| 8569 | verify_details2.cert_verify_result.verified_cert = cert; |
| 8570 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8571 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8572 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8573 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8574 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8575 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8576 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8577 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8578 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8579 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8580 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8581 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8582 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8583 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8584 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8585 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8586 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8587 | QuicStreamRequest request1(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8588 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8589 | request1.Request( |
| 8590 | destination, version_, PRIVACY_MODE_DISABLED, DEFAULT_PRIORITY, |
| 8591 | SocketTag(), |
| 8592 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8593 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8594 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8595 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8596 | EXPECT_TRUE(stream1.get()); |
| 8597 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8598 | |
| 8599 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8600 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8601 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8602 | request2.Request( |
| 8603 | destination, version_, PRIVACY_MODE_ENABLED, DEFAULT_PRIORITY, |
| 8604 | SocketTag(), |
| 8605 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8606 | failed_on_default_network_callback_, callback2.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8607 | EXPECT_EQ(OK, callback2.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8608 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8609 | EXPECT_TRUE(stream2.get()); |
| 8610 | |
| 8611 | // |request2| does not pool to the first session, because PrivacyMode does not |
| 8612 | // match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8613 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8614 | QuicChromiumClientSession::Handle* session1 = |
| 8615 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8616 | QuicChromiumClientSession::Handle* session2 = |
| 8617 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8618 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8619 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8620 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), false), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8621 | session1->server_id()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8622 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), true), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8623 | session2->server_id()); |
| 8624 | |
| 8625 | EXPECT_TRUE(AllDataConsumed()); |
| 8626 | } |
| 8627 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8628 | // QuicStreamRequest is not pooled if certificate does not match its origin. |
| 8629 | TEST_P(QuicStreamFactoryWithDestinationTest, DisjointCertificate) { |
| 8630 | Initialize(); |
| 8631 | |
| 8632 | GURL url1("https://news.example.org/"); |
| 8633 | GURL url2("https://mail.example.com/"); |
| 8634 | origin1_ = HostPortPair::FromURL(url1); |
| 8635 | origin2_ = HostPortPair::FromURL(url2); |
| 8636 | |
| 8637 | HostPortPair destination = GetDestination(); |
| 8638 | |
| 8639 | scoped_refptr<X509Certificate> cert1( |
| 8640 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8641 | ASSERT_TRUE(cert1->VerifyNameMatch(origin1_.host())); |
| 8642 | ASSERT_FALSE(cert1->VerifyNameMatch(origin2_.host())); |
| 8643 | ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8644 | |
| 8645 | ProofVerifyDetailsChromium verify_details1; |
| 8646 | verify_details1.cert_verify_result.verified_cert = cert1; |
| 8647 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8648 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8649 | |
| 8650 | scoped_refptr<X509Certificate> cert2( |
| 8651 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8652 | ASSERT_TRUE(cert2->VerifyNameMatch(origin2_.host())); |
| 8653 | ASSERT_FALSE(cert2->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8654 | |
| 8655 | ProofVerifyDetailsChromium verify_details2; |
| 8656 | verify_details2.cert_verify_result.verified_cert = cert2; |
| 8657 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8658 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8659 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8660 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8661 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8662 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8663 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8664 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8665 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8666 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8667 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8668 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8669 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8670 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8671 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8672 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8673 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8674 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8675 | EXPECT_EQ( |
| 8676 | ERR_IO_PENDING, |
| 8677 | request1.Request( |
| 8678 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8679 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8680 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8681 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8682 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8683 | EXPECT_TRUE(stream1.get()); |
| 8684 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8685 | |
| 8686 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8687 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8688 | EXPECT_EQ( |
| 8689 | ERR_IO_PENDING, |
| 8690 | request2.Request( |
| 8691 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8692 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8693 | failed_on_default_network_callback_, callback2.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8694 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8695 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8696 | EXPECT_TRUE(stream2.get()); |
| 8697 | |
| 8698 | // |request2| does not pool to the first session, because the certificate does |
| 8699 | // not match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8700 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8701 | QuicChromiumClientSession::Handle* session1 = |
| 8702 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8703 | QuicChromiumClientSession::Handle* session2 = |
| 8704 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8705 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8706 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8707 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8708 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8709 | session1->server_id()); |
| 8710 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), |
| 8711 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8712 | session2->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8713 | |
| 8714 | EXPECT_TRUE(AllDataConsumed()); |
| 8715 | } |
| 8716 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8717 | // This test verifies that QuicStreamFactory::ClearCachedStatesInCryptoConfig |
| 8718 | // correctly transform an origin filter to a ServerIdFilter. Whether the |
| 8719 | // deletion itself works correctly is tested in QuicCryptoClientConfigTest. |
| 8720 | TEST_P(QuicStreamFactoryTest, ClearCachedStatesInCryptoConfig) { |
| 8721 | Initialize(); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8722 | quic::QuicCryptoClientConfig* crypto_config = |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8723 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 8724 | |
| 8725 | struct TestCase { |
| 8726 | TestCase(const std::string& host, |
| 8727 | int port, |
| 8728 | PrivacyMode privacy_mode, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8729 | quic::QuicCryptoClientConfig* crypto_config) |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8730 | : server_id(host, port, privacy_mode), |
| 8731 | state(crypto_config->LookupOrCreate(server_id)) { |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8732 | std::vector<string> certs(1); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8733 | certs[0] = "cert"; |
| 8734 | state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); |
| 8735 | state->set_source_address_token("TOKEN"); |
| 8736 | state->SetProofValid(); |
| 8737 | |
| 8738 | EXPECT_FALSE(state->certs().empty()); |
| 8739 | } |
| 8740 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8741 | quic::QuicServerId server_id; |
| 8742 | quic::QuicCryptoClientConfig::CachedState* state; |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8743 | } test_cases[] = { |
| 8744 | TestCase("www.google.com", 443, privacy_mode_, crypto_config), |
| 8745 | TestCase("www.example.com", 443, privacy_mode_, crypto_config), |
| 8746 | TestCase("www.example.com", 4433, privacy_mode_, crypto_config)}; |
| 8747 | |
| 8748 | // Clear cached states for the origin https://www.example.com:4433. |
| 8749 | GURL origin("https://www.example.com:4433"); |
csharrison | ebeca8e | 2016-10-18 02:35:36 | [diff] [blame] | 8750 | factory_->ClearCachedStatesInCryptoConfig(base::Bind( |
| 8751 | static_cast<bool (*)(const GURL&, const GURL&)>(::operator==), origin)); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8752 | EXPECT_FALSE(test_cases[0].state->certs().empty()); |
| 8753 | EXPECT_FALSE(test_cases[1].state->certs().empty()); |
| 8754 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8755 | |
| 8756 | // Clear all cached states. |
| 8757 | factory_->ClearCachedStatesInCryptoConfig( |
| 8758 | base::Callback<bool(const GURL&)>()); |
| 8759 | EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 8760 | EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 8761 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8762 | } |
| 8763 | |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8764 | // Passes connection options and client connection options to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8765 | // then checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8766 | TEST_P(QuicStreamFactoryTest, ConfigConnectionOptions) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8767 | test_params_.quic_connection_options.push_back(quic::kTIME); |
| 8768 | test_params_.quic_connection_options.push_back(quic::kTBBR); |
| 8769 | test_params_.quic_connection_options.push_back(quic::kREJ); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8770 | |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8771 | test_params_.quic_client_connection_options.push_back(quic::kTBBR); |
| 8772 | test_params_.quic_client_connection_options.push_back(quic::k1RTT); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8773 | |
| 8774 | Initialize(); |
| 8775 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8776 | const quic::QuicConfig* config = |
| 8777 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8778 | EXPECT_EQ(test_params_.quic_connection_options, |
| 8779 | config->SendConnectionOptions()); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8780 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8781 | quic::kTBBR, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8782 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8783 | quic::k1RTT, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8784 | } |
| 8785 | |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8786 | // Verifies that the host resolver uses the request priority passed to |
| 8787 | // QuicStreamRequest::Request(). |
| 8788 | TEST_P(QuicStreamFactoryTest, HostResolverUsesRequestPriority) { |
| 8789 | Initialize(); |
| 8790 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8791 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8792 | |
| 8793 | MockQuicData socket_data; |
| 8794 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8795 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8796 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8797 | |
| 8798 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8799 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8800 | request.Request( |
| 8801 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8802 | SocketTag(), |
| 8803 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8804 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8805 | |
| 8806 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8807 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8808 | EXPECT_TRUE(stream.get()); |
| 8809 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8810 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8811 | |
| 8812 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8813 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8814 | } |
| 8815 | |
Lily Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 8816 | TEST_P(QuicStreamFactoryTest, HostResolverRequestReprioritizedOnSetPriority) { |
| 8817 | Initialize(); |
| 8818 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8819 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8820 | |
| 8821 | MockQuicData socket_data; |
| 8822 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8823 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8824 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8825 | |
| 8826 | QuicStreamRequest request(factory_.get()); |
| 8827 | EXPECT_EQ(ERR_IO_PENDING, |
| 8828 | request.Request( |
| 8829 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8830 | SocketTag(), |
| 8831 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8832 | failed_on_default_network_callback_, callback_.callback())); |
| 8833 | |
| 8834 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
| 8835 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->request_priority(1)); |
| 8836 | |
| 8837 | QuicStreamRequest request2(factory_.get()); |
| 8838 | EXPECT_EQ(ERR_IO_PENDING, |
| 8839 | request2.Request( |
| 8840 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8841 | SocketTag(), |
| 8842 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 8843 | failed_on_default_network_callback_, callback_.callback())); |
| 8844 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
| 8845 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8846 | |
| 8847 | request.SetPriority(LOWEST); |
| 8848 | EXPECT_EQ(LOWEST, host_resolver_->request_priority(1)); |
| 8849 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8850 | } |
| 8851 | |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8852 | // Passes |quic_max_time_before_crypto_handshake_seconds| and |
| 8853 | // |quic_max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8854 | // checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8855 | TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 8856 | test_params_.quic_max_time_before_crypto_handshake_seconds = 11; |
| 8857 | test_params_.quic_max_idle_time_before_crypto_handshake_seconds = 13; |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8858 | Initialize(); |
| 8859 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8860 | const quic::QuicConfig* config = |
| 8861 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 8862 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(11), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8863 | config->max_time_before_crypto_handshake()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8864 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(13), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8865 | config->max_idle_time_before_crypto_handshake()); |
| 8866 | } |
| 8867 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8868 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8869 | // succeeds asynchronously, then crypto handshake fails synchronously. |
| 8870 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncSync) { |
| 8871 | Initialize(); |
| 8872 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8873 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8874 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8875 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8876 | |
| 8877 | MockQuicData socket_data; |
| 8878 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8879 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8880 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8881 | |
| 8882 | QuicStreamRequest request(factory_.get()); |
| 8883 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8884 | request.Request( |
| 8885 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8886 | SocketTag(), |
| 8887 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8888 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8889 | |
| 8890 | TestCompletionCallback host_resolution_callback; |
| 8891 | EXPECT_TRUE( |
| 8892 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8893 | |
| 8894 | // |host_resolver_| has not finished host resolution at this point, so |
| 8895 | // |host_resolution_callback| should not have a result. |
| 8896 | base::RunLoop().RunUntilIdle(); |
| 8897 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8898 | |
| 8899 | // Allow |host_resolver_| to finish host resolution. |
| 8900 | // Since the request fails immediately after host resolution (getting |
| 8901 | // ERR_FAILED from socket reads/writes), |host_resolution_callback| should be |
| 8902 | // called with ERR_QUIC_PROTOCOL_ERROR since that's the next result in |
| 8903 | // forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8904 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8905 | base::RunLoop().RunUntilIdle(); |
| 8906 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8907 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, host_resolution_callback.WaitForResult()); |
| 8908 | |
| 8909 | // Calling WaitForHostResolution() a second time should return |
| 8910 | // false since host resolution has finished already. |
| 8911 | EXPECT_FALSE( |
| 8912 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8913 | |
| 8914 | EXPECT_TRUE(callback_.have_result()); |
| 8915 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8916 | } |
| 8917 | |
| 8918 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8919 | // succeeds asynchronously, then crypto handshake fails asynchronously. |
| 8920 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncAsync) { |
| 8921 | Initialize(); |
| 8922 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8923 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8924 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8925 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8926 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8927 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8928 | factory_->set_require_confirmation(true); |
| 8929 | |
| 8930 | MockQuicData socket_data; |
| 8931 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8932 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8933 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8934 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8935 | |
| 8936 | QuicStreamRequest request(factory_.get()); |
| 8937 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8938 | request.Request( |
| 8939 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8940 | SocketTag(), |
| 8941 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8942 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8943 | |
| 8944 | TestCompletionCallback host_resolution_callback; |
| 8945 | EXPECT_TRUE( |
| 8946 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8947 | |
| 8948 | // |host_resolver_| has not finished host resolution at this point, so |
| 8949 | // |host_resolution_callback| should not have a result. |
| 8950 | base::RunLoop().RunUntilIdle(); |
| 8951 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8952 | |
| 8953 | // Allow |host_resolver_| to finish host resolution. Since crypto handshake |
| 8954 | // will hang after host resolution, |host_resolution_callback| should run with |
| 8955 | // ERR_IO_PENDING since that's the next result in forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8956 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8957 | base::RunLoop().RunUntilIdle(); |
| 8958 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8959 | EXPECT_EQ(ERR_IO_PENDING, host_resolution_callback.WaitForResult()); |
| 8960 | |
| 8961 | // Calling WaitForHostResolution() a second time should return |
| 8962 | // false since host resolution has finished already. |
| 8963 | EXPECT_FALSE( |
| 8964 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8965 | |
| 8966 | EXPECT_FALSE(callback_.have_result()); |
| 8967 | socket_data.GetSequencedSocketData()->Resume(); |
| 8968 | base::RunLoop().RunUntilIdle(); |
| 8969 | EXPECT_TRUE(callback_.have_result()); |
| 8970 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8971 | } |
| 8972 | |
| 8973 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8974 | // succeeds synchronously, then crypto handshake fails synchronously. |
| 8975 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncSync) { |
| 8976 | Initialize(); |
| 8977 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8978 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8979 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8980 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8981 | |
| 8982 | MockQuicData socket_data; |
| 8983 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8984 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8985 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8986 | |
| 8987 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8988 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8989 | request.Request( |
| 8990 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8991 | SocketTag(), |
| 8992 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8993 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8994 | |
| 8995 | // WaitForHostResolution() should return false since host |
| 8996 | // resolution has finished already. |
| 8997 | TestCompletionCallback host_resolution_callback; |
| 8998 | EXPECT_FALSE( |
| 8999 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9000 | base::RunLoop().RunUntilIdle(); |
| 9001 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9002 | EXPECT_FALSE(callback_.have_result()); |
| 9003 | } |
| 9004 | |
| 9005 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 9006 | // succeeds synchronously, then crypto handshake fails asynchronously. |
| 9007 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncAsync) { |
| 9008 | Initialize(); |
| 9009 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9010 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9011 | |
| 9012 | // Host resolution will succeed synchronously, but Request() as a whole |
| 9013 | // will fail asynchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9014 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9015 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 9016 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9017 | factory_->set_require_confirmation(true); |
| 9018 | |
| 9019 | MockQuicData socket_data; |
| 9020 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 9021 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 9022 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 9023 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9024 | |
| 9025 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9026 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9027 | request.Request( |
| 9028 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9029 | SocketTag(), |
| 9030 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9031 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9032 | |
| 9033 | // WaitForHostResolution() should return false since host |
| 9034 | // resolution has finished already. |
| 9035 | TestCompletionCallback host_resolution_callback; |
| 9036 | EXPECT_FALSE( |
| 9037 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9038 | base::RunLoop().RunUntilIdle(); |
| 9039 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9040 | |
| 9041 | EXPECT_FALSE(callback_.have_result()); |
| 9042 | socket_data.GetSequencedSocketData()->Resume(); |
| 9043 | base::RunLoop().RunUntilIdle(); |
| 9044 | EXPECT_TRUE(callback_.have_result()); |
| 9045 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 9046 | } |
| 9047 | |
| 9048 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 9049 | // synchronously. |
| 9050 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailSync) { |
| 9051 | Initialize(); |
| 9052 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9053 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9054 | |
| 9055 | // Host resolution will fail synchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9056 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9057 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9058 | |
| 9059 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9060 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9061 | request.Request( |
| 9062 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9063 | SocketTag(), |
| 9064 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9065 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9066 | |
| 9067 | // WaitForHostResolution() should return false since host |
| 9068 | // resolution has failed already. |
| 9069 | TestCompletionCallback host_resolution_callback; |
| 9070 | EXPECT_FALSE( |
| 9071 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9072 | base::RunLoop().RunUntilIdle(); |
| 9073 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9074 | } |
| 9075 | |
| 9076 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 9077 | // asynchronously. |
| 9078 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { |
| 9079 | Initialize(); |
| 9080 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9081 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9082 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9083 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9084 | |
| 9085 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9086 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9087 | request.Request( |
| 9088 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9089 | SocketTag(), |
| 9090 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9091 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 9092 | |
| 9093 | TestCompletionCallback host_resolution_callback; |
| 9094 | EXPECT_TRUE( |
| 9095 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9096 | |
| 9097 | // Allow |host_resolver_| to fail host resolution. |host_resolution_callback| |
| 9098 | // Should run with ERR_NAME_NOT_RESOLVED since that's the error host |
| 9099 | // resolution failed with. |
| 9100 | base::RunLoop().RunUntilIdle(); |
| 9101 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 9102 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, host_resolution_callback.WaitForResult()); |
| 9103 | |
| 9104 | EXPECT_TRUE(callback_.have_result()); |
| 9105 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 9106 | } |
| 9107 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9108 | // With dns race experiment turned on, and DNS resolve succeeds synchronously, |
| 9109 | // the final connection is established through the resolved DNS. No racing |
| 9110 | // connection. |
| 9111 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9112 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9113 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9114 | Initialize(); |
| 9115 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9116 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9117 | |
| 9118 | // Set an address in resolver for synchronous return. |
| 9119 | host_resolver_->set_synchronous_mode(true); |
| 9120 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9121 | kNonCachedIPAddress, ""); |
| 9122 | |
| 9123 | // Set up a different address in stale resolver cache. |
| 9124 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9125 | HostCache::Entry entry(OK, |
| 9126 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9127 | HostCache::Entry::SOURCE_DNS); |
| 9128 | base::TimeDelta zero; |
| 9129 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9130 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9131 | // Expire the cache |
| 9132 | cache->OnNetworkChange(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9133 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9134 | MockQuicData quic_data; |
| 9135 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9136 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9137 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9138 | |
| 9139 | QuicStreamRequest request(factory_.get()); |
| 9140 | EXPECT_THAT(request.Request( |
| 9141 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9142 | SocketTag(), |
| 9143 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9144 | failed_on_default_network_callback_, callback_.callback()), |
| 9145 | IsOk()); |
| 9146 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9147 | EXPECT_TRUE(stream.get()); |
| 9148 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9149 | EXPECT_EQ( |
| 9150 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9151 | kNonCachedIPAddress); |
| 9152 | |
| 9153 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9154 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9155 | } |
| 9156 | |
| 9157 | // With dns race experiment on, DNS resolve returns async, no matching cache in |
| 9158 | // host resolver, connection should be successful and through resolved DNS. No |
| 9159 | // racing connection. |
| 9160 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9161 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9162 | Initialize(); |
| 9163 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9164 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9165 | |
| 9166 | // Set an address in resolver for asynchronous return. |
| 9167 | host_resolver_->set_ondemand_mode(true); |
| 9168 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9169 | kNonCachedIPAddress, ""); |
| 9170 | |
| 9171 | MockQuicData quic_data; |
| 9172 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9173 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9174 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9175 | |
| 9176 | QuicStreamRequest request(factory_.get()); |
| 9177 | EXPECT_EQ(ERR_IO_PENDING, |
| 9178 | request.Request( |
| 9179 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9180 | SocketTag(), |
| 9181 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9182 | failed_on_default_network_callback_, callback_.callback())); |
| 9183 | TestCompletionCallback host_resolution_callback; |
| 9184 | EXPECT_TRUE( |
| 9185 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9186 | base::RunLoop().RunUntilIdle(); |
| 9187 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9188 | |
| 9189 | // Cause the host resolution to return. |
| 9190 | host_resolver_->ResolveAllPending(); |
| 9191 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 9192 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9193 | |
| 9194 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9195 | EXPECT_TRUE(stream.get()); |
| 9196 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9197 | |
| 9198 | EXPECT_EQ( |
| 9199 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9200 | kNonCachedIPAddress); |
| 9201 | |
| 9202 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9203 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9204 | } |
| 9205 | |
| 9206 | // With dns race experiment on, DNS resolve returns async, stale dns used, |
| 9207 | // connects synchrounously, and then the resolved DNS matches. |
| 9208 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9209 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9210 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9211 | Initialize(); |
| 9212 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9213 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9214 | |
| 9215 | // Set an address in resolver for asynchronous return. |
| 9216 | host_resolver_->set_ondemand_mode(true); |
| 9217 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9218 | kCachedIPAddress.ToString(), ""); |
| 9219 | |
| 9220 | // Set up the same address in the stale resolver cache. |
| 9221 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9222 | HostCache::Entry entry(OK, |
| 9223 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9224 | HostCache::Entry::SOURCE_DNS); |
| 9225 | base::TimeDelta zero; |
| 9226 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9227 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9228 | // Expire the cache |
| 9229 | cache->OnNetworkChange(); |
| 9230 | |
| 9231 | MockQuicData quic_data; |
| 9232 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9233 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9234 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9235 | |
| 9236 | QuicStreamRequest request(factory_.get()); |
| 9237 | EXPECT_EQ(ERR_IO_PENDING, |
| 9238 | request.Request( |
| 9239 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9240 | SocketTag(), |
| 9241 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9242 | failed_on_default_network_callback_, callback_.callback())); |
| 9243 | |
| 9244 | // Check that the racing job is running. |
| 9245 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9246 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9247 | |
| 9248 | // Resolve dns and return. |
| 9249 | host_resolver_->ResolveAllPending(); |
| 9250 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9251 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9252 | EXPECT_TRUE(stream.get()); |
| 9253 | |
| 9254 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9255 | |
| 9256 | EXPECT_EQ( |
| 9257 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9258 | kCachedIPAddress.ToString()); |
| 9259 | |
| 9260 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9261 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9262 | } |
| 9263 | |
| 9264 | // With dns race experiment on, dns resolve async, stale dns used, connect |
| 9265 | // async, and then the result matches. |
| 9266 | TEST_P(QuicStreamFactoryTest, |
| 9267 | ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9268 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9269 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9270 | Initialize(); |
| 9271 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9272 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9273 | |
| 9274 | // Set an address in resolver for asynchronous return. |
| 9275 | host_resolver_->set_ondemand_mode(true); |
| 9276 | factory_->set_require_confirmation(true); |
| 9277 | crypto_client_stream_factory_.set_handshake_mode( |
| 9278 | MockCryptoClientStream::ZERO_RTT); |
| 9279 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9280 | kCachedIPAddress.ToString(), ""); |
| 9281 | |
| 9282 | // Set up the same address in the stale resolver cache. |
| 9283 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9284 | HostCache::Entry entry(OK, |
| 9285 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9286 | HostCache::Entry::SOURCE_DNS); |
| 9287 | base::TimeDelta zero; |
| 9288 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9289 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9290 | // Expire the cache |
| 9291 | cache->OnNetworkChange(); |
| 9292 | |
| 9293 | MockQuicData quic_data; |
| 9294 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9295 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9296 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9297 | |
| 9298 | QuicStreamRequest request(factory_.get()); |
| 9299 | EXPECT_EQ(ERR_IO_PENDING, |
| 9300 | request.Request( |
| 9301 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9302 | SocketTag(), |
| 9303 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9304 | failed_on_default_network_callback_, callback_.callback())); |
| 9305 | |
| 9306 | // Send Crypto handshake so connect will call back. |
| 9307 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9308 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9309 | base::RunLoop().RunUntilIdle(); |
| 9310 | |
| 9311 | // Check that the racing job is running. |
| 9312 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9313 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9314 | |
| 9315 | // Resolve dns and call back, make sure job finishes. |
| 9316 | host_resolver_->ResolveAllPending(); |
| 9317 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9318 | |
| 9319 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9320 | EXPECT_TRUE(stream.get()); |
| 9321 | |
| 9322 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9323 | |
| 9324 | EXPECT_EQ( |
| 9325 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9326 | kCachedIPAddress.ToString()); |
| 9327 | |
| 9328 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9329 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9330 | } |
| 9331 | |
| 9332 | // With dns race experiment on, dns resolve async, stale dns used, dns resolve |
| 9333 | // return, then connection finishes and matches with the result. |
| 9334 | TEST_P(QuicStreamFactoryTest, |
| 9335 | ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9336 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9337 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9338 | Initialize(); |
| 9339 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9340 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9341 | |
| 9342 | // Set an address in resolver for asynchronous return. |
| 9343 | host_resolver_->set_ondemand_mode(true); |
| 9344 | factory_->set_require_confirmation(true); |
| 9345 | crypto_client_stream_factory_.set_handshake_mode( |
| 9346 | MockCryptoClientStream::ZERO_RTT); |
| 9347 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9348 | kCachedIPAddress.ToString(), ""); |
| 9349 | |
| 9350 | // Set up the same address in the stale resolver cache. |
| 9351 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9352 | HostCache::Entry entry(OK, |
| 9353 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9354 | HostCache::Entry::SOURCE_DNS); |
| 9355 | base::TimeDelta zero; |
| 9356 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9357 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9358 | // Expire the cache |
| 9359 | cache->OnNetworkChange(); |
| 9360 | |
| 9361 | MockQuicData quic_data; |
| 9362 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9363 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9364 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9365 | |
| 9366 | QuicStreamRequest request(factory_.get()); |
| 9367 | EXPECT_EQ(ERR_IO_PENDING, |
| 9368 | request.Request( |
| 9369 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9370 | SocketTag(), |
| 9371 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9372 | failed_on_default_network_callback_, callback_.callback())); |
| 9373 | |
| 9374 | // Finish dns async, check we still need to wait for stale connection async. |
| 9375 | host_resolver_->ResolveAllPending(); |
| 9376 | base::RunLoop().RunUntilIdle(); |
| 9377 | EXPECT_FALSE(callback_.have_result()); |
| 9378 | |
| 9379 | // Finish stale connection async, and the stale connection should pass dns |
| 9380 | // validation. |
| 9381 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9382 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9383 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9384 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9385 | EXPECT_TRUE(stream.get()); |
| 9386 | |
| 9387 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9388 | EXPECT_EQ( |
| 9389 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9390 | kCachedIPAddress.ToString()); |
| 9391 | |
| 9392 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9393 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9394 | } |
| 9395 | |
| 9396 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9397 | // sync, but dns no match |
| 9398 | TEST_P(QuicStreamFactoryTest, |
| 9399 | ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9400 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9401 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9402 | Initialize(); |
| 9403 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9404 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9405 | |
| 9406 | // Set an address in resolver for asynchronous return. |
| 9407 | host_resolver_->set_ondemand_mode(true); |
| 9408 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9409 | kNonCachedIPAddress, ""); |
| 9410 | |
| 9411 | // Set up a different address in the stale resolver cache. |
| 9412 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9413 | HostCache::Entry entry(OK, |
| 9414 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9415 | HostCache::Entry::SOURCE_DNS); |
| 9416 | base::TimeDelta zero; |
| 9417 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9418 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9419 | // Expire the cache |
| 9420 | cache->OnNetworkChange(); |
| 9421 | |
| 9422 | // Socket for the stale connection which will invoke connection closure. |
| 9423 | MockQuicData quic_data; |
| 9424 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9425 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9426 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9427 | SYNCHRONOUS, |
| 9428 | client_maker_.MakeConnectionClosePacket( |
| 9429 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9430 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9431 | |
| 9432 | // Socket for the new connection. |
| 9433 | MockQuicData quic_data2; |
| 9434 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9435 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9436 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9437 | |
| 9438 | QuicStreamRequest request(factory_.get()); |
| 9439 | EXPECT_EQ(ERR_IO_PENDING, |
| 9440 | request.Request( |
| 9441 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9442 | SocketTag(), |
| 9443 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9444 | failed_on_default_network_callback_, callback_.callback())); |
| 9445 | |
| 9446 | // Check the stale connection is running. |
| 9447 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9448 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9449 | |
| 9450 | // Finish dns resolution and check the job has finished. |
| 9451 | host_resolver_->ResolveAllPending(); |
| 9452 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9453 | |
| 9454 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9455 | EXPECT_TRUE(stream.get()); |
| 9456 | |
| 9457 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9458 | |
| 9459 | EXPECT_EQ( |
| 9460 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9461 | kNonCachedIPAddress); |
| 9462 | |
| 9463 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9464 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9465 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9466 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9467 | } |
| 9468 | |
| 9469 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9470 | // async, finishes before dns, but no match |
| 9471 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9472 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9473 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9474 | Initialize(); |
| 9475 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9476 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9477 | |
| 9478 | // Set an address in resolver for asynchronous return. |
| 9479 | host_resolver_->set_ondemand_mode(true); |
| 9480 | factory_->set_require_confirmation(true); |
| 9481 | crypto_client_stream_factory_.set_handshake_mode( |
| 9482 | MockCryptoClientStream::ZERO_RTT); |
| 9483 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9484 | kNonCachedIPAddress, ""); |
| 9485 | |
| 9486 | // Set up a different address in the stale resolvercache. |
| 9487 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9488 | HostCache::Entry entry(OK, |
| 9489 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9490 | HostCache::Entry::SOURCE_DNS); |
| 9491 | base::TimeDelta zero; |
| 9492 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9493 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9494 | // Expire the cache |
| 9495 | cache->OnNetworkChange(); |
| 9496 | |
| 9497 | MockQuicData quic_data; |
| 9498 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9499 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9500 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9501 | SYNCHRONOUS, |
| 9502 | client_maker_.MakeConnectionClosePacket( |
| 9503 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9504 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9505 | |
| 9506 | MockQuicData quic_data2; |
| 9507 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9508 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9509 | |
| 9510 | QuicStreamRequest request(factory_.get()); |
| 9511 | EXPECT_EQ(ERR_IO_PENDING, |
| 9512 | request.Request( |
| 9513 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9514 | SocketTag(), |
| 9515 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9516 | failed_on_default_network_callback_, callback_.callback())); |
| 9517 | |
| 9518 | // Finish the stale connection. |
| 9519 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9520 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9521 | base::RunLoop().RunUntilIdle(); |
| 9522 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9523 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9524 | |
| 9525 | // Finish host resolution and check the job is done. |
| 9526 | host_resolver_->ResolveAllPending(); |
| 9527 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9528 | |
| 9529 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9530 | EXPECT_TRUE(stream.get()); |
| 9531 | |
| 9532 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9533 | EXPECT_EQ( |
| 9534 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9535 | kNonCachedIPAddress); |
| 9536 | |
| 9537 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9538 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9539 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9540 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9541 | } |
| 9542 | |
| 9543 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9544 | // async, dns finishes first, but no match |
| 9545 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9546 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9547 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9548 | Initialize(); |
| 9549 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9550 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9551 | |
| 9552 | // Set an address in resolver for asynchronous return. |
| 9553 | host_resolver_->set_ondemand_mode(true); |
| 9554 | factory_->set_require_confirmation(true); |
| 9555 | crypto_client_stream_factory_.set_handshake_mode( |
| 9556 | MockCryptoClientStream::ZERO_RTT); |
| 9557 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9558 | kNonCachedIPAddress, ""); |
| 9559 | |
| 9560 | // Set up a different address in the stale resolver cache. |
| 9561 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9562 | HostCache::Entry entry(OK, |
| 9563 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9564 | HostCache::Entry::SOURCE_DNS); |
| 9565 | base::TimeDelta zero; |
| 9566 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9567 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9568 | // Expire the cache |
| 9569 | cache->OnNetworkChange(); |
| 9570 | |
| 9571 | MockQuicData quic_data; |
| 9572 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9573 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9574 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9575 | SYNCHRONOUS, |
| 9576 | client_maker_.MakeConnectionClosePacket( |
| 9577 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9578 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9579 | |
| 9580 | MockQuicData quic_data2; |
| 9581 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9582 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 9583 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9584 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9585 | |
| 9586 | QuicStreamRequest request(factory_.get()); |
| 9587 | EXPECT_EQ(ERR_IO_PENDING, |
| 9588 | request.Request( |
| 9589 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9590 | SocketTag(), |
| 9591 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9592 | failed_on_default_network_callback_, callback_.callback())); |
| 9593 | // Finish dns resolution, but need to wait for stale connection. |
| 9594 | host_resolver_->ResolveAllPending(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9595 | base::RunLoop().RunUntilIdle(); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9596 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9597 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9598 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9599 | |
| 9600 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9601 | EXPECT_TRUE(stream.get()); |
| 9602 | |
| 9603 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9604 | EXPECT_EQ( |
| 9605 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9606 | kNonCachedIPAddress); |
| 9607 | |
| 9608 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9609 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9610 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9611 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9612 | } |
| 9613 | |
| 9614 | // With dns race experiment on, dns resolve returns error sync, same behavior |
| 9615 | // as experiment is not on |
| 9616 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9617 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9618 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9619 | Initialize(); |
| 9620 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9621 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9622 | |
| 9623 | // Set synchronous failure in resolver. |
| 9624 | host_resolver_->set_synchronous_mode(true); |
| 9625 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9626 | |
| 9627 | MockQuicData quic_data; |
| 9628 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9629 | QuicStreamRequest request(factory_.get()); |
| 9630 | |
| 9631 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 9632 | request.Request( |
| 9633 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9634 | SocketTag(), |
| 9635 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9636 | failed_on_default_network_callback_, callback_.callback())); |
| 9637 | } |
| 9638 | |
| 9639 | // With dns race experiment on, no cache available, dns resolve returns error |
| 9640 | // async |
| 9641 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9642 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9643 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9644 | Initialize(); |
| 9645 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9646 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9647 | |
| 9648 | // Set asynchronous failure in resolver. |
| 9649 | host_resolver_->set_ondemand_mode(true); |
| 9650 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9651 | |
| 9652 | MockQuicData quic_data; |
| 9653 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9654 | QuicStreamRequest request(factory_.get()); |
| 9655 | |
| 9656 | EXPECT_EQ(ERR_IO_PENDING, |
| 9657 | request.Request( |
| 9658 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9659 | SocketTag(), |
| 9660 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9661 | failed_on_default_network_callback_, callback_.callback())); |
| 9662 | |
| 9663 | // Resolve and expect result that shows the resolution error. |
| 9664 | host_resolver_->ResolveAllPending(); |
| 9665 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9666 | } |
| 9667 | |
| 9668 | // With dns race experiment on, dns resolve async, staled used and connects |
| 9669 | // sync, dns returns error and no connection is established. |
| 9670 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9671 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9672 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9673 | Initialize(); |
| 9674 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9675 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9676 | |
| 9677 | // Set asynchronous failure in resolver. |
| 9678 | host_resolver_->set_ondemand_mode(true); |
| 9679 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9680 | |
| 9681 | // Set up an address in the stale cache. |
| 9682 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9683 | HostCache::Entry entry(OK, |
| 9684 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9685 | HostCache::Entry::SOURCE_DNS); |
| 9686 | base::TimeDelta zero; |
| 9687 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9688 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9689 | // Expire the cache |
| 9690 | cache->OnNetworkChange(); |
| 9691 | |
| 9692 | // Socket for the stale connection which is supposed to disconnect. |
| 9693 | MockQuicData quic_data; |
| 9694 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9695 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9696 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9697 | SYNCHRONOUS, |
| 9698 | client_maker_.MakeConnectionClosePacket( |
| 9699 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9700 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9701 | |
| 9702 | QuicStreamRequest request(factory_.get()); |
| 9703 | EXPECT_EQ(ERR_IO_PENDING, |
| 9704 | request.Request( |
| 9705 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9706 | SocketTag(), |
| 9707 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9708 | failed_on_default_network_callback_, callback_.callback())); |
| 9709 | |
| 9710 | // Check that the stale connection is running. |
| 9711 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9712 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9713 | |
| 9714 | // Finish host resolution. |
| 9715 | host_resolver_->ResolveAllPending(); |
| 9716 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9717 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9718 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9719 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9720 | } |
| 9721 | |
| 9722 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9723 | // return error, then dns matches |
| 9724 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9725 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9726 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9727 | Initialize(); |
| 9728 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9729 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9730 | |
| 9731 | // Set an address in host resolver for asynchronous return. |
| 9732 | host_resolver_->set_ondemand_mode(true); |
| 9733 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9734 | kCachedIPAddress.ToString(), ""); |
| 9735 | |
| 9736 | // Set up the same address in the stale resolver cache. |
| 9737 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9738 | HostCache::Entry entry(OK, |
| 9739 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9740 | HostCache::Entry::SOURCE_DNS); |
| 9741 | base::TimeDelta zero; |
| 9742 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9743 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9744 | // Expire the cache |
| 9745 | cache->OnNetworkChange(); |
| 9746 | |
| 9747 | // Simulate synchronous connect failure. |
| 9748 | MockQuicData quic_data; |
| 9749 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9750 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9751 | |
| 9752 | MockQuicData quic_data2; |
| 9753 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9754 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9755 | |
| 9756 | QuicStreamRequest request(factory_.get()); |
| 9757 | EXPECT_EQ(ERR_IO_PENDING, |
| 9758 | request.Request( |
| 9759 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9760 | SocketTag(), |
| 9761 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9762 | failed_on_default_network_callback_, callback_.callback())); |
| 9763 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9764 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9765 | |
| 9766 | host_resolver_->ResolveAllPending(); |
| 9767 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9768 | } |
| 9769 | |
| 9770 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9771 | // returns error, dns no match, new connection is established |
| 9772 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9773 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9774 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9775 | Initialize(); |
| 9776 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9777 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9778 | |
| 9779 | // Set an address in host resolver. |
| 9780 | host_resolver_->set_ondemand_mode(true); |
| 9781 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9782 | kNonCachedIPAddress, ""); |
| 9783 | |
| 9784 | // Set up a different address in stale resolver cache. |
| 9785 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9786 | HostCache::Entry entry(OK, |
| 9787 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9788 | HostCache::Entry::SOURCE_DNS); |
| 9789 | base::TimeDelta zero; |
| 9790 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9791 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9792 | // Expire the cache |
| 9793 | cache->OnNetworkChange(); |
| 9794 | |
| 9795 | // Add failure for the stale connection. |
| 9796 | MockQuicData quic_data; |
| 9797 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9798 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9799 | |
| 9800 | MockQuicData quic_data2; |
| 9801 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9802 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9803 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9804 | |
| 9805 | QuicStreamRequest request(factory_.get()); |
| 9806 | EXPECT_EQ(ERR_IO_PENDING, |
| 9807 | request.Request( |
| 9808 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9809 | SocketTag(), |
| 9810 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9811 | failed_on_default_network_callback_, callback_.callback())); |
| 9812 | |
| 9813 | // Check that the stale connection fails. |
| 9814 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9815 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9816 | |
| 9817 | // Finish host resolution and check the job finishes ok. |
| 9818 | host_resolver_->ResolveAllPending(); |
| 9819 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9820 | |
| 9821 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9822 | EXPECT_TRUE(stream.get()); |
| 9823 | |
| 9824 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9825 | |
| 9826 | EXPECT_EQ( |
| 9827 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9828 | kNonCachedIPAddress); |
| 9829 | |
| 9830 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9831 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9832 | } |
| 9833 | |
| 9834 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9835 | // returns error, dns no match, new connection error |
| 9836 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9837 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9838 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9839 | Initialize(); |
| 9840 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9841 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9842 | |
| 9843 | // Set an address in host resolver asynchronously. |
| 9844 | host_resolver_->set_ondemand_mode(true); |
| 9845 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9846 | kNonCachedIPAddress, ""); |
| 9847 | |
| 9848 | // Set up a different address in the stale cache. |
| 9849 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9850 | HostCache::Entry entry(OK, |
| 9851 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9852 | HostCache::Entry::SOURCE_DNS); |
| 9853 | base::TimeDelta zero; |
| 9854 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9855 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9856 | // Expire the cache |
| 9857 | cache->OnNetworkChange(); |
| 9858 | |
| 9859 | // Add failure for stale connection. |
| 9860 | MockQuicData quic_data; |
| 9861 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9862 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9863 | |
| 9864 | // Add failure for resolved dns connection. |
| 9865 | MockQuicData quic_data2; |
| 9866 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9867 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9868 | |
| 9869 | QuicStreamRequest request(factory_.get()); |
| 9870 | EXPECT_EQ(ERR_IO_PENDING, |
| 9871 | request.Request( |
| 9872 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9873 | SocketTag(), |
| 9874 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9875 | failed_on_default_network_callback_, callback_.callback())); |
| 9876 | |
| 9877 | // Check the stale connection fails. |
| 9878 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9879 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9880 | |
| 9881 | // Check the resolved dns connection fails. |
| 9882 | host_resolver_->ResolveAllPending(); |
| 9883 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9884 | } |
| 9885 | |
| 9886 | // With dns race experiment on, dns resolve async and stale connect async, dns |
| 9887 | // resolve returns error and then preconnect finishes |
| 9888 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9889 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9890 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9891 | Initialize(); |
| 9892 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9893 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9894 | |
| 9895 | // Add asynchronous failure in host resolver. |
| 9896 | host_resolver_->set_ondemand_mode(true); |
| 9897 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9898 | factory_->set_require_confirmation(true); |
| 9899 | crypto_client_stream_factory_.set_handshake_mode( |
| 9900 | MockCryptoClientStream::ZERO_RTT); |
| 9901 | |
| 9902 | // Set up an address in stale resolver cache. |
| 9903 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9904 | HostCache::Entry entry(OK, |
| 9905 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9906 | HostCache::Entry::SOURCE_DNS); |
| 9907 | base::TimeDelta zero; |
| 9908 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9909 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9910 | // Expire the cache |
| 9911 | cache->OnNetworkChange(); |
| 9912 | |
| 9913 | // Socket data for stale connection which is supposed to disconnect. |
| 9914 | MockQuicData quic_data; |
| 9915 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9916 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9917 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9918 | SYNCHRONOUS, |
| 9919 | client_maker_.MakeConnectionClosePacket( |
| 9920 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9921 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9922 | |
| 9923 | QuicStreamRequest request(factory_.get()); |
| 9924 | EXPECT_EQ(ERR_IO_PENDING, |
| 9925 | request.Request( |
| 9926 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9927 | SocketTag(), |
| 9928 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9929 | failed_on_default_network_callback_, callback_.callback())); |
| 9930 | |
| 9931 | // host resolution returned but stale connection hasn't finished yet. |
| 9932 | host_resolver_->ResolveAllPending(); |
| 9933 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9934 | |
| 9935 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9936 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9937 | } |
| 9938 | |
| 9939 | // With dns race experiment on, dns resolve async and stale connect async, dns |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9940 | // resolve returns error and then preconnect fails. |
| 9941 | TEST_P(QuicStreamFactoryTest, |
| 9942 | ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9943 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9944 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9945 | Initialize(); |
| 9946 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9947 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9948 | |
| 9949 | // Add asynchronous failure to host resolver. |
| 9950 | host_resolver_->set_ondemand_mode(true); |
| 9951 | factory_->set_require_confirmation(true); |
| 9952 | crypto_client_stream_factory_.set_handshake_mode( |
| 9953 | MockCryptoClientStream::ZERO_RTT); |
| 9954 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9955 | |
| 9956 | // Set up an address in stale resolver cache. |
| 9957 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9958 | HostCache::Entry entry(OK, |
| 9959 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9960 | HostCache::Entry::SOURCE_DNS); |
| 9961 | base::TimeDelta zero; |
| 9962 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9963 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9964 | // Expire the cache |
| 9965 | cache->OnNetworkChange(); |
| 9966 | |
| 9967 | MockQuicData quic_data; |
| 9968 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9969 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9970 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9971 | SYNCHRONOUS, |
| 9972 | client_maker_.MakeConnectionClosePacket( |
| 9973 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9974 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9975 | |
| 9976 | QuicStreamRequest request(factory_.get()); |
| 9977 | EXPECT_EQ(ERR_IO_PENDING, |
| 9978 | request.Request( |
| 9979 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9980 | SocketTag(), |
| 9981 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9982 | failed_on_default_network_callback_, callback_.callback())); |
| 9983 | |
| 9984 | // Host Resolution returns failure but stale connection hasn't finished. |
| 9985 | host_resolver_->ResolveAllPending(); |
| 9986 | |
| 9987 | // Check that the final error is on resolution failure. |
| 9988 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9989 | |
| 9990 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9991 | } |
| 9992 | |
| 9993 | // With dns race experiment on, test that host resolution callback behaves |
| 9994 | // normal as experiment is not on |
| 9995 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame] | 9996 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9997 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9998 | Initialize(); |
| 9999 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 10000 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 10001 | |
| 10002 | host_resolver_->set_ondemand_mode(true); |
| 10003 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 10004 | kNonCachedIPAddress, ""); |
| 10005 | |
| 10006 | MockQuicData quic_data; |
| 10007 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 10008 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 10009 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 10010 | |
| 10011 | QuicStreamRequest request(factory_.get()); |
| 10012 | EXPECT_EQ(ERR_IO_PENDING, |
| 10013 | request.Request( |
| 10014 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 10015 | SocketTag(), |
| 10016 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10017 | failed_on_default_network_callback_, callback_.callback())); |
| 10018 | |
| 10019 | // Check that expect_on_host_resolution_ is properlly set. |
| 10020 | TestCompletionCallback host_resolution_callback; |
| 10021 | EXPECT_TRUE( |
| 10022 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 10023 | base::RunLoop().RunUntilIdle(); |
| 10024 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 10025 | |
| 10026 | host_resolver_->ResolveAllPending(); |
| 10027 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 10028 | |
| 10029 | // Check that expect_on_host_resolution_ is flipped back. |
| 10030 | EXPECT_FALSE( |
| 10031 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 10032 | |
| 10033 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 10034 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 10035 | } |
| 10036 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10037 | // Test that QuicStreamRequests with similar and different tags results in |
| 10038 | // reused and unique QUIC streams using appropriately tagged sockets. |
| 10039 | TEST_P(QuicStreamFactoryTest, Tag) { |
| 10040 | MockTaggingClientSocketFactory* socket_factory = |
| 10041 | new MockTaggingClientSocketFactory(); |
| 10042 | socket_factory_.reset(socket_factory); |
| 10043 | Initialize(); |
| 10044 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 10045 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 10046 | |
| 10047 | // Prepare to establish two QUIC sessions. |
| 10048 | MockQuicData socket_data; |
| 10049 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 10050 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10051 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 10052 | MockQuicData socket_data2; |
| 10053 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 10054 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10055 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 10056 | |
| 10057 | #if defined(OS_ANDROID) |
| 10058 | SocketTag tag1(SocketTag::UNSET_UID, 0x12345678); |
| 10059 | SocketTag tag2(getuid(), 0x87654321); |
| 10060 | #else |
| 10061 | // On non-Android platforms we can only use the default constructor. |
| 10062 | SocketTag tag1, tag2; |
| 10063 | #endif |
| 10064 | |
| 10065 | // Request a stream with |tag1|. |
| 10066 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 10067 | int rv = request1.Request( |
| 10068 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 10069 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10070 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10071 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 10072 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag1); |
| 10073 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 10074 | ->tagged_before_data_transferred()); |
| 10075 | std::unique_ptr<QuicChromiumClientSession::Handle> stream1 = |
| 10076 | request1.ReleaseSessionHandle(); |
| 10077 | EXPECT_TRUE(stream1); |
| 10078 | EXPECT_TRUE(stream1->IsConnected()); |
| 10079 | |
| 10080 | // Request a stream with |tag1| and verify underlying session is reused. |
| 10081 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 10082 | rv = request2.Request( |
| 10083 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 10084 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10085 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10086 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 10087 | std::unique_ptr<QuicChromiumClientSession::Handle> stream2 = |
| 10088 | request2.ReleaseSessionHandle(); |
| 10089 | EXPECT_TRUE(stream2); |
| 10090 | EXPECT_TRUE(stream2->IsConnected()); |
| 10091 | EXPECT_TRUE(stream2->SharesSameSession(*stream1)); |
| 10092 | |
| 10093 | // Request a stream with |tag2| and verify a new session is created. |
| 10094 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 10095 | rv = request3.Request( |
| 10096 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag2, |
| 10097 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 10098 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 10099 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 10100 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag2); |
| 10101 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 10102 | ->tagged_before_data_transferred()); |
| 10103 | std::unique_ptr<QuicChromiumClientSession::Handle> stream3 = |
| 10104 | request3.ReleaseSessionHandle(); |
| 10105 | EXPECT_TRUE(stream3); |
| 10106 | EXPECT_TRUE(stream3->IsConnected()); |
| 10107 | #if defined(OS_ANDROID) |
| 10108 | EXPECT_FALSE(stream3->SharesSameSession(*stream1)); |
| 10109 | #else |
| 10110 | // Same tag should reuse session. |
| 10111 | EXPECT_TRUE(stream3->SharesSameSession(*stream1)); |
| 10112 | #endif |
| 10113 | } |
| 10114 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 10115 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 10116 | } // namespace net |