[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 5 | #include "net/quic/quic_stream_factory.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 6 | |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 7 | #include <memory> |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8 | #include <ostream> |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 9 | #include <utility> |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 10 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/callback.h" |
xunjieli | 48e4f10 | 2017-04-11 23:06:53 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 14 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 16 | #include "base/test/test_mock_time_task_runner.h" |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 17 | #include "build/build_config.h" |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 18 | #include "net/base/mock_network_change_notifier.h" |
rsleevi | d6de830 | 2016-06-21 01:33:20 | [diff] [blame] | 19 | #include "net/cert/ct_policy_enforcer.h" |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 20 | #include "net/cert/do_nothing_ct_verifier.h" |
| 21 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 22 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 23 | #include "net/http/http_response_headers.h" |
| 24 | #include "net/http/http_response_info.h" |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 25 | #include "net/http/http_server_properties_impl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 26 | #include "net/http/http_util.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 27 | #include "net/http/transport_security_state.h" |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 28 | #include "net/http/transport_security_state_test_util.h" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 29 | #include "net/quic/crypto/proof_verifier_chromium.h" |
| 30 | #include "net/quic/mock_crypto_client_stream_factory.h" |
| 31 | #include "net/quic/mock_quic_data.h" |
| 32 | #include "net/quic/properties_based_quic_server_info.h" |
| 33 | #include "net/quic/quic_http_stream.h" |
| 34 | #include "net/quic/quic_http_utils.h" |
| 35 | #include "net/quic/quic_server_info.h" |
| 36 | #include "net/quic/quic_stream_factory_peer.h" |
| 37 | #include "net/quic/quic_test_packet_maker.h" |
| 38 | #include "net/quic/test_task_runner.h" |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 39 | #include "net/socket/next_proto.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 40 | #include "net/socket/socket_test_util.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 41 | #include "net/spdy/spdy_session_test_util.h" |
| 42 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 43 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 44 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 45 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 46 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 47 | #include "net/third_party/quic/core/crypto/crypto_handshake.h" |
| 48 | #include "net/third_party/quic/core/crypto/quic_crypto_client_config.h" |
| 49 | #include "net/third_party/quic/core/crypto/quic_decrypter.h" |
| 50 | #include "net/third_party/quic/core/crypto/quic_encrypter.h" |
Victor Vasiliev | c5b409c2 | 2018-07-24 12:23:46 | [diff] [blame] | 51 | #include "net/third_party/quic/core/http/quic_client_promised_info.h" |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 52 | #include "net/third_party/quic/core/quic_utils.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 53 | #include "net/third_party/quic/platform/api/quic_test.h" |
| 54 | #include "net/third_party/quic/test_tools/mock_clock.h" |
| 55 | #include "net/third_party/quic/test_tools/mock_random.h" |
| 56 | #include "net/third_party/quic/test_tools/quic_config_peer.h" |
| 57 | #include "net/third_party/quic/test_tools/quic_spdy_session_peer.h" |
| 58 | #include "net/third_party/quic/test_tools/quic_test_utils.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 59 | #include "net/third_party/quiche/src/spdy/core/spdy_test_utils.h" |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 60 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 61 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 62 | #include "testing/gtest/include/gtest/gtest.h" |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 63 | #include "url/gurl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 64 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 65 | using std::string; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 66 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 67 | namespace net { |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 68 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 69 | namespace { |
| 70 | |
| 71 | class MockSSLConfigService : public SSLConfigService { |
| 72 | public: |
| 73 | MockSSLConfigService() {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 74 | ~MockSSLConfigService() override {} |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 75 | |
| 76 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 77 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 78 | bool CanShareConnectionWithClientCerts( |
| 79 | const std::string& hostname) const override { |
| 80 | return false; |
| 81 | } |
| 82 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 83 | private: |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 84 | SSLConfig config_; |
| 85 | }; |
| 86 | |
| 87 | } // namespace |
| 88 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 89 | namespace test { |
| 90 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 91 | namespace { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 92 | |
| 93 | enum DestinationType { |
| 94 | // In pooling tests with two requests for different origins to the same |
| 95 | // destination, the destination should be |
| 96 | SAME_AS_FIRST, // the same as the first origin, |
| 97 | SAME_AS_SECOND, // the same as the second origin, or |
| 98 | DIFFERENT, // different from both. |
| 99 | }; |
| 100 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 101 | const char kDefaultServerHostName[] = "www.example.org"; |
| 102 | const char kServer2HostName[] = "mail.example.org"; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 103 | const char kDifferentHostname[] = "different.example.com"; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 104 | const int kDefaultServerPort = 443; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 105 | const char kDefaultUrl[] = "https://www.example.org/"; |
| 106 | const char kServer2Url[] = "https://mail.example.org/"; |
| 107 | const char kServer3Url[] = "https://docs.example.org/"; |
| 108 | const char kServer4Url[] = "https://images.example.org/"; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 109 | const int kDefaultRTTMilliSecs = 300; |
| 110 | const size_t kMinRetryTimeForDefaultNetworkSecs = 1; |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 111 | const size_t kWaitTimeForNewNetworkSecs = 10; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 112 | const IPAddress kCachedIPAddress = IPAddress(192, 168, 0, 2); |
| 113 | const char kNonCachedIPAddress[] = "192.168.0.1"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 114 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 115 | // Run QuicStreamFactoryTest instances with all value combinations of version |
| 116 | // and enable_connection_racting. |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 117 | struct TestParams { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 118 | friend std::ostream& operator<<(std::ostream& os, const TestParams& p) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 119 | os << "{ version: " << QuicVersionToString(p.version) |
| 120 | << ", client_headers_include_h2_stream_dependency: " |
| 121 | << p.client_headers_include_h2_stream_dependency << " }"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 122 | return os; |
| 123 | } |
| 124 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 125 | quic::QuicTransportVersion version; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 126 | bool client_headers_include_h2_stream_dependency; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 127 | }; |
| 128 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 129 | std::vector<TestParams> GetTestParams() { |
| 130 | std::vector<TestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 131 | quic::QuicTransportVersionVector all_supported_versions = |
| 132 | quic::AllSupportedTransportVersions(); |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 133 | for (const auto& version : all_supported_versions) { |
| 134 | params.push_back(TestParams{version, false}); |
| 135 | params.push_back(TestParams{version, true}); |
| 136 | } |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 137 | return params; |
| 138 | } |
| 139 | |
| 140 | // Run QuicStreamFactoryWithDestinationTest instances with all value |
| 141 | // combinations of version, enable_connection_racting, and destination_type. |
| 142 | struct PoolingTestParams { |
| 143 | friend std::ostream& operator<<(std::ostream& os, |
| 144 | const PoolingTestParams& p) { |
| 145 | os << "{ version: " << QuicVersionToString(p.version) |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 146 | << ", destination_type: "; |
| 147 | switch (p.destination_type) { |
| 148 | case SAME_AS_FIRST: |
| 149 | os << "SAME_AS_FIRST"; |
| 150 | break; |
| 151 | case SAME_AS_SECOND: |
| 152 | os << "SAME_AS_SECOND"; |
| 153 | break; |
| 154 | case DIFFERENT: |
| 155 | os << "DIFFERENT"; |
| 156 | break; |
| 157 | } |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 158 | os << ", client_headers_include_h2_stream_dependency: " |
| 159 | << p.client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 160 | os << " }"; |
| 161 | return os; |
| 162 | } |
| 163 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 164 | quic::QuicTransportVersion version; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 165 | DestinationType destination_type; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 166 | bool client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 167 | }; |
| 168 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 169 | std::vector<PoolingTestParams> GetPoolingTestParams() { |
| 170 | std::vector<PoolingTestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 171 | quic::QuicTransportVersionVector all_supported_versions = |
| 172 | quic::AllSupportedTransportVersions(); |
| 173 | for (const quic::QuicTransportVersion version : all_supported_versions) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 174 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, false}); |
| 175 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, true}); |
| 176 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, false}); |
| 177 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, true}); |
| 178 | params.push_back(PoolingTestParams{version, DIFFERENT, false}); |
| 179 | params.push_back(PoolingTestParams{version, DIFFERENT, true}); |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 180 | } |
| 181 | return params; |
| 182 | } |
| 183 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 184 | } // namespace |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 185 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 186 | class QuicHttpStreamPeer { |
| 187 | public: |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 188 | static QuicChromiumClientSession::Handle* GetSessionHandle( |
| 189 | HttpStream* stream) { |
| 190 | return static_cast<QuicHttpStream*>(stream)->quic_session(); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 191 | } |
| 192 | }; |
| 193 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 194 | // TestConnectionMigrationSocketFactory will vend sockets with incremental port |
| 195 | // number. |
| 196 | class TestConnectionMigrationSocketFactory : public MockClientSocketFactory { |
| 197 | public: |
| 198 | TestConnectionMigrationSocketFactory() : next_source_port_num_(1u) {} |
| 199 | ~TestConnectionMigrationSocketFactory() override {} |
| 200 | |
| 201 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 202 | DatagramSocket::BindType bind_type, |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 203 | NetLog* net_log, |
| 204 | const NetLogSource& source) override { |
| 205 | SocketDataProvider* data_provider = mock_data().GetNext(); |
| 206 | std::unique_ptr<MockUDPClientSocket> socket( |
| 207 | new MockUDPClientSocket(data_provider, net_log)); |
| 208 | socket->set_source_port(next_source_port_num_++); |
| 209 | return std::move(socket); |
| 210 | } |
| 211 | |
| 212 | private: |
| 213 | uint16_t next_source_port_num_; |
| 214 | |
| 215 | DISALLOW_COPY_AND_ASSIGN(TestConnectionMigrationSocketFactory); |
| 216 | }; |
| 217 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 218 | class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 219 | protected: |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 220 | QuicStreamFactoryTestBase(quic::QuicTransportVersion version, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 221 | bool client_headers_include_h2_stream_dependency) |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 222 | : host_resolver_(new MockHostResolver), |
| 223 | ssl_config_service_(new MockSSLConfigService), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 224 | socket_factory_(new MockClientSocketFactory), |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 225 | random_generator_(0), |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 226 | runner_(new TestTaskRunner(&clock_)), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 227 | version_(version), |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 228 | client_headers_include_h2_stream_dependency_( |
| 229 | client_headers_include_h2_stream_dependency), |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 230 | client_maker_( |
| 231 | version_, |
| 232 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 233 | &clock_, |
| 234 | kDefaultServerHostName, |
| 235 | quic::Perspective::IS_CLIENT, |
| 236 | client_headers_include_h2_stream_dependency_), |
| 237 | server_maker_( |
| 238 | version_, |
| 239 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 240 | &clock_, |
| 241 | kDefaultServerHostName, |
| 242 | quic::Perspective::IS_SERVER, |
| 243 | false), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 244 | cert_verifier_(std::make_unique<MockCertVerifier>()), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 245 | cert_transparency_verifier_(std::make_unique<DoNothingCTVerifier>()), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 246 | scoped_mock_network_change_notifier_(nullptr), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 247 | factory_(nullptr), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 248 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 249 | url_(kDefaultUrl), |
| 250 | url2_(kServer2Url), |
| 251 | url3_(kServer3Url), |
| 252 | url4_(kServer4Url), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 253 | privacy_mode_(PRIVACY_MODE_DISABLED), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 254 | failed_on_default_network_callback_(base::BindRepeating( |
| 255 | &QuicStreamFactoryTestBase::OnFailedOnDefaultNetwork, |
| 256 | base::Unretained(this))), |
| 257 | failed_on_default_network_(false), |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 258 | store_server_configs_in_properties_(false), |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 259 | close_sessions_on_ip_change_(false), |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 260 | goaway_sessions_on_ip_change_(false), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 261 | idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 262 | reduced_ping_timeout_seconds_(quic::kPingTimeoutSecs), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 263 | max_time_before_crypto_handshake_seconds_( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 264 | quic::kMaxTimeForCryptoHandshakeSecs), |
| 265 | max_idle_time_before_crypto_handshake_seconds_( |
| 266 | quic::kInitialIdleTimeoutSecs), |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 267 | migrate_sessions_on_network_change_v2_(false), |
| 268 | migrate_sessions_early_v2_(false), |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 269 | retry_on_alternate_network_before_handshake_(false), |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 270 | race_stale_dns_on_connection_(false), |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 271 | go_away_on_path_degrading_(false), |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 272 | allow_server_migration_(false), |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 273 | race_cert_verification_(false), |
| 274 | estimate_initial_rtt_(false) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 275 | clock_.AdvanceTime(quic::QuicTime::Delta::FromSeconds(1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 276 | } |
| 277 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 278 | void Initialize() { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 279 | DCHECK(!factory_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 280 | factory_.reset(new QuicStreamFactory( |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 281 | net_log_.net_log(), host_resolver_.get(), ssl_config_service_.get(), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 282 | socket_factory_.get(), &http_server_properties_, cert_verifier_.get(), |
Nick Harper | ecf319d | 2018-10-16 07:58:54 | [diff] [blame] | 283 | &ct_policy_enforcer_, &transport_security_state_, |
| 284 | cert_transparency_verifier_.get(), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 285 | /*SocketPerformanceWatcherFactory*/ nullptr, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 286 | &crypto_client_stream_factory_, &random_generator_, &clock_, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 287 | quic::kDefaultMaxPacketSize, string(), |
| 288 | store_server_configs_in_properties_, close_sessions_on_ip_change_, |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 289 | goaway_sessions_on_ip_change_, |
rch | 9ecde09b | 2017-04-08 00:18:23 | [diff] [blame] | 290 | /*mark_quic_broken_when_network_blackholes*/ false, |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 291 | idle_connection_timeout_seconds_, reduced_ping_timeout_seconds_, |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 292 | max_time_before_crypto_handshake_seconds_, |
| 293 | max_idle_time_before_crypto_handshake_seconds_, |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 294 | migrate_sessions_on_network_change_v2_, migrate_sessions_early_v2_, |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 295 | retry_on_alternate_network_before_handshake_, |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 296 | base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 297 | kMaxMigrationsToNonDefaultNetworkOnWriteError, |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 298 | kMaxMigrationsToNonDefaultNetworkOnPathDegrading, |
Zhongyi Shi | dbce7f41 | 2019-02-01 23:16:29 | [diff] [blame] | 299 | allow_server_migration_, race_stale_dns_on_connection_, |
| 300 | go_away_on_path_degrading_, race_cert_verification_, |
| 301 | estimate_initial_rtt_, client_headers_include_h2_stream_dependency_, |
| 302 | connection_options_, client_connection_options_, |
kapishnikov | 7f8dd1e | 2018-01-24 06:10:49 | [diff] [blame] | 303 | /*enable_socket_recv_optimization*/ false)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 304 | } |
| 305 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 306 | void InitializeConnectionMigrationV2Test( |
| 307 | NetworkChangeNotifier::NetworkList connected_networks) { |
| 308 | scoped_mock_network_change_notifier_.reset( |
| 309 | new ScopedMockNetworkChangeNotifier()); |
| 310 | MockNetworkChangeNotifier* mock_ncn = |
| 311 | scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 312 | mock_ncn->ForceNetworkHandlesSupported(); |
| 313 | mock_ncn->SetConnectedNetworksList(connected_networks); |
| 314 | migrate_sessions_on_network_change_v2_ = true; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 315 | migrate_sessions_early_v2_ = true; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 316 | socket_factory_.reset(new TestConnectionMigrationSocketFactory); |
| 317 | Initialize(); |
| 318 | } |
| 319 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 320 | std::unique_ptr<HttpStream> CreateStream(QuicStreamRequest* request) { |
| 321 | std::unique_ptr<QuicChromiumClientSession::Handle> session = |
| 322 | request->ReleaseSessionHandle(); |
| 323 | if (!session || !session->IsConnected()) |
| 324 | return nullptr; |
| 325 | |
| 326 | return std::make_unique<QuicHttpStream>(std::move(session)); |
| 327 | } |
| 328 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 329 | bool HasActiveSession(const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 330 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 331 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 332 | return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 333 | } |
| 334 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 335 | bool HasLiveSession(const HostPortPair& host_port_pair) { |
| 336 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 337 | false); |
| 338 | return QuicStreamFactoryPeer::HasLiveSession(factory_.get(), host_port_pair, |
| 339 | server_id); |
| 340 | } |
| 341 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 342 | bool HasActiveJob(const HostPortPair& host_port_pair, |
| 343 | const PrivacyMode privacy_mode) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 344 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 345 | privacy_mode == PRIVACY_MODE_ENABLED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 346 | return QuicStreamFactoryPeer::HasActiveJob(factory_.get(), server_id); |
| 347 | } |
| 348 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 349 | bool HasActiveCertVerifierJob(const quic::QuicServerId& server_id) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 350 | return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 351 | server_id); |
| 352 | } |
| 353 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 354 | // Get the pending, not activated session, if there is only one session alive. |
| 355 | QuicChromiumClientSession* GetPendingSession( |
| 356 | const HostPortPair& host_port_pair) { |
| 357 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 358 | false); |
| 359 | return QuicStreamFactoryPeer::GetPendingSession(factory_.get(), server_id, |
| 360 | host_port_pair); |
| 361 | } |
| 362 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 363 | QuicChromiumClientSession* GetActiveSession( |
| 364 | const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 365 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 366 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 367 | return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 368 | } |
| 369 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 370 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 371 | return GetSourcePortForNewSessionInner(destination, false); |
| 372 | } |
| 373 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 374 | int GetSourcePortForNewSessionAndGoAway(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 375 | return GetSourcePortForNewSessionInner(destination, true); |
| 376 | } |
| 377 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 378 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 379 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 380 | // Should only be called if there is no active session for this destination. |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 381 | EXPECT_FALSE(HasActiveSession(destination)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 382 | size_t socket_count = socket_factory_->udp_client_socket_ports().size(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 383 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 384 | MockQuicData socket_data; |
| 385 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 386 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 387 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 388 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 389 | QuicStreamRequest request(factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 390 | GURL url("https://" + destination.host() + "/"); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 391 | EXPECT_EQ( |
| 392 | ERR_IO_PENDING, |
| 393 | request.Request( |
| 394 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 395 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 396 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 397 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 398 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 399 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 400 | EXPECT_TRUE(stream.get()); |
| 401 | stream.reset(); |
| 402 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 403 | QuicChromiumClientSession* session = GetActiveSession(destination); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 404 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 405 | if (socket_count + 1 != socket_factory_->udp_client_socket_ports().size()) { |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 406 | ADD_FAILURE(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 410 | if (goaway_received) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 411 | quic::QuicGoAwayFrame goaway(quic::kInvalidControlFrameId, |
| 412 | quic::QUIC_NO_ERROR, 1, ""); |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 413 | session->connection()->OnGoAwayFrame(goaway); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 414 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 415 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 416 | factory_->OnSessionClosed(session); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 417 | EXPECT_FALSE(HasActiveSession(destination)); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 418 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 419 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 420 | return socket_factory_->udp_client_socket_ports()[socket_count]; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 421 | } |
| 422 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 423 | std::unique_ptr<quic::QuicEncryptedPacket> |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 424 | ConstructClientConnectionClosePacket(uint64_t num) { |
Bin Wu | 5311aca | 2018-01-22 01:19:03 | [diff] [blame] | 425 | return client_maker_.MakeConnectionClosePacket( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 426 | num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 427 | } |
| 428 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 429 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 430 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 431 | quic::QuicRstStreamErrorCode error_code) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 432 | quic::QuicStreamId stream_id = |
| 433 | GetNthClientInitiatedBidirectionalStreamId(0); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 434 | return client_maker_.MakeRstPacket(packet_number, true, stream_id, |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 435 | error_code); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 436 | } |
| 437 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 438 | static ProofVerifyDetailsChromium DefaultProofVerifyDetails() { |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 439 | // Load a certificate that is valid for *.example.org |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 440 | scoped_refptr<X509Certificate> test_cert( |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 441 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 442 | EXPECT_TRUE(test_cert.get()); |
| 443 | ProofVerifyDetailsChromium verify_details; |
| 444 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 445 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 446 | return verify_details; |
| 447 | } |
| 448 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 449 | void NotifyIPAddressChanged() { |
| 450 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 451 | // Spin the message loop so the notification is delivered. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 452 | base::RunLoop().RunUntilIdle(); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 453 | } |
| 454 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 455 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 456 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 457 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 458 | bool should_include_version, |
| 459 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 460 | spdy::SpdyHeaderBlock headers = |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 461 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 462 | spdy::SpdyPriority priority = |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 463 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 464 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 465 | return client_maker_.MakeRequestHeadersPacket( |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 466 | packet_number, stream_id, should_include_version, fin, priority, |
Yixin Wang | 7a3f1b8d | 2018-01-17 21:40:48 | [diff] [blame] | 467 | std::move(headers), 0, &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 468 | } |
| 469 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 470 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 471 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 472 | quic::QuicStreamId stream_id, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 473 | quic::QuicStreamId parent_stream_id, |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 474 | bool should_include_version, |
| 475 | bool fin, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 476 | quic::QuicStreamOffset* offset) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 477 | spdy::SpdyHeaderBlock headers = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 478 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 479 | spdy::SpdyPriority priority = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 480 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 481 | size_t spdy_headers_frame_len; |
| 482 | return client_maker_.MakeRequestHeadersPacket( |
| 483 | packet_number, stream_id, should_include_version, fin, priority, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 484 | std::move(headers), parent_stream_id, &spdy_headers_frame_len, offset); |
| 485 | } |
| 486 | |
| 487 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 488 | uint64_t packet_number, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 489 | quic::QuicStreamId stream_id, |
| 490 | bool should_include_version, |
| 491 | bool fin, |
| 492 | quic::QuicStreamOffset* offset) { |
| 493 | return ConstructGetRequestPacket(packet_number, stream_id, |
| 494 | /*parent_stream_id=*/0, |
| 495 | should_include_version, fin, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 496 | } |
| 497 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 498 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 499 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 500 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 501 | bool should_include_version, |
| 502 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 503 | spdy::SpdyHeaderBlock headers = server_maker_.GetResponseHeaders("200 OK"); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 504 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 505 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 506 | packet_number, stream_id, should_include_version, fin, |
| 507 | std::move(headers), &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 508 | } |
| 509 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 510 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket() { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 511 | return client_maker_.MakeInitialSettingsPacket(1, nullptr); |
| 512 | } |
| 513 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 514 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 515 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 516 | quic::QuicStreamOffset* offset) { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 517 | return client_maker_.MakeInitialSettingsPacket(packet_number, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 518 | } |
| 519 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 520 | // Helper method for server migration tests. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 521 | void VerifyServerMigration(const quic::QuicConfig& config, |
bnc | 6a0348c | 2017-05-22 18:56:19 | [diff] [blame] | 522 | IPEndPoint expected_address) { |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 523 | allow_server_migration_ = true; |
| 524 | Initialize(); |
| 525 | |
| 526 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 527 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 528 | crypto_client_stream_factory_.SetConfig(config); |
| 529 | |
| 530 | // Set up first socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 531 | MockQuicData socket_data1; |
| 532 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 533 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 534 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 535 | // Set up second socket data provider that is used after |
| 536 | // migration. |
| 537 | MockQuicData socket_data2; |
| 538 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 539 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 540 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 541 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 542 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 543 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 544 | 3, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 545 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 546 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 547 | |
| 548 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 549 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 550 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 551 | request.Request( |
| 552 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 553 | SocketTag(), |
| 554 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 555 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 556 | EXPECT_EQ(OK, callback_.WaitForResult()); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 557 | |
| 558 | // Run QuicChromiumClientSession::WriteToNewSocket() |
| 559 | // posted by QuicChromiumClientSession::MigrateToSocket(). |
| 560 | base::RunLoop().RunUntilIdle(); |
| 561 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 562 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 563 | EXPECT_TRUE(stream.get()); |
| 564 | |
| 565 | // Cause QUIC stream to be created. |
| 566 | HttpRequestInfo request_info; |
| 567 | request_info.method = "GET"; |
| 568 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 569 | request_info.traffic_annotation = |
| 570 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 571 | EXPECT_EQ(OK, |
| 572 | stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 573 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 574 | // Ensure that session is alive and active. |
| 575 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 576 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 577 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 578 | |
| 579 | IPEndPoint actual_address; |
| 580 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 581 | EXPECT_EQ(actual_address, expected_address); |
| 582 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 583 | << " " << actual_address.port(); |
| 584 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 585 | << " " << expected_address.port(); |
| 586 | |
| 587 | stream.reset(); |
| 588 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 589 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 590 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 591 | } |
| 592 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 593 | // Verifies that the QUIC stream factory is initialized correctly. |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 594 | void VerifyInitialization() { |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 595 | store_server_configs_in_properties_ = true; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 596 | idle_connection_timeout_seconds_ = 500; |
| 597 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 598 | factory_->set_require_confirmation(false); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 599 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 600 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 601 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 602 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 603 | MockCryptoClientStream::ZERO_RTT); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 604 | const quic::QuicConfig* config = |
| 605 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
ckrasic | 32b17dcd | 2016-10-31 06:15:35 | [diff] [blame] | 606 | EXPECT_EQ(500, config->IdleNetworkTimeout().ToSeconds()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 607 | |
| 608 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 609 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 610 | const AlternativeService alternative_service1( |
| 611 | kProtoQUIC, host_port_pair_.host(), host_port_pair_.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 612 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 613 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 614 | alternative_service_info_vector.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 615 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 616 | alternative_service1, expiration, {version_})); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 617 | http_server_properties_.SetAlternativeServices( |
| 618 | url::SchemeHostPort(url_), alternative_service_info_vector); |
| 619 | |
| 620 | HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 621 | url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 622 | const AlternativeService alternative_service2( |
| 623 | kProtoQUIC, host_port_pair2.host(), host_port_pair2.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 624 | AlternativeServiceInfoVector alternative_service_info_vector2; |
| 625 | alternative_service_info_vector2.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 626 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 627 | alternative_service2, expiration, {version_})); |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 628 | |
| 629 | http_server_properties_.SetAlternativeServices( |
| 630 | server2, alternative_service_info_vector2); |
| 631 | // Verify that the properties of both QUIC servers are stored in the |
| 632 | // HTTP properties map. |
| 633 | EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 634 | |
| 635 | http_server_properties_.SetMaxServerConfigsStoredInProperties( |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 636 | kDefaultMaxQuicServerEntries); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 637 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 638 | quic::QuicServerId quic_server_id(kDefaultServerHostName, 443, |
| 639 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 640 | std::unique_ptr<QuicServerInfo> quic_server_info = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 641 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 642 | quic_server_id, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 643 | |
| 644 | // Update quic_server_info's server_config and persist it. |
| 645 | QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 646 | // Minimum SCFG that passes config validation checks. |
| 647 | const char scfg[] = {// SCFG |
| 648 | 0x53, 0x43, 0x46, 0x47, |
| 649 | // num entries |
| 650 | 0x01, 0x00, |
| 651 | // padding |
| 652 | 0x00, 0x00, |
| 653 | // EXPY |
| 654 | 0x45, 0x58, 0x50, 0x59, |
| 655 | // EXPY end offset |
| 656 | 0x08, 0x00, 0x00, 0x00, |
| 657 | // Value |
| 658 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 659 | |
| 660 | // Create temporary strings becasue Persist() clears string data in |state|. |
| 661 | string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 662 | string source_address_token("test_source_address_token"); |
| 663 | string cert_sct("test_cert_sct"); |
| 664 | string chlo_hash("test_chlo_hash"); |
| 665 | string signature("test_signature"); |
| 666 | string test_cert("test_cert"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 667 | std::vector<string> certs; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 668 | certs.push_back(test_cert); |
| 669 | state->server_config = server_config; |
| 670 | state->source_address_token = source_address_token; |
| 671 | state->cert_sct = cert_sct; |
| 672 | state->chlo_hash = chlo_hash; |
| 673 | state->server_config_sig = signature; |
| 674 | state->certs = certs; |
| 675 | |
| 676 | quic_server_info->Persist(); |
| 677 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 678 | quic::QuicServerId quic_server_id2(kServer2HostName, 443, |
| 679 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 680 | std::unique_ptr<QuicServerInfo> quic_server_info2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 681 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 682 | quic_server_id2, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 683 | // Update quic_server_info2's server_config and persist it. |
| 684 | QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 685 | |
| 686 | // Minimum SCFG that passes config validation checks. |
| 687 | const char scfg2[] = {// SCFG |
| 688 | 0x53, 0x43, 0x46, 0x47, |
| 689 | // num entries |
| 690 | 0x01, 0x00, |
| 691 | // padding |
| 692 | 0x00, 0x00, |
| 693 | // EXPY |
| 694 | 0x45, 0x58, 0x50, 0x59, |
| 695 | // EXPY end offset |
| 696 | 0x08, 0x00, 0x00, 0x00, |
| 697 | // Value |
| 698 | '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 699 | |
| 700 | // Create temporary strings becasue Persist() clears string data in |
| 701 | // |state2|. |
| 702 | string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 703 | string source_address_token2("test_source_address_token2"); |
| 704 | string cert_sct2("test_cert_sct2"); |
| 705 | string chlo_hash2("test_chlo_hash2"); |
| 706 | string signature2("test_signature2"); |
| 707 | string test_cert2("test_cert2"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 708 | std::vector<string> certs2; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 709 | certs2.push_back(test_cert2); |
| 710 | state2->server_config = server_config2; |
| 711 | state2->source_address_token = source_address_token2; |
| 712 | state2->cert_sct = cert_sct2; |
| 713 | state2->chlo_hash = chlo_hash2; |
| 714 | state2->server_config_sig = signature2; |
| 715 | state2->certs = certs2; |
| 716 | |
| 717 | quic_server_info2->Persist(); |
| 718 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 719 | // Verify the MRU order is maintained. |
| 720 | const QuicServerInfoMap& quic_server_info_map = |
| 721 | http_server_properties_.quic_server_info_map(); |
| 722 | EXPECT_EQ(2u, quic_server_info_map.size()); |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 723 | auto quic_server_info_map_it = quic_server_info_map.begin(); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 724 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 725 | ++quic_server_info_map_it; |
| 726 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 727 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 728 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 729 | "192.168.0.1", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 730 | |
| 731 | // Create a session and verify that the cached state is loaded. |
| 732 | MockQuicData socket_data; |
| 733 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 734 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 735 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 736 | QuicStreamRequest request(factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 737 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 738 | request.Request( |
| 739 | HostPortPair(quic_server_id.host(), quic_server_id.port()), |
| 740 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 741 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 742 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 743 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 744 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 745 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 746 | factory_.get(), quic_server_id)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 747 | quic::QuicCryptoClientConfig* crypto_config = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 748 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 749 | quic::QuicCryptoClientConfig::CachedState* cached = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 750 | crypto_config->LookupOrCreate(quic_server_id); |
| 751 | EXPECT_FALSE(cached->server_config().empty()); |
| 752 | EXPECT_TRUE(cached->GetServerConfig()); |
| 753 | EXPECT_EQ(server_config, cached->server_config()); |
| 754 | EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 755 | EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 756 | EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 757 | EXPECT_EQ(signature, cached->signature()); |
| 758 | ASSERT_EQ(1U, cached->certs().size()); |
| 759 | EXPECT_EQ(test_cert, cached->certs()[0]); |
| 760 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 761 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 762 | |
| 763 | // Create a session and verify that the cached state is loaded. |
| 764 | MockQuicData socket_data2; |
| 765 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 766 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 767 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 768 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 769 | "192.168.0.2", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 770 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 771 | QuicStreamRequest request2(factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 772 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 773 | request2.Request( |
| 774 | HostPortPair(quic_server_id2.host(), quic_server_id2.port()), |
| 775 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 776 | /*cert_verify_flags=*/0, GURL("https://mail.example.org/"), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 777 | net_log_, &net_error_details_, |
| 778 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 779 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 780 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 781 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 782 | factory_.get(), quic_server_id2)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 783 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 784 | crypto_config->LookupOrCreate(quic_server_id2); |
| 785 | EXPECT_FALSE(cached2->server_config().empty()); |
| 786 | EXPECT_TRUE(cached2->GetServerConfig()); |
| 787 | EXPECT_EQ(server_config2, cached2->server_config()); |
| 788 | EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 789 | EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 790 | EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 791 | EXPECT_EQ(signature2, cached2->signature()); |
| 792 | ASSERT_EQ(1U, cached->certs().size()); |
| 793 | EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 794 | } |
| 795 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 796 | void RunTestLoopUntilIdle() { |
| 797 | while (!runner_->GetPostedTasks().empty()) |
| 798 | runner_->RunNextTask(); |
| 799 | } |
| 800 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 801 | quic::QuicStreamId GetNthClientInitiatedBidirectionalStreamId(int n) { |
| 802 | return quic::test::GetNthClientInitiatedBidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 803 | } |
| 804 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 805 | quic::QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(int n) { |
| 806 | return quic::test::GetNthServerInitiatedUnidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 807 | } |
| 808 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 809 | void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } |
| 810 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 811 | // Helper methods for tests of connection migration on write error. |
| 812 | void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 813 | // Migratable stream triggers write error. |
| 814 | void TestMigrationOnWriteErrorMixedStreams(IoMode write_error_mode); |
| 815 | // Non-migratable stream triggers write error. |
| 816 | void TestMigrationOnWriteErrorMixedStreams2(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 817 | void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 818 | void TestMigrationOnWriteError(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 819 | void TestMigrationOnWriteErrorWithMultipleRequests(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 820 | void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 821 | void TestMigrationOnMultipleWriteErrors( |
| 822 | IoMode write_error_mode_on_old_network, |
| 823 | IoMode write_error_mode_on_new_network); |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 824 | void TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 825 | bool disconnected); |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 826 | void TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 827 | void TestMigrationOnNetworkDisconnected(bool async_write_before); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 828 | void TestMigrationOnNetworkMadeDefault(IoMode write_mode); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 829 | void TestMigrationOnPathDegrading(bool async_write_before); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 830 | void TestMigrateSessionWithDrainingStream( |
| 831 | IoMode write_mode_for_queued_packet); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 832 | void TestMigrationOnWriteErrorPauseBeforeConnected(IoMode write_error_mode); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 833 | void TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 834 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 835 | bool disconnect_before_connect); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 836 | void TestNoAlternateNetworkBeforeHandshake(quic::QuicErrorCode error); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 837 | void TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 838 | quic::QuicErrorCode error); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 839 | |
Jana Iyengar | f6b13d8 | 2017-09-04 02:09:10 | [diff] [blame] | 840 | QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 841 | std::unique_ptr<MockHostResolverBase> host_resolver_; |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 842 | std::unique_ptr<SSLConfigService> ssl_config_service_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 843 | std::unique_ptr<MockClientSocketFactory> socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 844 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 845 | quic::test::MockRandom random_generator_; |
| 846 | quic::MockClock clock_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 847 | scoped_refptr<TestTaskRunner> runner_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 848 | const quic::QuicTransportVersion version_; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 849 | const bool client_headers_include_h2_stream_dependency_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 850 | QuicTestPacketMaker client_maker_; |
| 851 | QuicTestPacketMaker server_maker_; |
rtenneti | ccab42b | 2015-10-09 06:38:16 | [diff] [blame] | 852 | HttpServerPropertiesImpl http_server_properties_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 853 | std::unique_ptr<CertVerifier> cert_verifier_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 854 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 855 | std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
Ryan Sleevi | 8a9c9c1 | 2018-05-09 02:36:23 | [diff] [blame] | 856 | DefaultCTPolicyEnforcer ct_policy_enforcer_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 857 | std::unique_ptr<ScopedMockNetworkChangeNotifier> |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 858 | scoped_mock_network_change_notifier_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 859 | std::unique_ptr<QuicStreamFactory> factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 860 | HostPortPair host_port_pair_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 861 | GURL url_; |
| 862 | GURL url2_; |
| 863 | GURL url3_; |
| 864 | GURL url4_; |
| 865 | |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 866 | PrivacyMode privacy_mode_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 867 | NetLogWithSource net_log_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 868 | TestCompletionCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 869 | const CompletionRepeatingCallback failed_on_default_network_callback_; |
| 870 | bool failed_on_default_network_; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 871 | NetErrorDetails net_error_details_; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 872 | |
| 873 | // Variables to configure QuicStreamFactory. |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 874 | bool store_server_configs_in_properties_; |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 875 | bool close_sessions_on_ip_change_; |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 876 | bool goaway_sessions_on_ip_change_; |
rtenneti | 41c0999 | 2015-11-30 18:24:01 | [diff] [blame] | 877 | int idle_connection_timeout_seconds_; |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 878 | int reduced_ping_timeout_seconds_; |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 879 | int max_time_before_crypto_handshake_seconds_; |
| 880 | int max_idle_time_before_crypto_handshake_seconds_; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 881 | bool migrate_sessions_on_network_change_v2_; |
| 882 | bool migrate_sessions_early_v2_; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 883 | bool retry_on_alternate_network_before_handshake_; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 884 | bool race_stale_dns_on_connection_; |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 885 | bool go_away_on_path_degrading_; |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 886 | bool allow_server_migration_; |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 887 | bool race_cert_verification_; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 888 | bool estimate_initial_rtt_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 889 | quic::QuicTagVector connection_options_; |
| 890 | quic::QuicTagVector client_connection_options_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 891 | }; |
| 892 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 893 | class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 894 | public ::testing::TestWithParam<TestParams> { |
| 895 | protected: |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 896 | QuicStreamFactoryTest() |
| 897 | : QuicStreamFactoryTestBase( |
| 898 | GetParam().version, |
| 899 | GetParam().client_headers_include_h2_stream_dependency) {} |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 900 | }; |
| 901 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 902 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 903 | QuicStreamFactoryTest, |
| 904 | ::testing::ValuesIn(GetTestParams())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 905 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 906 | TEST_P(QuicStreamFactoryTest, Create) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 907 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 908 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 909 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 910 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 911 | MockQuicData socket_data; |
| 912 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 913 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 914 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 915 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 916 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 917 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 918 | request.Request( |
| 919 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 920 | SocketTag(), |
| 921 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 922 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 923 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 924 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 925 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 926 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 927 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 928 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 929 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 930 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 931 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 932 | DEFAULT_PRIORITY, SocketTag(), |
| 933 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 934 | &net_error_details_, |
| 935 | failed_on_default_network_callback_, |
| 936 | callback_.callback())); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 937 | // Will reset stream 3. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 938 | stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 939 | |
| 940 | EXPECT_TRUE(stream.get()); |
| 941 | |
| 942 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 943 | // in streams on different sessions. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 944 | QuicStreamRequest request3(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 945 | EXPECT_EQ(OK, request3.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 946 | DEFAULT_PRIORITY, SocketTag(), |
| 947 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 948 | &net_error_details_, |
| 949 | failed_on_default_network_callback_, |
| 950 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 951 | stream = CreateStream(&request3); // Will reset stream 5. |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 952 | stream.reset(); // Will reset stream 7. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 953 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 954 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 955 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 956 | } |
| 957 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 958 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 959 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 960 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 961 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 962 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 963 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 964 | MockQuicData socket_data; |
| 965 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 966 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 967 | |
| 968 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 969 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 970 | host_resolver_->set_synchronous_mode(true); |
| 971 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 972 | "192.168.0.1", ""); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 973 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 974 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 975 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 976 | DEFAULT_PRIORITY, SocketTag(), |
| 977 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 978 | &net_error_details_, |
| 979 | failed_on_default_network_callback_, |
| 980 | callback_.callback())); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 981 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 982 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 983 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 984 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 985 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 986 | } |
| 987 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 988 | TEST_P(QuicStreamFactoryTest, DefaultInitialRtt) { |
| 989 | Initialize(); |
| 990 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 991 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 992 | |
| 993 | MockQuicData socket_data; |
| 994 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 995 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 996 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 997 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 998 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 999 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1000 | request.Request( |
| 1001 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1002 | SocketTag(), |
| 1003 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1004 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1005 | |
| 1006 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1007 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1008 | EXPECT_TRUE(stream.get()); |
| 1009 | |
| 1010 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1011 | EXPECT_TRUE(session->require_confirmation()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1012 | EXPECT_EQ(100000u, session->connection()->GetStats().srtt_us); |
| 1013 | ASSERT_FALSE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1014 | } |
| 1015 | |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1016 | TEST_P(QuicStreamFactoryTest, FactoryDestroyedWhenJobPending) { |
| 1017 | Initialize(); |
| 1018 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1019 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1020 | |
| 1021 | MockQuicData socket_data; |
| 1022 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1023 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1024 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1025 | |
| 1026 | auto request = std::make_unique<QuicStreamRequest>(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1027 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1028 | request->Request( |
| 1029 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1030 | SocketTag(), |
| 1031 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1032 | failed_on_default_network_callback_, callback_.callback())); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1033 | request.reset(); |
| 1034 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1035 | // Tearing down a QuicStreamFactory with a pending Job should not cause any |
| 1036 | // crash. crbug.com/768343. |
| 1037 | factory_.reset(); |
| 1038 | } |
| 1039 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1040 | TEST_P(QuicStreamFactoryTest, RequireConfirmation) { |
| 1041 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1042 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1043 | host_resolver_->set_synchronous_mode(true); |
| 1044 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1045 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1046 | Initialize(); |
| 1047 | factory_->set_require_confirmation(true); |
| 1048 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1049 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1050 | |
| 1051 | MockQuicData socket_data; |
| 1052 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1053 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1054 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1055 | |
| 1056 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1057 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1058 | request.Request( |
| 1059 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1060 | SocketTag(), |
| 1061 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1062 | failed_on_default_network_callback_, callback_.callback())); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1063 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1064 | IPAddress last_address; |
| 1065 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1066 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1067 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1068 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1069 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1070 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1071 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1072 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1073 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1074 | EXPECT_TRUE(stream.get()); |
| 1075 | |
| 1076 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1077 | EXPECT_TRUE(session->require_confirmation()); |
| 1078 | } |
| 1079 | |
| 1080 | TEST_P(QuicStreamFactoryTest, DontRequireConfirmationFromSameIP) { |
| 1081 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1082 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1083 | host_resolver_->set_synchronous_mode(true); |
| 1084 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1085 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1086 | Initialize(); |
| 1087 | factory_->set_require_confirmation(true); |
| 1088 | http_server_properties_.SetSupportsQuic(IPAddress(192, 0, 2, 33)); |
| 1089 | |
| 1090 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1091 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1092 | |
| 1093 | MockQuicData socket_data; |
| 1094 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1095 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1096 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1097 | |
| 1098 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1099 | EXPECT_THAT(request.Request( |
| 1100 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1101 | SocketTag(), |
| 1102 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1103 | failed_on_default_network_callback_, callback_.callback()), |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1104 | IsOk()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1105 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1106 | IPAddress last_address; |
| 1107 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1108 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1109 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1110 | EXPECT_TRUE(stream.get()); |
| 1111 | |
| 1112 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1113 | EXPECT_FALSE(session->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1114 | |
| 1115 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1116 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1117 | |
| 1118 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1119 | } |
| 1120 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1121 | TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { |
| 1122 | ServerNetworkStats stats; |
| 1123 | stats.srtt = base::TimeDelta::FromMilliseconds(10); |
| 1124 | http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), |
| 1125 | stats); |
| 1126 | estimate_initial_rtt_ = true; |
| 1127 | |
| 1128 | Initialize(); |
| 1129 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1130 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1131 | |
| 1132 | MockQuicData socket_data; |
| 1133 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1134 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1135 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1136 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1137 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1138 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1139 | request.Request( |
| 1140 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1141 | SocketTag(), |
| 1142 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1143 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1144 | |
| 1145 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1146 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1147 | EXPECT_TRUE(stream.get()); |
| 1148 | |
| 1149 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1150 | EXPECT_EQ(10000u, session->connection()->GetStats().srtt_us); |
| 1151 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1152 | EXPECT_EQ(10000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1153 | } |
| 1154 | |
| 1155 | TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { |
| 1156 | ScopedMockNetworkChangeNotifier notifier; |
| 1157 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1158 | NetworkChangeNotifier::CONNECTION_2G); |
| 1159 | estimate_initial_rtt_ = true; |
| 1160 | |
| 1161 | Initialize(); |
| 1162 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1163 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1164 | |
| 1165 | MockQuicData socket_data; |
| 1166 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1167 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1168 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1169 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1170 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1171 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1172 | request.Request( |
| 1173 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1174 | SocketTag(), |
| 1175 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1176 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1177 | |
| 1178 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1179 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1180 | EXPECT_TRUE(stream.get()); |
| 1181 | |
| 1182 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1183 | EXPECT_EQ(1200000u, session->connection()->GetStats().srtt_us); |
| 1184 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1185 | EXPECT_EQ(1200000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1186 | } |
| 1187 | |
| 1188 | TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { |
| 1189 | ScopedMockNetworkChangeNotifier notifier; |
| 1190 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1191 | NetworkChangeNotifier::CONNECTION_3G); |
| 1192 | estimate_initial_rtt_ = true; |
| 1193 | |
| 1194 | Initialize(); |
| 1195 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1196 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1197 | |
| 1198 | MockQuicData socket_data; |
| 1199 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1200 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1201 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1202 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1203 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1204 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1205 | request.Request( |
| 1206 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1207 | SocketTag(), |
| 1208 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1209 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1210 | |
| 1211 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1212 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1213 | EXPECT_TRUE(stream.get()); |
| 1214 | |
| 1215 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1216 | EXPECT_EQ(400000u, session->connection()->GetStats().srtt_us); |
| 1217 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1218 | EXPECT_EQ(400000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1219 | } |
| 1220 | |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1221 | TEST_P(QuicStreamFactoryTest, GoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1222 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1223 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1224 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1225 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1226 | MockQuicData socket_data; |
| 1227 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1228 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1229 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1230 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1231 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1232 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1233 | request.Request( |
| 1234 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1235 | SocketTag(), |
| 1236 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1237 | failed_on_default_network_callback_, callback_.callback())); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1238 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1239 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1240 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1241 | EXPECT_TRUE(stream.get()); |
| 1242 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1243 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1244 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1245 | session->OnGoAway(quic::QuicGoAwayFrame()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1246 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1247 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1248 | |
| 1249 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1250 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1251 | } |
| 1252 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1253 | TEST_P(QuicStreamFactoryTest, GoAwayForConnectionMigrationWithPortOnly) { |
| 1254 | Initialize(); |
| 1255 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1256 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1257 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1258 | MockQuicData socket_data; |
| 1259 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1260 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1261 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1262 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1263 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1264 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1265 | request.Request( |
| 1266 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1267 | SocketTag(), |
| 1268 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1269 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1270 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1271 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1272 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1273 | EXPECT_TRUE(stream.get()); |
| 1274 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1275 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1276 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1277 | session->OnGoAway(quic::QuicGoAwayFrame( |
| 1278 | quic::kInvalidControlFrameId, quic::QUIC_ERROR_MIGRATING_PORT, 0, |
| 1279 | "peer connection migration due to port change only")); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1280 | NetErrorDetails details; |
| 1281 | EXPECT_FALSE(details.quic_port_migration_detected); |
| 1282 | session->PopulateNetErrorDetails(&details); |
| 1283 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1284 | details.quic_port_migration_detected = false; |
| 1285 | stream->PopulateNetErrorDetails(&details); |
| 1286 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1287 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1288 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1289 | |
| 1290 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1291 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1292 | } |
| 1293 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1294 | TEST_P(QuicStreamFactoryTest, Pooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1295 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1296 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1297 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1298 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1299 | MockQuicData socket_data; |
| 1300 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1301 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1302 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1303 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1304 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1305 | host_resolver_->set_synchronous_mode(true); |
| 1306 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1307 | "192.168.0.1", ""); |
| 1308 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1309 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1310 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1311 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1312 | DEFAULT_PRIORITY, SocketTag(), |
| 1313 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1314 | &net_error_details_, |
| 1315 | failed_on_default_network_callback_, |
| 1316 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1317 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1318 | EXPECT_TRUE(stream.get()); |
| 1319 | |
| 1320 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1321 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1322 | EXPECT_EQ(OK, |
| 1323 | request2.Request( |
| 1324 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1325 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1326 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1327 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1328 | EXPECT_TRUE(stream2.get()); |
| 1329 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1330 | EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1331 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1332 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1333 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1334 | } |
| 1335 | |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1336 | TEST_P(QuicStreamFactoryTest, PoolingWithServerMigration) { |
| 1337 | // Set up session to migrate. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1338 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1339 | "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1340 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 443); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1341 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 1342 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1343 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1344 | |
| 1345 | VerifyServerMigration(config, alt_address); |
| 1346 | |
| 1347 | // Close server-migrated session. |
| 1348 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1349 | session->CloseSessionOnError(0u, quic::QUIC_NO_ERROR, |
| 1350 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1351 | |
| 1352 | // Set up server IP, socket, proof, and config for new session. |
| 1353 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1354 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1355 | |
| 1356 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1357 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 1358 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 1359 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 1360 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1361 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1362 | SequencedSocketData socket_data(reads, writes); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1363 | socket_factory_->AddSocketDataProvider(&socket_data); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1364 | |
| 1365 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1366 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1367 | quic::QuicConfig config2; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1368 | crypto_client_stream_factory_.SetConfig(config2); |
| 1369 | |
| 1370 | // Create new request to cause new session creation. |
| 1371 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1372 | QuicStreamRequest request2(factory_.get()); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1373 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1374 | request2.Request( |
| 1375 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1376 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1377 | failed_on_default_network_callback_, callback.callback())); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1378 | EXPECT_EQ(OK, callback.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1379 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1380 | EXPECT_TRUE(stream2.get()); |
| 1381 | |
| 1382 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1383 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1384 | // EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
| 1385 | } |
| 1386 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1387 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1388 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1389 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1390 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1391 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1392 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1393 | MockQuicData socket_data1; |
| 1394 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1395 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1396 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1397 | MockQuicData socket_data2; |
| 1398 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1399 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1400 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1401 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1402 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1403 | host_resolver_->set_synchronous_mode(true); |
| 1404 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1405 | "192.168.0.1", ""); |
| 1406 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1407 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1408 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1409 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1410 | DEFAULT_PRIORITY, SocketTag(), |
| 1411 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1412 | &net_error_details_, |
| 1413 | failed_on_default_network_callback_, |
| 1414 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1415 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1416 | EXPECT_TRUE(stream.get()); |
| 1417 | |
| 1418 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1419 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1420 | EXPECT_EQ(OK, |
| 1421 | request2.Request( |
| 1422 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1423 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1424 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1425 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1426 | EXPECT_TRUE(stream2.get()); |
| 1427 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1428 | factory_->OnSessionGoingAway(GetActiveSession(host_port_pair_)); |
| 1429 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1430 | EXPECT_FALSE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1431 | |
| 1432 | TestCompletionCallback callback3; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1433 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1434 | EXPECT_EQ(OK, |
| 1435 | request3.Request( |
| 1436 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1437 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1438 | failed_on_default_network_callback_, callback3.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1439 | std::unique_ptr<HttpStream> stream3 = CreateStream(&request3); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1440 | EXPECT_TRUE(stream3.get()); |
| 1441 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1442 | EXPECT_TRUE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1443 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1444 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1445 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1446 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1447 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1448 | } |
| 1449 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1450 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1451 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1452 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1453 | MockQuicData socket_data; |
| 1454 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1455 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1456 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1457 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1458 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1459 | HostPortPair server2(kServer2HostName, 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1460 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1461 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1462 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1463 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1464 | host_resolver_->set_synchronous_mode(true); |
| 1465 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1466 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1467 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1468 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1469 | EXPECT_EQ(OK, |
| 1470 | request.Request( |
| 1471 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1472 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1473 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1474 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1475 | EXPECT_TRUE(stream.get()); |
| 1476 | |
| 1477 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1478 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1479 | EXPECT_EQ(OK, |
| 1480 | request2.Request( |
| 1481 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1482 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1483 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1484 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1485 | EXPECT_TRUE(stream2.get()); |
| 1486 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1487 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1488 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1489 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1490 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1491 | } |
| 1492 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1493 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1494 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1495 | MockQuicData socket_data; |
| 1496 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1497 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1498 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1499 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1500 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1501 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1502 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1503 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1504 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1505 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1506 | EXPECT_TRUE(primary_pin.FromString( |
| 1507 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1508 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1509 | verify_details.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1510 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1511 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1512 | host_resolver_->set_synchronous_mode(true); |
| 1513 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1514 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1515 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1516 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1517 | EXPECT_EQ(OK, |
| 1518 | request.Request( |
| 1519 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1520 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1521 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1522 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1523 | EXPECT_TRUE(stream.get()); |
| 1524 | |
| 1525 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1526 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1527 | EXPECT_EQ(OK, |
| 1528 | request2.Request( |
| 1529 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1530 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1531 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1532 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1533 | EXPECT_TRUE(stream2.get()); |
| 1534 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1535 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1536 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1537 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1538 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1542 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1543 | |
| 1544 | MockQuicData socket_data1; |
| 1545 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1546 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1547 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1548 | MockQuicData socket_data2; |
| 1549 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1550 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1551 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1552 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1553 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1554 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1555 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1556 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1557 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1558 | ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1559 | uint8_t bad_pin = 3; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1560 | verify_details1.cert_verify_result.public_key_hashes.push_back( |
| 1561 | test::GetTestHashValue(bad_pin)); |
| 1562 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 1563 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1564 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1565 | EXPECT_TRUE(primary_pin.FromString( |
| 1566 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1567 | ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1568 | verify_details2.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1569 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1570 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1571 | host_resolver_->set_synchronous_mode(true); |
| 1572 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1573 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1574 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1575 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1576 | EXPECT_EQ(OK, |
| 1577 | request.Request( |
| 1578 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1579 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1580 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1581 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1582 | EXPECT_TRUE(stream.get()); |
| 1583 | |
| 1584 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1585 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1586 | EXPECT_EQ(OK, |
| 1587 | request2.Request( |
| 1588 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1589 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1590 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1591 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1592 | EXPECT_TRUE(stream2.get()); |
| 1593 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1594 | EXPECT_NE(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1595 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1596 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1597 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1598 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1599 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1600 | } |
| 1601 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1602 | TEST_P(QuicStreamFactoryTest, Goaway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1603 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1604 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1605 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1606 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1607 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1608 | MockQuicData socket_data; |
| 1609 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1610 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1611 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1612 | MockQuicData socket_data2; |
| 1613 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1614 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1615 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1616 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1617 | QuicStreamRequest request(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 | request.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())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1624 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1625 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1626 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1627 | EXPECT_TRUE(stream.get()); |
| 1628 | |
| 1629 | // Mark the session as going away. Ensure that while it is still alive |
| 1630 | // that it is no longer active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1631 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1632 | factory_->OnSessionGoingAway(session); |
| 1633 | EXPECT_EQ(true, |
| 1634 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1635 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1636 | |
| 1637 | // Create a new request for the same destination and verify that a |
| 1638 | // new session is created. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1639 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1640 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1641 | request2.Request( |
| 1642 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1643 | SocketTag(), |
| 1644 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1645 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1646 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1647 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1648 | EXPECT_TRUE(stream2.get()); |
| 1649 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1650 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1651 | EXPECT_NE(session, GetActiveSession(host_port_pair_)); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1652 | EXPECT_EQ(true, |
| 1653 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1654 | |
| 1655 | stream2.reset(); |
| 1656 | stream.reset(); |
| 1657 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1658 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1659 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1660 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1661 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1662 | } |
| 1663 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1664 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1665 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1666 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1667 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1668 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1669 | quic::QuicStreamId stream_id = GetNthClientInitiatedBidirectionalStreamId(0); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1670 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1671 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1672 | if (version_ == quic::QUIC_VERSION_99) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1673 | socket_data.AddWrite( |
| 1674 | SYNCHRONOUS, |
| 1675 | client_maker_.MakeStreamIdBlockedPacket( |
| 1676 | 2, true, GetNthClientInitiatedBidirectionalStreamId(49))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1677 | socket_data.AddWrite( |
| 1678 | SYNCHRONOUS, client_maker_.MakeRstPacket(3, true, stream_id, |
| 1679 | quic::QUIC_STREAM_CANCELLED)); |
| 1680 | socket_data.AddRead( |
| 1681 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1682 | quic::QUIC_STREAM_CANCELLED)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1683 | socket_data.AddRead( |
| 1684 | ASYNC, server_maker_.MakeMaxStreamIdPacket( |
| 1685 | 4, true, GetNthClientInitiatedBidirectionalStreamId(50))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1686 | } else { |
| 1687 | socket_data.AddWrite( |
| 1688 | SYNCHRONOUS, client_maker_.MakeRstPacket(2, true, stream_id, |
| 1689 | quic::QUIC_STREAM_CANCELLED)); |
| 1690 | socket_data.AddRead( |
| 1691 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1692 | quic::QUIC_STREAM_CANCELLED)); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1693 | } |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1694 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1695 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1696 | |
| 1697 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1698 | request_info.traffic_annotation = |
| 1699 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1700 | |
xunjieli | 1d2b427 | 2017-04-25 22:37:17 | [diff] [blame] | 1701 | std::vector<std::unique_ptr<HttpStream>> streams; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1702 | // The MockCryptoClientStream sets max_open_streams to be |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1703 | // quic::kDefaultMaxStreamsPerConnection / 2. |
| 1704 | for (size_t i = 0; i < quic::kDefaultMaxStreamsPerConnection / 2; i++) { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1705 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1706 | int rv = request.Request( |
| 1707 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1708 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1709 | failed_on_default_network_callback_, callback_.callback()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1710 | if (i == 0) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1712 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1713 | } else { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1714 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1715 | } |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1716 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1717 | EXPECT_TRUE(stream); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1718 | EXPECT_EQ(OK, |
| 1719 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1720 | net_log_, CompletionOnceCallback())); |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 1721 | streams.push_back(std::move(stream)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1722 | } |
| 1723 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1724 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1725 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1726 | DEFAULT_PRIORITY, SocketTag(), |
| 1727 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1728 | &net_error_details_, |
| 1729 | failed_on_default_network_callback_, |
| 1730 | CompletionOnceCallback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1731 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1732 | EXPECT_TRUE(stream); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1733 | EXPECT_EQ(ERR_IO_PENDING, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1734 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
| 1735 | net_log_, callback_.callback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1736 | |
| 1737 | // Close the first stream. |
| 1738 | streams.front()->Close(false); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1739 | // Trigger exchange of RSTs that in turn allow progress for the last |
| 1740 | // stream. |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1741 | base::RunLoop().RunUntilIdle(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1742 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1743 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1744 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1745 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1746 | |
| 1747 | // Force close of the connection to suppress the generation of RST |
| 1748 | // packets when streams are torn down, which wouldn't be relevant to |
| 1749 | // this test anyway. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1750 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1751 | session->connection()->CloseConnection( |
| 1752 | quic::QUIC_PUBLIC_RESET, "test", |
| 1753 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1754 | } |
| 1755 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1756 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1757 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1758 | MockQuicData socket_data; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1759 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1760 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1761 | host_resolver_->rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1762 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1763 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1764 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1765 | request.Request( |
| 1766 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1767 | SocketTag(), |
| 1768 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1769 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1770 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1771 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1772 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1773 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1774 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1775 | } |
| 1776 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1777 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1778 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1779 | |
| 1780 | MockQuicData socket_data; |
| 1781 | socket_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1782 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1783 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1784 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1785 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1786 | request.Request( |
| 1787 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1788 | SocketTag(), |
| 1789 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1790 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1791 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1792 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1793 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1794 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1795 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1796 | } |
| 1797 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1798 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1799 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1800 | MockQuicData socket_data; |
| 1801 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1802 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1803 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1804 | { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1805 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1806 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1807 | request.Request( |
| 1808 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1809 | SocketTag(), |
| 1810 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1811 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1812 | } |
| 1813 | |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 1814 | base::RunLoop().RunUntilIdle(); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1815 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1816 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 1817 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1818 | DEFAULT_PRIORITY, SocketTag(), |
| 1819 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1820 | &net_error_details_, |
| 1821 | failed_on_default_network_callback_, |
| 1822 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1823 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 1824 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1825 | EXPECT_TRUE(stream.get()); |
| 1826 | stream.reset(); |
| 1827 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1828 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1829 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1830 | } |
| 1831 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1832 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1833 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1834 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1835 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1836 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1837 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1838 | MockQuicData socket_data; |
| 1839 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1840 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1841 | socket_data.AddWrite( |
| 1842 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1843 | socket_data.AddWrite(SYNCHRONOUS, |
| 1844 | client_maker_.MakeConnectionClosePacket( |
| 1845 | 3, true, quic::QUIC_INTERNAL_ERROR, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1846 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1847 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1848 | MockQuicData socket_data2; |
| 1849 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1850 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1851 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1852 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1853 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1854 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1855 | request.Request( |
| 1856 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1857 | SocketTag(), |
| 1858 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1859 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1860 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1861 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1862 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1863 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1864 | request_info.traffic_annotation = |
| 1865 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1866 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1867 | net_log_, CompletionOnceCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1868 | |
| 1869 | // Close the session and verify that stream saw the error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1870 | factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, |
| 1871 | quic::QUIC_INTERNAL_ERROR); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1872 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1873 | stream->ReadResponseHeaders(callback_.callback())); |
| 1874 | |
| 1875 | // Now attempting to request a stream to the same origin should create |
| 1876 | // a new session. |
| 1877 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1878 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1879 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1880 | request2.Request( |
| 1881 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1882 | SocketTag(), |
| 1883 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1884 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1885 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1886 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1887 | stream = CreateStream(&request2); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1888 | stream.reset(); // Will reset stream 3. |
| 1889 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1890 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1891 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1892 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1893 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1894 | } |
| 1895 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1896 | // Regression test for crbug.com/700617. Test a write error during the |
| 1897 | // crypto handshake will not hang QuicStreamFactory::Job and should |
| 1898 | // report QUIC_HANDSHAKE_FAILED to upper layers. Subsequent |
| 1899 | // QuicStreamRequest should succeed without hanging. |
| 1900 | TEST_P(QuicStreamFactoryTest, |
| 1901 | WriteErrorInCryptoConnectWithAsyncHostResolution) { |
| 1902 | Initialize(); |
| 1903 | // Use unmocked crypto stream to do crypto connect. |
| 1904 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1905 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1906 | |
| 1907 | MockQuicData socket_data; |
| 1908 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1909 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1910 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1911 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1912 | |
| 1913 | // Create request, should fail after the write of the CHLO fails. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1914 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1915 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1916 | request.Request( |
| 1917 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1918 | SocketTag(), |
| 1919 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1920 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1921 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 1922 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1923 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1924 | |
| 1925 | // Verify new requests can be sent normally without hanging. |
| 1926 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1927 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1928 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1929 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1930 | MockQuicData socket_data2; |
| 1931 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1932 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1933 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1934 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1935 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1936 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1937 | request2.Request( |
| 1938 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1939 | SocketTag(), |
| 1940 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1941 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1942 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1943 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1944 | // Run the message loop to complete host resolution. |
| 1945 | base::RunLoop().RunUntilIdle(); |
| 1946 | |
| 1947 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 1948 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1949 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1950 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1951 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1952 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1953 | |
| 1954 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1955 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1956 | EXPECT_TRUE(stream.get()); |
| 1957 | stream.reset(); |
| 1958 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1959 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1960 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1961 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1962 | } |
| 1963 | |
| 1964 | TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { |
| 1965 | Initialize(); |
| 1966 | // Use unmocked crypto stream to do crypto connect. |
| 1967 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1968 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1969 | host_resolver_->set_synchronous_mode(true); |
| 1970 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1971 | "192.168.0.1", ""); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1972 | |
| 1973 | MockQuicData socket_data; |
| 1974 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1975 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1976 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1977 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1978 | |
| 1979 | // Create request, should fail immediately. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1980 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1981 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1982 | request.Request( |
| 1983 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1984 | SocketTag(), |
| 1985 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1986 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1987 | // Check no active session, or active jobs left for this server. |
| 1988 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1989 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1990 | |
| 1991 | // Verify new requests can be sent normally without hanging. |
| 1992 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1993 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1994 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1995 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1996 | MockQuicData socket_data2; |
| 1997 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1998 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1999 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2000 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2001 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2002 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2003 | request2.Request( |
| 2004 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2005 | SocketTag(), |
| 2006 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2007 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2008 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2009 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 2010 | |
| 2011 | // Complete handshake. |
| 2012 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2013 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2014 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2015 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2016 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 2017 | |
| 2018 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2019 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2020 | EXPECT_TRUE(stream.get()); |
| 2021 | stream.reset(); |
| 2022 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2023 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2024 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2025 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2026 | } |
| 2027 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2028 | TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 2029 | close_sessions_on_ip_change_ = true; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2030 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 2031 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2032 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2033 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2034 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2035 | MockQuicData socket_data; |
| 2036 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2037 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2038 | socket_data.AddWrite( |
| 2039 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2040 | socket_data.AddWrite( |
| 2041 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 2042 | 3, true, quic::QUIC_IP_ADDRESS_CHANGED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2043 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2044 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2045 | MockQuicData socket_data2; |
| 2046 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2047 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2048 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2049 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2050 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2051 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2052 | request.Request( |
| 2053 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2054 | SocketTag(), |
| 2055 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2056 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2057 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2058 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2059 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 2060 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2061 | request_info.traffic_annotation = |
| 2062 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2063 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2064 | net_log_, CompletionOnceCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2065 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2066 | // Check an active session exisits for the destination. |
| 2067 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2068 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2069 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2070 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2071 | IPAddress last_address; |
| 2072 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2073 | // Change the IP address and verify that stream saw the error and the active |
| 2074 | // session is closed. |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2075 | NotifyIPAddressChanged(); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2076 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 2077 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2078 | EXPECT_TRUE(factory_->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2079 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2080 | // Check no active session exists for the destination. |
| 2081 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2082 | |
| 2083 | // Now attempting to request a stream to the same origin should create |
| 2084 | // a new session. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2085 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2086 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2087 | request2.Request( |
| 2088 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2089 | SocketTag(), |
| 2090 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2091 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2092 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2093 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2094 | stream = CreateStream(&request2); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2095 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2096 | // Check a new active session exisits for the destination and the old session |
| 2097 | // is no longer live. |
| 2098 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2099 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2100 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2101 | |
| 2102 | stream.reset(); // Will reset stream 3. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2103 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2104 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2105 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2106 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2107 | } |
| 2108 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2109 | // Test that if goaway_session_on_ip_change is set, old sessions will be marked |
| 2110 | // as going away on IP address change instead of being closed. New requests will |
| 2111 | // go to a new connection. |
| 2112 | TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { |
| 2113 | goaway_sessions_on_ip_change_ = true; |
| 2114 | Initialize(); |
| 2115 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2116 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2117 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2118 | |
| 2119 | MockQuicData quic_data1; |
| 2120 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2121 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2122 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2123 | quic_data1.AddWrite( |
| 2124 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2125 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2126 | true, &header_stream_offset)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2127 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2128 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2129 | ASYNC, |
| 2130 | ConstructOkResponsePacket( |
| 2131 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2132 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2133 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2134 | |
| 2135 | MockQuicData quic_data2; |
| 2136 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 2137 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2138 | quic_data2.AddWrite( |
| 2139 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 2140 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2141 | |
| 2142 | // Create request and QuicHttpStream. |
| 2143 | QuicStreamRequest request(factory_.get()); |
| 2144 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2145 | request.Request( |
| 2146 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2147 | SocketTag(), |
| 2148 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2149 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2150 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2151 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2152 | EXPECT_TRUE(stream.get()); |
| 2153 | |
| 2154 | // Cause QUIC stream to be created. |
| 2155 | HttpRequestInfo request_info; |
| 2156 | request_info.method = "GET"; |
| 2157 | request_info.url = url_; |
| 2158 | request_info.traffic_annotation = |
| 2159 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2160 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2161 | net_log_, CompletionOnceCallback())); |
| 2162 | |
| 2163 | // Ensure that session is alive and active. |
| 2164 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2165 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2166 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2167 | |
| 2168 | // Send GET request on stream. |
| 2169 | HttpResponseInfo response; |
| 2170 | HttpRequestHeaders request_headers; |
| 2171 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2172 | callback_.callback())); |
| 2173 | |
| 2174 | // Receive an IP address change notification. |
| 2175 | NotifyIPAddressChanged(); |
| 2176 | |
| 2177 | // The connection should still be alive, but marked as going away. |
| 2178 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2179 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2180 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2181 | |
| 2182 | // Resume the data, response should be read from the original connection. |
| 2183 | quic_data1.Resume(); |
| 2184 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2185 | EXPECT_EQ(200, response.headers->response_code()); |
| 2186 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2187 | |
| 2188 | // Second request should be sent on a new connection. |
| 2189 | QuicStreamRequest request2(factory_.get()); |
| 2190 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2191 | request2.Request( |
| 2192 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2193 | SocketTag(), |
| 2194 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2195 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2196 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2197 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 2198 | EXPECT_TRUE(stream2.get()); |
| 2199 | |
| 2200 | // Check an active session exisits for the destination. |
| 2201 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2202 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2203 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2204 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2205 | |
| 2206 | stream.reset(); |
| 2207 | stream2.reset(); |
| 2208 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2209 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2210 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2211 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2212 | } |
| 2213 | |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2214 | TEST_P(QuicStreamFactoryTest, OnIPAddressChangedWithConnectionMigration) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 2215 | InitializeConnectionMigrationV2Test( |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2216 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2217 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2218 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2219 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2220 | |
| 2221 | MockQuicData socket_data; |
| 2222 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2223 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2224 | socket_data.AddWrite( |
| 2225 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2226 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2227 | |
| 2228 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2229 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2230 | request.Request( |
| 2231 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2232 | SocketTag(), |
| 2233 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2234 | failed_on_default_network_callback_, callback_.callback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2235 | |
| 2236 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2237 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2238 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2239 | request_info.traffic_annotation = |
| 2240 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2241 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2242 | net_log_, CompletionOnceCallback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2243 | |
| 2244 | IPAddress last_address; |
| 2245 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2246 | |
| 2247 | // Change the IP address and verify that the connection is unaffected. |
| 2248 | NotifyIPAddressChanged(); |
| 2249 | EXPECT_FALSE(factory_->require_confirmation()); |
| 2250 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2251 | |
| 2252 | // Attempting a new request to the same origin uses the same connection. |
| 2253 | QuicStreamRequest request2(factory_.get()); |
| 2254 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2255 | DEFAULT_PRIORITY, SocketTag(), |
| 2256 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2257 | &net_error_details_, |
| 2258 | failed_on_default_network_callback_, |
| 2259 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2260 | stream = CreateStream(&request2); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2261 | |
| 2262 | stream.reset(); |
| 2263 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2264 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2265 | } |
| 2266 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2267 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithSynchronousWrite) { |
| 2268 | TestMigrationOnNetworkMadeDefault(SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2269 | } |
| 2270 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2271 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithAsyncWrite) { |
| 2272 | TestMigrationOnNetworkMadeDefault(ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2273 | } |
| 2274 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2275 | // Sets up a test which attempts connection migration successfully after probing |
| 2276 | // when a new network is made as default and the old default is still available. |
| 2277 | // |write_mode| specifies the write mode for the last write before |
| 2278 | // OnNetworkMadeDefault is delivered to session. |
| 2279 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkMadeDefault( |
| 2280 | IoMode write_mode) { |
| 2281 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2282 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2283 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2284 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2285 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2286 | // Using a testing task runner so that we can control time. |
| 2287 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2288 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2289 | |
| 2290 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2291 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2292 | |
| 2293 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2294 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2295 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2296 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2297 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2298 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2299 | write_mode, ConstructGetRequestPacket( |
| 2300 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2301 | true, &header_stream_offset)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2302 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2303 | |
| 2304 | // Set up the second socket data provider that is used after migration. |
| 2305 | // The response to the earlier request is read on the new socket. |
| 2306 | MockQuicData quic_data2; |
| 2307 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2308 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2309 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2310 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2311 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2312 | quic_data2.AddRead(ASYNC, |
| 2313 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2314 | // Ping packet to send after migration is completed. |
| 2315 | quic_data2.AddWrite(ASYNC, |
| 2316 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2317 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2318 | ASYNC, |
| 2319 | ConstructOkResponsePacket( |
| 2320 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2321 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2322 | quic_data2.AddWrite( |
| 2323 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2324 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2325 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2326 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2327 | |
| 2328 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2329 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2330 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2331 | request.Request( |
| 2332 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2333 | SocketTag(), |
| 2334 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2335 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2336 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2337 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2338 | EXPECT_TRUE(stream.get()); |
| 2339 | |
| 2340 | // Cause QUIC stream to be created. |
| 2341 | HttpRequestInfo request_info; |
| 2342 | request_info.method = "GET"; |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 2343 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2344 | request_info.traffic_annotation = |
| 2345 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2346 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2347 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2348 | |
| 2349 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2350 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2351 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2352 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2353 | |
| 2354 | // Send GET request on stream. |
| 2355 | HttpResponseInfo response; |
| 2356 | HttpRequestHeaders request_headers; |
| 2357 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2358 | callback_.callback())); |
| 2359 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2360 | // Deliver a signal that a alternate network is connected now, this should |
| 2361 | // cause the connection to start early migration on path degrading. |
| 2362 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2363 | ->SetConnectedNetworksList( |
| 2364 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2365 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2366 | ->NotifyNetworkConnected(kNewNetworkForTests); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2367 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2368 | // Cause the connection to report path degrading to the session. |
| 2369 | // Due to lack of alternate network, session will not mgirate connection. |
| 2370 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2371 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2372 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2373 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2374 | // A task will be posted to migrate to the new default network. |
| 2375 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2376 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2377 | |
| 2378 | // Execute the posted task to migrate back to the default network. |
| 2379 | task_runner->RunUntilIdle(); |
| 2380 | // Another task to try send a new connectivity probe is posted. And a task to |
| 2381 | // retry migrate back to default network is scheduled. |
| 2382 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2383 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2384 | // kDefaultRTTMilliSecs. |
| 2385 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2386 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2387 | next_task_delay); |
| 2388 | |
| 2389 | // The connection should still be alive, and not marked as going away. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2390 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2391 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2392 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2393 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2394 | |
| 2395 | // Resume quic data and a connectivity probe response will be read on the new |
| 2396 | // socket, declare probing as successful. And a new task to WriteToNewSocket |
| 2397 | // will be posted to complete migration. |
| 2398 | quic_data2.Resume(); |
| 2399 | |
| 2400 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2401 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2402 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2403 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2404 | // There should be three pending tasks, the nearest one will complete |
| 2405 | // migration to the new network. |
| 2406 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2407 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2408 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 2409 | task_runner->FastForwardBy(next_task_delay); |
| 2410 | |
| 2411 | // Response headers are received over the new network. |
| 2412 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2413 | EXPECT_EQ(200, response.headers->response_code()); |
| 2414 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2415 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 2416 | // probe and has been cancelled due to successful migration. |
| 2417 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2418 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2419 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2420 | next_task_delay); |
| 2421 | task_runner->FastForwardBy(next_task_delay); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2422 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2423 | // There's one more task to mgirate back to the default network in 0.4s, which |
| 2424 | // is also cancelled due to the success migration on the previous trial. |
| 2425 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2426 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2427 | base::TimeDelta expected_delay = |
| 2428 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2429 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2430 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2431 | task_runner->FastForwardBy(next_task_delay); |
| 2432 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2433 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2434 | // Verify that the session is still alive. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2435 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2436 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2437 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2438 | stream.reset(); |
| 2439 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2440 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2441 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2442 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2443 | } |
| 2444 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2445 | // Regression test for http://859674. |
| 2446 | // This test veries that a writer will not attempt to write packets until being |
| 2447 | // unblocked on both socket level and network level. In this test, a probing |
| 2448 | // writer is used to send two connectivity probes to the peer: where the first |
| 2449 | // one completes successfully, while a connectivity response is received before |
| 2450 | // completes sending the second one. The connection migration attempt will |
| 2451 | // proceed while the probing writer is blocked at the socket level, which will |
| 2452 | // block the writer on the network level. Once connection migration completes |
| 2453 | // successfully, the probing writer will be unblocked on the network level, it |
| 2454 | // will not attempt to write new packets until the socket level is unblocked. |
| 2455 | TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { |
| 2456 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 2457 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2458 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2459 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2460 | |
| 2461 | // Using a testing task runner so that we can control time. |
| 2462 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2463 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2464 | |
| 2465 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2466 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2467 | |
| 2468 | MockQuicData quic_data1; |
| 2469 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2470 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2471 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2472 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2473 | quic_data1.AddWrite( |
| 2474 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2475 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2476 | true, &header_stream_offset)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2477 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2478 | |
| 2479 | // Set up the second socket data provider that is used after migration. |
| 2480 | // The response to the earlier request is read on the new socket. |
| 2481 | MockQuicData quic_data2; |
| 2482 | // First connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2483 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2484 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2485 | quic_data2.AddRead(ASYNC, |
| 2486 | ERR_IO_PENDING); // Pause so that we can control time. |
| 2487 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2488 | quic_data2.AddRead(ASYNC, |
| 2489 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2490 | // Second connectivity probe which will complete asynchronously. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2491 | quic_data2.AddWrite(ASYNC, |
| 2492 | client_maker_.MakeConnectivityProbingPacket(4, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2493 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2494 | ASYNC, |
| 2495 | ConstructOkResponsePacket( |
| 2496 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2497 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2498 | quic_data2.AddWrite(ASYNC, |
| 2499 | client_maker_.MakeAckAndPingPacket(5, false, 1, 1, 1)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2500 | quic_data2.AddWrite( |
| 2501 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2502 | 6, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2503 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2504 | |
| 2505 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2506 | |
| 2507 | // Create request and QuicHttpStream. |
| 2508 | QuicStreamRequest request(factory_.get()); |
| 2509 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2510 | request.Request( |
| 2511 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2512 | SocketTag(), |
| 2513 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2514 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2515 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2516 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2517 | EXPECT_TRUE(stream.get()); |
| 2518 | |
| 2519 | // Cause QUIC stream to be created. |
| 2520 | HttpRequestInfo request_info; |
| 2521 | request_info.method = "GET"; |
| 2522 | request_info.url = url_; |
| 2523 | request_info.traffic_annotation = |
| 2524 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2525 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2526 | net_log_, CompletionOnceCallback())); |
| 2527 | |
| 2528 | // Ensure that session is alive and active. |
| 2529 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2530 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2531 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2532 | |
| 2533 | // Send GET request on stream. |
| 2534 | HttpResponseInfo response; |
| 2535 | HttpRequestHeaders request_headers; |
| 2536 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2537 | callback_.callback())); |
| 2538 | |
| 2539 | // Deliver a signal that a alternate network is connected now, this should |
| 2540 | // cause the connection to start early migration on path degrading. |
| 2541 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2542 | ->SetConnectedNetworksList( |
| 2543 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2544 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2545 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 2546 | |
| 2547 | // Cause the connection to report path degrading to the session. |
| 2548 | // Due to lack of alternate network, session will not mgirate connection. |
| 2549 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2550 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2551 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2552 | |
| 2553 | // A task will be posted to migrate to the new default network. |
| 2554 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2555 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2556 | |
| 2557 | // Execute the posted task to migrate back to the default network. |
| 2558 | task_runner->RunUntilIdle(); |
| 2559 | // Another task to resend a new connectivity probe is posted. And a task to |
| 2560 | // retry migrate back to default network is scheduled. |
| 2561 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2562 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2563 | // kDefaultRTTMilliSecs. |
| 2564 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2565 | base::TimeDelta expected_delay = |
| 2566 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2567 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2568 | |
| 2569 | // Fast forward to send the second connectivity probe. The write will be |
| 2570 | // asynchronous and complete after the read completes. |
| 2571 | task_runner->FastForwardBy(next_task_delay); |
| 2572 | |
| 2573 | // Resume quic data and a connectivity probe response will be read on the new |
| 2574 | // socket, declare probing as successful. |
| 2575 | quic_data2.Resume(); |
| 2576 | |
| 2577 | // The connection should still be alive, and not marked as going away. |
| 2578 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2579 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2580 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2581 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2582 | |
| 2583 | // There should be three pending tasks, the nearest one will complete |
| 2584 | // migration to the new network. Second task will retry migrate back to |
| 2585 | // default but cancelled, and the third task will retry send connectivity |
| 2586 | // probe but also cancelled. |
| 2587 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2588 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2589 | task_runner->RunUntilIdle(); |
| 2590 | |
| 2591 | // Response headers are received over the new network. |
| 2592 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2593 | EXPECT_EQ(200, response.headers->response_code()); |
| 2594 | |
| 2595 | // Run the message loop to complete the asynchronous write of ack and ping. |
| 2596 | base::RunLoop().RunUntilIdle(); |
| 2597 | |
| 2598 | // Now there are two pending tasks, the nearest one was to retry migrate back |
| 2599 | // to default network and has been cancelled due to successful migration. |
| 2600 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2601 | expected_delay = |
| 2602 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2603 | expected_delay; |
| 2604 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2605 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2606 | task_runner->FastForwardBy(next_task_delay); |
| 2607 | |
| 2608 | // There's one more task to retry sending connectivity probe in 0.4s and has |
| 2609 | // also been cancelled due to the successful probing. |
| 2610 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2611 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2612 | expected_delay = |
| 2613 | base::TimeDelta::FromMilliseconds(3 * 2 * kDefaultRTTMilliSecs) - |
| 2614 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 2615 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2616 | task_runner->FastForwardBy(next_task_delay); |
| 2617 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2618 | |
| 2619 | // Verify that the session is still alive. |
| 2620 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2621 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2622 | |
| 2623 | stream.reset(); |
| 2624 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2625 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2626 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2627 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2628 | } |
| 2629 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2630 | // This test verifies that session times out connection migration attempt |
| 2631 | // with signals delivered in the following order (no alternate network is |
| 2632 | // available): |
| 2633 | // - default network disconnected is delivered: session attempts connection |
| 2634 | // migration but found not alternate network. Session waits for a new network |
| 2635 | // comes up in the next kWaitTimeForNewNetworkSecs seonds. |
| 2636 | // - no new network is connected, migration times out. Session is closed. |
| 2637 | TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { |
| 2638 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2639 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2640 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2641 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2642 | // Using a testing task runner so that we can control time. |
| 2643 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2644 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2645 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2646 | MockQuicData socket_data; |
| 2647 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2648 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2649 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2650 | |
| 2651 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2652 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2653 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2654 | request.Request( |
| 2655 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2656 | SocketTag(), |
| 2657 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2658 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2659 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2660 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2661 | EXPECT_TRUE(stream.get()); |
| 2662 | |
| 2663 | // Cause QUIC stream to be created. |
| 2664 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2665 | request_info.traffic_annotation = |
| 2666 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2667 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2668 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2669 | |
| 2670 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2671 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2672 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2673 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2674 | |
| 2675 | // Trigger connection migration. Since there are no networks |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2676 | // to migrate to, this should cause the session to wait for a new network. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2677 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2678 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2679 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2680 | // The migration will not fail until the migration alarm timeout. |
| 2681 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2682 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2683 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2684 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2685 | EXPECT_EQ(true, session->connection()->writer()->IsWriteBlocked()); |
| 2686 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2687 | // Migration will be timed out after kWaitTimeForNewNetwokSecs. |
| 2688 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2689 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2690 | EXPECT_EQ(base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs), |
| 2691 | next_task_delay); |
| 2692 | task_runner->FastForwardBy(next_task_delay); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2693 | |
| 2694 | // The connection should now be closed. A request for response |
| 2695 | // headers should fail. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2696 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2697 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2698 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2699 | |
| 2700 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2701 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2702 | } |
| 2703 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2704 | // This test verifies that connectivity probes will be sent even if there is |
| 2705 | // a non-migratable stream. However, when connection migrates to the |
| 2706 | // successfully probed path, any non-migratable stream will be reset. And if |
| 2707 | // the connection becomes idle then, close the connection. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2708 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2709 | InitializeConnectionMigrationV2Test( |
| 2710 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2711 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2712 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2713 | |
| 2714 | MockQuicData socket_data; |
| 2715 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2716 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2717 | socket_data.AddWrite( |
| 2718 | SYNCHRONOUS, |
| 2719 | client_maker_.MakeRstAckAndConnectionClosePacket( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2720 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Fan Yang | 7c68f63 | 2018-11-06 03:05:38 | [diff] [blame] | 2721 | quic::QUIC_STREAM_CANCELLED, |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2722 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 2723 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
| 2724 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2725 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2726 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2727 | // Set up the second socket data provider that is used for probing. |
| 2728 | MockQuicData quic_data1; |
| 2729 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2730 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2731 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2732 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2733 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2734 | quic_data1.AddRead(ASYNC, |
| 2735 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2736 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2737 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2738 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2739 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2740 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2741 | request.Request( |
| 2742 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2743 | SocketTag(), |
| 2744 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2745 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2746 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2747 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2748 | EXPECT_TRUE(stream.get()); |
| 2749 | |
| 2750 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2751 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2752 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2753 | request_info.traffic_annotation = |
| 2754 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2755 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2756 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2757 | |
| 2758 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2759 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2760 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2761 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2762 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2763 | // Trigger connection migration. Session will start to probe the alternative |
| 2764 | // network. Although there is a non-migratable stream, session will still be |
| 2765 | // active until probing is declared as successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2766 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2767 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2768 | |
| 2769 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2770 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2771 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2772 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2773 | // Resume data to read a connectivity probing response, which will cause |
| 2774 | // non-migtable streams to be closed. As session becomes idle, connection will |
| 2775 | // be closed. |
| 2776 | quic_data1.Resume(); |
| 2777 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2778 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2779 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2780 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2781 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2782 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2783 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2784 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2785 | } |
| 2786 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2787 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2788 | InitializeConnectionMigrationV2Test( |
| 2789 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2790 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2791 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2792 | |
| 2793 | MockQuicData socket_data; |
| 2794 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2795 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2796 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2797 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2798 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2799 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2800 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2801 | |
| 2802 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2803 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2804 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2805 | request.Request( |
| 2806 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2807 | SocketTag(), |
| 2808 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2809 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2810 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2811 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2812 | EXPECT_TRUE(stream.get()); |
| 2813 | |
| 2814 | // Cause QUIC stream to be created. |
| 2815 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2816 | request_info.traffic_annotation = |
| 2817 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2818 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2819 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2820 | |
| 2821 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2822 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2823 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2824 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2825 | |
| 2826 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2827 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2828 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2829 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2830 | |
| 2831 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2832 | // this should cause session to continue but be marked as going away. |
| 2833 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2834 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2835 | |
| 2836 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2837 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2838 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2839 | |
| 2840 | stream.reset(); |
| 2841 | |
| 2842 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2843 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2844 | } |
| 2845 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2846 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2847 | InitializeConnectionMigrationV2Test( |
| 2848 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2849 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2850 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2851 | |
| 2852 | MockQuicData socket_data; |
| 2853 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2854 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2855 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2856 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2857 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2858 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2859 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2860 | |
| 2861 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2862 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2863 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2864 | request.Request( |
| 2865 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2866 | SocketTag(), |
| 2867 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2868 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2869 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2870 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2871 | EXPECT_TRUE(stream.get()); |
| 2872 | |
| 2873 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2874 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2875 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2876 | request_info.traffic_annotation = |
| 2877 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2878 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2879 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2880 | |
| 2881 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2882 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2883 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2884 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2885 | |
| 2886 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2887 | // this should cause a RST_STREAM frame to be emitted with |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 2888 | // quic::QUIC_STREAM_CANCELLED error code, and the session will be closed. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2889 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2890 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2891 | |
| 2892 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2893 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2894 | |
| 2895 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2896 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2897 | } |
| 2898 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2899 | TEST_P(QuicStreamFactoryTest, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2900 | OnNetworkDisconnectedConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2901 | InitializeConnectionMigrationV2Test( |
| 2902 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2903 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2904 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2905 | |
| 2906 | MockQuicData socket_data; |
| 2907 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2908 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2909 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2910 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2911 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2912 | quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2913 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2914 | |
| 2915 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2916 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2917 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2918 | request.Request( |
| 2919 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2920 | SocketTag(), |
| 2921 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2922 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2923 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2924 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2925 | EXPECT_TRUE(stream.get()); |
| 2926 | |
| 2927 | // Cause QUIC stream to be created. |
| 2928 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2929 | request_info.traffic_annotation = |
| 2930 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2931 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2932 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2933 | |
| 2934 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2935 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2936 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2937 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2938 | |
| 2939 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2940 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2941 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2942 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2943 | |
| 2944 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2945 | // this should cause a RST_STREAM frame to be emitted with |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2946 | // quic::QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2947 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2948 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2949 | |
| 2950 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2951 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2952 | |
| 2953 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2954 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2955 | } |
| 2956 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2957 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2958 | InitializeConnectionMigrationV2Test( |
| 2959 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2960 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2961 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2962 | |
| 2963 | MockQuicData socket_data; |
| 2964 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2965 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2966 | socket_data.AddWrite( |
| 2967 | SYNCHRONOUS, |
| 2968 | client_maker_.MakeConnectionClosePacket( |
| 2969 | 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 2970 | "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2971 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2972 | |
| 2973 | // Create request and QuicHttpStream. |
| 2974 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2975 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2976 | request.Request( |
| 2977 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2978 | SocketTag(), |
| 2979 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2980 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2981 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2982 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2983 | EXPECT_TRUE(stream.get()); |
| 2984 | |
| 2985 | // Ensure that session is alive and active. |
| 2986 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2987 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2988 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2989 | |
| 2990 | // Trigger connection migration. |
| 2991 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2992 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2993 | |
| 2994 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2995 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2996 | |
| 2997 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2998 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2999 | } |
| 3000 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 3001 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3002 | InitializeConnectionMigrationV2Test( |
| 3003 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3004 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3005 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3006 | |
| 3007 | MockQuicData socket_data; |
| 3008 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3009 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3010 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3011 | |
| 3012 | // Create request and QuicHttpStream. |
| 3013 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3014 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3015 | request.Request( |
| 3016 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3017 | SocketTag(), |
| 3018 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3019 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3020 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3021 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3022 | EXPECT_TRUE(stream.get()); |
| 3023 | |
| 3024 | // Ensure that session is alive and active. |
| 3025 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3026 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3027 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3028 | |
| 3029 | // Trigger connection migration. Since there are no active streams, |
| 3030 | // the session will be closed. |
| 3031 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3032 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3033 | |
| 3034 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3035 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3036 | |
| 3037 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3038 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3039 | } |
| 3040 | |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3041 | // This test verifies session migrates to the alternate network immediately when |
| 3042 | // default network disconnects with a synchronous write before migration. |
| 3043 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedSync) { |
| 3044 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ false); |
| 3045 | } |
| 3046 | |
| 3047 | // This test verifies session migrates to the alternate network immediately when |
| 3048 | // default network disconnects with an asynchronously write before migration. |
| 3049 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedAsync) { |
| 3050 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ true); |
| 3051 | } |
| 3052 | |
| 3053 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkDisconnected( |
| 3054 | bool async_write_before) { |
| 3055 | InitializeConnectionMigrationV2Test( |
| 3056 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3057 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3058 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 3059 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3060 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3061 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3062 | |
| 3063 | // Use the test task runner. |
| 3064 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3065 | |
| 3066 | int packet_number = 1; |
| 3067 | MockQuicData socket_data; |
| 3068 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3069 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3070 | socket_data.AddWrite( |
| 3071 | SYNCHRONOUS, |
| 3072 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 3073 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3074 | SYNCHRONOUS, |
| 3075 | ConstructGetRequestPacket(packet_number++, |
| 3076 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3077 | true, true, &header_stream_offset)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3078 | if (async_write_before) { |
| 3079 | socket_data.AddWrite(ASYNC, OK); |
| 3080 | packet_number++; |
| 3081 | } |
| 3082 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3083 | |
| 3084 | // Create request and QuicHttpStream. |
| 3085 | QuicStreamRequest request(factory_.get()); |
| 3086 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3087 | request.Request( |
| 3088 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3089 | SocketTag(), |
| 3090 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3091 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3092 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3093 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3094 | EXPECT_TRUE(stream.get()); |
| 3095 | |
| 3096 | // Cause QUIC stream to be created. |
| 3097 | HttpRequestInfo request_info; |
| 3098 | request_info.method = "GET"; |
| 3099 | request_info.url = url_; |
| 3100 | request_info.traffic_annotation = |
| 3101 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3102 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3103 | net_log_, CompletionOnceCallback())); |
| 3104 | |
| 3105 | // Ensure that session is alive and active. |
| 3106 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3107 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3108 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3109 | |
| 3110 | // Send GET request on stream. |
| 3111 | HttpResponseInfo response; |
| 3112 | HttpRequestHeaders request_headers; |
| 3113 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3114 | callback_.callback())); |
| 3115 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3116 | if (async_write_before) |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3117 | session->SendPing(); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3118 | |
| 3119 | // Set up second socket data provider that is used after migration. |
| 3120 | // The response to the earlier request is read on this new socket. |
| 3121 | MockQuicData socket_data1; |
| 3122 | socket_data1.AddWrite( |
| 3123 | SYNCHRONOUS, |
| 3124 | client_maker_.MakePingPacket(packet_number++, /*include_version=*/true)); |
| 3125 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3126 | ASYNC, |
| 3127 | ConstructOkResponsePacket( |
| 3128 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3129 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3130 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3131 | SYNCHRONOUS, |
| 3132 | client_maker_.MakeAckAndRstPacket( |
| 3133 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3134 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3135 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3136 | |
| 3137 | // Trigger connection migration. |
| 3138 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3139 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3140 | |
| 3141 | // The connection should still be alive, not marked as going away. |
| 3142 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3143 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3144 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3145 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3146 | |
| 3147 | // Ensure that the session is still alive. |
| 3148 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3149 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3150 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3151 | |
| 3152 | // Run the message loop so that data queued in the new socket is read by the |
| 3153 | // packet reader. |
| 3154 | runner_->RunNextTask(); |
| 3155 | |
| 3156 | // Response headers are received over the new network. |
| 3157 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3158 | EXPECT_EQ(200, response.headers->response_code()); |
| 3159 | |
| 3160 | // Check that the session is still alive. |
| 3161 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3162 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3163 | |
| 3164 | // There should be posted tasks not executed, which is to migrate back to |
| 3165 | // default network. |
| 3166 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3167 | |
| 3168 | // Receive signal to mark new network as default. |
| 3169 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3170 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3171 | |
| 3172 | stream.reset(); |
| 3173 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3174 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3175 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3176 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3177 | } |
| 3178 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3179 | // This test receives NCN signals in the following order: |
| 3180 | // - default network disconnected |
| 3181 | // - after a pause, new network is connected. |
| 3182 | // - new network is made default. |
| 3183 | TEST_P(QuicStreamFactoryTest, NewNetworkConnectedAfterNoNetwork) { |
| 3184 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 3185 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3186 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3187 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3188 | |
| 3189 | // Use the test task runner. |
| 3190 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3191 | |
| 3192 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3193 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3194 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3195 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3196 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3197 | socket_data.AddWrite( |
| 3198 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3199 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3200 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3201 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3202 | |
| 3203 | // Create request and QuicHttpStream. |
| 3204 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3205 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3206 | request.Request( |
| 3207 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3208 | SocketTag(), |
| 3209 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3210 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3211 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3212 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3213 | EXPECT_TRUE(stream.get()); |
| 3214 | |
| 3215 | // Cause QUIC stream to be created. |
| 3216 | HttpRequestInfo request_info; |
| 3217 | request_info.method = "GET"; |
| 3218 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 3219 | request_info.traffic_annotation = |
| 3220 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 3221 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 3222 | net_log_, CompletionOnceCallback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3223 | |
| 3224 | // Ensure that session is alive and active. |
| 3225 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3226 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3227 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3228 | |
| 3229 | // Send GET request on stream. |
| 3230 | HttpResponseInfo response; |
| 3231 | HttpRequestHeaders request_headers; |
| 3232 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3233 | callback_.callback())); |
| 3234 | |
| 3235 | // Trigger connection migration. Since there are no networks |
| 3236 | // to migrate to, this should cause the session to wait for a new network. |
| 3237 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3238 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3239 | |
| 3240 | // The connection should still be alive, not marked as going away. |
| 3241 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3242 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3243 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3244 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3245 | |
| 3246 | // Set up second socket data provider that is used after migration. |
| 3247 | // The response to the earlier request is read on this new socket. |
| 3248 | MockQuicData socket_data1; |
| 3249 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3250 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 3251 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3252 | ASYNC, |
| 3253 | ConstructOkResponsePacket( |
| 3254 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3255 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3256 | socket_data1.AddWrite( |
| 3257 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3258 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3259 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3260 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3261 | |
| 3262 | // Add a new network and notify the stream factory of a new connected network. |
| 3263 | // This causes a PING packet to be sent over the new network. |
| 3264 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3265 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 3266 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3267 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 3268 | |
| 3269 | // Ensure that the session is still alive. |
| 3270 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3271 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3272 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3273 | |
| 3274 | // Run the message loop so that data queued in the new socket is read by the |
| 3275 | // packet reader. |
| 3276 | runner_->RunNextTask(); |
| 3277 | |
| 3278 | // Response headers are received over the new network. |
| 3279 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3280 | EXPECT_EQ(200, response.headers->response_code()); |
| 3281 | |
| 3282 | // Check that the session is still alive. |
| 3283 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3284 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3285 | |
| 3286 | // There should posted tasks not executed, which is to migrate back to default |
| 3287 | // network. |
| 3288 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3289 | |
| 3290 | // Receive signal to mark new network as default. |
| 3291 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3292 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3293 | |
| 3294 | stream.reset(); |
| 3295 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3296 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3297 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3298 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3299 | } |
| 3300 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3301 | // Regression test for http://crbug.com/872011. |
| 3302 | // This test verifies that migrate to the probing socket will not trigger |
| 3303 | // new packets being read synchronously and generate ACK frame while |
| 3304 | // processing the initial connectivity probe response, which may cause a |
| 3305 | // connection being closed with INTERNAL_ERROR as pending ACK frame is not |
| 3306 | // allowed when processing a new packet. |
Zhongyi Shi | 6a7323b | 2018-12-07 01:26:32 | [diff] [blame] | 3307 | TEST_P(QuicStreamFactoryTest, MigrateToProbingSocket) { |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3308 | InitializeConnectionMigrationV2Test( |
| 3309 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3310 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3311 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3312 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3313 | |
| 3314 | // Using a testing task runner so that we can control time. |
| 3315 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3316 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3317 | |
| 3318 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3319 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3320 | |
| 3321 | int packet_number = 1; |
| 3322 | MockQuicData quic_data1; |
| 3323 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3324 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 3325 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3326 | packet_number++, &header_stream_offset)); |
| 3327 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3328 | SYNCHRONOUS, |
| 3329 | ConstructGetRequestPacket(packet_number++, |
| 3330 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3331 | true, true, &header_stream_offset)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3332 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3333 | |
| 3334 | // Set up the second socket data provider that is used for probing on the |
| 3335 | // alternate network. |
| 3336 | MockQuicData quic_data2; |
| 3337 | // Connectivity probe to be sent on the new path. |
| 3338 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
| 3339 | packet_number++, true)); |
| 3340 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3341 | // First connectivity probe to receive from the server, which will complete |
| 3342 | // connection migraiton on path degrading. |
| 3343 | quic_data2.AddRead(ASYNC, |
| 3344 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3345 | // Read multiple connectivity probes synchronously. |
| 3346 | quic_data2.AddRead(SYNCHRONOUS, |
| 3347 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
| 3348 | quic_data2.AddRead(SYNCHRONOUS, |
| 3349 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
| 3350 | quic_data2.AddRead(SYNCHRONOUS, |
| 3351 | server_maker_.MakeConnectivityProbingPacket(4, false)); |
| 3352 | quic_data2.AddWrite( |
| 3353 | ASYNC, client_maker_.MakeAckPacket(packet_number++, 1, 4, 1, 1, true)); |
| 3354 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3355 | ASYNC, |
| 3356 | ConstructOkResponsePacket( |
| 3357 | 5, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3358 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3359 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3360 | SYNCHRONOUS, |
| 3361 | client_maker_.MakeAckAndRstPacket( |
| 3362 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3363 | quic::QUIC_STREAM_CANCELLED, 5, 1, 1, true)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3364 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3365 | |
| 3366 | // Create request and QuicHttpStream. |
| 3367 | QuicStreamRequest request(factory_.get()); |
| 3368 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3369 | request.Request( |
| 3370 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3371 | SocketTag(), |
| 3372 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3373 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3374 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3375 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3376 | EXPECT_TRUE(stream.get()); |
| 3377 | |
| 3378 | // Cause QUIC stream to be created. |
| 3379 | HttpRequestInfo request_info; |
| 3380 | request_info.method = "GET"; |
| 3381 | request_info.url = url_; |
| 3382 | request_info.traffic_annotation = |
| 3383 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3384 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3385 | net_log_, CompletionOnceCallback())); |
| 3386 | |
| 3387 | // Ensure that session is alive and active. |
| 3388 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3389 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3390 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3391 | |
| 3392 | // Send GET request on stream. |
| 3393 | HttpResponseInfo response; |
| 3394 | HttpRequestHeaders request_headers; |
| 3395 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3396 | callback_.callback())); |
| 3397 | |
| 3398 | // Cause the connection to report path degrading to the session. |
| 3399 | // Session will start to probe the alternate network. |
| 3400 | session->connection()->OnPathDegradingTimeout(); |
| 3401 | |
| 3402 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3403 | // kDefaultRTTMilliSecs. |
| 3404 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3405 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3406 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3407 | next_task_delay); |
| 3408 | |
| 3409 | // The connection should still be alive, and not marked as going away. |
| 3410 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3411 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3412 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3413 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3414 | |
| 3415 | // Resume quic data and a connectivity probe response will be read on the new |
| 3416 | // socket. |
| 3417 | quic_data2.Resume(); |
| 3418 | |
| 3419 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3420 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3421 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3422 | |
| 3423 | // There should be three pending tasks, the nearest one will complete |
| 3424 | // migration to the new network. |
| 3425 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3426 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3427 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3428 | task_runner->FastForwardBy(next_task_delay); |
| 3429 | |
| 3430 | // Response headers are received over the new network. |
| 3431 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3432 | EXPECT_EQ(200, response.headers->response_code()); |
| 3433 | |
| 3434 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3435 | // probe and has been cancelled due to successful migration. |
| 3436 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3437 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3438 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3439 | next_task_delay); |
| 3440 | task_runner->FastForwardBy(next_task_delay); |
| 3441 | |
| 3442 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3443 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3444 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3445 | base::TimeDelta expected_delay = |
| 3446 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3447 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3448 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3449 | |
| 3450 | // Deliver a signal that the alternate network now becomes default to session, |
| 3451 | // this will cancel mgirate back to default network timer. |
| 3452 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3453 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3454 | |
| 3455 | task_runner->FastForwardBy(next_task_delay); |
| 3456 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3457 | |
| 3458 | // Verify that the session is still alive. |
| 3459 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3460 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3461 | |
| 3462 | stream.reset(); |
| 3463 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3464 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3465 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3466 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3467 | } |
| 3468 | |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3469 | // This test verifies that the connection migrates to the alternate network |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3470 | // early when path degrading is detected with an ASYNCHRONOUS write before |
| 3471 | // migration. |
| 3472 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingAysnc) { |
| 3473 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ true); |
| 3474 | } |
| 3475 | |
| 3476 | // This test verifies that the connection migrates to the alternate network |
| 3477 | // early when path degrading is detected with a SYNCHRONOUS write before |
| 3478 | // migration. |
| 3479 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingSync) { |
| 3480 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ false); |
| 3481 | } |
| 3482 | |
| 3483 | void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( |
| 3484 | bool async_write_before) { |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3485 | InitializeConnectionMigrationV2Test( |
| 3486 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3487 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3488 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3489 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3490 | |
| 3491 | // Using a testing task runner so that we can control time. |
| 3492 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3493 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3494 | |
| 3495 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3496 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3497 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3498 | int packet_number = 1; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3499 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3500 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3501 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3502 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3503 | packet_number++, &header_stream_offset)); |
| 3504 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3505 | SYNCHRONOUS, |
| 3506 | ConstructGetRequestPacket(packet_number++, |
| 3507 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3508 | true, true, &header_stream_offset)); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3509 | if (async_write_before) { |
| 3510 | quic_data1.AddWrite(ASYNC, OK); |
| 3511 | packet_number++; |
| 3512 | } |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3513 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3514 | |
| 3515 | // Set up the second socket data provider that is used after migration. |
| 3516 | // The response to the earlier request is read on the new socket. |
| 3517 | MockQuicData quic_data2; |
| 3518 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3519 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3520 | packet_number++, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3521 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3522 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3523 | quic_data2.AddRead(ASYNC, |
| 3524 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3525 | // Ping packet to send after migration is completed. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3526 | quic_data2.AddWrite(ASYNC, client_maker_.MakeAckAndPingPacket( |
| 3527 | packet_number++, false, 1, 1, 1)); |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 3528 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3529 | ASYNC, |
| 3530 | ConstructOkResponsePacket( |
| 3531 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3532 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3533 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3534 | SYNCHRONOUS, |
| 3535 | client_maker_.MakeAckAndRstPacket( |
| 3536 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3537 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3538 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3539 | |
| 3540 | // Create request and QuicHttpStream. |
| 3541 | QuicStreamRequest request(factory_.get()); |
| 3542 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3543 | request.Request( |
| 3544 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3545 | SocketTag(), |
| 3546 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3547 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3548 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3549 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3550 | EXPECT_TRUE(stream.get()); |
| 3551 | |
| 3552 | // Cause QUIC stream to be created. |
| 3553 | HttpRequestInfo request_info; |
| 3554 | request_info.method = "GET"; |
| 3555 | request_info.url = url_; |
| 3556 | request_info.traffic_annotation = |
| 3557 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3558 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3559 | net_log_, CompletionOnceCallback())); |
| 3560 | |
| 3561 | // Ensure that session is alive and active. |
| 3562 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3563 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3564 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3565 | |
| 3566 | // Send GET request on stream. |
| 3567 | HttpResponseInfo response; |
| 3568 | HttpRequestHeaders request_headers; |
| 3569 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3570 | callback_.callback())); |
| 3571 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3572 | if (async_write_before) |
| 3573 | session->SendPing(); |
| 3574 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 3575 | // Cause the connection to report path degrading to the session. |
| 3576 | // Session will start to probe the alternate network. |
| 3577 | session->connection()->OnPathDegradingTimeout(); |
| 3578 | |
| 3579 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3580 | // kDefaultRTTMilliSecs. |
| 3581 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3582 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3583 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3584 | next_task_delay); |
| 3585 | |
| 3586 | // The connection should still be alive, and not marked as going away. |
| 3587 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3588 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3589 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3590 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3591 | |
| 3592 | // Resume quic data and a connectivity probe response will be read on the new |
| 3593 | // socket. |
| 3594 | quic_data2.Resume(); |
| 3595 | |
| 3596 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3597 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3598 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3599 | |
| 3600 | // There should be three pending tasks, the nearest one will complete |
| 3601 | // migration to the new network. |
| 3602 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3603 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3604 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3605 | task_runner->FastForwardBy(next_task_delay); |
| 3606 | |
| 3607 | // Response headers are received over the new network. |
| 3608 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3609 | EXPECT_EQ(200, response.headers->response_code()); |
| 3610 | |
| 3611 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3612 | // probe and has been cancelled due to successful migration. |
| 3613 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3614 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3615 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3616 | next_task_delay); |
| 3617 | task_runner->FastForwardBy(next_task_delay); |
| 3618 | |
| 3619 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3620 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3621 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3622 | base::TimeDelta expected_delay = |
| 3623 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3624 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3625 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3626 | |
| 3627 | // Deliver a signal that the alternate network now becomes default to session, |
| 3628 | // this will cancel mgirate back to default network timer. |
| 3629 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3630 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3631 | |
| 3632 | task_runner->FastForwardBy(next_task_delay); |
| 3633 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3634 | |
| 3635 | // Verify that the session is still alive. |
| 3636 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3637 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3638 | |
| 3639 | stream.reset(); |
| 3640 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3641 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3642 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3643 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3644 | } |
| 3645 | |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3646 | // This test verifies that the session marks itself GOAWAY on path degrading |
| 3647 | // and it does not receive any new request |
| 3648 | TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { |
| 3649 | go_away_on_path_degrading_ = true; |
| 3650 | Initialize(); |
| 3651 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3652 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3653 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3654 | |
| 3655 | MockQuicData quic_data1; |
| 3656 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3657 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3658 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3659 | quic_data1.AddWrite( |
| 3660 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3661 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3662 | true, &header_stream_offset)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3663 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3664 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3665 | ASYNC, |
| 3666 | ConstructOkResponsePacket( |
| 3667 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3668 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3669 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3670 | |
| 3671 | MockQuicData quic_data2; |
| 3672 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 3673 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3674 | quic_data2.AddWrite( |
| 3675 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 3676 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3677 | |
| 3678 | // Creat request and QuicHttpStream. |
| 3679 | QuicStreamRequest request(factory_.get()); |
| 3680 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3681 | request.Request( |
| 3682 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3683 | SocketTag(), |
| 3684 | /*cerf_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3685 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3686 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3687 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3688 | EXPECT_TRUE(stream.get()); |
| 3689 | |
| 3690 | // Cause QUIC stream to be created. |
| 3691 | HttpRequestInfo request_info; |
| 3692 | request_info.method = "GET"; |
| 3693 | request_info.url = url_; |
| 3694 | request_info.traffic_annotation = |
| 3695 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3696 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3697 | net_log_, CompletionOnceCallback())); |
| 3698 | |
| 3699 | // Ensure that session is alive and active. |
| 3700 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3701 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3702 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3703 | |
| 3704 | // Send GET request on stream. |
| 3705 | HttpResponseInfo response; |
| 3706 | HttpRequestHeaders request_headers; |
| 3707 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3708 | callback_.callback())); |
| 3709 | |
| 3710 | // Trigger the connection to report path degrading to the session. |
| 3711 | // Session will mark itself GOAWAY. |
| 3712 | session->connection()->OnPathDegradingTimeout(); |
| 3713 | |
| 3714 | // The connection should still be alive, but marked as going away. |
| 3715 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3716 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3717 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3718 | |
| 3719 | // Second request should be sent on a new connection. |
| 3720 | QuicStreamRequest request2(factory_.get()); |
| 3721 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3722 | request2.Request( |
| 3723 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3724 | SocketTag(), |
| 3725 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3726 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3727 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3728 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 3729 | EXPECT_TRUE(stream2.get()); |
| 3730 | |
| 3731 | // Resume the data, verify old request can read response on the old session |
| 3732 | // successfully. |
| 3733 | quic_data1.Resume(); |
| 3734 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 3735 | EXPECT_EQ(200, response.headers->response_code()); |
| 3736 | EXPECT_EQ(0U, session->GetNumActiveStreams()); |
| 3737 | |
| 3738 | // Check an active session exists for the destination. |
| 3739 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3740 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3741 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 3742 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 3743 | EXPECT_NE(session, session2); |
| 3744 | |
| 3745 | stream.reset(); |
| 3746 | stream2.reset(); |
| 3747 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3748 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3749 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3750 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3751 | } |
| 3752 | |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3753 | // This test verifies that the connection will not migrate to a bad socket |
| 3754 | // when path degrading is detected. |
| 3755 | TEST_P(QuicStreamFactoryTest, DoNotMigrateToBadSocketOnPathDegrading) { |
| 3756 | InitializeConnectionMigrationV2Test( |
| 3757 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3758 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3759 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3760 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3761 | |
| 3762 | // Using a testing task runner so that we can control time. |
| 3763 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3764 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3765 | |
| 3766 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3767 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3768 | |
| 3769 | MockQuicData quic_data; |
| 3770 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3771 | quic_data.AddWrite(SYNCHRONOUS, |
| 3772 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3773 | quic_data.AddWrite(SYNCHRONOUS, |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3774 | ConstructGetRequestPacket( |
| 3775 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3776 | true, &header_stream_offset)); |
| 3777 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3778 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 3779 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3780 | false, false)); |
| 3781 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3782 | quic_data.AddWrite( |
| 3783 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3784 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3785 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3786 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3787 | |
| 3788 | // Set up second socket that will immediately return disconnected. |
| 3789 | // The stream factory will abort probe the alternate network. |
| 3790 | MockConnect bad_connect = MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
| 3791 | SequencedSocketData socket_data(bad_connect, base::span<MockRead>(), |
| 3792 | base::span<MockWrite>()); |
| 3793 | socket_factory_->AddSocketDataProvider(&socket_data); |
| 3794 | |
| 3795 | // Create request and QuicHttpStream. |
| 3796 | QuicStreamRequest request(factory_.get()); |
| 3797 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3798 | request.Request( |
| 3799 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3800 | SocketTag(), |
| 3801 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3802 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3803 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3804 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3805 | EXPECT_TRUE(stream.get()); |
| 3806 | |
| 3807 | // Cause QUIC stream to be created. |
| 3808 | HttpRequestInfo request_info; |
| 3809 | request_info.method = "GET"; |
| 3810 | request_info.url = url_; |
| 3811 | request_info.traffic_annotation = |
| 3812 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3813 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3814 | net_log_, CompletionOnceCallback())); |
| 3815 | |
| 3816 | // Ensure that session is alive and active. |
| 3817 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3818 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3819 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3820 | |
| 3821 | // Send GET request on stream. |
| 3822 | HttpResponseInfo response; |
| 3823 | HttpRequestHeaders request_headers; |
| 3824 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3825 | callback_.callback())); |
| 3826 | |
| 3827 | // Cause the connection to report path degrading to the session. |
| 3828 | // Session will start to probe the alternate network. |
| 3829 | session->connection()->OnPathDegradingTimeout(); |
| 3830 | |
| 3831 | // The connection should still be alive, and not marked as going away. |
| 3832 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3833 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3834 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3835 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3836 | |
| 3837 | // Resume the data, and response header is received over the original network. |
| 3838 | quic_data.Resume(); |
| 3839 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3840 | EXPECT_EQ(200, response.headers->response_code()); |
| 3841 | |
| 3842 | // Verify there is no pending task as probing alternate network is halted. |
| 3843 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3844 | |
| 3845 | // Verify that the session is still alive. |
| 3846 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3847 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3848 | |
| 3849 | stream.reset(); |
| 3850 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 3851 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 3852 | } |
| 3853 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3854 | // Regression test for http://crbug.com/847569. |
| 3855 | // This test verifies that the connection migrates to the alternate network |
| 3856 | // early when there is no active stream but a draining stream. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3857 | // The first packet being written after migration is a synchrnous write, which |
| 3858 | // will cause a PING packet being sent. |
| 3859 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamSync) { |
| 3860 | TestMigrateSessionWithDrainingStream(SYNCHRONOUS); |
| 3861 | } |
| 3862 | |
| 3863 | // Regression test for http://crbug.com/847569. |
| 3864 | // This test verifies that the connection migrates to the alternate network |
| 3865 | // early when there is no active stream but a draining stream. |
| 3866 | // The first packet being written after migration is an asynchronous write, no |
| 3867 | // PING packet will be sent. |
| 3868 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamAsync) { |
| 3869 | TestMigrateSessionWithDrainingStream(ASYNC); |
| 3870 | } |
| 3871 | |
| 3872 | void QuicStreamFactoryTestBase::TestMigrateSessionWithDrainingStream( |
| 3873 | IoMode write_mode_for_queued_packet) { |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3874 | InitializeConnectionMigrationV2Test( |
| 3875 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3876 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3877 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3878 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3879 | |
| 3880 | // Using a testing task runner so that we can control time. |
| 3881 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3882 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3883 | |
| 3884 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3885 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3886 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3887 | int packet_number = 1; |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3888 | MockQuicData quic_data1; |
| 3889 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3890 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3891 | packet_number++, &header_stream_offset)); |
| 3892 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3893 | SYNCHRONOUS, |
| 3894 | ConstructGetRequestPacket(packet_number++, |
| 3895 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3896 | true, true, &header_stream_offset)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3897 | // Read an out of order packet with FIN to drain the stream. |
| 3898 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3899 | ASYNC, ConstructOkResponsePacket( |
| 3900 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, |
| 3901 | true)); // keep sending version. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3902 | quic_data1.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3903 | packet_number++, 2, 2, 2, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3904 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3905 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3906 | |
| 3907 | // Set up the second socket data provider that is used after migration. |
| 3908 | MockQuicData quic_data2; |
| 3909 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3910 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3911 | packet_number++, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3912 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3913 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3914 | quic_data2.AddRead(ASYNC, |
| 3915 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3916 | // Ping packet to send after migration is completed. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3917 | quic_data2.AddWrite( |
| 3918 | write_mode_for_queued_packet, |
| 3919 | client_maker_.MakeAckPacket(packet_number++, 2, 3, 3, 1, true)); |
| 3920 | if (write_mode_for_queued_packet == SYNCHRONOUS) { |
| 3921 | quic_data2.AddWrite(ASYNC, |
| 3922 | client_maker_.MakePingPacket(packet_number++, false)); |
| 3923 | } |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3924 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3925 | ASYNC, |
| 3926 | ConstructOkResponsePacket( |
| 3927 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3928 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3929 | packet_number++, 1, 3, 1, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3930 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3931 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3932 | |
| 3933 | // Create request and QuicHttpStream. |
| 3934 | QuicStreamRequest request(factory_.get()); |
| 3935 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3936 | request.Request( |
| 3937 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3938 | SocketTag(), |
| 3939 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3940 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3941 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3942 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3943 | EXPECT_TRUE(stream.get()); |
| 3944 | |
| 3945 | // Cause QUIC stream to be created. |
| 3946 | HttpRequestInfo request_info; |
| 3947 | request_info.method = "GET"; |
| 3948 | request_info.url = url_; |
| 3949 | request_info.traffic_annotation = |
| 3950 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3951 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3952 | net_log_, CompletionOnceCallback())); |
| 3953 | |
| 3954 | // Ensure that session is alive and active. |
| 3955 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3956 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3957 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3958 | |
| 3959 | // Send GET request on stream. |
| 3960 | HttpResponseInfo response; |
| 3961 | HttpRequestHeaders request_headers; |
| 3962 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3963 | callback_.callback())); |
| 3964 | |
| 3965 | // Run the message loop to receive the out of order packet which contains a |
| 3966 | // FIN and drains the stream. |
| 3967 | base::RunLoop().RunUntilIdle(); |
| 3968 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3969 | |
| 3970 | // Cause the connection to report path degrading to the session. |
| 3971 | // Session should still start to probe the alternate network. |
| 3972 | session->connection()->OnPathDegradingTimeout(); |
| 3973 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3974 | |
| 3975 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3976 | // kDefaultRTTMilliSecs. |
| 3977 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3978 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3979 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3980 | next_task_delay); |
| 3981 | |
| 3982 | // The connection should still be alive, and not marked as going away. |
| 3983 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3984 | |
| 3985 | // Resume quic data and a connectivity probe response will be read on the new |
| 3986 | // socket. |
| 3987 | quic_data2.Resume(); |
| 3988 | |
| 3989 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3990 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 3991 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3992 | EXPECT_EQ(1u, session->GetNumDrainingStreams()); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3993 | |
| 3994 | // There should be three pending tasks, the nearest one will complete |
| 3995 | // migration to the new network. |
| 3996 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3997 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3998 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3999 | task_runner->FastForwardBy(next_task_delay); |
| 4000 | |
| 4001 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4002 | // probe and has been cancelled due to successful migration. |
| 4003 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4004 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4005 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4006 | next_task_delay); |
| 4007 | task_runner->FastForwardBy(next_task_delay); |
| 4008 | |
| 4009 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4010 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4011 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4012 | base::TimeDelta expected_delay = |
| 4013 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4014 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4015 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4016 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4017 | base::RunLoop().RunUntilIdle(); |
| 4018 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4019 | // Deliver a signal that the alternate network now becomes default to session, |
| 4020 | // this will cancel mgirate back to default network timer. |
| 4021 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4022 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4023 | |
| 4024 | task_runner->FastForwardBy(next_task_delay); |
| 4025 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4026 | |
| 4027 | // Verify that the session is still alive. |
| 4028 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4029 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4030 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4031 | |
| 4032 | stream.reset(); |
| 4033 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4034 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4035 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4036 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4037 | } |
| 4038 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4039 | // Regression test for http://crbug.com/835444. |
| 4040 | // This test verifies that the connection migrates to the alternate network |
| 4041 | // when the alternate network is connected after path has been degrading. |
| 4042 | TEST_P(QuicStreamFactoryTest, MigrateOnNewNetworkConnectAfterPathDegrading) { |
| 4043 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4044 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4045 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4046 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4047 | |
| 4048 | // Using a testing task runner so that we can control time. |
| 4049 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4050 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4051 | |
| 4052 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4053 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4054 | |
| 4055 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4056 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4057 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 4058 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4059 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4060 | quic_data1.AddWrite( |
| 4061 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4062 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4063 | true, &header_stream_offset)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4064 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4065 | |
| 4066 | // Set up the second socket data provider that is used after migration. |
| 4067 | // The response to the earlier request is read on the new socket. |
| 4068 | MockQuicData quic_data2; |
| 4069 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4070 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4071 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4072 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4073 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4074 | quic_data2.AddRead(ASYNC, |
| 4075 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4076 | // Ping packet to send after migration is completed. |
| 4077 | quic_data2.AddWrite(ASYNC, |
| 4078 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4079 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4080 | ASYNC, |
| 4081 | ConstructOkResponsePacket( |
| 4082 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4083 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4084 | quic_data2.AddWrite( |
| 4085 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4086 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4087 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4088 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4089 | |
| 4090 | // Create request and QuicHttpStream. |
| 4091 | QuicStreamRequest request(factory_.get()); |
| 4092 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4093 | request.Request( |
| 4094 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4095 | SocketTag(), |
| 4096 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4097 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4098 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4099 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4100 | EXPECT_TRUE(stream.get()); |
| 4101 | |
| 4102 | // Cause QUIC stream to be created. |
| 4103 | HttpRequestInfo request_info; |
| 4104 | request_info.method = "GET"; |
| 4105 | request_info.url = url_; |
| 4106 | request_info.traffic_annotation = |
| 4107 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4108 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4109 | net_log_, CompletionOnceCallback())); |
| 4110 | |
| 4111 | // Ensure that session is alive and active. |
| 4112 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4113 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4114 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4115 | |
| 4116 | // Send GET request on stream. |
| 4117 | HttpResponseInfo response; |
| 4118 | HttpRequestHeaders request_headers; |
| 4119 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4120 | callback_.callback())); |
| 4121 | |
| 4122 | // Cause the connection to report path degrading to the session. |
| 4123 | // Due to lack of alternate network, session will not mgirate connection. |
| 4124 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4125 | session->connection()->OnPathDegradingTimeout(); |
| 4126 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4127 | |
| 4128 | // Deliver a signal that a alternate network is connected now, this should |
| 4129 | // cause the connection to start early migration on path degrading. |
| 4130 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4131 | ->SetConnectedNetworksList( |
| 4132 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4133 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4134 | ->NotifyNetworkConnected(kNewNetworkForTests); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 4135 | |
| 4136 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4137 | // kDefaultRTTMilliSecs. |
| 4138 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4139 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4140 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4141 | next_task_delay); |
| 4142 | |
| 4143 | // The connection should still be alive, and not marked as going away. |
| 4144 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4145 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4146 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4147 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4148 | |
| 4149 | // Resume quic data and a connectivity probe response will be read on the new |
| 4150 | // socket. |
| 4151 | quic_data2.Resume(); |
| 4152 | |
| 4153 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4154 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4155 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4156 | |
| 4157 | // There should be three pending tasks, the nearest one will complete |
| 4158 | // migration to the new network. |
| 4159 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4160 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4161 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4162 | task_runner->FastForwardBy(next_task_delay); |
| 4163 | |
| 4164 | // Response headers are received over the new network. |
| 4165 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4166 | EXPECT_EQ(200, response.headers->response_code()); |
| 4167 | |
| 4168 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4169 | // probe and has been cancelled due to successful migration. |
| 4170 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4171 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4172 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4173 | next_task_delay); |
| 4174 | task_runner->FastForwardBy(next_task_delay); |
| 4175 | |
| 4176 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4177 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4178 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4179 | base::TimeDelta expected_delay = |
| 4180 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4181 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4182 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4183 | |
| 4184 | // Deliver a signal that the alternate network now becomes default to session, |
| 4185 | // this will cancel mgirate back to default network timer. |
| 4186 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4187 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4188 | |
| 4189 | task_runner->FastForwardBy(next_task_delay); |
| 4190 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4191 | |
| 4192 | // Verify that the session is still alive. |
| 4193 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4194 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4195 | |
| 4196 | stream.reset(); |
| 4197 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4198 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4199 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4200 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4201 | } |
| 4202 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4203 | // This test verifies that multiple sessions are migrated on connection |
| 4204 | // migration signal. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4205 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4206 | MigrateMultipleSessionsToBadSocketsAfterDisconnected) { |
| 4207 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4208 | |
| 4209 | MockQuicData socket_data1; |
| 4210 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4211 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4212 | socket_data1.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4213 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4214 | MockQuicData socket_data2; |
| 4215 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4216 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4217 | socket_data2.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4218 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4219 | |
| 4220 | HostPortPair server1(kDefaultServerHostName, 443); |
| 4221 | HostPortPair server2(kServer2HostName, 443); |
| 4222 | |
| 4223 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4224 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4225 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4226 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 4227 | host_resolver_->set_synchronous_mode(true); |
| 4228 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 4229 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.2", ""); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4230 | |
| 4231 | // Create request and QuicHttpStream to create session1. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4232 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4233 | EXPECT_EQ(OK, |
| 4234 | request1.Request( |
| 4235 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4236 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4237 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4238 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4239 | EXPECT_TRUE(stream1.get()); |
| 4240 | |
| 4241 | // Create request and QuicHttpStream to create session2. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4242 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4243 | EXPECT_EQ(OK, |
| 4244 | request2.Request( |
| 4245 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4246 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 4247 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4248 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4249 | EXPECT_TRUE(stream2.get()); |
| 4250 | |
| 4251 | QuicChromiumClientSession* session1 = GetActiveSession(server1); |
| 4252 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 4253 | EXPECT_NE(session1, session2); |
| 4254 | |
| 4255 | // Cause QUIC stream to be created and send GET so session1 has an open |
| 4256 | // stream. |
| 4257 | HttpRequestInfo request_info1; |
| 4258 | request_info1.method = "GET"; |
| 4259 | request_info1.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4260 | request_info1.traffic_annotation = |
| 4261 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4262 | EXPECT_EQ(OK, |
| 4263 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4264 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4265 | HttpResponseInfo response1; |
| 4266 | HttpRequestHeaders request_headers1; |
| 4267 | EXPECT_EQ(OK, stream1->SendRequest(request_headers1, &response1, |
| 4268 | callback_.callback())); |
| 4269 | |
| 4270 | // Cause QUIC stream to be created and send GET so session2 has an open |
| 4271 | // stream. |
| 4272 | HttpRequestInfo request_info2; |
| 4273 | request_info2.method = "GET"; |
| 4274 | request_info2.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4275 | request_info2.traffic_annotation = |
| 4276 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4277 | EXPECT_EQ(OK, |
| 4278 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4279 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4280 | HttpResponseInfo response2; |
| 4281 | HttpRequestHeaders request_headers2; |
| 4282 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4283 | callback_.callback())); |
| 4284 | |
| 4285 | // Cause both sessions to be paused due to DISCONNECTED. |
| 4286 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4287 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 4288 | |
| 4289 | // Ensure that both sessions are paused but alive. |
| 4290 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4291 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4292 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4293 | // Add new sockets to use post migration. Those are bad sockets and will cause |
| 4294 | // migration to fail. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4295 | MockConnect connect_result = |
| 4296 | MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4297 | SequencedSocketData socket_data3(connect_result, base::span<MockRead>(), |
| 4298 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4299 | socket_factory_->AddSocketDataProvider(&socket_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4300 | SequencedSocketData socket_data4(connect_result, base::span<MockRead>(), |
| 4301 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4302 | socket_factory_->AddSocketDataProvider(&socket_data4); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4303 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4304 | // Connect the new network and cause migration to bad sockets, causing |
| 4305 | // sessions to close. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4306 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4307 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 4308 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4309 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 4310 | |
| 4311 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4312 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4313 | |
| 4314 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4315 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4316 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 4317 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 4318 | } |
| 4319 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4320 | // This test verifies that session attempts connection migration with signals |
| 4321 | // delivered in the following order (no alternate network is available): |
| 4322 | // - path degrading is detected: session attempts connection migration but no |
| 4323 | // alternate network is available, session caches path degrading signal in |
| 4324 | // connection and stays on the original network. |
| 4325 | // - original network backs up, request is served in the orignal network, |
| 4326 | // session is not marked as going away. |
| 4327 | TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { |
| 4328 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4329 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4330 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4331 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4332 | MockQuicData quic_data; |
| 4333 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4334 | quic_data.AddWrite(SYNCHRONOUS, |
| 4335 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4336 | quic_data.AddWrite(SYNCHRONOUS, |
| 4337 | ConstructGetRequestPacket( |
| 4338 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4339 | true, &header_stream_offset)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4340 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause for path degrading signal. |
| 4341 | |
| 4342 | // The rest of the data will still flow in the original socket as there is no |
| 4343 | // new network after path degrading. |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4344 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 4345 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4346 | false, false)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4347 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4348 | quic_data.AddWrite( |
| 4349 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4350 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4351 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4352 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4353 | |
| 4354 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4355 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4356 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4357 | request.Request( |
| 4358 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4359 | SocketTag(), |
| 4360 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4361 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4362 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4363 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4364 | EXPECT_TRUE(stream.get()); |
| 4365 | |
| 4366 | // Cause QUIC stream to be created. |
| 4367 | HttpRequestInfo request_info; |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4368 | request_info.method = "GET"; |
| 4369 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4370 | request_info.traffic_annotation = |
| 4371 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4372 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4373 | net_log_, CompletionOnceCallback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4374 | |
| 4375 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4376 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4377 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4378 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4379 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4380 | // Send GET request on stream. |
| 4381 | HttpResponseInfo response; |
| 4382 | HttpRequestHeaders request_headers; |
| 4383 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4384 | callback_.callback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4385 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4386 | // Trigger connection migration on path degrading. Since there are no networks |
| 4387 | // to migrate to, the session will remain on the original network, not marked |
| 4388 | // as going away. |
| 4389 | session->connection()->OnPathDegradingTimeout(); |
| 4390 | EXPECT_TRUE(session->connection()->IsPathDegrading()); |
| 4391 | |
| 4392 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4393 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4394 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4395 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4396 | |
| 4397 | // Resume so that rest of the data will flow in the original socket. |
| 4398 | quic_data.Resume(); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4399 | |
| 4400 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4401 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4402 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4403 | |
| 4404 | stream.reset(); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4405 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 4406 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4407 | } |
| 4408 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4409 | // This test verifies that session with non-migratable stream will probe the |
| 4410 | // alternate network on path degrading, and close the non-migratable streams |
| 4411 | // when probe is successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4412 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4413 | InitializeConnectionMigrationV2Test( |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4414 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4415 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4416 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4417 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4418 | MockQuicData socket_data; |
| 4419 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4420 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4421 | socket_data.AddWrite( |
| 4422 | SYNCHRONOUS, |
| 4423 | client_maker_.MakeRstAckAndConnectionClosePacket( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4424 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Fan Yang | 7c68f63 | 2018-11-06 03:05:38 | [diff] [blame] | 4425 | quic::QUIC_STREAM_CANCELLED, |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4426 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 4427 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4428 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4429 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4430 | // Set up the second socket data provider that is used for probing. |
| 4431 | MockQuicData quic_data1; |
| 4432 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4433 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4434 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4435 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4436 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4437 | quic_data1.AddRead(ASYNC, |
| 4438 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4439 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4440 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4441 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4442 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4443 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4444 | request.Request( |
| 4445 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4446 | SocketTag(), |
| 4447 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4448 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4449 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4450 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4451 | EXPECT_TRUE(stream.get()); |
| 4452 | |
| 4453 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 4454 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 4455 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4456 | request_info.traffic_annotation = |
| 4457 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4458 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4459 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4460 | |
| 4461 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4462 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4463 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4464 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4465 | |
| 4466 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4467 | // this should cause session to be continue without migrating. |
| 4468 | session->OnPathDegrading(); |
| 4469 | |
| 4470 | // Run the message loop so that data queued in the new socket is read by the |
| 4471 | // packet reader. |
| 4472 | base::RunLoop().RunUntilIdle(); |
| 4473 | |
| 4474 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4475 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4476 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4477 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4478 | // Resume the data to read the connectivity probing response to declare probe |
| 4479 | // as successful. Non-migratable streams will be closed. |
| 4480 | quic_data1.Resume(); |
| 4481 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4482 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4483 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4484 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4485 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4486 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4487 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4488 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4489 | } |
| 4490 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4491 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyConnectionMigrationDisabled) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4492 | InitializeConnectionMigrationV2Test( |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4493 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4494 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4495 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4496 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4497 | MockQuicData socket_data; |
| 4498 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4499 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 4500 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4501 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4502 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4503 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4504 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4505 | |
| 4506 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4507 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4508 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4509 | request.Request( |
| 4510 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4511 | SocketTag(), |
| 4512 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4513 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4514 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4515 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4516 | EXPECT_TRUE(stream.get()); |
| 4517 | |
| 4518 | // Cause QUIC stream to be created. |
| 4519 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4520 | request_info.traffic_annotation = |
| 4521 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4522 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4523 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4524 | |
| 4525 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4526 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4527 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4528 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4529 | |
| 4530 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4531 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 4532 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4533 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 4534 | |
| 4535 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4536 | // this should cause session to be continue without migrating. |
| 4537 | session->OnPathDegrading(); |
| 4538 | |
| 4539 | // Run the message loop so that data queued in the new socket is read by the |
| 4540 | // packet reader. |
| 4541 | base::RunLoop().RunUntilIdle(); |
| 4542 | |
| 4543 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4544 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4545 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4546 | |
| 4547 | stream.reset(); |
| 4548 | |
| 4549 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4550 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4551 | } |
| 4552 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4553 | // Regression test for http://crbug.com/791886. |
| 4554 | // This test verifies that the old packet writer which encountered an |
| 4555 | // asynchronous write error will be blocked during migration on write error. New |
| 4556 | // packets would not be written until the one with write error is rewritten on |
| 4557 | // the new network. |
| 4558 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { |
| 4559 | InitializeConnectionMigrationV2Test( |
| 4560 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4561 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4562 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4563 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4564 | |
| 4565 | // Using a testing task runner so that we can control time. |
| 4566 | // base::RunLoop() controls mocked socket writes and reads. |
| 4567 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4568 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4569 | |
| 4570 | MockQuicData socket_data; |
| 4571 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4572 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4573 | socket_data.AddWrite( |
| 4574 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4575 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4576 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4577 | |
| 4578 | // Set up second socket data provider that is used after |
| 4579 | // migration. The request is rewritten to this new socket, and the |
| 4580 | // response to the request is read on this new socket. |
| 4581 | MockQuicData socket_data1; |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4582 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4583 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4584 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4585 | true, &header_stream_offset)); |
| 4586 | socket_data1.AddWrite(SYNCHRONOUS, |
| 4587 | ConstructGetRequestPacket( |
| 4588 | 3, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4589 | GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4590 | true, &header_stream_offset)); |
| 4591 | socket_data1.AddRead( |
| 4592 | ASYNC, |
| 4593 | ConstructOkResponsePacket( |
| 4594 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 4595 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4596 | socket_data1.AddWrite( |
| 4597 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4598 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4599 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4600 | socket_data1.AddWrite( |
| 4601 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4602 | 5, false, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4603 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4604 | |
| 4605 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4606 | |
| 4607 | // Create request #1 and QuicHttpStream. |
| 4608 | QuicStreamRequest request1(factory_.get()); |
| 4609 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4610 | request1.Request( |
| 4611 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4612 | SocketTag(), |
| 4613 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4614 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4615 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4616 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4617 | EXPECT_TRUE(stream1.get()); |
| 4618 | |
| 4619 | HttpRequestInfo request_info1; |
| 4620 | request_info1.method = "GET"; |
| 4621 | request_info1.url = GURL("https://www.example.org/"); |
| 4622 | request_info1.traffic_annotation = |
| 4623 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4624 | EXPECT_EQ(OK, |
| 4625 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4626 | net_log_, CompletionOnceCallback())); |
| 4627 | |
| 4628 | // Request #2 returns synchronously because it pools to existing session. |
| 4629 | TestCompletionCallback callback2; |
| 4630 | QuicStreamRequest request2(factory_.get()); |
| 4631 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 4632 | DEFAULT_PRIORITY, SocketTag(), |
| 4633 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4634 | &net_error_details_, |
| 4635 | failed_on_default_network_callback_, |
| 4636 | callback2.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4637 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 4638 | EXPECT_TRUE(stream2.get()); |
| 4639 | |
| 4640 | HttpRequestInfo request_info2; |
| 4641 | request_info2.method = "GET"; |
| 4642 | request_info2.url = GURL("https://www.example.org/"); |
| 4643 | request_info2.traffic_annotation = |
| 4644 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4645 | EXPECT_EQ(OK, |
| 4646 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 4647 | net_log_, CompletionOnceCallback())); |
| 4648 | |
| 4649 | // Ensure that session is alive and active. |
| 4650 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4651 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4652 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4653 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 4654 | |
| 4655 | // Send GET request on stream1. This should cause an async write error. |
| 4656 | HttpResponseInfo response; |
| 4657 | HttpRequestHeaders request_headers; |
| 4658 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4659 | callback_.callback())); |
| 4660 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4661 | |
| 4662 | // Run the message loop so that asynchronous write completes and a connection |
| 4663 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4664 | // runner. |
| 4665 | base::RunLoop().RunUntilIdle(); |
| 4666 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4667 | |
| 4668 | // Send GET request on stream. This will cause another write attempt before |
| 4669 | // migration on write error is exectued. |
| 4670 | HttpResponseInfo response2; |
| 4671 | HttpRequestHeaders request_headers2; |
| 4672 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4673 | callback2.callback())); |
| 4674 | |
| 4675 | // Run the task runner so that migration on write error is finally executed. |
| 4676 | task_runner->RunUntilIdle(); |
| 4677 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4678 | // Verify the session is still alive and not marked as going away. |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4679 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4680 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4681 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4682 | // There should be one task posted to migrate back to the default network in |
| 4683 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4684 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4685 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 4686 | task_runner->NextPendingTaskDelay()); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4687 | |
| 4688 | // Verify that response headers on the migrated socket were delivered to the |
| 4689 | // stream. |
| 4690 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4691 | EXPECT_EQ(200, response.headers->response_code()); |
| 4692 | |
| 4693 | stream1.reset(); |
| 4694 | stream2.reset(); |
| 4695 | |
| 4696 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4697 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4698 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4699 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4700 | } |
| 4701 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4702 | // Verify session is not marked as going away after connection migration on |
| 4703 | // write error and migrate back to default network logic is applied to bring the |
| 4704 | // migrated session back to the default network. Migration singals delivered |
| 4705 | // in the following order (alternate network is always availabe): |
| 4706 | // - session on the default network encountered a write error; |
| 4707 | // - session successfully migrated to the non-default network; |
| 4708 | // - session attempts to migrate back to default network post migration; |
| 4709 | // - migration back to the default network is successful. |
| 4710 | TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { |
| 4711 | InitializeConnectionMigrationV2Test( |
| 4712 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4713 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4714 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4715 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4716 | |
| 4717 | // Using a testing task runner so that we can control time. |
| 4718 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4719 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4720 | |
| 4721 | MockQuicData socket_data; |
| 4722 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4723 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4724 | socket_data.AddWrite( |
| 4725 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4726 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4727 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4728 | |
| 4729 | // Set up second socket data provider that is used after |
| 4730 | // migration. The request is rewritten to this new socket, and the |
| 4731 | // response to the request is read on this new socket. |
| 4732 | MockQuicData quic_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4733 | quic_data2.AddWrite( |
| 4734 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4735 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4736 | true, &header_stream_offset)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4737 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4738 | ASYNC, |
| 4739 | ConstructOkResponsePacket( |
| 4740 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4741 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4742 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4743 | |
| 4744 | // Create request QuicHttpStream. |
| 4745 | QuicStreamRequest request1(factory_.get()); |
| 4746 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4747 | request1.Request( |
| 4748 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4749 | SocketTag(), |
| 4750 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4751 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4752 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4753 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4754 | EXPECT_TRUE(stream1.get()); |
| 4755 | |
| 4756 | HttpRequestInfo request_info1; |
| 4757 | request_info1.method = "GET"; |
| 4758 | request_info1.url = GURL("https://www.example.org/"); |
| 4759 | request_info1.traffic_annotation = |
| 4760 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4761 | EXPECT_EQ(OK, |
| 4762 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4763 | net_log_, CompletionOnceCallback())); |
| 4764 | |
| 4765 | // Ensure that session is alive and active. |
| 4766 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4767 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4768 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4769 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4770 | |
| 4771 | // Send GET request. This should cause an async write error. |
| 4772 | HttpResponseInfo response; |
| 4773 | HttpRequestHeaders request_headers; |
| 4774 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4775 | callback_.callback())); |
| 4776 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4777 | |
| 4778 | // Run the message loop so that asynchronous write completes and a connection |
| 4779 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4780 | // runner. |
| 4781 | base::RunLoop().RunUntilIdle(); |
| 4782 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4783 | |
| 4784 | // Run the task runner so that migration on write error is finally executed. |
| 4785 | task_runner->RunUntilIdle(); |
| 4786 | |
| 4787 | // Verify the session is still alive and not marked as going away. |
| 4788 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4789 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4790 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4791 | // There should be one task posted to migrate back to the default network in |
| 4792 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4793 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4794 | base::TimeDelta expected_delay = |
| 4795 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 4796 | EXPECT_EQ(expected_delay, task_runner->NextPendingTaskDelay()); |
| 4797 | |
| 4798 | // Verify that response headers on the migrated socket were delivered to the |
| 4799 | // stream. |
| 4800 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4801 | EXPECT_EQ(200, response.headers->response_code()); |
| 4802 | |
| 4803 | // Set up the third socket data provider for migrate back to default network. |
| 4804 | MockQuicData quic_data3; |
| 4805 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4806 | quic_data3.AddWrite(SYNCHRONOUS, |
| 4807 | client_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4808 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4809 | quic_data3.AddRead(ASYNC, |
| 4810 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4811 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4812 | quic_data3.AddWrite(ASYNC, client_maker_.MakeAckPacket(4, 1, 2, 1, 1, true)); |
| 4813 | quic_data3.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4814 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4815 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4816 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4817 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 4818 | |
| 4819 | // Fast forward to fire the migrate back timer and verify the session |
| 4820 | // successfully migrates back to the default network. |
| 4821 | task_runner->FastForwardBy(expected_delay); |
| 4822 | |
| 4823 | // Verify the session is still alive and not marked as going away. |
| 4824 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4825 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4826 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4827 | |
| 4828 | // There should be one task posted to one will resend a connectivity probe and |
| 4829 | // the other will retry migrate back, both are cancelled. |
| 4830 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4831 | task_runner->FastForwardBy( |
| 4832 | base::TimeDelta::FromSeconds(2 * kMinRetryTimeForDefaultNetworkSecs)); |
| 4833 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4834 | |
| 4835 | stream1.reset(); |
| 4836 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4837 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4838 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4839 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4840 | EXPECT_TRUE(quic_data3.AllReadDataConsumed()); |
| 4841 | EXPECT_TRUE(quic_data3.AllWriteDataConsumed()); |
| 4842 | } |
| 4843 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4844 | // This test verifies that the connection will not attempt connection migration |
| 4845 | // (send connectivity probes on alternate path) when path degrading is detected |
| 4846 | // and handshake is not confirmed. |
| 4847 | TEST_P(QuicStreamFactoryTest, |
| 4848 | NoMigrationOnPathDegradingBeforeHandshakeConfirmed) { |
| 4849 | InitializeConnectionMigrationV2Test( |
| 4850 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4851 | |
| 4852 | // Using a testing task runner. |
| 4853 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4854 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4855 | |
| 4856 | // Use cold start mode to send crypto message for handshake. |
| 4857 | crypto_client_stream_factory_.set_handshake_mode( |
| 4858 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4859 | |
| 4860 | MockQuicData socket_data; |
| 4861 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4862 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4863 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4864 | |
| 4865 | // Create request and QuicHttpStream. |
| 4866 | QuicStreamRequest request(factory_.get()); |
| 4867 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4868 | request.Request( |
| 4869 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4870 | SocketTag(), |
| 4871 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4872 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4873 | |
| 4874 | base::RunLoop().RunUntilIdle(); |
| 4875 | |
| 4876 | // Ensure that session is alive but not active. |
| 4877 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4878 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4879 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4880 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4881 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4882 | |
| 4883 | // Cause the connection to report path degrading to the session. |
| 4884 | // Session will ignore the signal as handshake is not completed. |
| 4885 | session->connection()->OnPathDegradingTimeout(); |
| 4886 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4887 | |
| 4888 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4889 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4890 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4891 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4892 | } |
| 4893 | |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4894 | // This test verifies that if a connection is closed with |
| 4895 | // QUIC_NETWORK_IDLE_TIMEOUT before handshake is completed and there is no |
| 4896 | // alternate network, no new connection will be created. |
| 4897 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkBeforeHandshakeOnIdleTimeout) { |
| 4898 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4899 | } |
| 4900 | |
| 4901 | // This test verifies that if a connection is closed with QUIC_HANDSHAKE_TIMEOUT |
| 4902 | // and there is no alternate network, no new connection will be created. |
| 4903 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkOnHandshakeTimeout) { |
| 4904 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4905 | } |
| 4906 | |
| 4907 | void QuicStreamFactoryTestBase::TestNoAlternateNetworkBeforeHandshake( |
| 4908 | quic::QuicErrorCode quic_error) { |
| 4909 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4910 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4911 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4912 | |
| 4913 | // Using a testing task runner. |
| 4914 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4915 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4916 | |
| 4917 | // Use cold start mode to send crypto message for handshake. |
| 4918 | crypto_client_stream_factory_.set_handshake_mode( |
| 4919 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4920 | |
| 4921 | MockQuicData socket_data; |
| 4922 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4923 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4924 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4925 | |
| 4926 | // Create request. |
| 4927 | QuicStreamRequest request(factory_.get()); |
| 4928 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4929 | request.Request( |
| 4930 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4931 | SocketTag(), |
| 4932 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4933 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4934 | |
| 4935 | base::RunLoop().RunUntilIdle(); |
| 4936 | |
| 4937 | // Ensure that session is alive but not active. |
| 4938 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4939 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4940 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4941 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4942 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4943 | |
| 4944 | // Cause the connection to report path degrading to the session. |
| 4945 | // Session will ignore the signal as handshake is not completed. |
| 4946 | session->connection()->OnPathDegradingTimeout(); |
| 4947 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4948 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4949 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4950 | |
| 4951 | // Cause the connection to close due to |quic_error| before handshake. |
| 4952 | quic::QuicString error_details; |
| 4953 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 4954 | error_details = "No recent network activity."; |
| 4955 | } else { |
| 4956 | error_details = "Handshake timeout expired."; |
| 4957 | } |
| 4958 | session->connection()->CloseConnection( |
| 4959 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 4960 | |
| 4961 | // A task will be posted to clean up the session in the factory. |
| 4962 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4963 | task_runner->FastForwardUntilNoTasksRemain(); |
| 4964 | |
| 4965 | // No new session should be created as there is no alternate network. |
| 4966 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4967 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4968 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4969 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4970 | } |
| 4971 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4972 | TEST_P(QuicStreamFactoryTest, NewConnectionBeforeHandshakeAfterIdleTimeout) { |
| 4973 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4974 | quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4975 | } |
| 4976 | |
| 4977 | TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) { |
| 4978 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4979 | quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4980 | } |
| 4981 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 4982 | // Sets up a test to verify that a new connection will be created on the |
| 4983 | // alternate network after the initial connection fails before handshake with |
| 4984 | // signals delivered in the following order (alternate network is available): |
| 4985 | // - the default network is not able to complete crypto handshake; |
| 4986 | // - the original connection is closed with |quic_error|; |
| 4987 | // - a new connection is created on the alternate network and is able to finish |
| 4988 | // crypto handshake; |
| 4989 | // - the new session on the alternate network attempts to migrate back to the |
| 4990 | // default network by sending probes; |
| 4991 | // - default network being disconnected is delivered: session will stop probing |
| 4992 | // the original network. |
| 4993 | // - alternate network is made by default. |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4994 | void QuicStreamFactoryTestBase:: |
| 4995 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4996 | quic::QuicErrorCode quic_error) { |
| 4997 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4998 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 4999 | retry_on_alternate_network_before_handshake_ = true; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5000 | InitializeConnectionMigrationV2Test( |
| 5001 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5002 | |
| 5003 | // Using a testing task runner. |
| 5004 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5005 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 5006 | |
| 5007 | // Use cold start mode to send crypto message for handshake. |
| 5008 | crypto_client_stream_factory_.set_handshake_mode( |
| 5009 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5010 | |
| 5011 | // Socket data for connection on the default network. |
| 5012 | MockQuicData socket_data; |
| 5013 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5014 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 5015 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5016 | |
| 5017 | // Socket data for connection on the alternate network. |
| 5018 | MockQuicData socket_data2; |
| 5019 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5020 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5021 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5022 | // Change the encryption level after handshake is confirmed. |
| 5023 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5024 | socket_data2.AddWrite( |
| 5025 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5026 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5027 | ASYNC, ConstructGetRequestPacket( |
| 5028 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5029 | &header_stream_offset)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5030 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5031 | ASYNC, |
| 5032 | ConstructOkResponsePacket( |
| 5033 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5034 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5035 | socket_data2.AddWrite( |
| 5036 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5037 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5038 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5039 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5040 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5041 | // Socket data for probing on the default network. |
| 5042 | MockQuicData probing_data; |
| 5043 | probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5044 | probing_data.AddWrite(SYNCHRONOUS, |
| 5045 | client_maker_.MakeConnectivityProbingPacket(4, false)); |
| 5046 | probing_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5047 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5048 | // Create request and QuicHttpStream. |
| 5049 | QuicStreamRequest request(factory_.get()); |
| 5050 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5051 | request.Request( |
| 5052 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5053 | SocketTag(), |
| 5054 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5055 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5056 | |
| 5057 | base::RunLoop().RunUntilIdle(); |
| 5058 | |
| 5059 | // Ensure that session is alive but not active. |
| 5060 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5061 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5062 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5063 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5064 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5065 | EXPECT_FALSE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5066 | |
| 5067 | quic::QuicString error_details; |
| 5068 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5069 | error_details = "No recent network activity."; |
| 5070 | } else { |
| 5071 | error_details = "Handshake timeout expired."; |
| 5072 | } |
| 5073 | session->connection()->CloseConnection( |
| 5074 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5075 | |
| 5076 | // A task will be posted to clean up the session in the factory. |
| 5077 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5078 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5079 | |
| 5080 | // Verify a new session is created on the alternate network. |
| 5081 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5082 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5083 | QuicChromiumClientSession* session2 = GetPendingSession(host_port_pair_); |
| 5084 | EXPECT_NE(session, session2); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5085 | EXPECT_TRUE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5086 | |
| 5087 | // Confirm the handshake on the alternate network. |
| 5088 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5089 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5090 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5091 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5092 | // Resume the data now so that data can be sent and read. |
| 5093 | socket_data2.Resume(); |
| 5094 | |
| 5095 | // Create the stream. |
| 5096 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5097 | EXPECT_TRUE(stream.get()); |
| 5098 | HttpRequestInfo request_info; |
| 5099 | request_info.method = "GET"; |
| 5100 | request_info.url = GURL("https://www.example.org/"); |
| 5101 | request_info.traffic_annotation = |
| 5102 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5103 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5104 | net_log_, CompletionOnceCallback())); |
| 5105 | // Send the request. |
| 5106 | HttpResponseInfo response; |
| 5107 | HttpRequestHeaders request_headers; |
| 5108 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5109 | callback_.callback())); |
| 5110 | // Run the message loop to finish asynchronous mock write. |
| 5111 | base::RunLoop().RunUntilIdle(); |
| 5112 | // Read the response. |
| 5113 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5114 | EXPECT_EQ(200, response.headers->response_code()); |
| 5115 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5116 | // There should be a new task posted to migrate back to the default network. |
| 5117 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5118 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5119 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 5120 | next_task_delay); |
| 5121 | task_runner->FastForwardBy(next_task_delay); |
| 5122 | |
| 5123 | // There should be two tasks posted. One will retry probing and the other |
| 5124 | // will retry migrate back. |
| 5125 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 5126 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5127 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 5128 | next_task_delay); |
| 5129 | |
| 5130 | // Deliver the signal that the default network is disconnected. |
| 5131 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5132 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 5133 | // Verify no connectivity probes will be sent as probing will be cancelled. |
| 5134 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5135 | // Deliver the signal that the alternate network is made default. |
| 5136 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5137 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 5138 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5139 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5140 | stream.reset(); |
| 5141 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5142 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5143 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5144 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5145 | } |
| 5146 | |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5147 | // Test that connection will be closed with PACKET_WRITE_ERROR if a write error |
| 5148 | // is triggered before handshake is confirmed and connection migration is turned |
| 5149 | // on. |
| 5150 | TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5151 | DCHECK(!retry_on_alternate_network_before_handshake_); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5152 | InitializeConnectionMigrationV2Test( |
| 5153 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5154 | |
| 5155 | // Use unmocked crypto stream to do crypto connect. |
| 5156 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 5157 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5158 | |
| 5159 | MockQuicData socket_data; |
| 5160 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5161 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5162 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5163 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5164 | |
| 5165 | // Create request, should fail after the write of the CHLO fails. |
| 5166 | QuicStreamRequest request(factory_.get()); |
| 5167 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5168 | request.Request( |
| 5169 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5170 | SocketTag(), |
| 5171 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5172 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5173 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 5174 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5175 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5176 | |
| 5177 | // Verify new requests can be sent normally. |
| 5178 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 5179 | MockCryptoClientStream::COLD_START); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5180 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5181 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5182 | MockQuicData socket_data2; |
| 5183 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5184 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 5185 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5186 | |
| 5187 | QuicStreamRequest request2(factory_.get()); |
| 5188 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5189 | request2.Request( |
| 5190 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5191 | SocketTag(), |
| 5192 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5193 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5194 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5195 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5196 | // Run the message loop to complete host resolution. |
| 5197 | base::RunLoop().RunUntilIdle(); |
| 5198 | |
| 5199 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 5200 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5201 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5202 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5203 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5204 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5205 | |
| 5206 | // Create QuicHttpStream. |
| 5207 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
| 5208 | EXPECT_TRUE(stream.get()); |
| 5209 | stream.reset(); |
| 5210 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5211 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5212 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5213 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5214 | } |
| 5215 | |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5216 | // Test that if the original connection is closed with QUIC_PACKET_WRITE_ERROR |
| 5217 | // before handshake is confirmed and new connection before handshake is turned |
| 5218 | // on, a new connection will be retried on the alternate network. |
| 5219 | TEST_P(QuicStreamFactoryTest, |
| 5220 | RetryConnectionOnWriteErrorBeforeHandshakeConfirmed) { |
| 5221 | retry_on_alternate_network_before_handshake_ = true; |
| 5222 | InitializeConnectionMigrationV2Test( |
| 5223 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5224 | |
| 5225 | // Use unmocked crypto stream to do crypto connect. |
| 5226 | crypto_client_stream_factory_.set_handshake_mode( |
| 5227 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5228 | |
| 5229 | // Socket data for connection on the default network. |
| 5230 | MockQuicData socket_data; |
| 5231 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5232 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5233 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5234 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5235 | |
| 5236 | // Socket data for connection on the alternate network. |
| 5237 | MockQuicData socket_data2; |
| 5238 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5239 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5240 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5241 | // Change the encryption level after handshake is confirmed. |
| 5242 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5243 | socket_data2.AddWrite( |
| 5244 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5245 | socket_data2.AddWrite( |
| 5246 | ASYNC, ConstructGetRequestPacket( |
| 5247 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5248 | &header_stream_offset)); |
| 5249 | socket_data2.AddRead( |
| 5250 | ASYNC, |
| 5251 | ConstructOkResponsePacket( |
| 5252 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5253 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5254 | socket_data2.AddWrite( |
| 5255 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5256 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5257 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5258 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5259 | |
| 5260 | // Create request, should fail after the write of the CHLO fails. |
| 5261 | QuicStreamRequest request(factory_.get()); |
| 5262 | EXPECT_EQ(ERR_IO_PENDING, |
| 5263 | request.Request( |
| 5264 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5265 | SocketTag(), |
| 5266 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5267 | failed_on_default_network_callback_, callback_.callback())); |
| 5268 | // Ensure that the session is alive but not active. |
| 5269 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5270 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5271 | base::RunLoop().RunUntilIdle(); |
| 5272 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5273 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5274 | |
| 5275 | // Confirm the handshake on the alternate network. |
| 5276 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5277 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5278 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5279 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5280 | |
| 5281 | // Resume the data now so that data can be sent and read. |
| 5282 | socket_data2.Resume(); |
| 5283 | |
| 5284 | // Create the stream. |
| 5285 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5286 | EXPECT_TRUE(stream.get()); |
| 5287 | HttpRequestInfo request_info; |
| 5288 | request_info.method = "GET"; |
| 5289 | request_info.url = GURL("https://www.example.org/"); |
| 5290 | request_info.traffic_annotation = |
| 5291 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5292 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5293 | net_log_, CompletionOnceCallback())); |
| 5294 | // Send the request. |
| 5295 | HttpResponseInfo response; |
| 5296 | HttpRequestHeaders request_headers; |
| 5297 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5298 | callback_.callback())); |
| 5299 | // Run the message loop to finish asynchronous mock write. |
| 5300 | base::RunLoop().RunUntilIdle(); |
| 5301 | // Read the response. |
| 5302 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5303 | EXPECT_EQ(200, response.headers->response_code()); |
| 5304 | |
| 5305 | stream.reset(); |
| 5306 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5307 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5308 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5309 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5310 | } |
| 5311 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5312 | void QuicStreamFactoryTestBase::TestMigrationOnWriteError( |
| 5313 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5314 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5315 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5316 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5317 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5318 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5319 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 5320 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5321 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5322 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5323 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5324 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 5325 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5326 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5327 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5328 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5329 | |
| 5330 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5331 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5332 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5333 | request.Request( |
| 5334 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5335 | SocketTag(), |
| 5336 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5337 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5338 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5339 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5340 | EXPECT_TRUE(stream.get()); |
| 5341 | |
| 5342 | // Cause QUIC stream to be created. |
| 5343 | HttpRequestInfo request_info; |
| 5344 | request_info.method = "GET"; |
| 5345 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5346 | request_info.traffic_annotation = |
| 5347 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5348 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5349 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5350 | |
| 5351 | // Ensure that session is alive and active. |
| 5352 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5353 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5354 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5355 | |
| 5356 | // Set up second socket data provider that is used after |
| 5357 | // migration. The request is rewritten to this new socket, and the |
| 5358 | // response to the request is read on this new socket. |
| 5359 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5360 | socket_data1.AddWrite( |
| 5361 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5362 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5363 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5364 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5365 | ASYNC, |
| 5366 | ConstructOkResponsePacket( |
| 5367 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5368 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5369 | socket_data1.AddWrite( |
| 5370 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5371 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5372 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5373 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5374 | |
| 5375 | // Send GET request on stream. This should cause a write error, which triggers |
| 5376 | // a connection migration attempt. |
| 5377 | HttpResponseInfo response; |
| 5378 | HttpRequestHeaders request_headers; |
| 5379 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5380 | callback_.callback())); |
| 5381 | |
| 5382 | // Run the message loop so that the migration attempt is executed and |
| 5383 | // data queued in the new socket is read by the packet reader. |
| 5384 | base::RunLoop().RunUntilIdle(); |
| 5385 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5386 | // Verify that session is alive and not marked as going awya. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5387 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5388 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5389 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5390 | |
| 5391 | // Verify that response headers on the migrated socket were delivered to the |
| 5392 | // stream. |
| 5393 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5394 | EXPECT_EQ(200, response.headers->response_code()); |
| 5395 | |
| 5396 | stream.reset(); |
| 5397 | |
| 5398 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5399 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5400 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5401 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5402 | } |
| 5403 | |
| 5404 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 5405 | TestMigrationOnWriteError(SYNCHRONOUS); |
| 5406 | } |
| 5407 | |
| 5408 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 5409 | TestMigrationOnWriteError(ASYNC); |
| 5410 | } |
| 5411 | |
| 5412 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNoNewNetwork( |
| 5413 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5414 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5415 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5416 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5417 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5418 | // Use the test task runner, to force the migration alarm timeout later. |
| 5419 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 5420 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5421 | MockQuicData socket_data; |
| 5422 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5423 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5424 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5425 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5426 | |
| 5427 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5428 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5429 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5430 | request.Request( |
| 5431 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5432 | SocketTag(), |
| 5433 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5434 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5435 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5436 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5437 | EXPECT_TRUE(stream.get()); |
| 5438 | |
| 5439 | // Cause QUIC stream to be created. |
| 5440 | HttpRequestInfo request_info; |
| 5441 | request_info.method = "GET"; |
| 5442 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5443 | request_info.traffic_annotation = |
| 5444 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5445 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5446 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5447 | |
| 5448 | // Ensure that session is alive and active. |
| 5449 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5450 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5451 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5452 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5453 | // Send GET request on stream. This causes a write error, which triggers |
| 5454 | // a connection migration attempt. Since there are no networks |
| 5455 | // to migrate to, this causes the session to wait for a new network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5456 | HttpResponseInfo response; |
| 5457 | HttpRequestHeaders request_headers; |
| 5458 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5459 | callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5460 | |
| 5461 | // Complete any pending writes. Pending async MockQuicData writes |
| 5462 | // are run on the message loop, not on the test runner. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5463 | base::RunLoop().RunUntilIdle(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5464 | |
| 5465 | // Write error causes migration task to be posted. Spin the loop. |
| 5466 | if (write_error_mode == ASYNC) |
| 5467 | runner_->RunNextTask(); |
| 5468 | |
| 5469 | // Migration has not yet failed. The session should be alive and active. |
| 5470 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5471 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5472 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5473 | EXPECT_TRUE(session->connection()->writer()->IsWriteBlocked()); |
| 5474 | |
| 5475 | // The migration will not fail until the migration alarm timeout. |
| 5476 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5477 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5478 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5479 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 5480 | |
| 5481 | // Force migration alarm timeout to run. |
| 5482 | RunTestLoopUntilIdle(); |
| 5483 | |
| 5484 | // The connection should be closed. A request for response headers |
| 5485 | // should fail. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5486 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5487 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5488 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
| 5489 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 5490 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5491 | |
Zhongyi Shi | 59aaf07 | 2019-01-17 03:32:13 | [diff] [blame] | 5492 | NetErrorDetails error_details; |
| 5493 | stream->PopulateNetErrorDetails(&error_details); |
| 5494 | EXPECT_EQ(error_details.quic_connection_error, |
| 5495 | quic::QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
| 5496 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5497 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5498 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5499 | } |
| 5500 | |
| 5501 | TEST_P(QuicStreamFactoryTest, |
| 5502 | MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 5503 | TestMigrationOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 5504 | } |
| 5505 | |
| 5506 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 5507 | TestMigrationOnWriteErrorNoNewNetwork(ASYNC); |
| 5508 | } |
| 5509 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5510 | TEST_P(QuicStreamFactoryTest, |
| 5511 | MigrateSessionOnWriteErrorWithMultipleRequestsSync) { |
| 5512 | TestMigrationOnWriteErrorWithMultipleRequests(SYNCHRONOUS); |
| 5513 | } |
| 5514 | |
| 5515 | TEST_P(QuicStreamFactoryTest, |
| 5516 | MigrateSessionOnWriteErrorWithMultipleRequestsAsync) { |
| 5517 | TestMigrationOnWriteErrorWithMultipleRequests(ASYNC); |
| 5518 | } |
| 5519 | |
| 5520 | // Sets up a test which verifies that connection migration on write error can |
| 5521 | // eventually succeed and rewrite the packet on the new network with *multiple* |
| 5522 | // migratable streams. |
| 5523 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( |
| 5524 | IoMode write_error_mode) { |
| 5525 | InitializeConnectionMigrationV2Test( |
| 5526 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5527 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5528 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5529 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5530 | |
| 5531 | MockQuicData socket_data; |
| 5532 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5533 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5534 | socket_data.AddWrite( |
| 5535 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5536 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5537 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5538 | |
| 5539 | // Set up second socket data provider that is used after |
| 5540 | // migration. The request is rewritten to this new socket, and the |
| 5541 | // response to the request is read on this new socket. |
| 5542 | MockQuicData socket_data1; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5543 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5544 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5545 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5546 | true, &header_stream_offset)); |
| 5547 | socket_data1.AddRead( |
| 5548 | ASYNC, |
| 5549 | ConstructOkResponsePacket( |
| 5550 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5551 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5552 | socket_data1.AddWrite( |
| 5553 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5554 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5555 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5556 | socket_data1.AddWrite( |
| 5557 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 5558 | 4, false, GetNthClientInitiatedBidirectionalStreamId(1), |
| 5559 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5560 | |
| 5561 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5562 | |
| 5563 | // Create request #1 and QuicHttpStream. |
| 5564 | QuicStreamRequest request1(factory_.get()); |
| 5565 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5566 | request1.Request( |
| 5567 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5568 | SocketTag(), |
| 5569 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5570 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5571 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5572 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5573 | EXPECT_TRUE(stream1.get()); |
| 5574 | |
| 5575 | HttpRequestInfo request_info1; |
| 5576 | request_info1.method = "GET"; |
| 5577 | request_info1.url = GURL("https://www.example.org/"); |
| 5578 | request_info1.traffic_annotation = |
| 5579 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5580 | EXPECT_EQ(OK, |
| 5581 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5582 | net_log_, CompletionOnceCallback())); |
| 5583 | |
| 5584 | // Second request returns synchronously because it pools to existing session. |
| 5585 | TestCompletionCallback callback2; |
| 5586 | QuicStreamRequest request2(factory_.get()); |
| 5587 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5588 | DEFAULT_PRIORITY, SocketTag(), |
| 5589 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5590 | &net_error_details_, |
| 5591 | failed_on_default_network_callback_, |
| 5592 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5593 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5594 | EXPECT_TRUE(stream2.get()); |
| 5595 | HttpRequestInfo request_info2; |
| 5596 | request_info2.method = "GET"; |
| 5597 | request_info2.url = GURL("https://www.example.org/"); |
| 5598 | request_info2.traffic_annotation = |
| 5599 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5600 | EXPECT_EQ(OK, |
| 5601 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5602 | net_log_, CompletionOnceCallback())); |
| 5603 | |
| 5604 | // Ensure that session is alive and active. |
| 5605 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5606 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5607 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5608 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5609 | |
| 5610 | // Send GET request on stream. This should cause a write error, which triggers |
| 5611 | // a connection migration attempt. |
| 5612 | HttpResponseInfo response; |
| 5613 | HttpRequestHeaders request_headers; |
| 5614 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5615 | callback_.callback())); |
| 5616 | |
| 5617 | // Run the message loop so that the migration attempt is executed and |
| 5618 | // data queued in the new socket is read by the packet reader. |
| 5619 | base::RunLoop().RunUntilIdle(); |
| 5620 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5621 | // Verify session is still alive and not marked as going away. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5622 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5623 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5624 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5625 | |
| 5626 | // Verify that response headers on the migrated socket were delivered to the |
| 5627 | // stream. |
| 5628 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5629 | EXPECT_EQ(200, response.headers->response_code()); |
| 5630 | |
| 5631 | stream1.reset(); |
| 5632 | stream2.reset(); |
| 5633 | |
| 5634 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5635 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5636 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5637 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5638 | } |
| 5639 | |
| 5640 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsSync) { |
| 5641 | TestMigrationOnWriteErrorMixedStreams(SYNCHRONOUS); |
| 5642 | } |
| 5643 | |
| 5644 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsAsync) { |
| 5645 | TestMigrationOnWriteErrorMixedStreams(ASYNC); |
| 5646 | } |
| 5647 | |
| 5648 | // Sets up a test that verifies connection migration manages to migrate to |
| 5649 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5650 | // |write_error_mode| on the original network. |
| 5651 | // Note there are mixed types of unfinished requests before migration: one |
| 5652 | // migratable and one non-migratable. The *migratable* one triggers write |
| 5653 | // error. |
| 5654 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( |
| 5655 | IoMode write_error_mode) { |
| 5656 | InitializeConnectionMigrationV2Test( |
| 5657 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5658 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5659 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5660 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5661 | |
| 5662 | int packet_number = 1; |
| 5663 | MockQuicData socket_data; |
| 5664 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5665 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5666 | socket_data.AddWrite( |
| 5667 | SYNCHRONOUS, |
| 5668 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5669 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5670 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5671 | |
| 5672 | // Set up second socket data provider that is used after |
| 5673 | // migration. The request is rewritten to this new socket, and the |
| 5674 | // response to the request is read on this new socket. |
| 5675 | MockQuicData socket_data1; |
| 5676 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5677 | SYNCHRONOUS, |
| 5678 | ConstructGetRequestPacket(packet_number++, |
| 5679 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5680 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5681 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5682 | SYNCHRONOUS, |
| 5683 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5684 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5685 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5686 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5687 | ASYNC, |
| 5688 | ConstructOkResponsePacket( |
| 5689 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5690 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5691 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5692 | SYNCHRONOUS, |
| 5693 | client_maker_.MakeAckAndRstPacket( |
| 5694 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5695 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5696 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5697 | |
| 5698 | // Create request #1 and QuicHttpStream. |
| 5699 | QuicStreamRequest request1(factory_.get()); |
| 5700 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5701 | request1.Request( |
| 5702 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5703 | SocketTag(), |
| 5704 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5705 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5706 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5707 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5708 | EXPECT_TRUE(stream1.get()); |
| 5709 | |
| 5710 | HttpRequestInfo request_info1; |
| 5711 | request_info1.method = "GET"; |
| 5712 | request_info1.url = GURL("https://www.example.org/"); |
| 5713 | request_info1.traffic_annotation = |
| 5714 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5715 | EXPECT_EQ(OK, |
| 5716 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5717 | net_log_, CompletionOnceCallback())); |
| 5718 | |
| 5719 | // Second request returns synchronously because it pools to existing session. |
| 5720 | TestCompletionCallback callback2; |
| 5721 | QuicStreamRequest request2(factory_.get()); |
| 5722 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5723 | DEFAULT_PRIORITY, SocketTag(), |
| 5724 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5725 | &net_error_details_, |
| 5726 | failed_on_default_network_callback_, |
| 5727 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5728 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5729 | EXPECT_TRUE(stream2.get()); |
| 5730 | |
| 5731 | HttpRequestInfo request_info2; |
| 5732 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5733 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5734 | request_info2.url = GURL("https://www.example.org/"); |
| 5735 | request_info2.traffic_annotation = |
| 5736 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5737 | EXPECT_EQ(OK, |
| 5738 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5739 | net_log_, CompletionOnceCallback())); |
| 5740 | |
| 5741 | // Ensure that session is alive and active. |
| 5742 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5743 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5744 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5745 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5746 | |
| 5747 | // Send GET request on stream 1. This should cause a write error, which |
| 5748 | // triggers a connection migration attempt. |
| 5749 | HttpResponseInfo response; |
| 5750 | HttpRequestHeaders request_headers; |
| 5751 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5752 | callback_.callback())); |
| 5753 | |
| 5754 | // Run the message loop so that the migration attempt is executed and |
| 5755 | // data queued in the new socket is read by the packet reader. |
| 5756 | base::RunLoop().RunUntilIdle(); |
| 5757 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5758 | // Verify that the session is still alive and not marked as going away. |
| 5759 | // Non-migratable stream should be closed due to migration. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5760 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5761 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5762 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5763 | |
| 5764 | // Verify that response headers on the migrated socket were delivered to the |
| 5765 | // stream. |
| 5766 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5767 | EXPECT_EQ(200, response.headers->response_code()); |
| 5768 | |
| 5769 | stream1.reset(); |
| 5770 | |
| 5771 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5772 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5773 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5774 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5775 | } |
| 5776 | |
| 5777 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Sync) { |
| 5778 | TestMigrationOnWriteErrorMixedStreams2(SYNCHRONOUS); |
| 5779 | } |
| 5780 | |
| 5781 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Async) { |
| 5782 | TestMigrationOnWriteErrorMixedStreams2(ASYNC); |
| 5783 | } |
| 5784 | |
| 5785 | // The one triggers write error is a non-migratable stream. |
| 5786 | // Sets up a test that verifies connection migration manages to migrate to |
| 5787 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5788 | // |write_error_mode| on the original network. |
| 5789 | // Note there are mixed types of unfinished requests before migration: one |
| 5790 | // migratable and one non-migratable. The *non-migratable* one triggers write |
| 5791 | // error. |
| 5792 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( |
| 5793 | IoMode write_error_mode) { |
| 5794 | InitializeConnectionMigrationV2Test( |
| 5795 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5796 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5797 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5798 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5799 | |
| 5800 | int packet_number = 1; |
| 5801 | MockQuicData socket_data; |
| 5802 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5803 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5804 | socket_data.AddWrite( |
| 5805 | SYNCHRONOUS, |
| 5806 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5807 | socket_data.AddWrite(write_error_mode, |
| 5808 | ERR_ADDRESS_UNREACHABLE); // Write error. |
| 5809 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5810 | |
| 5811 | // Set up second socket data provider that is used after |
| 5812 | // migration. The request is rewritten to this new socket, and the |
| 5813 | // response to the request is read on this new socket. |
| 5814 | MockQuicData socket_data1; |
| 5815 | // The packet triggered writer error will be sent anyway even if the stream |
| 5816 | // will be cancelled later. |
| 5817 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5818 | SYNCHRONOUS, |
| 5819 | ConstructGetRequestPacket(packet_number++, |
| 5820 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5821 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5822 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5823 | SYNCHRONOUS, |
| 5824 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5825 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5826 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5827 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5828 | SYNCHRONOUS, |
| 5829 | ConstructGetRequestPacket(packet_number++, |
| 5830 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5831 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5832 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5833 | ASYNC, |
| 5834 | ConstructOkResponsePacket( |
| 5835 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5836 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5837 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5838 | SYNCHRONOUS, |
| 5839 | client_maker_.MakeAckAndRstPacket( |
| 5840 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5841 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5842 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5843 | |
| 5844 | // Create request #1 and QuicHttpStream. |
| 5845 | QuicStreamRequest request1(factory_.get()); |
| 5846 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5847 | request1.Request( |
| 5848 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5849 | SocketTag(), |
| 5850 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5851 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5852 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5853 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5854 | EXPECT_TRUE(stream1.get()); |
| 5855 | |
| 5856 | HttpRequestInfo request_info1; |
| 5857 | request_info1.method = "GET"; |
| 5858 | request_info1.url = GURL("https://www.example.org/"); |
| 5859 | request_info1.traffic_annotation = |
| 5860 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5861 | EXPECT_EQ(OK, |
| 5862 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5863 | net_log_, CompletionOnceCallback())); |
| 5864 | |
| 5865 | // Second request returns synchronously because it pools to existing session. |
| 5866 | TestCompletionCallback callback2; |
| 5867 | QuicStreamRequest request2(factory_.get()); |
| 5868 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5869 | DEFAULT_PRIORITY, SocketTag(), |
| 5870 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5871 | &net_error_details_, |
| 5872 | failed_on_default_network_callback_, |
| 5873 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5874 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5875 | EXPECT_TRUE(stream2.get()); |
| 5876 | |
| 5877 | HttpRequestInfo request_info2; |
| 5878 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5879 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5880 | request_info2.url = GURL("https://www.example.org/"); |
| 5881 | request_info2.traffic_annotation = |
| 5882 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5883 | EXPECT_EQ(OK, |
| 5884 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5885 | net_log_, CompletionOnceCallback())); |
| 5886 | |
| 5887 | // Ensure that session is alive and active. |
| 5888 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5889 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5890 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5891 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5892 | |
| 5893 | // Send GET request on stream 2 which is non-migratable. This should cause a |
| 5894 | // write error, which triggers a connection migration attempt. |
| 5895 | HttpResponseInfo response2; |
| 5896 | HttpRequestHeaders request_headers2; |
| 5897 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 5898 | callback2.callback())); |
| 5899 | |
| 5900 | // Run the message loop so that the migration attempt is executed and |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5901 | // data queued in the new socket is read by the packet reader. Session is |
| 5902 | // still alive and not marked as going away, non-migratable stream will be |
| 5903 | // closed. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5904 | base::RunLoop().RunUntilIdle(); |
| 5905 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5906 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5907 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5908 | |
| 5909 | // Send GET request on stream 1. |
| 5910 | HttpResponseInfo response; |
| 5911 | HttpRequestHeaders request_headers; |
| 5912 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5913 | callback_.callback())); |
| 5914 | |
| 5915 | base::RunLoop().RunUntilIdle(); |
| 5916 | |
| 5917 | // Verify that response headers on the migrated socket were delivered to the |
| 5918 | // stream. |
| 5919 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5920 | EXPECT_EQ(200, response.headers->response_code()); |
| 5921 | |
| 5922 | stream1.reset(); |
| 5923 | |
| 5924 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5925 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5926 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5927 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5928 | } |
| 5929 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5930 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( |
| 5931 | IoMode write_error_mode) { |
| 5932 | DVLOG(1) << "Mode: " |
| 5933 | << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5934 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5935 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5936 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5937 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5938 | |
| 5939 | MockQuicData socket_data; |
| 5940 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5941 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5942 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5943 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5944 | |
| 5945 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5946 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5947 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5948 | request.Request( |
| 5949 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5950 | SocketTag(), |
| 5951 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5952 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5953 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5954 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5955 | EXPECT_TRUE(stream.get()); |
| 5956 | |
| 5957 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 5958 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5959 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5960 | request_info.method = "GET"; |
| 5961 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5962 | request_info.traffic_annotation = |
| 5963 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5964 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5965 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5966 | |
| 5967 | // Ensure that session is alive and active. |
| 5968 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5969 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5970 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5971 | |
| 5972 | // Send GET request on stream. This should cause a write error, which triggers |
| 5973 | // a connection migration attempt. |
| 5974 | HttpResponseInfo response; |
| 5975 | HttpRequestHeaders request_headers; |
| 5976 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5977 | callback_.callback())); |
| 5978 | |
| 5979 | // Run message loop to execute migration attempt. |
| 5980 | base::RunLoop().RunUntilIdle(); |
| 5981 | |
| 5982 | // Migration fails, and session is closed and deleted. |
| 5983 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5984 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5985 | |
| 5986 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5987 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5988 | } |
| 5989 | |
| 5990 | TEST_P(QuicStreamFactoryTest, |
| 5991 | MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { |
| 5992 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS); |
| 5993 | } |
| 5994 | |
| 5995 | TEST_P(QuicStreamFactoryTest, |
| 5996 | MigrateSessionOnWriteErrorNonMigratableStreamAsync) { |
| 5997 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC); |
| 5998 | } |
| 5999 | |
| 6000 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( |
| 6001 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6002 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6003 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6004 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6005 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6006 | |
| 6007 | MockQuicData socket_data; |
| 6008 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6009 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6010 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6011 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6012 | |
| 6013 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6014 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6015 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6016 | request.Request( |
| 6017 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6018 | SocketTag(), |
| 6019 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6020 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6021 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6022 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6023 | EXPECT_TRUE(stream.get()); |
| 6024 | |
| 6025 | // Cause QUIC stream to be created. |
| 6026 | HttpRequestInfo request_info; |
| 6027 | request_info.method = "GET"; |
| 6028 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6029 | request_info.traffic_annotation = |
| 6030 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6031 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6032 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6033 | |
| 6034 | // Ensure that session is alive and active. |
| 6035 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6036 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6037 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6038 | |
| 6039 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6040 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 6041 | session->config()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6042 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 6043 | |
| 6044 | // Send GET request on stream. This should cause a write error, which triggers |
| 6045 | // a connection migration attempt. |
| 6046 | HttpResponseInfo response; |
| 6047 | HttpRequestHeaders request_headers; |
| 6048 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6049 | callback_.callback())); |
| 6050 | // Run message loop to execute migration attempt. |
| 6051 | base::RunLoop().RunUntilIdle(); |
| 6052 | // Migration fails, and session is closed and deleted. |
| 6053 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6054 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6055 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6056 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6057 | } |
| 6058 | |
| 6059 | TEST_P(QuicStreamFactoryTest, |
| 6060 | MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 6061 | TestMigrationOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 6062 | } |
| 6063 | |
| 6064 | TEST_P(QuicStreamFactoryTest, |
| 6065 | MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 6066 | TestMigrationOnWriteErrorMigrationDisabled(ASYNC); |
| 6067 | } |
| 6068 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6069 | // Sets up a test which verifies that connection migration on write error can |
| 6070 | // eventually succeed and rewrite the packet on the new network with singals |
| 6071 | // delivered in the following order (alternate network is always availabe): |
| 6072 | // - original network encounters a SYNC/ASYNC write error based on |
| 6073 | // |write_error_mode_on_old_network|, the packet failed to be written is |
| 6074 | // cached, session migrates immediately to the alternate network. |
| 6075 | // - an immediate SYNC/ASYNC write error based on |
| 6076 | // |write_error_mode_on_new_network| is encountered after migration to the |
| 6077 | // alternate network, session migrates immediately to the original network. |
| 6078 | // - an immediate SYNC/ASYNC write error based on |
| 6079 | // |write_error_mode_on_old_network| is encountered after migration to the |
| 6080 | // original network, session migrates immediately to the alternate network. |
| 6081 | // - finally, session successfully sends the packet and reads the response on |
| 6082 | // the alternate network. |
| 6083 | // TODO(zhongyi): once https://crbug.com/855666 is fixed, this test should be |
| 6084 | // modified to test that session is closed early if hopping between networks |
| 6085 | // with consecutive write errors is detected. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6086 | void QuicStreamFactoryTestBase::TestMigrationOnMultipleWriteErrors( |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6087 | IoMode write_error_mode_on_old_network, |
| 6088 | IoMode write_error_mode_on_new_network) { |
| 6089 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6090 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6091 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6092 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6093 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6094 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6095 | // Set up the socket data used by the original network, which encounters a |
| 6096 | // write erorr. |
| 6097 | MockQuicData socket_data1; |
| 6098 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6099 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6100 | socket_data1.AddWrite( |
| 6101 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6102 | socket_data1.AddWrite(write_error_mode_on_old_network, |
| 6103 | ERR_ADDRESS_UNREACHABLE); // Write Error |
| 6104 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6105 | |
| 6106 | // Set up the socket data used by the alternate network, which also |
| 6107 | // encounters a write error. |
| 6108 | MockQuicData failed_quic_data2; |
| 6109 | failed_quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6110 | failed_quic_data2.AddWrite(write_error_mode_on_new_network, ERR_FAILED); |
| 6111 | failed_quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 6112 | |
| 6113 | // Set up the third socket data used by original network, which encounters a |
| 6114 | // write error again. |
| 6115 | MockQuicData failed_quic_data1; |
| 6116 | failed_quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6117 | failed_quic_data1.AddWrite(write_error_mode_on_old_network, ERR_FAILED); |
| 6118 | failed_quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6119 | |
| 6120 | // Set up the last socket data used by the alternate network, which will |
| 6121 | // finish migration successfully. The request is rewritten to this new socket, |
| 6122 | // and the response to the request is read on this socket. |
| 6123 | MockQuicData socket_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6124 | socket_data2.AddWrite( |
| 6125 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6126 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6127 | true, &header_stream_offset)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6128 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6129 | ASYNC, |
| 6130 | ConstructOkResponsePacket( |
| 6131 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6132 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6133 | socket_data2.AddWrite( |
| 6134 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6135 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6136 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6137 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6138 | |
| 6139 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6140 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6141 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6142 | request.Request( |
| 6143 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6144 | SocketTag(), |
| 6145 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6146 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6147 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6148 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6149 | EXPECT_TRUE(stream.get()); |
| 6150 | |
| 6151 | // Cause QUIC stream to be created. |
| 6152 | HttpRequestInfo request_info; |
| 6153 | request_info.method = "GET"; |
| 6154 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6155 | request_info.traffic_annotation = |
| 6156 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6157 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6158 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6159 | |
| 6160 | // Ensure that session is alive and active. |
| 6161 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6162 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6163 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6164 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6165 | // Send GET request on stream. |
| 6166 | // This should encounter a write error on network 1, |
| 6167 | // then migrate to network 2, which encounters another write error, |
| 6168 | // and migrate again to network 1, which encoutners one more write error. |
| 6169 | // Finally the session migrates to network 2 successfully. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6170 | HttpResponseInfo response; |
| 6171 | HttpRequestHeaders request_headers; |
| 6172 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6173 | callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6174 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6175 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6176 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6177 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6178 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6179 | // Verify that response headers on the migrated socket were delivered to the |
| 6180 | // stream. |
| 6181 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6182 | EXPECT_EQ(200, response.headers->response_code()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6183 | |
| 6184 | stream.reset(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6185 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6186 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6187 | EXPECT_TRUE(failed_quic_data2.AllReadDataConsumed()); |
| 6188 | EXPECT_TRUE(failed_quic_data2.AllWriteDataConsumed()); |
| 6189 | EXPECT_TRUE(failed_quic_data1.AllReadDataConsumed()); |
| 6190 | EXPECT_TRUE(failed_quic_data1.AllWriteDataConsumed()); |
| 6191 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 6192 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6196 | TestMigrationOnMultipleWriteErrors( |
| 6197 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6198 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6202 | TestMigrationOnMultipleWriteErrors( |
| 6203 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6204 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6208 | TestMigrationOnMultipleWriteErrors( |
| 6209 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6210 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6211 | } |
| 6212 | |
| 6213 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6214 | TestMigrationOnMultipleWriteErrors( |
| 6215 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6216 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6217 | } |
| 6218 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6219 | // Verifies that a connection is closed when connection migration is triggered |
| 6220 | // on network being disconnected and the handshake is not confirmed. |
| 6221 | TEST_P(QuicStreamFactoryTest, NoMigrationBeforeHandshakeOnNetworkDisconnected) { |
| 6222 | InitializeConnectionMigrationV2Test( |
| 6223 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6224 | |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6225 | // 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] | 6226 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6227 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6228 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6229 | MockQuicData socket_data; |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6230 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5068bb0 | 2018-08-03 02:44:09 | [diff] [blame] | 6231 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6232 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6233 | |
| 6234 | // Create request and QuicHttpStream. |
| 6235 | QuicStreamRequest request(factory_.get()); |
| 6236 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6237 | request.Request( |
| 6238 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6239 | SocketTag(), |
| 6240 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6241 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6242 | // Deliver the network notification, which should cause the connection to be |
| 6243 | // closed. |
| 6244 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6245 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6246 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6247 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6248 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6249 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6250 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6251 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6252 | } |
| 6253 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6254 | // Sets up the connection migration test where network change notification is |
| 6255 | // queued BEFORE connection migration attempt on write error is posted. |
| 6256 | void QuicStreamFactoryTestBase:: |
| 6257 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6258 | bool disconnected) { |
| 6259 | InitializeConnectionMigrationV2Test( |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6260 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6261 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6262 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6263 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6264 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6265 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6266 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6267 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6268 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6269 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6270 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6271 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6272 | |
| 6273 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6274 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6275 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6276 | request.Request( |
| 6277 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6278 | SocketTag(), |
| 6279 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6280 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6281 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6282 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6283 | EXPECT_TRUE(stream.get()); |
| 6284 | |
| 6285 | // Cause QUIC stream to be created. |
| 6286 | HttpRequestInfo request_info; |
| 6287 | request_info.method = "GET"; |
| 6288 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6289 | request_info.traffic_annotation = |
| 6290 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6291 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6292 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6293 | |
| 6294 | // Ensure that session is alive and active. |
| 6295 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6296 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6297 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6298 | |
| 6299 | // Set up second socket data provider that is used after |
| 6300 | // migration. The request is rewritten to this new socket, and the |
| 6301 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6302 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6303 | socket_data1.AddWrite( |
| 6304 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6305 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6306 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6307 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6308 | ASYNC, |
| 6309 | ConstructOkResponsePacket( |
| 6310 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6311 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6312 | socket_data1.AddWrite( |
| 6313 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6314 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6315 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6316 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6317 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6318 | // First queue a network change notification in the message loop. |
| 6319 | if (disconnected) { |
| 6320 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6321 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6322 | } else { |
| 6323 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6324 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6325 | } |
| 6326 | // Send GET request on stream. This should cause a write error, |
| 6327 | // which triggers a connection migration attempt. This will queue a |
| 6328 | // migration attempt behind the notification in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6329 | HttpResponseInfo response; |
| 6330 | HttpRequestHeaders request_headers; |
| 6331 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6332 | callback_.callback())); |
| 6333 | |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6334 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6335 | // Verify the session is still alive and not marked as going away post |
| 6336 | // migration. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6337 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6338 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6339 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6340 | |
| 6341 | // Verify that response headers on the migrated socket were delivered to the |
| 6342 | // stream. |
| 6343 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6344 | EXPECT_EQ(200, response.headers->response_code()); |
| 6345 | |
| 6346 | stream.reset(); |
| 6347 | |
| 6348 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6349 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6350 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6351 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6352 | } |
| 6353 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6354 | // This test verifies that session attempts connection migration successfully |
| 6355 | // with signals delivered in the following order (alternate network is always |
| 6356 | // available): |
| 6357 | // - a notification that default network is disconnected is queued. |
| 6358 | // - write error is triggered: session posts a task to attempt connection |
| 6359 | // migration, |migration_pending_| set to true. |
| 6360 | // - default network disconnected is delivered: session immediately migrates to |
| 6361 | // the alternate network, |migration_pending_| set to false. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6362 | // - connection migration on write error attempt aborts: writer encountered |
| 6363 | // error is no longer in active use. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6364 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6365 | MigrateOnNetworkDisconnectedWithWriteErrorQueuedLater) { |
| 6366 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6367 | /*disconnected=*/true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6368 | } |
| 6369 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6370 | // This test verifies that session attempts connection migration successfully |
| 6371 | // with signals delivered in the following order (alternate network is always |
| 6372 | // available): |
| 6373 | // - a notification that alternate network is made default is queued. |
| 6374 | // - write error is triggered: session posts a task to attempt connection |
| 6375 | // migration, block future migrations. |
| 6376 | // - new default notification is delivered: migrate back timer spins and task is |
| 6377 | // posted to migrate to the new default network. |
| 6378 | // - connection migration on write error attempt proceeds successfully: session |
| 6379 | // is |
| 6380 | // marked as going away, future migrations unblocked. |
| 6381 | // - migrate back to default network task executed: session is already on the |
| 6382 | // default network, no-op. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6383 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6384 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedEarlier) { |
| 6385 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6386 | /*disconnected=*/false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6387 | } |
| 6388 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6389 | // Sets up the connection migration test where network change notification is |
| 6390 | // queued AFTER connection migration attempt on write error is posted. |
| 6391 | void QuicStreamFactoryTestBase:: |
| 6392 | TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6393 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6394 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6395 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6396 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6397 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6398 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6399 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6400 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6401 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6402 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6403 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6404 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6405 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6406 | |
| 6407 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6408 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6409 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6410 | request.Request( |
| 6411 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6412 | SocketTag(), |
| 6413 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6414 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6415 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6416 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6417 | EXPECT_TRUE(stream.get()); |
| 6418 | |
| 6419 | // Cause QUIC stream to be created. |
| 6420 | HttpRequestInfo request_info; |
| 6421 | request_info.method = "GET"; |
| 6422 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6423 | request_info.traffic_annotation = |
| 6424 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6425 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6426 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6427 | |
| 6428 | // Ensure that session is alive and active. |
| 6429 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6430 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6431 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6432 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6433 | // Set up second socket data provider that is used after |
| 6434 | // migration. The request is rewritten to this new socket, and the |
| 6435 | // response to the request is read on this new socket. |
| 6436 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6437 | socket_data1.AddWrite( |
| 6438 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6439 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6440 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6441 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6442 | ASYNC, |
| 6443 | ConstructOkResponsePacket( |
| 6444 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6445 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6446 | socket_data1.AddWrite( |
| 6447 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6448 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6449 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6450 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6451 | |
| 6452 | // Send GET request on stream. This should cause a write error, |
| 6453 | // which triggers a connection migration attempt. This will queue a |
| 6454 | // migration attempt in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6455 | HttpResponseInfo response; |
| 6456 | HttpRequestHeaders request_headers; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6457 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6458 | callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6459 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6460 | // Now queue a network change notification in the message loop behind |
| 6461 | // the migration attempt. |
| 6462 | if (disconnected) { |
| 6463 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6464 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6465 | } else { |
| 6466 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6467 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6468 | } |
| 6469 | |
| 6470 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6471 | // Verify session is still alive and not marked as going away. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6472 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6473 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6474 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6475 | |
| 6476 | // Verify that response headers on the migrated socket were delivered to the |
| 6477 | // stream. |
| 6478 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6479 | EXPECT_EQ(200, response.headers->response_code()); |
| 6480 | |
| 6481 | stream.reset(); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6482 | |
| 6483 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6484 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6485 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6486 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6487 | } |
| 6488 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6489 | // This test verifies that session attempts connection migration successfully |
| 6490 | // with signals delivered in the following order (alternate network is always |
| 6491 | // available): |
| 6492 | // - write error is triggered: session posts a task to complete connection |
| 6493 | // migration. |
| 6494 | // - a notification that alternate network is made default is queued. |
| 6495 | // - connection migration attempt proceeds successfully, session is marked as |
| 6496 | // going away. |
| 6497 | // - new default notification is delivered after connection migration has been |
| 6498 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6499 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6500 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedLater) { |
| 6501 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/false); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6502 | } |
| 6503 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6504 | // This test verifies that session attempts connection migration successfully |
| 6505 | // with signals delivered in the following order (alternate network is always |
| 6506 | // available): |
| 6507 | // - write error is triggered: session posts a task to complete connection |
| 6508 | // migration. |
| 6509 | // - a notification that default network is diconnected is queued. |
| 6510 | // - connection migration attempt proceeds successfully, session is marked as |
| 6511 | // going away. |
| 6512 | // - disconnect notification is delivered after connection migration has been |
| 6513 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6514 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6515 | MigrateOnWriteErrorWithNetworkDisconnectedQueuedLater) { |
| 6516 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/true); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6517 | } |
| 6518 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6519 | // This tests connection migration on write error with signals delivered in the |
| 6520 | // following order: |
| 6521 | // - a synchronous/asynchronous write error is triggered base on |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6522 | // |write_error_mode|: connection migration attempt is posted. |
| 6523 | // - old default network disconnects, migration waits for a new network. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6524 | // - after a pause, new network is connected: session will migrate to new |
| 6525 | // network immediately. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6526 | // - migration on writer error is exectued and aborts as writer passed in is no |
| 6527 | // longer active in use. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6528 | // - new network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6529 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorPauseBeforeConnected( |
| 6530 | IoMode write_error_mode) { |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6531 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6532 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6533 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6534 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6535 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6536 | // Use the test task runner. |
| 6537 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 6538 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6539 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6540 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6541 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6542 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6543 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6544 | socket_data.AddWrite(write_error_mode, ERR_FAILED); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6545 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6546 | |
| 6547 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6548 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6549 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6550 | request.Request( |
| 6551 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6552 | SocketTag(), |
| 6553 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6554 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6555 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6556 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6557 | EXPECT_TRUE(stream.get()); |
| 6558 | |
| 6559 | // Cause QUIC stream to be created. |
| 6560 | HttpRequestInfo request_info; |
| 6561 | request_info.method = "GET"; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6562 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6563 | request_info.traffic_annotation = |
| 6564 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6565 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6566 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6567 | |
| 6568 | // Ensure that session is alive and active. |
| 6569 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6570 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6571 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6572 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6573 | // Send GET request on stream. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6574 | HttpResponseInfo response; |
| 6575 | HttpRequestHeaders request_headers; |
| 6576 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6577 | callback_.callback())); |
| 6578 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6579 | // The connection should still be alive, not marked as going away. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6580 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6581 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6582 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6583 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6584 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6585 | // Set up second socket data provider that is used after migration. |
| 6586 | // The response to the earlier request is read on this new socket. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6587 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6588 | socket_data1.AddWrite( |
| 6589 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6590 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6591 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6592 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6593 | ASYNC, |
| 6594 | ConstructOkResponsePacket( |
| 6595 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6596 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6597 | socket_data1.AddWrite( |
| 6598 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6599 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6600 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6601 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6602 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6603 | // On a DISCONNECTED notification, nothing happens. |
| 6604 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6605 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6606 | // Add a new network and notify the stream factory of a new connected network. |
| 6607 | // This causes a PING packet to be sent over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6608 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6609 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 6610 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6611 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 6612 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6613 | // Ensure that the session is still alive. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6614 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6615 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6616 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6617 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6618 | // Run the message loop migration for write error can finish. |
| 6619 | runner_->RunUntilIdle(); |
| 6620 | |
| 6621 | // Response headers are received over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6622 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6623 | EXPECT_EQ(200, response.headers->response_code()); |
| 6624 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6625 | // Check that the session is still alive. |
| 6626 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6627 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6628 | |
| 6629 | // There should be no posted tasks not executed, no way to migrate back to |
| 6630 | // default network. |
| 6631 | EXPECT_TRUE(runner_->GetPostedTasks().empty()); |
| 6632 | |
| 6633 | // Receive signal to mark new network as default. |
| 6634 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6635 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6636 | |
| 6637 | stream.reset(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6638 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6639 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6640 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6641 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6642 | } |
| 6643 | |
| 6644 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6645 | MigrateSessionOnSyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6646 | TestMigrationOnWriteErrorPauseBeforeConnected(SYNCHRONOUS); |
| 6647 | } |
| 6648 | |
| 6649 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6650 | MigrateSessionOnAsyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6651 | TestMigrationOnWriteErrorPauseBeforeConnected(ASYNC); |
| 6652 | } |
| 6653 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6654 | // This test verifies that when session successfully migrate to the alternate |
| 6655 | // network, packet write error on the old writer will be ignored and will not |
| 6656 | // trigger connection migration on write error. |
| 6657 | TEST_P(QuicStreamFactoryTest, IgnoreWriteErrorFromOldWriterAfterMigration) { |
| 6658 | InitializeConnectionMigrationV2Test( |
| 6659 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6660 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6661 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6662 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6663 | |
| 6664 | // Using a testing task runner so that we can verify whether the migrate on |
| 6665 | // write error task is posted. |
| 6666 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6667 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6668 | |
| 6669 | MockQuicData socket_data; |
| 6670 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6671 | socket_data.AddWrite( |
| 6672 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6673 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6674 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6675 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6676 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6677 | |
| 6678 | // Create request and QuicHttpStream. |
| 6679 | QuicStreamRequest request(factory_.get()); |
| 6680 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6681 | request.Request( |
| 6682 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6683 | SocketTag(), |
| 6684 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6685 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6686 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6687 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6688 | EXPECT_TRUE(stream.get()); |
| 6689 | |
| 6690 | // Cause QUIC stream to be created. |
| 6691 | HttpRequestInfo request_info; |
| 6692 | request_info.method = "GET"; |
| 6693 | request_info.url = GURL("https://www.example.org/"); |
| 6694 | request_info.traffic_annotation = |
| 6695 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6696 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6697 | net_log_, CompletionOnceCallback())); |
| 6698 | |
| 6699 | // Ensure that session is alive and active. |
| 6700 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6701 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6702 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6703 | |
| 6704 | // Set up second socket data provider that is used after |
| 6705 | // migration. The response to the request is read on this new socket. |
| 6706 | MockQuicData socket_data1; |
| 6707 | socket_data1.AddWrite( |
| 6708 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 6709 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6710 | ASYNC, |
| 6711 | ConstructOkResponsePacket( |
| 6712 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6713 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6714 | socket_data1.AddWrite( |
| 6715 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6716 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6717 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6718 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6719 | |
| 6720 | // Send GET request on stream. |
| 6721 | HttpResponseInfo response; |
| 6722 | HttpRequestHeaders request_headers; |
| 6723 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6724 | callback_.callback())); |
| 6725 | |
| 6726 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6727 | // Now notify network is disconnected, cause the migration to complete |
| 6728 | // immediately. |
| 6729 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6730 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6731 | // There will be two pending task, one will complete migration with no delay |
| 6732 | // and the other will attempt to migrate back to the default network with |
| 6733 | // delay. |
| 6734 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6735 | |
| 6736 | // Complete migration. |
| 6737 | task_runner->RunUntilIdle(); |
| 6738 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6739 | |
| 6740 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6741 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6742 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6743 | |
| 6744 | // Verify that response headers on the migrated socket were delivered to the |
| 6745 | // stream. |
| 6746 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6747 | EXPECT_EQ(200, response.headers->response_code()); |
| 6748 | |
| 6749 | // Resume the old socket data, a write error will be delivered to the old |
| 6750 | // packet writer. Verify no additional task is posted. |
| 6751 | socket_data.Resume(); |
| 6752 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6753 | |
| 6754 | stream.reset(); |
| 6755 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6756 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6757 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6758 | } |
| 6759 | |
| 6760 | // This test verifies that when session successfully migrate to the alternate |
| 6761 | // network, packet read error on the old reader will be ignored and will not |
| 6762 | // close the connection. |
| 6763 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorFromOldReaderAfterMigration) { |
| 6764 | InitializeConnectionMigrationV2Test( |
| 6765 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6766 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6767 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6768 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6769 | |
| 6770 | // Using a testing task runner. |
| 6771 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6772 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6773 | |
| 6774 | MockQuicData socket_data; |
| 6775 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6776 | socket_data.AddWrite( |
| 6777 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6778 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6779 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6780 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6781 | |
| 6782 | // Create request and QuicHttpStream. |
| 6783 | QuicStreamRequest request(factory_.get()); |
| 6784 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6785 | request.Request( |
| 6786 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6787 | SocketTag(), |
| 6788 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6789 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6790 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6791 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6792 | EXPECT_TRUE(stream.get()); |
| 6793 | |
| 6794 | // Cause QUIC stream to be created. |
| 6795 | HttpRequestInfo request_info; |
| 6796 | request_info.method = "GET"; |
| 6797 | request_info.url = GURL("https://www.example.org/"); |
| 6798 | request_info.traffic_annotation = |
| 6799 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6800 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6801 | net_log_, CompletionOnceCallback())); |
| 6802 | |
| 6803 | // Ensure that session is alive and active. |
| 6804 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6805 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6806 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6807 | |
| 6808 | // Set up second socket data provider that is used after |
| 6809 | // migration. The request is written to this new socket, and the |
| 6810 | // response to the request is read on this new socket. |
| 6811 | MockQuicData socket_data1; |
| 6812 | socket_data1.AddWrite( |
| 6813 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6814 | socket_data1.AddWrite( |
| 6815 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6816 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6817 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6818 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6819 | ASYNC, |
| 6820 | ConstructOkResponsePacket( |
| 6821 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6822 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6823 | socket_data1.AddWrite( |
| 6824 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6825 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6826 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6827 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6828 | |
| 6829 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6830 | // Now notify network is disconnected, cause the migration to complete |
| 6831 | // immediately. |
| 6832 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6833 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6834 | // There will be two pending task, one will complete migration with no delay |
| 6835 | // and the other will attempt to migrate back to the default network with |
| 6836 | // delay. |
| 6837 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6838 | |
| 6839 | // Complete migration. |
| 6840 | task_runner->RunUntilIdle(); |
| 6841 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6842 | |
| 6843 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6844 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6845 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6846 | |
| 6847 | // Send GET request on stream. |
| 6848 | HttpResponseInfo response; |
| 6849 | HttpRequestHeaders request_headers; |
| 6850 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6851 | callback_.callback())); |
| 6852 | |
| 6853 | // Verify that response headers on the migrated socket were delivered to the |
| 6854 | // stream. |
| 6855 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6856 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6857 | EXPECT_EQ(200, response.headers->response_code()); |
| 6858 | |
| 6859 | // Resume the old socket data, a read error will be delivered to the old |
| 6860 | // packet reader. Verify that the session is not affected. |
| 6861 | socket_data.Resume(); |
| 6862 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6863 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6864 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6865 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6866 | |
| 6867 | stream.reset(); |
| 6868 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6869 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6870 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6871 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6872 | } |
| 6873 | |
| 6874 | // This test verifies that after migration on network is executed, packet |
| 6875 | // read error on the old reader will be ignored and will not close the |
| 6876 | // connection. |
| 6877 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorOnOldReaderDuringMigration) { |
| 6878 | InitializeConnectionMigrationV2Test( |
| 6879 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6880 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6881 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6882 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6883 | |
| 6884 | // Using a testing task runner. |
| 6885 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6886 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6887 | |
| 6888 | MockQuicData socket_data; |
| 6889 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6890 | socket_data.AddWrite( |
| 6891 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6892 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6893 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6894 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6895 | |
| 6896 | // Create request and QuicHttpStream. |
| 6897 | QuicStreamRequest request(factory_.get()); |
| 6898 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6899 | request.Request( |
| 6900 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6901 | SocketTag(), |
| 6902 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6903 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6904 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6905 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6906 | EXPECT_TRUE(stream.get()); |
| 6907 | |
| 6908 | // Cause QUIC stream to be created. |
| 6909 | HttpRequestInfo request_info; |
| 6910 | request_info.method = "GET"; |
| 6911 | request_info.url = GURL("https://www.example.org/"); |
| 6912 | request_info.traffic_annotation = |
| 6913 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6914 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6915 | net_log_, CompletionOnceCallback())); |
| 6916 | |
| 6917 | // Ensure that session is alive and active. |
| 6918 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6919 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6920 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6921 | |
| 6922 | // Set up second socket data provider that is used after |
| 6923 | // migration. The request is written to this new socket, and the |
| 6924 | // response to the request is read on this new socket. |
| 6925 | MockQuicData socket_data1; |
| 6926 | socket_data1.AddWrite( |
| 6927 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6928 | socket_data1.AddWrite( |
| 6929 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6930 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6931 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6932 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6933 | ASYNC, |
| 6934 | ConstructOkResponsePacket( |
| 6935 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6936 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6937 | socket_data1.AddWrite( |
| 6938 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6939 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6940 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6941 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6942 | |
| 6943 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6944 | // Now notify network is disconnected, cause the migration to complete |
| 6945 | // immediately. |
| 6946 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6947 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6948 | // There will be two pending task, one will complete migration with no delay |
| 6949 | // and the other will attempt to migrate back to the default network with |
| 6950 | // delay. |
| 6951 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6952 | |
| 6953 | // Resume the old socket data, a read error will be delivered to the old |
| 6954 | // packet reader. Verify that the session is not affected. |
| 6955 | socket_data.Resume(); |
| 6956 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6957 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6958 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6959 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6960 | |
| 6961 | // Complete migration. |
| 6962 | task_runner->RunUntilIdle(); |
| 6963 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6964 | |
| 6965 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6966 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6967 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6968 | |
| 6969 | // Send GET request on stream. |
| 6970 | HttpResponseInfo response; |
| 6971 | HttpRequestHeaders request_headers; |
| 6972 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6973 | callback_.callback())); |
| 6974 | |
| 6975 | // Verify that response headers on the migrated socket were delivered to the |
| 6976 | // stream. |
| 6977 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6978 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6979 | EXPECT_EQ(200, response.headers->response_code()); |
| 6980 | |
| 6981 | stream.reset(); |
| 6982 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6983 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6984 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6985 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6986 | } |
| 6987 | |
| 6988 | // This test verifies that after migration on write error is posted, packet |
| 6989 | // read error on the old reader will be ignored and will not close the |
| 6990 | // connection. |
| 6991 | TEST_P(QuicStreamFactoryTest, |
| 6992 | IgnoreReadErrorOnOldReaderDuringPendingMigrationOnWriteError) { |
| 6993 | InitializeConnectionMigrationV2Test( |
| 6994 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6995 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6996 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6997 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6998 | |
| 6999 | // Using a testing task runner. |
| 7000 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 7001 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 7002 | |
| 7003 | MockQuicData socket_data; |
| 7004 | quic::QuicStreamOffset header_stream_offset = 0; |
| 7005 | socket_data.AddWrite( |
| 7006 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 7007 | socket_data.AddWrite(ASYNC, ERR_FAILED); // Write error. |
| 7008 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); // Read error. |
| 7009 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 7010 | |
| 7011 | // Create request and QuicHttpStream. |
| 7012 | QuicStreamRequest request(factory_.get()); |
| 7013 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7014 | request.Request( |
| 7015 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7016 | SocketTag(), |
| 7017 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7018 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7019 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7020 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 7021 | EXPECT_TRUE(stream.get()); |
| 7022 | |
| 7023 | // Cause QUIC stream to be created. |
| 7024 | HttpRequestInfo request_info; |
| 7025 | request_info.method = "GET"; |
| 7026 | request_info.url = GURL("https://www.example.org/"); |
| 7027 | request_info.traffic_annotation = |
| 7028 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7029 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 7030 | net_log_, CompletionOnceCallback())); |
| 7031 | |
| 7032 | // Ensure that session is alive and active. |
| 7033 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7034 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7035 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7036 | |
| 7037 | // Set up second socket data provider that is used after |
| 7038 | // migration. The request is written to this new socket, and the |
| 7039 | // response to the request is read on this new socket. |
| 7040 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7041 | socket_data1.AddWrite( |
| 7042 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7043 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7044 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7045 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7046 | ASYNC, |
| 7047 | ConstructOkResponsePacket( |
| 7048 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7049 | |
| 7050 | socket_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 7051 | socket_data1.AddRead(ASYNC, ERR_FAILED); // Read error to close connection. |
| 7052 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7053 | |
| 7054 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7055 | // Send GET request on stream. |
| 7056 | HttpResponseInfo response; |
| 7057 | HttpRequestHeaders request_headers; |
| 7058 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7059 | callback_.callback())); |
| 7060 | // Run the message loop to complete asynchronous write and read with errors. |
| 7061 | base::RunLoop().RunUntilIdle(); |
| 7062 | // There will be one pending task to complete migration on write error. |
| 7063 | // Verify session is not closed with read error. |
| 7064 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7065 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7066 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7067 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7068 | |
| 7069 | // Complete migration. |
| 7070 | task_runner->RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7071 | // There will be one more task posted attempting to migrate back to the |
| 7072 | // default network. |
| 7073 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7074 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7075 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7076 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7077 | |
| 7078 | // Verify that response headers on the migrated socket were delivered to the |
| 7079 | // stream. |
| 7080 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7081 | EXPECT_EQ(200, response.headers->response_code()); |
| 7082 | |
| 7083 | // Resume to consume the read error on new socket, which will close |
| 7084 | // the connection. |
| 7085 | socket_data1.Resume(); |
| 7086 | |
| 7087 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7088 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7089 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7090 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7091 | } |
| 7092 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7093 | // Migrate on asynchronous write error, old network disconnects after alternate |
| 7094 | // network connects. |
| 7095 | TEST_P(QuicStreamFactoryTest, |
| 7096 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectAysnc) { |
| 7097 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7098 | ASYNC, /*disconnect_before_connect*/ false); |
| 7099 | } |
| 7100 | |
| 7101 | // Migrate on synchronous write error, old network disconnects after alternate |
| 7102 | // network connects. |
| 7103 | TEST_P(QuicStreamFactoryTest, |
| 7104 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectSync) { |
| 7105 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7106 | SYNCHRONOUS, /*disconnect_before_connect*/ false); |
| 7107 | } |
| 7108 | |
| 7109 | // Migrate on asynchronous write error, old network disconnects before alternate |
| 7110 | // network connects. |
| 7111 | TEST_P(QuicStreamFactoryTest, |
| 7112 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectAysnc) { |
| 7113 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7114 | ASYNC, /*disconnect_before_connect*/ true); |
| 7115 | } |
| 7116 | |
| 7117 | // Migrate on synchronous write error, old network disconnects before alternate |
| 7118 | // network connects. |
| 7119 | TEST_P(QuicStreamFactoryTest, |
| 7120 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectSync) { |
| 7121 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7122 | SYNCHRONOUS, /*disconnect_before_connect*/ true); |
| 7123 | } |
| 7124 | |
| 7125 | // Setps up test which verifies that session successfully migrate to alternate |
| 7126 | // network with signals delivered in the following order: |
| 7127 | // *NOTE* Signal (A) and (B) can reverse order based on |
| 7128 | // |disconnect_before_connect|. |
| 7129 | // - (No alternate network is connected) session connects to |
| 7130 | // kDefaultNetworkForTests. |
| 7131 | // - An async/sync write error is encountered based on |write_error_mode|: |
| 7132 | // session posted task to migrate session on write error. |
| 7133 | // - Posted task is executed, miration moves to pending state due to lack of |
| 7134 | // alternate network. |
| 7135 | // - (A) An alternate network is connected, pending migration completes. |
| 7136 | // - (B) Old default network disconnects, no migration will be attempted as |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7137 | // session has already migrate to the alternate network. |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7138 | // - The alternate network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7139 | void QuicStreamFactoryTestBase:: |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7140 | TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7141 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7142 | bool disconnect_before_connect) { |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7143 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7144 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7145 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7146 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7147 | |
| 7148 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7149 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7150 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7151 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7152 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7153 | socket_data.AddWrite(write_error_mode, ERR_FAILED); // Write error. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7154 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7155 | |
| 7156 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7157 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7158 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7159 | request.Request( |
| 7160 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7161 | SocketTag(), |
| 7162 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7163 | failed_on_default_network_callback_, callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7164 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7165 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7166 | EXPECT_TRUE(stream.get()); |
| 7167 | |
| 7168 | // Cause QUIC stream to be created. |
| 7169 | HttpRequestInfo request_info; |
| 7170 | request_info.method = "GET"; |
| 7171 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7172 | request_info.traffic_annotation = |
| 7173 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7174 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7175 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7176 | |
| 7177 | // Ensure that session is alive and active. |
| 7178 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7179 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7180 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7181 | |
| 7182 | // Send GET request on stream. This should cause a write error, which triggers |
| 7183 | // a connection migration attempt. |
| 7184 | HttpResponseInfo response; |
| 7185 | HttpRequestHeaders request_headers; |
| 7186 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7187 | callback_.callback())); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7188 | // Run the message loop so that posted task to migrate to socket will be |
| 7189 | // executed. A new task will be posted to wait for a new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7190 | base::RunLoop().RunUntilIdle(); |
| 7191 | |
| 7192 | // In this particular code path, the network will not yet be marked |
| 7193 | // as going away and the session will still be alive. |
| 7194 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7195 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7196 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7197 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7198 | |
| 7199 | // Set up second socket data provider that is used after |
| 7200 | // migration. The request is rewritten to this new socket, and the |
| 7201 | // response to the request is read on this new socket. |
| 7202 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7203 | socket_data1.AddWrite( |
| 7204 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7205 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7206 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7207 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7208 | ASYNC, |
| 7209 | ConstructOkResponsePacket( |
| 7210 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7211 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7212 | socket_data1.AddWrite( |
| 7213 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7214 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7215 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7216 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7217 | |
| 7218 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7219 | ->SetConnectedNetworksList( |
| 7220 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7221 | if (disconnect_before_connect) { |
| 7222 | // Now deliver a DISCONNECT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7223 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7224 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7225 | |
| 7226 | // Now deliver a CONNECTED notification and completes migration. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7227 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7228 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7229 | } else { |
| 7230 | // Now deliver a CONNECTED notification and completes migration. |
| 7231 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7232 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7233 | |
| 7234 | // Now deliver a DISCONNECT notification. |
| 7235 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7236 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7237 | } |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7238 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7239 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7240 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7241 | |
| 7242 | // This is the callback for the response headers that returned |
| 7243 | // pending previously, because no result was available. Check that |
| 7244 | // the result is now available due to the successful migration. |
| 7245 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7246 | EXPECT_EQ(200, response.headers->response_code()); |
| 7247 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7248 | // Deliver a MADEDEFAULT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7249 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7250 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7251 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7252 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7253 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 7254 | DEFAULT_PRIORITY, SocketTag(), |
| 7255 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7256 | &net_error_details_, |
| 7257 | failed_on_default_network_callback_, |
| 7258 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7259 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7260 | EXPECT_TRUE(stream2.get()); |
| 7261 | |
| 7262 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7263 | EXPECT_EQ(session, GetActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7264 | |
| 7265 | stream.reset(); |
| 7266 | stream2.reset(); |
| 7267 | |
| 7268 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7269 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7270 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7271 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7272 | } |
| 7273 | |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7274 | TEST_P(QuicStreamFactoryTest, ServerMigration) { |
| 7275 | allow_server_migration_ = true; |
| 7276 | Initialize(); |
| 7277 | |
| 7278 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7279 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7280 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7281 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7282 | MockQuicData socket_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7283 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7284 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7285 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7286 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7287 | socket_data1.AddWrite( |
| 7288 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7289 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7290 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7291 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7292 | |
| 7293 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7294 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7295 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7296 | request.Request( |
| 7297 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7298 | SocketTag(), |
| 7299 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7300 | failed_on_default_network_callback_, callback_.callback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7301 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7302 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7303 | EXPECT_TRUE(stream.get()); |
| 7304 | |
| 7305 | // Cause QUIC stream to be created. |
| 7306 | HttpRequestInfo request_info; |
| 7307 | request_info.method = "GET"; |
| 7308 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7309 | request_info.traffic_annotation = |
| 7310 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7311 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7312 | net_log_, CompletionOnceCallback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7313 | |
| 7314 | // Ensure that session is alive and active. |
| 7315 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7316 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7317 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7318 | |
| 7319 | // Send GET request on stream. |
| 7320 | HttpResponseInfo response; |
| 7321 | HttpRequestHeaders request_headers; |
| 7322 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7323 | callback_.callback())); |
| 7324 | |
| 7325 | IPEndPoint ip; |
| 7326 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7327 | DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 7328 | << ip.port(); |
| 7329 | |
| 7330 | // Set up second socket data provider that is used after |
| 7331 | // migration. The request is rewritten to this new socket, and the |
| 7332 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7333 | MockQuicData socket_data2; |
| 7334 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7335 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 7336 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7337 | ASYNC, |
| 7338 | ConstructOkResponsePacket( |
| 7339 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7340 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7341 | socket_data2.AddWrite( |
| 7342 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7343 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7344 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7345 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7346 | |
| 7347 | const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 7348 | const uint16_t kTestPort = 123; |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 7349 | session->Migrate(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 7350 | IPEndPoint(IPAddress(kTestIpAddress), kTestPort), true, |
| 7351 | net_log_); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7352 | |
| 7353 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7354 | DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 7355 | << ip.port(); |
| 7356 | |
| 7357 | // The session should be alive and active. |
| 7358 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7359 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7360 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7361 | |
| 7362 | // Run the message loop so that data queued in the new socket is read by the |
| 7363 | // packet reader. |
| 7364 | base::RunLoop().RunUntilIdle(); |
| 7365 | |
| 7366 | // Verify that response headers on the migrated socket were delivered to the |
| 7367 | // stream. |
| 7368 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7369 | EXPECT_EQ(200, response.headers->response_code()); |
| 7370 | |
| 7371 | stream.reset(); |
| 7372 | |
| 7373 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7374 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7375 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7376 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7377 | } |
| 7378 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7379 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv4) { |
| 7380 | // Add alternate IPv4 server address to config. |
| 7381 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7382 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7383 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7384 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7385 | VerifyServerMigration(config, alt_address); |
| 7386 | } |
| 7387 | |
| 7388 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv6) { |
| 7389 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7390 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7391 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7392 | // Add alternate IPv6 server address to config. |
| 7393 | IPEndPoint alt_address = IPEndPoint( |
| 7394 | 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] | 7395 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7396 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7397 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7398 | VerifyServerMigration(config, alt_address); |
| 7399 | } |
| 7400 | |
| 7401 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { |
| 7402 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7403 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7404 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7405 | // Add alternate IPv4 server address to config. |
| 7406 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7407 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7408 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7409 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7410 | IPEndPoint expected_address( |
| 7411 | ConvertIPv4ToIPv4MappedIPv6(alt_address.address()), alt_address.port()); |
| 7412 | VerifyServerMigration(config, expected_address); |
| 7413 | } |
| 7414 | |
| 7415 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { |
| 7416 | allow_server_migration_ = true; |
| 7417 | Initialize(); |
| 7418 | |
| 7419 | // Add a resolver rule to make initial connection to an IPv4 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7420 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), "1.2.3.4", |
| 7421 | ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7422 | // Add alternate IPv6 server address to config. |
| 7423 | IPEndPoint alt_address = IPEndPoint( |
| 7424 | 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] | 7425 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7426 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7427 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7428 | |
| 7429 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7430 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7431 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7432 | |
| 7433 | crypto_client_stream_factory_.SetConfig(config); |
| 7434 | |
| 7435 | // Set up only socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7436 | MockQuicData socket_data1; |
| 7437 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7438 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7439 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7440 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7441 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7442 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7443 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7444 | |
| 7445 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7446 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7447 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7448 | request.Request( |
| 7449 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7450 | SocketTag(), |
| 7451 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7452 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7453 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7454 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7455 | EXPECT_TRUE(stream.get()); |
| 7456 | |
| 7457 | // Cause QUIC stream to be created. |
| 7458 | HttpRequestInfo request_info; |
| 7459 | request_info.method = "GET"; |
| 7460 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7461 | request_info.traffic_annotation = |
| 7462 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7463 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7464 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7465 | |
| 7466 | // Ensure that session is alive and active. |
| 7467 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7468 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7469 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7470 | |
| 7471 | IPEndPoint actual_address; |
| 7472 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 7473 | // No migration should have happened. |
| 7474 | IPEndPoint expected_address = |
| 7475 | IPEndPoint(IPAddress(1, 2, 3, 4), kDefaultServerPort); |
| 7476 | EXPECT_EQ(actual_address, expected_address); |
| 7477 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 7478 | << " " << actual_address.port(); |
| 7479 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 7480 | << " " << expected_address.port(); |
| 7481 | |
| 7482 | stream.reset(); |
| 7483 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7484 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7485 | } |
| 7486 | |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 7487 | TEST_P(QuicStreamFactoryTest, OnCertDBChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7488 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7489 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7490 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7491 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7492 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7493 | MockQuicData socket_data; |
| 7494 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7495 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7496 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7497 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7498 | MockQuicData socket_data2; |
| 7499 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7500 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7501 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7502 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7503 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7504 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7505 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7506 | request.Request( |
| 7507 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7508 | SocketTag(), |
| 7509 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7510 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7511 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7512 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7513 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7514 | EXPECT_TRUE(stream); |
| 7515 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7516 | |
| 7517 | // Change the CA cert and verify that stream saw the event. |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 7518 | factory_->OnCertDBChanged(); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7519 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7520 | EXPECT_FALSE(factory_->require_confirmation()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7521 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7522 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7523 | |
| 7524 | // Now attempting to request a stream to the same origin should create |
| 7525 | // a new session. |
| 7526 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7527 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7528 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7529 | request2.Request( |
| 7530 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7531 | SocketTag(), |
| 7532 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7533 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7534 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7535 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7536 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 7537 | EXPECT_TRUE(stream2); |
| 7538 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 7539 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7540 | EXPECT_NE(session, session2); |
| 7541 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7542 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 7543 | |
| 7544 | stream2.reset(); |
| 7545 | stream.reset(); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7546 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7547 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7548 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7549 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7550 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7551 | } |
| 7552 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7553 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7554 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7555 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7556 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7557 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7558 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7559 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7560 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7561 | string r1_host_name("r1"); |
| 7562 | string r2_host_name("r2"); |
| 7563 | r1_host_name.append(cannoncial_suffixes[i]); |
| 7564 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7565 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7566 | HostPortPair host_port_pair1(r1_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7567 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7568 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7569 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7570 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7571 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7572 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7573 | EXPECT_FALSE(cached1->proof_valid()); |
| 7574 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7575 | |
| 7576 | // Mutate the cached1 to have different data. |
| 7577 | // TODO(rtenneti): mutate other members of CachedState. |
| 7578 | cached1->set_source_address_token(r1_host_name); |
| 7579 | cached1->SetProofValid(); |
| 7580 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7581 | HostPortPair host_port_pair2(r2_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7582 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7583 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7584 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7585 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7586 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 7587 | EXPECT_TRUE(cached2->proof_valid()); |
| 7588 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7589 | } |
| 7590 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7591 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7592 | Initialize(); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7593 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7594 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7595 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7596 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7597 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7598 | string r3_host_name("r3"); |
| 7599 | string r4_host_name("r4"); |
| 7600 | r3_host_name.append(cannoncial_suffixes[i]); |
| 7601 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7602 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7603 | HostPortPair host_port_pair1(r3_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7604 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7605 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7606 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7607 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7608 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7609 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7610 | EXPECT_FALSE(cached1->proof_valid()); |
| 7611 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7612 | |
| 7613 | // Mutate the cached1 to have different data. |
| 7614 | // TODO(rtenneti): mutate other members of CachedState. |
| 7615 | cached1->set_source_address_token(r3_host_name); |
| 7616 | cached1->SetProofInvalid(); |
| 7617 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7618 | HostPortPair host_port_pair2(r4_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7619 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7620 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7621 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7622 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7623 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 7624 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 7625 | EXPECT_FALSE(cached2->proof_valid()); |
| 7626 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7627 | } |
| 7628 | |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7629 | TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7630 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7631 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7632 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7633 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7634 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7635 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7636 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7637 | MockQuicData socket_data; |
| 7638 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7639 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7640 | |
| 7641 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7642 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7643 | host_resolver_->set_synchronous_mode(true); |
| 7644 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7645 | "192.168.0.1", ""); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7646 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7647 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7648 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7649 | DEFAULT_PRIORITY, SocketTag(), |
| 7650 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7651 | &net_error_details_, |
| 7652 | failed_on_default_network_callback_, |
| 7653 | callback_.callback())); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7654 | |
| 7655 | // If we are waiting for disk cache, we would have posted a task. Verify that |
| 7656 | // the CancelWaitForDataReady task hasn't been posted. |
| 7657 | ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
| 7658 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7659 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7660 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7661 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7662 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7663 | } |
| 7664 | |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7665 | TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { |
| 7666 | reduced_ping_timeout_seconds_ = 10; |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7667 | Initialize(); |
| 7668 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7669 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7670 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7671 | |
| 7672 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7673 | |
| 7674 | MockQuicData socket_data; |
| 7675 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7676 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7677 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7678 | |
| 7679 | MockQuicData socket_data2; |
| 7680 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7681 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7682 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7683 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7684 | |
| 7685 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
| 7686 | |
| 7687 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7688 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7689 | host_resolver_->set_synchronous_mode(true); |
| 7690 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7691 | "192.168.0.1", ""); |
| 7692 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7693 | |
| 7694 | // Quic should use default PING timeout when no previous connection times out |
| 7695 | // with open stream. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7696 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7697 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7698 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7699 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7700 | DEFAULT_PRIORITY, SocketTag(), |
| 7701 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7702 | &net_error_details_, |
| 7703 | failed_on_default_network_callback_, |
| 7704 | callback_.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7705 | |
| 7706 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7707 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7708 | session->connection()->ping_timeout()); |
| 7709 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7710 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7711 | EXPECT_TRUE(stream.get()); |
| 7712 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7713 | request_info.traffic_annotation = |
| 7714 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7715 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7716 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7717 | |
| 7718 | DVLOG(1) |
| 7719 | << "Created 1st session and initialized a stream. Now trigger timeout"; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7720 | session->connection()->CloseConnection( |
| 7721 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7722 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7723 | // Need to spin the loop now to ensure that |
| 7724 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7725 | base::RunLoop run_loop; |
| 7726 | run_loop.RunUntilIdle(); |
| 7727 | |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7728 | // The first connection times out with open stream, QUIC should reduce initial |
| 7729 | // PING time for subsequent connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7730 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7731 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 7732 | |
| 7733 | // Test two-in-a-row timeouts with open streams. |
| 7734 | DVLOG(1) << "Create 2nd session and timeout with open stream"; |
| 7735 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7736 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7737 | EXPECT_EQ(OK, |
| 7738 | request2.Request( |
| 7739 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 7740 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 7741 | failed_on_default_network_callback_, callback2.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7742 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7743 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7744 | session2->connection()->ping_timeout()); |
| 7745 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7746 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7747 | EXPECT_TRUE(stream2.get()); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7748 | EXPECT_EQ(OK, |
| 7749 | stream2->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7750 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7751 | session2->connection()->CloseConnection( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7752 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7753 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7754 | // Need to spin the loop now to ensure that |
| 7755 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7756 | base::RunLoop run_loop2; |
| 7757 | run_loop2.RunUntilIdle(); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7758 | |
| 7759 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7760 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7761 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7762 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7763 | } |
| 7764 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 7765 | // Verifies that the QUIC stream factory is initialized correctly. |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 7766 | TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 7767 | VerifyInitialization(); |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 7768 | } |
| 7769 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7770 | TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 7771 | Initialize(); |
| 7772 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7773 | MockQuicData socket_data; |
| 7774 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7775 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7776 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7777 | |
| 7778 | // Save current state of |race_cert_verification|. |
| 7779 | bool race_cert_verification = |
| 7780 | QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 7781 | |
| 7782 | // Load server config. |
| 7783 | HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7784 | quic::QuicServerId quic_server_id(host_port_pair_.host(), |
| 7785 | host_port_pair_.port(), |
| 7786 | privacy_mode_ == PRIVACY_MODE_ENABLED); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7787 | QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 7788 | |
| 7789 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 7790 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7791 | |
| 7792 | // Start CertVerifyJob. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7793 | quic::QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7794 | factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7795 | if (status == quic::QUIC_PENDING) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7796 | // Verify CertVerifierJob has started. |
| 7797 | EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 7798 | |
| 7799 | while (HasActiveCertVerifierJob(quic_server_id)) { |
| 7800 | base::RunLoop().RunUntilIdle(); |
| 7801 | } |
| 7802 | } |
| 7803 | // Verify CertVerifierJob has finished. |
| 7804 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7805 | |
| 7806 | // Start a QUIC request. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7807 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7808 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7809 | request.Request( |
| 7810 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7811 | SocketTag(), |
| 7812 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7813 | failed_on_default_network_callback_, callback_.callback())); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7814 | |
| 7815 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7816 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7817 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7818 | EXPECT_TRUE(stream.get()); |
| 7819 | |
| 7820 | // Restore |race_cert_verification|. |
| 7821 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 7822 | race_cert_verification); |
| 7823 | |
| 7824 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7825 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7826 | |
| 7827 | // Verify there are no outstanding CertVerifierJobs after request has |
| 7828 | // finished. |
| 7829 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7830 | } |
| 7831 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7832 | TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7833 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7834 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7835 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7836 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7837 | QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7838 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7839 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 7840 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7841 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7842 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7843 | |
| 7844 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7845 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7846 | host_resolver_->set_synchronous_mode(true); |
| 7847 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7848 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7849 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7850 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7851 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7852 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7853 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7854 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7855 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7856 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7857 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7858 | DEFAULT_PRIORITY, SocketTag(), |
| 7859 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7860 | &net_error_details_, |
| 7861 | failed_on_default_network_callback_, |
| 7862 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7863 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7864 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7865 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7866 | base::RunLoop run_loop; |
| 7867 | run_loop.RunUntilIdle(); |
| 7868 | |
| 7869 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7870 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7871 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7872 | EXPECT_EQ(1u, observer.executed_count()); |
| 7873 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7874 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7875 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7876 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7877 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7878 | } |
| 7879 | |
| 7880 | TEST_P(QuicStreamFactoryTest, YieldAfterDuration) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7881 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7882 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7883 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7884 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7885 | QuicStreamFactoryPeer::SetYieldAfterDuration( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7886 | factory_.get(), quic::QuicTime::Delta::FromMilliseconds(-1)); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7887 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7888 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 7889 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7890 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7891 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7892 | |
| 7893 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7894 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7895 | host_resolver_->set_synchronous_mode(true); |
| 7896 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7897 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7898 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7899 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7900 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7901 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7902 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7903 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7904 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7905 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7906 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7907 | DEFAULT_PRIORITY, SocketTag(), |
| 7908 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7909 | &net_error_details_, |
| 7910 | failed_on_default_network_callback_, |
| 7911 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7912 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7913 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7914 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7915 | base::RunLoop run_loop; |
| 7916 | run_loop.RunUntilIdle(); |
| 7917 | |
| 7918 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7919 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7920 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7921 | EXPECT_EQ(1u, observer.executed_count()); |
| 7922 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7923 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7924 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7925 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7926 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7927 | } |
| 7928 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7929 | TEST_P(QuicStreamFactoryTest, ServerPushSessionAffinity) { |
| 7930 | Initialize(); |
| 7931 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7932 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7933 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7934 | MockQuicData socket_data; |
| 7935 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7936 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7937 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7938 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7939 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7940 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7941 | request.Request( |
| 7942 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7943 | SocketTag(), |
| 7944 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7945 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7946 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7947 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7948 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7949 | EXPECT_TRUE(stream.get()); |
| 7950 | |
| 7951 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7952 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 7953 | string url = "https://www.example.org/"; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7954 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 7955 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7956 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7957 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7958 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7959 | (*QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()) |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7960 | ->promised_by_url())[kDefaultUrl] = &promised; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7961 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7962 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 7963 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7964 | DEFAULT_PRIORITY, SocketTag(), |
| 7965 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7966 | &net_error_details_, |
| 7967 | failed_on_default_network_callback_, |
| 7968 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7969 | |
| 7970 | EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7971 | } |
| 7972 | |
| 7973 | TEST_P(QuicStreamFactoryTest, ServerPushPrivacyModeMismatch) { |
| 7974 | Initialize(); |
| 7975 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7976 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7977 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7978 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7979 | MockQuicData socket_data1; |
| 7980 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7981 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7982 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7983 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7984 | 2, true, GetNthServerInitiatedUnidirectionalStreamId(0), |
| 7985 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7986 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7987 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7988 | MockQuicData socket_data2; |
| 7989 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7990 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7991 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7992 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7993 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7994 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7995 | request.Request( |
| 7996 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7997 | SocketTag(), |
| 7998 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7999 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8000 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8001 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8002 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8003 | EXPECT_TRUE(stream.get()); |
| 8004 | |
| 8005 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 8006 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 8007 | string url = "https://www.example.org/"; |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 8008 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8009 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8010 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 8011 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8012 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8013 | quic::QuicClientPushPromiseIndex* index = |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8014 | QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()); |
| 8015 | |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8016 | (*index->promised_by_url())[kDefaultUrl] = &promised; |
| 8017 | EXPECT_EQ(index->GetPromised(kDefaultUrl), &promised); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8018 | |
| 8019 | // Doing the request should not use the push stream, but rather |
| 8020 | // cancel it because the privacy modes do not match. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8021 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8022 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8023 | request2.Request( |
| 8024 | host_port_pair_, version_, PRIVACY_MODE_ENABLED, |
| 8025 | DEFAULT_PRIORITY, SocketTag(), |
| 8026 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8027 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8028 | |
| 8029 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8030 | EXPECT_EQ(index->GetPromised(kDefaultUrl), nullptr); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8031 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8032 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8033 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8034 | EXPECT_TRUE(stream2.get()); |
| 8035 | |
| 8036 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 8037 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 8038 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 8039 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 8040 | } |
| 8041 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8042 | // Pool to existing session with matching quic::QuicServerId |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8043 | // even if destination is different. |
| 8044 | TEST_P(QuicStreamFactoryTest, PoolByOrigin) { |
| 8045 | Initialize(); |
| 8046 | |
| 8047 | HostPortPair destination1("first.example.com", 443); |
| 8048 | HostPortPair destination2("second.example.com", 443); |
| 8049 | |
| 8050 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8051 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8052 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8053 | MockQuicData socket_data; |
| 8054 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8055 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8056 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8057 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8058 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8059 | EXPECT_EQ( |
| 8060 | ERR_IO_PENDING, |
| 8061 | request1.Request( |
| 8062 | destination1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8063 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8064 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8065 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8066 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8067 | EXPECT_TRUE(stream1.get()); |
| 8068 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 8069 | |
| 8070 | // Second request returns synchronously because it pools to existing session. |
| 8071 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8072 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8073 | EXPECT_EQ(OK, request2.Request(destination2, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8074 | DEFAULT_PRIORITY, SocketTag(), |
| 8075 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8076 | &net_error_details_, |
| 8077 | failed_on_default_network_callback_, |
| 8078 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8079 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8080 | EXPECT_TRUE(stream2.get()); |
| 8081 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8082 | QuicChromiumClientSession::Handle* session1 = |
| 8083 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8084 | QuicChromiumClientSession::Handle* session2 = |
| 8085 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8086 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8087 | EXPECT_EQ(quic::QuicServerId(host_port_pair_.host(), host_port_pair_.port(), |
| 8088 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8089 | session1->server_id()); |
| 8090 | |
| 8091 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8092 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8093 | } |
| 8094 | |
| 8095 | class QuicStreamFactoryWithDestinationTest |
| 8096 | : public QuicStreamFactoryTestBase, |
| 8097 | public ::testing::TestWithParam<PoolingTestParams> { |
| 8098 | protected: |
| 8099 | QuicStreamFactoryWithDestinationTest() |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 8100 | : QuicStreamFactoryTestBase( |
| 8101 | GetParam().version, |
| 8102 | GetParam().client_headers_include_h2_stream_dependency), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8103 | destination_type_(GetParam().destination_type), |
| 8104 | hanging_read_(SYNCHRONOUS, ERR_IO_PENDING, 0) {} |
| 8105 | |
| 8106 | HostPortPair GetDestination() { |
| 8107 | switch (destination_type_) { |
| 8108 | case SAME_AS_FIRST: |
| 8109 | return origin1_; |
| 8110 | case SAME_AS_SECOND: |
| 8111 | return origin2_; |
| 8112 | case DIFFERENT: |
| 8113 | return HostPortPair(kDifferentHostname, 443); |
| 8114 | default: |
| 8115 | NOTREACHED(); |
| 8116 | return HostPortPair(); |
| 8117 | } |
| 8118 | } |
| 8119 | |
| 8120 | void AddHangingSocketData() { |
| 8121 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8122 | new SequencedSocketData(base::make_span(&hanging_read_, 1), |
| 8123 | base::span<MockWrite>())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8124 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8125 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8126 | } |
| 8127 | |
| 8128 | bool AllDataConsumed() { |
| 8129 | for (const auto& socket_data_ptr : sequenced_socket_data_vector_) { |
| 8130 | if (!socket_data_ptr->AllReadDataConsumed() || |
| 8131 | !socket_data_ptr->AllWriteDataConsumed()) { |
| 8132 | return false; |
| 8133 | } |
| 8134 | } |
| 8135 | return true; |
| 8136 | } |
| 8137 | |
| 8138 | DestinationType destination_type_; |
| 8139 | HostPortPair origin1_; |
| 8140 | HostPortPair origin2_; |
| 8141 | MockRead hanging_read_; |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8142 | std::vector<std::unique_ptr<SequencedSocketData>> |
| 8143 | sequenced_socket_data_vector_; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8144 | }; |
| 8145 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 8146 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 8147 | QuicStreamFactoryWithDestinationTest, |
| 8148 | ::testing::ValuesIn(GetPoolingTestParams())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8149 | |
| 8150 | // A single QUIC request fails because the certificate does not match the origin |
| 8151 | // hostname, regardless of whether it matches the alternative service hostname. |
| 8152 | TEST_P(QuicStreamFactoryWithDestinationTest, InvalidCertificate) { |
| 8153 | if (destination_type_ == DIFFERENT) |
| 8154 | return; |
| 8155 | |
| 8156 | Initialize(); |
| 8157 | |
| 8158 | GURL url("https://mail.example.com/"); |
| 8159 | origin1_ = HostPortPair::FromURL(url); |
| 8160 | |
| 8161 | // Not used for requests, but this provides a test case where the certificate |
| 8162 | // is valid for the hostname of the alternative service. |
| 8163 | origin2_ = HostPortPair("mail.example.org", 433); |
| 8164 | |
| 8165 | HostPortPair destination = GetDestination(); |
| 8166 | |
| 8167 | scoped_refptr<X509Certificate> cert( |
| 8168 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8169 | ASSERT_FALSE(cert->VerifyNameMatch(origin1_.host())); |
| 8170 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8171 | |
| 8172 | ProofVerifyDetailsChromium verify_details; |
| 8173 | verify_details.cert_verify_result.verified_cert = cert; |
| 8174 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8175 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8176 | |
| 8177 | AddHangingSocketData(); |
| 8178 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8179 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8180 | EXPECT_EQ( |
| 8181 | ERR_IO_PENDING, |
| 8182 | request.Request( |
| 8183 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8184 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 8185 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8186 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8187 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_QUIC_HANDSHAKE_FAILED)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8188 | |
| 8189 | EXPECT_TRUE(AllDataConsumed()); |
| 8190 | } |
| 8191 | |
| 8192 | // QuicStreamRequest is pooled based on |destination| if certificate matches. |
| 8193 | TEST_P(QuicStreamFactoryWithDestinationTest, SharedCertificate) { |
| 8194 | Initialize(); |
| 8195 | |
| 8196 | GURL url1("https://www.example.org/"); |
| 8197 | GURL url2("https://mail.example.org/"); |
| 8198 | origin1_ = HostPortPair::FromURL(url1); |
| 8199 | origin2_ = HostPortPair::FromURL(url2); |
| 8200 | |
| 8201 | HostPortPair destination = GetDestination(); |
| 8202 | |
| 8203 | scoped_refptr<X509Certificate> cert( |
| 8204 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8205 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8206 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8207 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8208 | |
| 8209 | ProofVerifyDetailsChromium verify_details; |
| 8210 | verify_details.cert_verify_result.verified_cert = cert; |
| 8211 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8212 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8213 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8214 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8215 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8216 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8217 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8218 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8219 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8220 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8221 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8222 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8223 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8224 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8225 | EXPECT_EQ( |
| 8226 | ERR_IO_PENDING, |
| 8227 | request1.Request( |
| 8228 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8229 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8230 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8231 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8232 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8233 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8234 | EXPECT_TRUE(stream1.get()); |
| 8235 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8236 | |
| 8237 | // Second request returns synchronously because it pools to existing session. |
| 8238 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8239 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8240 | EXPECT_EQ(OK, request2.Request(destination, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8241 | DEFAULT_PRIORITY, SocketTag(), |
| 8242 | /*cert_verify_flags=*/0, url2, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8243 | &net_error_details_, |
| 8244 | failed_on_default_network_callback_, |
| 8245 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8246 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8247 | EXPECT_TRUE(stream2.get()); |
| 8248 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8249 | QuicChromiumClientSession::Handle* session1 = |
| 8250 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8251 | QuicChromiumClientSession::Handle* session2 = |
| 8252 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8253 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8254 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8255 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8256 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8257 | session1->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8258 | |
| 8259 | EXPECT_TRUE(AllDataConsumed()); |
| 8260 | } |
| 8261 | |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8262 | // QuicStreamRequest is not pooled if PrivacyMode differs. |
| 8263 | TEST_P(QuicStreamFactoryWithDestinationTest, DifferentPrivacyMode) { |
| 8264 | Initialize(); |
| 8265 | |
| 8266 | GURL url1("https://www.example.org/"); |
| 8267 | GURL url2("https://mail.example.org/"); |
| 8268 | origin1_ = HostPortPair::FromURL(url1); |
| 8269 | origin2_ = HostPortPair::FromURL(url2); |
| 8270 | |
| 8271 | HostPortPair destination = GetDestination(); |
| 8272 | |
| 8273 | scoped_refptr<X509Certificate> cert( |
| 8274 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8275 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8276 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8277 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8278 | |
| 8279 | ProofVerifyDetailsChromium verify_details1; |
| 8280 | verify_details1.cert_verify_result.verified_cert = cert; |
| 8281 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8282 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8283 | |
| 8284 | ProofVerifyDetailsChromium verify_details2; |
| 8285 | verify_details2.cert_verify_result.verified_cert = cert; |
| 8286 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8287 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8288 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8289 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8290 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8291 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8292 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8293 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8294 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8295 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8296 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8297 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8298 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8299 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8300 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8301 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8302 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8303 | QuicStreamRequest request1(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8304 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8305 | request1.Request( |
| 8306 | destination, version_, PRIVACY_MODE_DISABLED, DEFAULT_PRIORITY, |
| 8307 | SocketTag(), |
| 8308 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8309 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8310 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8311 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8312 | EXPECT_TRUE(stream1.get()); |
| 8313 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8314 | |
| 8315 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8316 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8317 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8318 | request2.Request( |
| 8319 | destination, version_, PRIVACY_MODE_ENABLED, DEFAULT_PRIORITY, |
| 8320 | SocketTag(), |
| 8321 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8322 | failed_on_default_network_callback_, callback2.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8323 | EXPECT_EQ(OK, callback2.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8324 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8325 | EXPECT_TRUE(stream2.get()); |
| 8326 | |
| 8327 | // |request2| does not pool to the first session, because PrivacyMode does not |
| 8328 | // match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8329 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8330 | QuicChromiumClientSession::Handle* session1 = |
| 8331 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8332 | QuicChromiumClientSession::Handle* session2 = |
| 8333 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8334 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8335 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8336 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), false), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8337 | session1->server_id()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8338 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), true), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8339 | session2->server_id()); |
| 8340 | |
| 8341 | EXPECT_TRUE(AllDataConsumed()); |
| 8342 | } |
| 8343 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8344 | // QuicStreamRequest is not pooled if certificate does not match its origin. |
| 8345 | TEST_P(QuicStreamFactoryWithDestinationTest, DisjointCertificate) { |
| 8346 | Initialize(); |
| 8347 | |
| 8348 | GURL url1("https://news.example.org/"); |
| 8349 | GURL url2("https://mail.example.com/"); |
| 8350 | origin1_ = HostPortPair::FromURL(url1); |
| 8351 | origin2_ = HostPortPair::FromURL(url2); |
| 8352 | |
| 8353 | HostPortPair destination = GetDestination(); |
| 8354 | |
| 8355 | scoped_refptr<X509Certificate> cert1( |
| 8356 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8357 | ASSERT_TRUE(cert1->VerifyNameMatch(origin1_.host())); |
| 8358 | ASSERT_FALSE(cert1->VerifyNameMatch(origin2_.host())); |
| 8359 | ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8360 | |
| 8361 | ProofVerifyDetailsChromium verify_details1; |
| 8362 | verify_details1.cert_verify_result.verified_cert = cert1; |
| 8363 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8364 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8365 | |
| 8366 | scoped_refptr<X509Certificate> cert2( |
| 8367 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8368 | ASSERT_TRUE(cert2->VerifyNameMatch(origin2_.host())); |
| 8369 | ASSERT_FALSE(cert2->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8370 | |
| 8371 | ProofVerifyDetailsChromium verify_details2; |
| 8372 | verify_details2.cert_verify_result.verified_cert = cert2; |
| 8373 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8374 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8375 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8376 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8377 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8378 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8379 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8380 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8381 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8382 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8383 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8384 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8385 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8386 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8387 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8388 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8389 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8390 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8391 | EXPECT_EQ( |
| 8392 | ERR_IO_PENDING, |
| 8393 | request1.Request( |
| 8394 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8395 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8396 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8397 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8398 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8399 | EXPECT_TRUE(stream1.get()); |
| 8400 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8401 | |
| 8402 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8403 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8404 | EXPECT_EQ( |
| 8405 | ERR_IO_PENDING, |
| 8406 | request2.Request( |
| 8407 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8408 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8409 | failed_on_default_network_callback_, callback2.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8410 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8411 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8412 | EXPECT_TRUE(stream2.get()); |
| 8413 | |
| 8414 | // |request2| does not pool to the first session, because the certificate does |
| 8415 | // not match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8416 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8417 | QuicChromiumClientSession::Handle* session1 = |
| 8418 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8419 | QuicChromiumClientSession::Handle* session2 = |
| 8420 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8421 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8422 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8423 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8424 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8425 | session1->server_id()); |
| 8426 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), |
| 8427 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8428 | session2->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8429 | |
| 8430 | EXPECT_TRUE(AllDataConsumed()); |
| 8431 | } |
| 8432 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8433 | // This test verifies that QuicStreamFactory::ClearCachedStatesInCryptoConfig |
| 8434 | // correctly transform an origin filter to a ServerIdFilter. Whether the |
| 8435 | // deletion itself works correctly is tested in QuicCryptoClientConfigTest. |
| 8436 | TEST_P(QuicStreamFactoryTest, ClearCachedStatesInCryptoConfig) { |
| 8437 | Initialize(); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8438 | quic::QuicCryptoClientConfig* crypto_config = |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8439 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 8440 | |
| 8441 | struct TestCase { |
| 8442 | TestCase(const std::string& host, |
| 8443 | int port, |
| 8444 | PrivacyMode privacy_mode, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8445 | quic::QuicCryptoClientConfig* crypto_config) |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8446 | : server_id(host, port, privacy_mode), |
| 8447 | state(crypto_config->LookupOrCreate(server_id)) { |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8448 | std::vector<string> certs(1); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8449 | certs[0] = "cert"; |
| 8450 | state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); |
| 8451 | state->set_source_address_token("TOKEN"); |
| 8452 | state->SetProofValid(); |
| 8453 | |
| 8454 | EXPECT_FALSE(state->certs().empty()); |
| 8455 | } |
| 8456 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8457 | quic::QuicServerId server_id; |
| 8458 | quic::QuicCryptoClientConfig::CachedState* state; |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8459 | } test_cases[] = { |
| 8460 | TestCase("www.google.com", 443, privacy_mode_, crypto_config), |
| 8461 | TestCase("www.example.com", 443, privacy_mode_, crypto_config), |
| 8462 | TestCase("www.example.com", 4433, privacy_mode_, crypto_config)}; |
| 8463 | |
| 8464 | // Clear cached states for the origin https://www.example.com:4433. |
| 8465 | GURL origin("https://www.example.com:4433"); |
csharrison | ebeca8e | 2016-10-18 02:35:36 | [diff] [blame] | 8466 | factory_->ClearCachedStatesInCryptoConfig(base::Bind( |
| 8467 | static_cast<bool (*)(const GURL&, const GURL&)>(::operator==), origin)); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8468 | EXPECT_FALSE(test_cases[0].state->certs().empty()); |
| 8469 | EXPECT_FALSE(test_cases[1].state->certs().empty()); |
| 8470 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8471 | |
| 8472 | // Clear all cached states. |
| 8473 | factory_->ClearCachedStatesInCryptoConfig( |
| 8474 | base::Callback<bool(const GURL&)>()); |
| 8475 | EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 8476 | EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 8477 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8478 | } |
| 8479 | |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8480 | // Passes connection options and client connection options to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8481 | // then checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8482 | TEST_P(QuicStreamFactoryTest, ConfigConnectionOptions) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8483 | connection_options_.push_back(quic::kTIME); |
| 8484 | connection_options_.push_back(quic::kTBBR); |
| 8485 | connection_options_.push_back(quic::kREJ); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8486 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8487 | client_connection_options_.push_back(quic::kTBBR); |
| 8488 | client_connection_options_.push_back(quic::k1RTT); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8489 | |
| 8490 | Initialize(); |
| 8491 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8492 | const quic::QuicConfig* config = |
| 8493 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8494 | EXPECT_EQ(connection_options_, config->SendConnectionOptions()); |
| 8495 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8496 | quic::kTBBR, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8497 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8498 | quic::k1RTT, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8499 | } |
| 8500 | |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8501 | // Verifies that the host resolver uses the request priority passed to |
| 8502 | // QuicStreamRequest::Request(). |
| 8503 | TEST_P(QuicStreamFactoryTest, HostResolverUsesRequestPriority) { |
| 8504 | Initialize(); |
| 8505 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8506 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8507 | |
| 8508 | MockQuicData socket_data; |
| 8509 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8510 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8511 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8512 | |
| 8513 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8514 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8515 | request.Request( |
| 8516 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8517 | SocketTag(), |
| 8518 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8519 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8520 | |
| 8521 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8522 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8523 | EXPECT_TRUE(stream.get()); |
| 8524 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8525 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8526 | |
| 8527 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8528 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8529 | } |
| 8530 | |
Lily Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 8531 | TEST_P(QuicStreamFactoryTest, HostResolverRequestReprioritizedOnSetPriority) { |
| 8532 | Initialize(); |
| 8533 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8534 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8535 | |
| 8536 | MockQuicData socket_data; |
| 8537 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8538 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8539 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8540 | |
| 8541 | QuicStreamRequest request(factory_.get()); |
| 8542 | EXPECT_EQ(ERR_IO_PENDING, |
| 8543 | request.Request( |
| 8544 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8545 | SocketTag(), |
| 8546 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8547 | failed_on_default_network_callback_, callback_.callback())); |
| 8548 | |
| 8549 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
| 8550 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->request_priority(1)); |
| 8551 | |
| 8552 | QuicStreamRequest request2(factory_.get()); |
| 8553 | EXPECT_EQ(ERR_IO_PENDING, |
| 8554 | request2.Request( |
| 8555 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8556 | SocketTag(), |
| 8557 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 8558 | failed_on_default_network_callback_, callback_.callback())); |
| 8559 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
| 8560 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8561 | |
| 8562 | request.SetPriority(LOWEST); |
| 8563 | EXPECT_EQ(LOWEST, host_resolver_->request_priority(1)); |
| 8564 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8565 | } |
| 8566 | |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8567 | // Passes |max_time_before_crypto_handshake_seconds| and |
| 8568 | // |max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, then |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8569 | // checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8570 | TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { |
| 8571 | max_time_before_crypto_handshake_seconds_ = 11; |
| 8572 | max_idle_time_before_crypto_handshake_seconds_ = 13; |
| 8573 | |
| 8574 | Initialize(); |
| 8575 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8576 | const quic::QuicConfig* config = |
| 8577 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 8578 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(11), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8579 | config->max_time_before_crypto_handshake()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8580 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(13), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8581 | config->max_idle_time_before_crypto_handshake()); |
| 8582 | } |
| 8583 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8584 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8585 | // succeeds asynchronously, then crypto handshake fails synchronously. |
| 8586 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncSync) { |
| 8587 | Initialize(); |
| 8588 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8589 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8590 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8591 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8592 | |
| 8593 | MockQuicData socket_data; |
| 8594 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8595 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8596 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8597 | |
| 8598 | QuicStreamRequest request(factory_.get()); |
| 8599 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8600 | request.Request( |
| 8601 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8602 | SocketTag(), |
| 8603 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8604 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8605 | |
| 8606 | TestCompletionCallback host_resolution_callback; |
| 8607 | EXPECT_TRUE( |
| 8608 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8609 | |
| 8610 | // |host_resolver_| has not finished host resolution at this point, so |
| 8611 | // |host_resolution_callback| should not have a result. |
| 8612 | base::RunLoop().RunUntilIdle(); |
| 8613 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8614 | |
| 8615 | // Allow |host_resolver_| to finish host resolution. |
| 8616 | // Since the request fails immediately after host resolution (getting |
| 8617 | // ERR_FAILED from socket reads/writes), |host_resolution_callback| should be |
| 8618 | // called with ERR_QUIC_PROTOCOL_ERROR since that's the next result in |
| 8619 | // forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8620 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8621 | base::RunLoop().RunUntilIdle(); |
| 8622 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8623 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, host_resolution_callback.WaitForResult()); |
| 8624 | |
| 8625 | // Calling WaitForHostResolution() a second time should return |
| 8626 | // false since host resolution has finished already. |
| 8627 | EXPECT_FALSE( |
| 8628 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8629 | |
| 8630 | EXPECT_TRUE(callback_.have_result()); |
| 8631 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8632 | } |
| 8633 | |
| 8634 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8635 | // succeeds asynchronously, then crypto handshake fails asynchronously. |
| 8636 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncAsync) { |
| 8637 | Initialize(); |
| 8638 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8639 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8640 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8641 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8642 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8643 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8644 | factory_->set_require_confirmation(true); |
| 8645 | |
| 8646 | MockQuicData socket_data; |
| 8647 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8648 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8649 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8650 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8651 | |
| 8652 | QuicStreamRequest request(factory_.get()); |
| 8653 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8654 | request.Request( |
| 8655 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8656 | SocketTag(), |
| 8657 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8658 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8659 | |
| 8660 | TestCompletionCallback host_resolution_callback; |
| 8661 | EXPECT_TRUE( |
| 8662 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8663 | |
| 8664 | // |host_resolver_| has not finished host resolution at this point, so |
| 8665 | // |host_resolution_callback| should not have a result. |
| 8666 | base::RunLoop().RunUntilIdle(); |
| 8667 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8668 | |
| 8669 | // Allow |host_resolver_| to finish host resolution. Since crypto handshake |
| 8670 | // will hang after host resolution, |host_resolution_callback| should run with |
| 8671 | // ERR_IO_PENDING since that's the next result in forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8672 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8673 | base::RunLoop().RunUntilIdle(); |
| 8674 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8675 | EXPECT_EQ(ERR_IO_PENDING, host_resolution_callback.WaitForResult()); |
| 8676 | |
| 8677 | // Calling WaitForHostResolution() a second time should return |
| 8678 | // false since host resolution has finished already. |
| 8679 | EXPECT_FALSE( |
| 8680 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8681 | |
| 8682 | EXPECT_FALSE(callback_.have_result()); |
| 8683 | socket_data.GetSequencedSocketData()->Resume(); |
| 8684 | base::RunLoop().RunUntilIdle(); |
| 8685 | EXPECT_TRUE(callback_.have_result()); |
| 8686 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8687 | } |
| 8688 | |
| 8689 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8690 | // succeeds synchronously, then crypto handshake fails synchronously. |
| 8691 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncSync) { |
| 8692 | Initialize(); |
| 8693 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8694 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8695 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8696 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8697 | |
| 8698 | MockQuicData socket_data; |
| 8699 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8700 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8701 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8702 | |
| 8703 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8704 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8705 | request.Request( |
| 8706 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8707 | SocketTag(), |
| 8708 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8709 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8710 | |
| 8711 | // WaitForHostResolution() should return false since host |
| 8712 | // resolution has finished already. |
| 8713 | TestCompletionCallback host_resolution_callback; |
| 8714 | EXPECT_FALSE( |
| 8715 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8716 | base::RunLoop().RunUntilIdle(); |
| 8717 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8718 | EXPECT_FALSE(callback_.have_result()); |
| 8719 | } |
| 8720 | |
| 8721 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8722 | // succeeds synchronously, then crypto handshake fails asynchronously. |
| 8723 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncAsync) { |
| 8724 | Initialize(); |
| 8725 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8726 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8727 | |
| 8728 | // Host resolution will succeed synchronously, but Request() as a whole |
| 8729 | // will fail asynchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8730 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8731 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8732 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8733 | factory_->set_require_confirmation(true); |
| 8734 | |
| 8735 | MockQuicData socket_data; |
| 8736 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8737 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8738 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8739 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8740 | |
| 8741 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8742 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8743 | request.Request( |
| 8744 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8745 | SocketTag(), |
| 8746 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8747 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8748 | |
| 8749 | // WaitForHostResolution() should return false since host |
| 8750 | // resolution has finished already. |
| 8751 | TestCompletionCallback host_resolution_callback; |
| 8752 | EXPECT_FALSE( |
| 8753 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8754 | base::RunLoop().RunUntilIdle(); |
| 8755 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8756 | |
| 8757 | EXPECT_FALSE(callback_.have_result()); |
| 8758 | socket_data.GetSequencedSocketData()->Resume(); |
| 8759 | base::RunLoop().RunUntilIdle(); |
| 8760 | EXPECT_TRUE(callback_.have_result()); |
| 8761 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8762 | } |
| 8763 | |
| 8764 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8765 | // synchronously. |
| 8766 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailSync) { |
| 8767 | Initialize(); |
| 8768 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8769 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8770 | |
| 8771 | // Host resolution will fail synchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8772 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 8773 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8774 | |
| 8775 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8776 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8777 | request.Request( |
| 8778 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8779 | SocketTag(), |
| 8780 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8781 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8782 | |
| 8783 | // WaitForHostResolution() should return false since host |
| 8784 | // resolution has failed already. |
| 8785 | TestCompletionCallback host_resolution_callback; |
| 8786 | EXPECT_FALSE( |
| 8787 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8788 | base::RunLoop().RunUntilIdle(); |
| 8789 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8790 | } |
| 8791 | |
| 8792 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8793 | // asynchronously. |
| 8794 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { |
| 8795 | Initialize(); |
| 8796 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8797 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8798 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8799 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8800 | |
| 8801 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8802 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8803 | request.Request( |
| 8804 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8805 | SocketTag(), |
| 8806 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8807 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8808 | |
| 8809 | TestCompletionCallback host_resolution_callback; |
| 8810 | EXPECT_TRUE( |
| 8811 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8812 | |
| 8813 | // Allow |host_resolver_| to fail host resolution. |host_resolution_callback| |
| 8814 | // Should run with ERR_NAME_NOT_RESOLVED since that's the error host |
| 8815 | // resolution failed with. |
| 8816 | base::RunLoop().RunUntilIdle(); |
| 8817 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8818 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, host_resolution_callback.WaitForResult()); |
| 8819 | |
| 8820 | EXPECT_TRUE(callback_.have_result()); |
| 8821 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 8822 | } |
| 8823 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8824 | // With dns race experiment turned on, and DNS resolve succeeds synchronously, |
| 8825 | // the final connection is established through the resolved DNS. No racing |
| 8826 | // connection. |
| 8827 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { |
| 8828 | race_stale_dns_on_connection_ = true; |
| 8829 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8830 | Initialize(); |
| 8831 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8832 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8833 | |
| 8834 | // Set an address in resolver for synchronous return. |
| 8835 | host_resolver_->set_synchronous_mode(true); |
| 8836 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8837 | kNonCachedIPAddress, ""); |
| 8838 | |
| 8839 | // Set up a different address in stale resolver cache. |
| 8840 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8841 | HostCache::Entry entry(OK, |
| 8842 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8843 | HostCache::Entry::SOURCE_DNS); |
| 8844 | base::TimeDelta zero; |
| 8845 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8846 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8847 | // Expire the cache |
| 8848 | cache->OnNetworkChange(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 8849 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8850 | MockQuicData quic_data; |
| 8851 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8852 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8853 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8854 | |
| 8855 | QuicStreamRequest request(factory_.get()); |
| 8856 | EXPECT_THAT(request.Request( |
| 8857 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8858 | SocketTag(), |
| 8859 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8860 | failed_on_default_network_callback_, callback_.callback()), |
| 8861 | IsOk()); |
| 8862 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8863 | EXPECT_TRUE(stream.get()); |
| 8864 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8865 | EXPECT_EQ( |
| 8866 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8867 | kNonCachedIPAddress); |
| 8868 | |
| 8869 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8870 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8871 | } |
| 8872 | |
| 8873 | // With dns race experiment on, DNS resolve returns async, no matching cache in |
| 8874 | // host resolver, connection should be successful and through resolved DNS. No |
| 8875 | // racing connection. |
| 8876 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { |
| 8877 | race_stale_dns_on_connection_ = true; |
| 8878 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8879 | Initialize(); |
| 8880 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8881 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8882 | |
| 8883 | // Set an address in resolver for asynchronous return. |
| 8884 | host_resolver_->set_ondemand_mode(true); |
| 8885 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8886 | kNonCachedIPAddress, ""); |
| 8887 | |
| 8888 | MockQuicData quic_data; |
| 8889 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8890 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8891 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8892 | |
| 8893 | QuicStreamRequest request(factory_.get()); |
| 8894 | EXPECT_EQ(ERR_IO_PENDING, |
| 8895 | request.Request( |
| 8896 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8897 | SocketTag(), |
| 8898 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8899 | failed_on_default_network_callback_, callback_.callback())); |
| 8900 | TestCompletionCallback host_resolution_callback; |
| 8901 | EXPECT_TRUE( |
| 8902 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8903 | base::RunLoop().RunUntilIdle(); |
| 8904 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8905 | |
| 8906 | // Cause the host resolution to return. |
| 8907 | host_resolver_->ResolveAllPending(); |
| 8908 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 8909 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8910 | |
| 8911 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8912 | EXPECT_TRUE(stream.get()); |
| 8913 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8914 | |
| 8915 | EXPECT_EQ( |
| 8916 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8917 | kNonCachedIPAddress); |
| 8918 | |
| 8919 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8920 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8921 | } |
| 8922 | |
| 8923 | // With dns race experiment on, DNS resolve returns async, stale dns used, |
| 8924 | // connects synchrounously, and then the resolved DNS matches. |
| 8925 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { |
| 8926 | race_stale_dns_on_connection_ = true; |
| 8927 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8928 | Initialize(); |
| 8929 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8930 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8931 | |
| 8932 | // Set an address in resolver for asynchronous return. |
| 8933 | host_resolver_->set_ondemand_mode(true); |
| 8934 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8935 | kCachedIPAddress.ToString(), ""); |
| 8936 | |
| 8937 | // Set up the same address in the stale resolver cache. |
| 8938 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8939 | HostCache::Entry entry(OK, |
| 8940 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8941 | HostCache::Entry::SOURCE_DNS); |
| 8942 | base::TimeDelta zero; |
| 8943 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8944 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8945 | // Expire the cache |
| 8946 | cache->OnNetworkChange(); |
| 8947 | |
| 8948 | MockQuicData quic_data; |
| 8949 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8950 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8951 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8952 | |
| 8953 | QuicStreamRequest request(factory_.get()); |
| 8954 | EXPECT_EQ(ERR_IO_PENDING, |
| 8955 | request.Request( |
| 8956 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8957 | SocketTag(), |
| 8958 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8959 | failed_on_default_network_callback_, callback_.callback())); |
| 8960 | |
| 8961 | // Check that the racing job is running. |
| 8962 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8963 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8964 | |
| 8965 | // Resolve dns and return. |
| 8966 | host_resolver_->ResolveAllPending(); |
| 8967 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8968 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8969 | EXPECT_TRUE(stream.get()); |
| 8970 | |
| 8971 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8972 | |
| 8973 | EXPECT_EQ( |
| 8974 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8975 | kCachedIPAddress.ToString()); |
| 8976 | |
| 8977 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8978 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8979 | } |
| 8980 | |
| 8981 | // With dns race experiment on, dns resolve async, stale dns used, connect |
| 8982 | // async, and then the result matches. |
| 8983 | TEST_P(QuicStreamFactoryTest, |
| 8984 | ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { |
| 8985 | race_stale_dns_on_connection_ = true; |
| 8986 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8987 | Initialize(); |
| 8988 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8989 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8990 | |
| 8991 | // Set an address in resolver for asynchronous return. |
| 8992 | host_resolver_->set_ondemand_mode(true); |
| 8993 | factory_->set_require_confirmation(true); |
| 8994 | crypto_client_stream_factory_.set_handshake_mode( |
| 8995 | MockCryptoClientStream::ZERO_RTT); |
| 8996 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8997 | kCachedIPAddress.ToString(), ""); |
| 8998 | |
| 8999 | // Set up the same address in the stale resolver cache. |
| 9000 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9001 | HostCache::Entry entry(OK, |
| 9002 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9003 | HostCache::Entry::SOURCE_DNS); |
| 9004 | base::TimeDelta zero; |
| 9005 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9006 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9007 | // Expire the cache |
| 9008 | cache->OnNetworkChange(); |
| 9009 | |
| 9010 | MockQuicData quic_data; |
| 9011 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9012 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9013 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9014 | |
| 9015 | QuicStreamRequest request(factory_.get()); |
| 9016 | EXPECT_EQ(ERR_IO_PENDING, |
| 9017 | request.Request( |
| 9018 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9019 | SocketTag(), |
| 9020 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9021 | failed_on_default_network_callback_, callback_.callback())); |
| 9022 | |
| 9023 | // Send Crypto handshake so connect will call back. |
| 9024 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9025 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9026 | base::RunLoop().RunUntilIdle(); |
| 9027 | |
| 9028 | // Check that the racing job is running. |
| 9029 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9030 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9031 | |
| 9032 | // Resolve dns and call back, make sure job finishes. |
| 9033 | host_resolver_->ResolveAllPending(); |
| 9034 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9035 | |
| 9036 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9037 | EXPECT_TRUE(stream.get()); |
| 9038 | |
| 9039 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9040 | |
| 9041 | EXPECT_EQ( |
| 9042 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9043 | kCachedIPAddress.ToString()); |
| 9044 | |
| 9045 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9046 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9047 | } |
| 9048 | |
| 9049 | // With dns race experiment on, dns resolve async, stale dns used, dns resolve |
| 9050 | // return, then connection finishes and matches with the result. |
| 9051 | TEST_P(QuicStreamFactoryTest, |
| 9052 | ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { |
| 9053 | race_stale_dns_on_connection_ = true; |
| 9054 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9055 | Initialize(); |
| 9056 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9057 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9058 | |
| 9059 | // Set an address in resolver for asynchronous return. |
| 9060 | host_resolver_->set_ondemand_mode(true); |
| 9061 | factory_->set_require_confirmation(true); |
| 9062 | crypto_client_stream_factory_.set_handshake_mode( |
| 9063 | MockCryptoClientStream::ZERO_RTT); |
| 9064 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9065 | kCachedIPAddress.ToString(), ""); |
| 9066 | |
| 9067 | // Set up the same address in the stale resolver cache. |
| 9068 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9069 | HostCache::Entry entry(OK, |
| 9070 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9071 | HostCache::Entry::SOURCE_DNS); |
| 9072 | base::TimeDelta zero; |
| 9073 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9074 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9075 | // Expire the cache |
| 9076 | cache->OnNetworkChange(); |
| 9077 | |
| 9078 | MockQuicData quic_data; |
| 9079 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9080 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9081 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9082 | |
| 9083 | QuicStreamRequest request(factory_.get()); |
| 9084 | EXPECT_EQ(ERR_IO_PENDING, |
| 9085 | request.Request( |
| 9086 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9087 | SocketTag(), |
| 9088 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9089 | failed_on_default_network_callback_, callback_.callback())); |
| 9090 | |
| 9091 | // Finish dns async, check we still need to wait for stale connection async. |
| 9092 | host_resolver_->ResolveAllPending(); |
| 9093 | base::RunLoop().RunUntilIdle(); |
| 9094 | EXPECT_FALSE(callback_.have_result()); |
| 9095 | |
| 9096 | // Finish stale connection async, and the stale connection should pass dns |
| 9097 | // validation. |
| 9098 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9099 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9100 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9101 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9102 | EXPECT_TRUE(stream.get()); |
| 9103 | |
| 9104 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9105 | EXPECT_EQ( |
| 9106 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9107 | kCachedIPAddress.ToString()); |
| 9108 | |
| 9109 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9110 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9111 | } |
| 9112 | |
| 9113 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9114 | // sync, but dns no match |
| 9115 | TEST_P(QuicStreamFactoryTest, |
| 9116 | ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { |
| 9117 | race_stale_dns_on_connection_ = true; |
| 9118 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9119 | Initialize(); |
| 9120 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9121 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9122 | |
| 9123 | // Set an address in resolver for asynchronous return. |
| 9124 | host_resolver_->set_ondemand_mode(true); |
| 9125 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9126 | kNonCachedIPAddress, ""); |
| 9127 | |
| 9128 | // Set up a different address in the stale resolver cache. |
| 9129 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9130 | HostCache::Entry entry(OK, |
| 9131 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9132 | HostCache::Entry::SOURCE_DNS); |
| 9133 | base::TimeDelta zero; |
| 9134 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9135 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9136 | // Expire the cache |
| 9137 | cache->OnNetworkChange(); |
| 9138 | |
| 9139 | // Socket for the stale connection which will invoke connection closure. |
| 9140 | MockQuicData quic_data; |
| 9141 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9142 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9143 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9144 | SYNCHRONOUS, |
| 9145 | client_maker_.MakeConnectionClosePacket( |
| 9146 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9147 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9148 | |
| 9149 | // Socket for the new connection. |
| 9150 | MockQuicData quic_data2; |
| 9151 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9152 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9153 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9154 | |
| 9155 | QuicStreamRequest request(factory_.get()); |
| 9156 | EXPECT_EQ(ERR_IO_PENDING, |
| 9157 | request.Request( |
| 9158 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9159 | SocketTag(), |
| 9160 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9161 | failed_on_default_network_callback_, callback_.callback())); |
| 9162 | |
| 9163 | // Check the stale connection is running. |
| 9164 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9165 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9166 | |
| 9167 | // Finish dns resolution and check the job has finished. |
| 9168 | host_resolver_->ResolveAllPending(); |
| 9169 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9170 | |
| 9171 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9172 | EXPECT_TRUE(stream.get()); |
| 9173 | |
| 9174 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9175 | |
| 9176 | EXPECT_EQ( |
| 9177 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9178 | kNonCachedIPAddress); |
| 9179 | |
| 9180 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9181 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9182 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9183 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9184 | } |
| 9185 | |
| 9186 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9187 | // async, finishes before dns, but no match |
| 9188 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { |
| 9189 | race_stale_dns_on_connection_ = true; |
| 9190 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9191 | Initialize(); |
| 9192 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9193 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9194 | |
| 9195 | // Set an address in resolver for asynchronous return. |
| 9196 | host_resolver_->set_ondemand_mode(true); |
| 9197 | factory_->set_require_confirmation(true); |
| 9198 | crypto_client_stream_factory_.set_handshake_mode( |
| 9199 | MockCryptoClientStream::ZERO_RTT); |
| 9200 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9201 | kNonCachedIPAddress, ""); |
| 9202 | |
| 9203 | // Set up a different address in the stale resolvercache. |
| 9204 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9205 | HostCache::Entry entry(OK, |
| 9206 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9207 | HostCache::Entry::SOURCE_DNS); |
| 9208 | base::TimeDelta zero; |
| 9209 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9210 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9211 | // Expire the cache |
| 9212 | cache->OnNetworkChange(); |
| 9213 | |
| 9214 | MockQuicData quic_data; |
| 9215 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9216 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9217 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9218 | SYNCHRONOUS, |
| 9219 | client_maker_.MakeConnectionClosePacket( |
| 9220 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9221 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9222 | |
| 9223 | MockQuicData quic_data2; |
| 9224 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9225 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9226 | |
| 9227 | QuicStreamRequest request(factory_.get()); |
| 9228 | EXPECT_EQ(ERR_IO_PENDING, |
| 9229 | request.Request( |
| 9230 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9231 | SocketTag(), |
| 9232 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9233 | failed_on_default_network_callback_, callback_.callback())); |
| 9234 | |
| 9235 | // Finish the stale connection. |
| 9236 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9237 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9238 | base::RunLoop().RunUntilIdle(); |
| 9239 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9240 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9241 | |
| 9242 | // Finish host resolution and check the job is done. |
| 9243 | host_resolver_->ResolveAllPending(); |
| 9244 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9245 | |
| 9246 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9247 | EXPECT_TRUE(stream.get()); |
| 9248 | |
| 9249 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9250 | EXPECT_EQ( |
| 9251 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9252 | kNonCachedIPAddress); |
| 9253 | |
| 9254 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9255 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9256 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9257 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9258 | } |
| 9259 | |
| 9260 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9261 | // async, dns finishes first, but no match |
| 9262 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { |
| 9263 | race_stale_dns_on_connection_ = true; |
| 9264 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9265 | Initialize(); |
| 9266 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9267 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9268 | |
| 9269 | // Set an address in resolver for asynchronous return. |
| 9270 | host_resolver_->set_ondemand_mode(true); |
| 9271 | factory_->set_require_confirmation(true); |
| 9272 | crypto_client_stream_factory_.set_handshake_mode( |
| 9273 | MockCryptoClientStream::ZERO_RTT); |
| 9274 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9275 | kNonCachedIPAddress, ""); |
| 9276 | |
| 9277 | // Set up a different address in the stale resolver cache. |
| 9278 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9279 | HostCache::Entry entry(OK, |
| 9280 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9281 | HostCache::Entry::SOURCE_DNS); |
| 9282 | base::TimeDelta zero; |
| 9283 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9284 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9285 | // Expire the cache |
| 9286 | cache->OnNetworkChange(); |
| 9287 | |
| 9288 | MockQuicData quic_data; |
| 9289 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9290 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9291 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9292 | SYNCHRONOUS, |
| 9293 | client_maker_.MakeConnectionClosePacket( |
| 9294 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9295 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9296 | |
| 9297 | MockQuicData quic_data2; |
| 9298 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9299 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 9300 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9301 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9302 | |
| 9303 | QuicStreamRequest request(factory_.get()); |
| 9304 | EXPECT_EQ(ERR_IO_PENDING, |
| 9305 | request.Request( |
| 9306 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9307 | SocketTag(), |
| 9308 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9309 | failed_on_default_network_callback_, callback_.callback())); |
| 9310 | // Finish dns resolution, but need to wait for stale connection. |
| 9311 | host_resolver_->ResolveAllPending(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9312 | base::RunLoop().RunUntilIdle(); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9313 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9314 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9315 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9316 | |
| 9317 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9318 | EXPECT_TRUE(stream.get()); |
| 9319 | |
| 9320 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9321 | EXPECT_EQ( |
| 9322 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9323 | kNonCachedIPAddress); |
| 9324 | |
| 9325 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9326 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9327 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9328 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9329 | } |
| 9330 | |
| 9331 | // With dns race experiment on, dns resolve returns error sync, same behavior |
| 9332 | // as experiment is not on |
| 9333 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { |
| 9334 | race_stale_dns_on_connection_ = true; |
| 9335 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9336 | Initialize(); |
| 9337 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9338 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9339 | |
| 9340 | // Set synchronous failure in resolver. |
| 9341 | host_resolver_->set_synchronous_mode(true); |
| 9342 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9343 | |
| 9344 | MockQuicData quic_data; |
| 9345 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9346 | QuicStreamRequest request(factory_.get()); |
| 9347 | |
| 9348 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 9349 | request.Request( |
| 9350 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9351 | SocketTag(), |
| 9352 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9353 | failed_on_default_network_callback_, callback_.callback())); |
| 9354 | } |
| 9355 | |
| 9356 | // With dns race experiment on, no cache available, dns resolve returns error |
| 9357 | // async |
| 9358 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { |
| 9359 | race_stale_dns_on_connection_ = true; |
| 9360 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9361 | Initialize(); |
| 9362 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9363 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9364 | |
| 9365 | // Set asynchronous failure in resolver. |
| 9366 | host_resolver_->set_ondemand_mode(true); |
| 9367 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9368 | |
| 9369 | MockQuicData quic_data; |
| 9370 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9371 | QuicStreamRequest request(factory_.get()); |
| 9372 | |
| 9373 | EXPECT_EQ(ERR_IO_PENDING, |
| 9374 | request.Request( |
| 9375 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9376 | SocketTag(), |
| 9377 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9378 | failed_on_default_network_callback_, callback_.callback())); |
| 9379 | |
| 9380 | // Resolve and expect result that shows the resolution error. |
| 9381 | host_resolver_->ResolveAllPending(); |
| 9382 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9383 | } |
| 9384 | |
| 9385 | // With dns race experiment on, dns resolve async, staled used and connects |
| 9386 | // sync, dns returns error and no connection is established. |
| 9387 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { |
| 9388 | race_stale_dns_on_connection_ = true; |
| 9389 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9390 | Initialize(); |
| 9391 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9392 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9393 | |
| 9394 | // Set asynchronous failure in resolver. |
| 9395 | host_resolver_->set_ondemand_mode(true); |
| 9396 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9397 | |
| 9398 | // Set up an address in the stale cache. |
| 9399 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9400 | HostCache::Entry entry(OK, |
| 9401 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9402 | HostCache::Entry::SOURCE_DNS); |
| 9403 | base::TimeDelta zero; |
| 9404 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9405 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9406 | // Expire the cache |
| 9407 | cache->OnNetworkChange(); |
| 9408 | |
| 9409 | // Socket for the stale connection which is supposed to disconnect. |
| 9410 | MockQuicData quic_data; |
| 9411 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9412 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9413 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9414 | SYNCHRONOUS, |
| 9415 | client_maker_.MakeConnectionClosePacket( |
| 9416 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9417 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9418 | |
| 9419 | QuicStreamRequest request(factory_.get()); |
| 9420 | EXPECT_EQ(ERR_IO_PENDING, |
| 9421 | request.Request( |
| 9422 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9423 | SocketTag(), |
| 9424 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9425 | failed_on_default_network_callback_, callback_.callback())); |
| 9426 | |
| 9427 | // Check that the stale connection is running. |
| 9428 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9429 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9430 | |
| 9431 | // Finish host resolution. |
| 9432 | host_resolver_->ResolveAllPending(); |
| 9433 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9434 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9435 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9436 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9437 | } |
| 9438 | |
| 9439 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9440 | // return error, then dns matches |
| 9441 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { |
| 9442 | race_stale_dns_on_connection_ = true; |
| 9443 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9444 | Initialize(); |
| 9445 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9446 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9447 | |
| 9448 | // Set an address in host resolver for asynchronous return. |
| 9449 | host_resolver_->set_ondemand_mode(true); |
| 9450 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9451 | kCachedIPAddress.ToString(), ""); |
| 9452 | |
| 9453 | // Set up the same address in the stale resolver cache. |
| 9454 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9455 | HostCache::Entry entry(OK, |
| 9456 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9457 | HostCache::Entry::SOURCE_DNS); |
| 9458 | base::TimeDelta zero; |
| 9459 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9460 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9461 | // Expire the cache |
| 9462 | cache->OnNetworkChange(); |
| 9463 | |
| 9464 | // Simulate synchronous connect failure. |
| 9465 | MockQuicData quic_data; |
| 9466 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9467 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9468 | |
| 9469 | MockQuicData quic_data2; |
| 9470 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9471 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9472 | |
| 9473 | QuicStreamRequest request(factory_.get()); |
| 9474 | EXPECT_EQ(ERR_IO_PENDING, |
| 9475 | request.Request( |
| 9476 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9477 | SocketTag(), |
| 9478 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9479 | failed_on_default_network_callback_, callback_.callback())); |
| 9480 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9481 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9482 | |
| 9483 | host_resolver_->ResolveAllPending(); |
| 9484 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9485 | } |
| 9486 | |
| 9487 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9488 | // returns error, dns no match, new connection is established |
| 9489 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { |
| 9490 | race_stale_dns_on_connection_ = true; |
| 9491 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9492 | Initialize(); |
| 9493 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9494 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9495 | |
| 9496 | // Set an address in host resolver. |
| 9497 | host_resolver_->set_ondemand_mode(true); |
| 9498 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9499 | kNonCachedIPAddress, ""); |
| 9500 | |
| 9501 | // Set up a different address in stale resolver cache. |
| 9502 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9503 | HostCache::Entry entry(OK, |
| 9504 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9505 | HostCache::Entry::SOURCE_DNS); |
| 9506 | base::TimeDelta zero; |
| 9507 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9508 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9509 | // Expire the cache |
| 9510 | cache->OnNetworkChange(); |
| 9511 | |
| 9512 | // Add failure for the stale connection. |
| 9513 | MockQuicData quic_data; |
| 9514 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9515 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9516 | |
| 9517 | MockQuicData quic_data2; |
| 9518 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9519 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9520 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9521 | |
| 9522 | QuicStreamRequest request(factory_.get()); |
| 9523 | EXPECT_EQ(ERR_IO_PENDING, |
| 9524 | request.Request( |
| 9525 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9526 | SocketTag(), |
| 9527 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9528 | failed_on_default_network_callback_, callback_.callback())); |
| 9529 | |
| 9530 | // Check that the stale connection fails. |
| 9531 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9532 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9533 | |
| 9534 | // Finish host resolution and check the job finishes ok. |
| 9535 | host_resolver_->ResolveAllPending(); |
| 9536 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9537 | |
| 9538 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9539 | EXPECT_TRUE(stream.get()); |
| 9540 | |
| 9541 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9542 | |
| 9543 | EXPECT_EQ( |
| 9544 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9545 | kNonCachedIPAddress); |
| 9546 | |
| 9547 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9548 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9549 | } |
| 9550 | |
| 9551 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9552 | // returns error, dns no match, new connection error |
| 9553 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { |
| 9554 | race_stale_dns_on_connection_ = true; |
| 9555 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9556 | Initialize(); |
| 9557 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9558 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9559 | |
| 9560 | // Set an address in host resolver asynchronously. |
| 9561 | host_resolver_->set_ondemand_mode(true); |
| 9562 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9563 | kNonCachedIPAddress, ""); |
| 9564 | |
| 9565 | // Set up a different address in the stale cache. |
| 9566 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9567 | HostCache::Entry entry(OK, |
| 9568 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9569 | HostCache::Entry::SOURCE_DNS); |
| 9570 | base::TimeDelta zero; |
| 9571 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9572 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9573 | // Expire the cache |
| 9574 | cache->OnNetworkChange(); |
| 9575 | |
| 9576 | // Add failure for stale connection. |
| 9577 | MockQuicData quic_data; |
| 9578 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9579 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9580 | |
| 9581 | // Add failure for resolved dns connection. |
| 9582 | MockQuicData quic_data2; |
| 9583 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 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 | |
| 9594 | // Check the stale connection fails. |
| 9595 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9596 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9597 | |
| 9598 | // Check the resolved dns connection fails. |
| 9599 | host_resolver_->ResolveAllPending(); |
| 9600 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9601 | } |
| 9602 | |
| 9603 | // With dns race experiment on, dns resolve async and stale connect async, dns |
| 9604 | // resolve returns error and then preconnect finishes |
| 9605 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { |
| 9606 | race_stale_dns_on_connection_ = true; |
| 9607 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9608 | Initialize(); |
| 9609 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9610 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9611 | |
| 9612 | // Add asynchronous failure in host resolver. |
| 9613 | host_resolver_->set_ondemand_mode(true); |
| 9614 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9615 | factory_->set_require_confirmation(true); |
| 9616 | crypto_client_stream_factory_.set_handshake_mode( |
| 9617 | MockCryptoClientStream::ZERO_RTT); |
| 9618 | |
| 9619 | // Set up an address in stale resolver cache. |
| 9620 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9621 | HostCache::Entry entry(OK, |
| 9622 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9623 | HostCache::Entry::SOURCE_DNS); |
| 9624 | base::TimeDelta zero; |
| 9625 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9626 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9627 | // Expire the cache |
| 9628 | cache->OnNetworkChange(); |
| 9629 | |
| 9630 | // Socket data for stale connection which is supposed to disconnect. |
| 9631 | MockQuicData quic_data; |
| 9632 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9633 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9634 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9635 | SYNCHRONOUS, |
| 9636 | client_maker_.MakeConnectionClosePacket( |
| 9637 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9638 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9639 | |
| 9640 | QuicStreamRequest request(factory_.get()); |
| 9641 | EXPECT_EQ(ERR_IO_PENDING, |
| 9642 | request.Request( |
| 9643 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9644 | SocketTag(), |
| 9645 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9646 | failed_on_default_network_callback_, callback_.callback())); |
| 9647 | |
| 9648 | // host resolution returned but stale connection hasn't finished yet. |
| 9649 | host_resolver_->ResolveAllPending(); |
| 9650 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9651 | |
| 9652 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9653 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9654 | } |
| 9655 | |
| 9656 | // With dns race experiment on, dns resolve async and stale connect async, dns |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9657 | // resolve returns error and then preconnect fails. |
| 9658 | TEST_P(QuicStreamFactoryTest, |
| 9659 | ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { |
| 9660 | race_stale_dns_on_connection_ = true; |
| 9661 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9662 | Initialize(); |
| 9663 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9664 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9665 | |
| 9666 | // Add asynchronous failure to host resolver. |
| 9667 | host_resolver_->set_ondemand_mode(true); |
| 9668 | factory_->set_require_confirmation(true); |
| 9669 | crypto_client_stream_factory_.set_handshake_mode( |
| 9670 | MockCryptoClientStream::ZERO_RTT); |
| 9671 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9672 | |
| 9673 | // Set up an address in stale resolver cache. |
| 9674 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9675 | HostCache::Entry entry(OK, |
| 9676 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9677 | HostCache::Entry::SOURCE_DNS); |
| 9678 | base::TimeDelta zero; |
| 9679 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9680 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9681 | // Expire the cache |
| 9682 | cache->OnNetworkChange(); |
| 9683 | |
| 9684 | MockQuicData quic_data; |
| 9685 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9686 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9687 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9688 | SYNCHRONOUS, |
| 9689 | client_maker_.MakeConnectionClosePacket( |
| 9690 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9691 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9692 | |
| 9693 | QuicStreamRequest request(factory_.get()); |
| 9694 | EXPECT_EQ(ERR_IO_PENDING, |
| 9695 | request.Request( |
| 9696 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9697 | SocketTag(), |
| 9698 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9699 | failed_on_default_network_callback_, callback_.callback())); |
| 9700 | |
| 9701 | // Host Resolution returns failure but stale connection hasn't finished. |
| 9702 | host_resolver_->ResolveAllPending(); |
| 9703 | |
| 9704 | // Check that the final error is on resolution failure. |
| 9705 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9706 | |
| 9707 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9708 | } |
| 9709 | |
| 9710 | // With dns race experiment on, test that host resolution callback behaves |
| 9711 | // normal as experiment is not on |
| 9712 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { |
| 9713 | race_stale_dns_on_connection_ = true; |
| 9714 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9715 | Initialize(); |
| 9716 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9717 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9718 | |
| 9719 | host_resolver_->set_ondemand_mode(true); |
| 9720 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9721 | kNonCachedIPAddress, ""); |
| 9722 | |
| 9723 | MockQuicData quic_data; |
| 9724 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9725 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9726 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9727 | |
| 9728 | QuicStreamRequest request(factory_.get()); |
| 9729 | EXPECT_EQ(ERR_IO_PENDING, |
| 9730 | request.Request( |
| 9731 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9732 | SocketTag(), |
| 9733 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9734 | failed_on_default_network_callback_, callback_.callback())); |
| 9735 | |
| 9736 | // Check that expect_on_host_resolution_ is properlly set. |
| 9737 | TestCompletionCallback host_resolution_callback; |
| 9738 | EXPECT_TRUE( |
| 9739 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9740 | base::RunLoop().RunUntilIdle(); |
| 9741 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9742 | |
| 9743 | host_resolver_->ResolveAllPending(); |
| 9744 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 9745 | |
| 9746 | // Check that expect_on_host_resolution_ is flipped back. |
| 9747 | EXPECT_FALSE( |
| 9748 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9749 | |
| 9750 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9751 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9752 | } |
| 9753 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9754 | // Test that QuicStreamRequests with similar and different tags results in |
| 9755 | // reused and unique QUIC streams using appropriately tagged sockets. |
| 9756 | TEST_P(QuicStreamFactoryTest, Tag) { |
| 9757 | MockTaggingClientSocketFactory* socket_factory = |
| 9758 | new MockTaggingClientSocketFactory(); |
| 9759 | socket_factory_.reset(socket_factory); |
| 9760 | Initialize(); |
| 9761 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9762 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9763 | |
| 9764 | // Prepare to establish two QUIC sessions. |
| 9765 | MockQuicData socket_data; |
| 9766 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9767 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9768 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9769 | MockQuicData socket_data2; |
| 9770 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9771 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9772 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9773 | |
| 9774 | #if defined(OS_ANDROID) |
| 9775 | SocketTag tag1(SocketTag::UNSET_UID, 0x12345678); |
| 9776 | SocketTag tag2(getuid(), 0x87654321); |
| 9777 | #else |
| 9778 | // On non-Android platforms we can only use the default constructor. |
| 9779 | SocketTag tag1, tag2; |
| 9780 | #endif |
| 9781 | |
| 9782 | // Request a stream with |tag1|. |
| 9783 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9784 | int rv = request1.Request( |
| 9785 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9786 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9787 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9788 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9789 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag1); |
| 9790 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9791 | ->tagged_before_data_transferred()); |
| 9792 | std::unique_ptr<QuicChromiumClientSession::Handle> stream1 = |
| 9793 | request1.ReleaseSessionHandle(); |
| 9794 | EXPECT_TRUE(stream1); |
| 9795 | EXPECT_TRUE(stream1->IsConnected()); |
| 9796 | |
| 9797 | // Request a stream with |tag1| and verify underlying session is reused. |
| 9798 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9799 | rv = request2.Request( |
| 9800 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9801 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9802 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9803 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9804 | std::unique_ptr<QuicChromiumClientSession::Handle> stream2 = |
| 9805 | request2.ReleaseSessionHandle(); |
| 9806 | EXPECT_TRUE(stream2); |
| 9807 | EXPECT_TRUE(stream2->IsConnected()); |
| 9808 | EXPECT_TRUE(stream2->SharesSameSession(*stream1)); |
| 9809 | |
| 9810 | // Request a stream with |tag2| and verify a new session is created. |
| 9811 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9812 | rv = request3.Request( |
| 9813 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag2, |
| 9814 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9815 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9816 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9817 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag2); |
| 9818 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9819 | ->tagged_before_data_transferred()); |
| 9820 | std::unique_ptr<QuicChromiumClientSession::Handle> stream3 = |
| 9821 | request3.ReleaseSessionHandle(); |
| 9822 | EXPECT_TRUE(stream3); |
| 9823 | EXPECT_TRUE(stream3->IsConnected()); |
| 9824 | #if defined(OS_ANDROID) |
| 9825 | EXPECT_FALSE(stream3->SharesSameSession(*stream1)); |
| 9826 | #else |
| 9827 | // Same tag should reuse session. |
| 9828 | EXPECT_TRUE(stream3->SharesSameSession(*stream1)); |
| 9829 | #endif |
| 9830 | } |
| 9831 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9832 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9833 | } // namespace net |